github.com/m3db/m3@v1.5.0/src/dbnode/integration/generate/types.go (about)

     1  // Copyright (c) 2018 Uber Technologies, Inc.
     2  //
     3  // Permission is hereby granted, free of charge, to any person obtaining a copy
     4  // of this software and associated documentation files (the "Software"), to deal
     5  // in the Software without restriction, including without limitation the rights
     6  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     7  // copies of the Software, and to permit persons to whom the Software is
     8  // furnished to do so, subject to the following conditions:
     9  //
    10  // The above copyright notice and this permission notice shall be included in
    11  // all copies or substantial portions of the Software.
    12  //
    13  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    15  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    16  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    17  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    18  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    19  // THE SOFTWARE.
    20  
    21  package generate
    22  
    23  import (
    24  	"os"
    25  	"time"
    26  
    27  	"github.com/m3db/m3/src/dbnode/encoding"
    28  	ns "github.com/m3db/m3/src/dbnode/namespace"
    29  	"github.com/m3db/m3/src/dbnode/sharding"
    30  	"github.com/m3db/m3/src/dbnode/ts"
    31  	"github.com/m3db/m3/src/x/clock"
    32  	"github.com/m3db/m3/src/x/ident"
    33  	xtime "github.com/m3db/m3/src/x/time"
    34  )
    35  
    36  // AnnotationGenerator generates the next annotation.
    37  type AnnotationGenerator interface {
    38  	Next() []byte
    39  }
    40  
    41  // BlockConfig represents the configuration to generate a SeriesBlock.
    42  type BlockConfig struct {
    43  	IDs       []string
    44  	Tags      ident.Tags
    45  	NumPoints int
    46  	Start     xtime.UnixNano
    47  	AnnGen    AnnotationGenerator
    48  }
    49  
    50  // UpdateBlockConfig is a function used o update BlockConfigs.
    51  type UpdateBlockConfig func([]BlockConfig)
    52  
    53  // TestValue is a test datapoint and an annotation.
    54  type TestValue struct {
    55  	ts.Datapoint
    56  	ts.Annotation
    57  }
    58  
    59  // Series represents a generated series of data.
    60  type Series struct {
    61  	ID   ident.ID
    62  	Tags ident.Tags
    63  	Data []TestValue
    64  }
    65  
    66  // SeriesDataPoint represents a single data point of a generated series of data.
    67  type SeriesDataPoint struct {
    68  	Value TestValue
    69  	ID    ident.ID
    70  }
    71  
    72  // SeriesDataPointsByTime are a sorted list of SeriesDataPoints.
    73  type SeriesDataPointsByTime []SeriesDataPoint
    74  
    75  // SeriesBlock is a collection of Series.
    76  type SeriesBlock []Series
    77  
    78  // SeriesBlocksByStart is a map of time -> SeriesBlock.
    79  type SeriesBlocksByStart map[xtime.UnixNano]SeriesBlock
    80  
    81  // Writer writes generated data to disk.
    82  type Writer interface {
    83  	// WriteData writes the data as data files.
    84  	WriteData(
    85  		nsCtx ns.Context,
    86  		shards sharding.ShardSet,
    87  		data SeriesBlocksByStart,
    88  		volume int,
    89  	) error
    90  
    91  	// WriteSnapshot writes the data as snapshot files.
    92  	WriteSnapshot(
    93  		nsCtx ns.Context,
    94  		shards sharding.ShardSet,
    95  		data SeriesBlocksByStart,
    96  		volume int,
    97  		snapshotInterval time.Duration,
    98  	) error
    99  
   100  	// WriteDataWithPredicate writes all data that passes the predicate test as data files.
   101  	WriteDataWithPredicate(
   102  		nsCtx ns.Context,
   103  		shards sharding.ShardSet,
   104  		data SeriesBlocksByStart,
   105  		volume int,
   106  		pred WriteDatapointPredicate,
   107  	) error
   108  
   109  	// WriteSnapshotWithPredicate writes all data that passes the predicate test as snapshot files.
   110  	WriteSnapshotWithPredicate(
   111  		nsCtx ns.Context,
   112  		shards sharding.ShardSet,
   113  		data SeriesBlocksByStart,
   114  		volume int,
   115  		pred WriteDatapointPredicate,
   116  		snapshotInterval time.Duration,
   117  	) error
   118  }
   119  
   120  // Options represent the parameters needed for the Writer.
   121  type Options interface {
   122  	// SetClockOptions sets the clock options.
   123  	SetClockOptions(value clock.Options) Options
   124  
   125  	// ClockOptions returns the clock options.
   126  	ClockOptions() clock.Options
   127  
   128  	// SetRetentionPeriod sets how long we intend to keep data in memory.
   129  	SetRetentionPeriod(value time.Duration) Options
   130  
   131  	// RetentionPeriod returns how long we intend to keep data in memory.
   132  	RetentionPeriod() time.Duration
   133  
   134  	// SetBlockSize sets the blockSize.
   135  	SetBlockSize(value time.Duration) Options
   136  
   137  	// BlockSize returns the blockSize.
   138  	BlockSize() time.Duration
   139  
   140  	// SetFilePathPrefix sets the file path prefix for sharded TSDB files.
   141  	SetFilePathPrefix(value string) Options
   142  
   143  	// FilePathPrefix returns the file path prefix for sharded TSDB files.
   144  	FilePathPrefix() string
   145  
   146  	// SetNewFileMode sets the new file mode.
   147  	SetNewFileMode(value os.FileMode) Options
   148  
   149  	// NewFileMode returns the new file mode.
   150  	NewFileMode() os.FileMode
   151  
   152  	// SetNewDirectoryMode sets the new directory mode.
   153  	SetNewDirectoryMode(value os.FileMode) Options
   154  
   155  	// NewDirectoryMode returns the new directory mode.
   156  	NewDirectoryMode() os.FileMode
   157  
   158  	// SetWriterBufferSize sets the buffer size for writing TSDB files.
   159  	SetWriterBufferSize(value int) Options
   160  
   161  	// WriterBufferSize returns the buffer size for writing TSDB files.
   162  	WriterBufferSize() int
   163  
   164  	// SetWriteEmptyShards sets whether writes are done even for empty start periods.
   165  	SetWriteEmptyShards(bool) Options
   166  
   167  	// WriteEmptyShards returns whether writes are done even for empty start periods.
   168  	WriteEmptyShards() bool
   169  
   170  	// SetWriteSnapshot sets whether writes are written as snapshot files.
   171  	SetWriteSnapshot(bool) Options
   172  
   173  	// WriteSnapshots returns whether writes are written as snapshot files.
   174  	WriteSnapshot() bool
   175  
   176  	// SetEncoderPool sets the contextPool.
   177  	SetEncoderPool(value encoding.EncoderPool) Options
   178  
   179  	// EncoderPool returns the contextPool.
   180  	EncoderPool() encoding.EncoderPool
   181  }
   182  
   183  // WriteDatapointPredicate returns a boolean indicating whether a datapoint should be written.
   184  type WriteDatapointPredicate func(dp TestValue) bool