tsm1

package
v1.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 28, 2018 License: MIT Imports: 47 Imported by: 0

Documentation

Overview

Package tsm1 provides a TSDB in the Time Structured Merge tree format.

Index

Constants

View Source
const (
	// CompactionTempExtension is the extension used for temporary files created during compaction.
	CompactionTempExtension = "tmp"

	// TSMFileExtension is the extension used for TSM files.
	TSMFileExtension = "tsm"
)
View Source
const (
	// BlockFloat64 designates a block encodes float64 values.
	BlockFloat64 = byte(0)

	// BlockInteger designates a block encodes int64 values.
	BlockInteger = byte(1)

	// BlockBoolean designates a block encodes boolean values.
	BlockBoolean = byte(2)

	// BlockString designates a block encodes string values.
	BlockString = byte(3)

	// BlockUnsigned designates a block encodes uint64 values.
	BlockUnsigned = byte(4)
)
View Source
const (
	// The extension used to describe temporary snapshot files.
	TmpTSMFileExtension = "tmp"

	// The extension used to describe corrupt snapshot files.
	BadTSMFileExtension = "bad"
)
View Source
const (
	// DefaultSegmentSize of 10MB is the size at which segment files will be rolled over.
	DefaultSegmentSize = 10 * 1024 * 1024

	// WALFileExtension is the file extension we expect for wal segments.
	WALFileExtension = "wal"

	// WALFilePrefix is the prefix on all wal segment files.
	WALFilePrefix = "_"
)
View Source
const (
	// MagicNumber is written as the first 4 bytes of a data file to
	// identify the file as a tsm1 formatted file
	MagicNumber uint32 = 0x16D116D1

	// Version indicates the version of the TSM file format.
	Version byte = 1
)

Variables

View Source
var (
	// ErrWALClosed is returned when attempting to write to a closed WAL file.
	ErrWALClosed = fmt.Errorf("WAL closed")

	// ErrWALCorrupt is returned when reading a corrupt WAL entry.
	ErrWALCorrupt = fmt.Errorf("corrupted WAL entry")
)
View Source
var (
	//ErrNoValues is returned when TSMWriter.WriteIndex is called and there are no values to write.
	ErrNoValues = fmt.Errorf("no values written")

	// ErrTSMClosed is returned when performing an operation against a closed TSM file.
	ErrTSMClosed = fmt.Errorf("tsm file closed")

	// ErrMaxKeyLengthExceeded is returned when attempting to write a key that is too long.
	ErrMaxKeyLengthExceeded = fmt.Errorf("max key length exceeded")

	// ErrMaxBlocksExceeded is returned when attempting to write a block past the allowed number.
	ErrMaxBlocksExceeded = fmt.Errorf("max blocks exceeded")
)
View Source
var ErrFileInUse = fmt.Errorf("file still in use")

ErrFileInUse is returned when attempting to remove or close a TSM file that is still being used.

View Source
var (
	// ErrSnapshotInProgress is returned if a snapshot is attempted while one is already running.
	ErrSnapshotInProgress = fmt.Errorf("snapshot in progress")
)

Functions

func BlockCount added in v0.10.0

func BlockCount(block []byte) int

BlockCount returns the number of timestamps encoded in block.

func BlockType added in v0.9.6

func BlockType(block []byte) (byte, error)

BlockType returns the type of value encoded in a block or an error if the block type is unknown.

func BlockTypeToInfluxQLDataType added in v1.5.0

func BlockTypeToInfluxQLDataType(typ byte) influxql.DataType

func CountTimestamps added in v0.10.0

func CountTimestamps(b []byte) int

func DefaultFormatFileName added in v1.6.0

func DefaultFormatFileName(generation, sequence int) string

DefaultFormatFileName is the default implementation to format TSM filenames.

func Digest added in v1.5.0

func Digest(dir string, w io.WriteCloser) error

Digest writes a digest of dir to w of a full shard dir.

func DigestWithOptions added in v1.5.0

func DigestWithOptions(dir string, opts DigestOptions, w io.WriteCloser) error

DigestWithOptions writes a digest of dir to w using options to filter by time and key range.

func ErrCacheMemorySizeLimitExceeded added in v1.1.0

func ErrCacheMemorySizeLimitExceeded(n, limit uint64) error

ErrCacheMemorySizeLimitExceeded returns an error indicating an operation could not be completed due to exceeding the cache-max-memory-size setting.

func MetricsGroupFromContext added in v1.5.0

func MetricsGroupFromContext(ctx context.Context) *metrics.Group

MetricsGroupFromContext returns the tsm1 metrics.Group associated with the context or nil if no group has been assigned.

func NewContextWithMetricsGroup added in v1.5.0

func NewContextWithMetricsGroup(ctx context.Context) context.Context

NewContextWithMetricsGroup creates a new context with a tsm1 metrics.Group for tracking various metrics when accessing TSM data.

func NewEngine

func NewEngine(id uint64, idx tsdb.Index, path string, walPath string, sfile *tsdb.SeriesFile, opt tsdb.EngineOptions) tsdb.Engine

NewEngine returns a new instance of Engine.

func NewIndirectIndex

func NewIndirectIndex() *indirectIndex

NewIndirectIndex returns a new indirect index.

func SeriesAndFieldFromCompositeKey added in v1.0.0

func SeriesAndFieldFromCompositeKey(key []byte) ([]byte, []byte)

SeriesAndFieldFromCompositeKey returns the series key and the field key extracted from the composite key.

func SeriesFieldKey

func SeriesFieldKey(seriesKey, field string) string

SeriesFieldKey combine a series key and field name for a unique string to be hashed to a numeric ID.

func SeriesFieldKeyBytes added in v1.4.0

func SeriesFieldKeyBytes(seriesKey, field string) []byte

func ZigZagDecode

func ZigZagDecode(v uint64) int64

ZigZagDecode converts a previously zigzag encoded uint64 back to a int64.

func ZigZagEncode

func ZigZagEncode(x int64) uint64

ZigZagEncode converts a int64 to a uint64 by zig zagging negative and positive values across even and odd numbers. Eg. [0,-1,1,-2] becomes [0, 1, 2, 3].

Types

type BatchDeleter added in v1.5.0

type BatchDeleter interface {
	DeleteRange(keys [][]byte, min, max int64) error
	Commit() error
	Rollback() error
}

type BatchDeleters added in v1.5.0

type BatchDeleters []BatchDeleter

func (BatchDeleters) Commit added in v1.5.0

func (a BatchDeleters) Commit() error

func (BatchDeleters) DeleteRange added in v1.5.0

func (a BatchDeleters) DeleteRange(keys [][]byte, min, max int64) error

func (BatchDeleters) Rollback added in v1.5.0

func (a BatchDeleters) Rollback() error

type BitReader added in v0.13.0

type BitReader struct {
	// contains filtered or unexported fields
}

BitReader reads bits from an io.Reader.

func NewBitReader added in v0.13.0

func NewBitReader(data []byte) *BitReader

NewBitReader returns a new instance of BitReader that reads from data.

func (*BitReader) CanReadBitFast added in v0.13.0

func (r *BitReader) CanReadBitFast() bool

CanReadBitFast returns true if calling ReadBitFast() is allowed. Fast bit reads are allowed when at least 2 values are in the buffer. This is because it is not required to refilled the buffer and the caller can inline the calls.

func (*BitReader) ReadBit added in v0.13.0

func (r *BitReader) ReadBit() (bool, error)

ReadBit returns the next bit from the underlying data.

func (*BitReader) ReadBitFast added in v0.13.0

func (r *BitReader) ReadBitFast() bool

ReadBitFast is an optimized bit read. IMPORTANT: Only allowed if CanReadFastBit() is true!

func (*BitReader) ReadBits added in v0.13.0

func (r *BitReader) ReadBits(nbits uint) (uint64, error)

ReadBits reads nbits from the underlying data into a uint64. nbits must be from 1 to 64, inclusive.

func (*BitReader) Reset added in v0.13.0

func (r *BitReader) Reset(data []byte)

Reset sets the underlying reader on b and reinitializes.

type BlockIterator added in v0.10.0

type BlockIterator struct {
	// contains filtered or unexported fields
}

BlockIterator allows iterating over each block in a TSM file in order. It provides raw access to the block bytes without decoding them.

func (*BlockIterator) Err added in v1.4.0

func (b *BlockIterator) Err() error

Err returns any errors encounter during iteration.

func (*BlockIterator) Next added in v0.10.0

func (b *BlockIterator) Next() bool

Next returns true if there are more blocks to iterate through.

func (*BlockIterator) PeekNext added in v0.10.0

func (b *BlockIterator) PeekNext() []byte

PeekNext returns the next key to be iterated or an empty string.

func (*BlockIterator) Read added in v0.10.0

func (b *BlockIterator) Read() (key []byte, minTime int64, maxTime int64, typ byte, checksum uint32, buf []byte, err error)

Read reads information about the next block to be iterated.

type BooleanDecoder added in v0.11.0

type BooleanDecoder struct {
	// contains filtered or unexported fields
}

BooleanDecoder decodes a series of booleans from an in-memory buffer.

func (*BooleanDecoder) Error added in v0.11.0

func (e *BooleanDecoder) Error() error

Error returns the error encountered during decoding, if one occurred.

func (*BooleanDecoder) Next added in v0.11.0

func (e *BooleanDecoder) Next() bool

Next returns whether there are any bits remaining in the decoder. It returns false if there was an error decoding. The error is available on the Error method.

func (*BooleanDecoder) Read added in v0.11.0

func (e *BooleanDecoder) Read() bool

Read returns the next bit from the decoder.

func (*BooleanDecoder) SetBytes added in v0.13.0

func (e *BooleanDecoder) SetBytes(b []byte)

SetBytes initializes the decoder with a new set of bytes to read from. This must be called before calling any other methods.

type BooleanEncoder added in v0.11.0

type BooleanEncoder struct {
	// contains filtered or unexported fields
}

BooleanEncoder encodes a series of booleans to an in-memory buffer.

func NewBooleanEncoder added in v0.11.0

func NewBooleanEncoder(sz int) BooleanEncoder

NewBooleanEncoder returns a new instance of BooleanEncoder.

func (*BooleanEncoder) Bytes added in v0.11.0

func (e *BooleanEncoder) Bytes() ([]byte, error)

Bytes returns a new byte slice containing the encoded booleans from previous calls to Write.

func (*BooleanEncoder) Flush added in v1.2.3

func (e *BooleanEncoder) Flush()

Flush is no-op

func (*BooleanEncoder) Reset added in v1.1.0

func (e *BooleanEncoder) Reset()

Reset sets the encoder to its initial state.

func (*BooleanEncoder) Write added in v0.11.0

func (e *BooleanEncoder) Write(b bool)

Write encodes b to the underlying buffer.

type BooleanValue added in v0.11.0

type BooleanValue struct {
	// contains filtered or unexported fields
}

BooleanValue represents a boolean value.

func DecodeBooleanBlock added in v0.11.0

func DecodeBooleanBlock(block []byte, a *[]BooleanValue) ([]BooleanValue, error)

DecodeBooleanBlock decodes the boolean block from the byte slice and appends the boolean values to a.

func (BooleanValue) Size added in v0.11.0

func (v BooleanValue) Size() int

Size returns the number of bytes necessary to represent the value and its timestamp.

func (BooleanValue) String added in v0.11.0

func (v BooleanValue) String() string

String returns the string representation of the value and its timestamp.

func (BooleanValue) UnixNano added in v0.11.0

func (v BooleanValue) UnixNano() int64

UnixNano returns the timestamp of the value in nanoseconds since unix epoch.

func (BooleanValue) Value added in v0.11.0

func (v BooleanValue) Value() interface{}

Value returns the underlying boolean value.

type BooleanValues added in v0.11.0

type BooleanValues []BooleanValue

BooleanValues represents a slice of Boolean values.

func (BooleanValues) Deduplicate added in v0.11.0

func (a BooleanValues) Deduplicate() BooleanValues

Deduplicate returns a new slice with any values that have the same timestamp removed. The Value that appears last in the slice is the one that is kept. The returned Values are sorted if necessary.

func (BooleanValues) Encode added in v1.2.3

func (a BooleanValues) Encode(buf []byte) ([]byte, error)

func (BooleanValues) Exclude added in v1.0.0

func (a BooleanValues) Exclude(min, max int64) BooleanValues

Exclude returns the subset of values not in [min, max]. The values must be deduplicated and sorted before calling Exclude or the results are undefined.

func (BooleanValues) FindRange added in v1.4.0

func (a BooleanValues) FindRange(min, max int64) (int, int)

FindRange returns the positions where min and max would be inserted into the array. If a[0].UnixNano() > max or a[len-1].UnixNano() < min then FindRange returns (-1, -1) indicating the array is outside the [min, max]. The values must be deduplicated and sorted before calling Exclude or the results are undefined.

func (BooleanValues) Include added in v1.0.0

func (a BooleanValues) Include(min, max int64) BooleanValues

Include returns the subset values between min and max inclusive. The values must be deduplicated and sorted before calling Exclude or the results are undefined.

func (BooleanValues) Len added in v0.11.0

func (a BooleanValues) Len() int

Sort methods

func (BooleanValues) Less added in v0.11.0

func (a BooleanValues) Less(i, j int) bool

func (BooleanValues) MaxTime added in v1.0.0

func (a BooleanValues) MaxTime() int64

func (BooleanValues) Merge added in v1.0.0

Merge overlays b to top of a. If two values conflict with the same timestamp, b is used. Both a and b must be sorted in ascending order.

func (BooleanValues) MinTime added in v1.0.0

func (a BooleanValues) MinTime() int64

func (BooleanValues) Size added in v1.0.0

func (a BooleanValues) Size() int

func (BooleanValues) Swap added in v0.11.0

func (a BooleanValues) Swap(i, j int)

type Cache added in v0.9.6

type Cache struct {
	// contains filtered or unexported fields
}

Cache maintains an in-memory store of Values for a set of keys.

func NewCache added in v0.9.6

func NewCache(maxSize uint64) *Cache

NewCache returns an instance of a cache which will use a maximum of maxSize bytes of memory. Only used for engine caches, never for snapshots.

func (*Cache) ApplyEntryFn added in v1.2.0

func (c *Cache) ApplyEntryFn(f func(key []byte, entry *entry) error) error

ApplyEntryFn applies the function f to each entry in the Cache. ApplyEntryFn calls f on each entry in turn, within the same goroutine. It is safe for use by multiple goroutines.

func (*Cache) ClearSnapshot added in v0.9.6

func (c *Cache) ClearSnapshot(success bool)

ClearSnapshot removes the snapshot cache from the list of flushing caches and adjusts the size.

func (*Cache) Count added in v1.4.0

func (c *Cache) Count() int

func (*Cache) Deduplicate added in v0.10.0

func (c *Cache) Deduplicate()

Deduplicate sorts the snapshot before returning it. The compactor and any queries coming in while it writes will need the values sorted.

func (*Cache) Delete added in v0.9.6

func (c *Cache) Delete(keys [][]byte)

Delete removes all values for the given keys from the cache.

func (*Cache) DeleteRange added in v0.13.0

func (c *Cache) DeleteRange(keys [][]byte, min, max int64)

DeleteRange removes the values for all keys containing points with timestamps between between min and max from the cache.

TODO(edd): Lock usage could possibly be optimised if necessary.

func (*Cache) Free added in v1.3.6

func (c *Cache) Free()

Free releases the underlying store and memory held by the Cache.

func (*Cache) Keys added in v0.9.6

func (c *Cache) Keys() [][]byte

Keys returns a sorted slice of all keys under management by the cache.

func (*Cache) LastWriteTime added in v1.6.0

func (c *Cache) LastWriteTime() time.Time

func (*Cache) MaxSize added in v0.9.6

func (c *Cache) MaxSize() uint64

MaxSize returns the maximum number of bytes the cache may consume.

func (*Cache) SetMaxSize added in v0.13.0

func (c *Cache) SetMaxSize(size uint64)

SetMaxSize updates the memory limit of the cache.

func (*Cache) Size added in v0.9.6

func (c *Cache) Size() uint64

Size returns the number of point-calcuated bytes the cache currently uses.

func (*Cache) Snapshot added in v0.9.6

func (c *Cache) Snapshot() (*Cache, error)

Snapshot takes a snapshot of the current cache, adds it to the slice of caches that are being flushed, and resets the current cache with new values.

func (*Cache) Split added in v1.4.0

func (c *Cache) Split(n int) []*Cache

func (*Cache) Statistics added in v1.0.0

func (c *Cache) Statistics(tags map[string]string) []models.Statistic

Statistics returns statistics for periodic monitoring.

func (*Cache) Type added in v1.6.0

func (c *Cache) Type(key []byte) (models.FieldType, error)

Type returns the series type for a key.

func (*Cache) UpdateAge added in v0.11.0

func (c *Cache) UpdateAge()

UpdateAge updates the age statistic based on the current time.

func (*Cache) UpdateCompactTime added in v0.11.0

func (c *Cache) UpdateCompactTime(d time.Duration)

UpdateCompactTime updates WAL compaction time statistic based on d.

func (*Cache) Values added in v0.9.6

func (c *Cache) Values(key []byte) Values

Values returns a copy of all values, deduped and sorted, for the given key.

func (*Cache) Write added in v0.9.6

func (c *Cache) Write(key []byte, values []Value) error

Write writes the set of values for the key to the cache. This function is goroutine-safe. It returns an error if the cache will exceed its max size by adding the new values.

func (*Cache) WriteMulti added in v0.9.6

func (c *Cache) WriteMulti(values map[string][]Value) error

WriteMulti writes the map of keys and associated values to the cache. This function is goroutine-safe. It returns an error if the cache will exceeded its max size by adding the new values. The write attempts to write as many values as possible. If one key fails, the others can still succeed and an error will be returned.

type CacheLoader added in v0.9.6

type CacheLoader struct {
	Logger *zap.Logger
	// contains filtered or unexported fields
}

CacheLoader processes a set of WAL segment files, and loads a cache with the data contained within those files. Processing of the supplied files take place in the order they exist in the files slice.

func NewCacheLoader added in v0.9.6

func NewCacheLoader(files []string) *CacheLoader

NewCacheLoader returns a new instance of a CacheLoader.

func (*CacheLoader) Load added in v0.9.6

func (cl *CacheLoader) Load(cache *Cache) error

Load returns a cache loaded with the data contained within the segment files. If, during reading of a segment file, corruption is encountered, that segment file is truncated up to and including the last valid byte, and processing continues with the next segment file.

func (*CacheLoader) WithLogger added in v1.2.0

func (cl *CacheLoader) WithLogger(log *zap.Logger)

WithLogger sets the logger on the CacheLoader.

type CacheStatistics added in v1.0.0

type CacheStatistics struct {
	MemSizeBytes        int64
	DiskSizeBytes       int64
	SnapshotCount       int64
	CacheAgeMs          int64
	CachedBytes         int64
	WALCompactionTimeMs int64
	WriteOK             int64
	WriteErr            int64
	WriteDropped        int64
}

CacheStatistics hold statistics related to the cache.

type CompactionGroup added in v0.10.0

type CompactionGroup []string

CompactionGroup represents a list of files eligible to be compacted together.

type CompactionPlanner added in v0.9.6

type CompactionPlanner interface {
	Plan(lastWrite time.Time) []CompactionGroup
	PlanLevel(level int) []CompactionGroup
	PlanOptimize() []CompactionGroup
	Release(group []CompactionGroup)
	FullyCompacted() bool

	// ForceFull causes the planner to return a full compaction plan the next
	// time Plan() is called if there are files that could be compacted.
	ForceFull()

	SetFileStore(fs *FileStore)
}

CompactionPlanner determines what TSM files and WAL segments to include in a given compaction run.

type Compactor added in v0.9.6

type Compactor struct {
	Dir  string
	Size int

	FileStore interface {
		NextGeneration() int
		TSMReader(path string) *TSMReader
	}

	// RateLimit is the limit for disk writes for all concurrent compactions.
	RateLimit limiter.Rate

	// Function used for generating TSM filenames during compaction.
	FormatFileName FormatFileNameFunc
	// contains filtered or unexported fields
}

Compactor merges multiple TSM files into new files or writes a Cache into 1 or more TSM files.

func NewCompactor added in v1.6.0

func NewCompactor() *Compactor

NewCompactor returns a new instance of Compactor.

func (*Compactor) Close added in v1.0.0

func (c *Compactor) Close()

Close disables the Compactor.

func (*Compactor) CompactFast added in v0.10.0

func (c *Compactor) CompactFast(tsmFiles []string) ([]string, error)

CompactFast writes multiple smaller TSM files into 1 or more larger files.

func (*Compactor) CompactFull added in v0.10.0

func (c *Compactor) CompactFull(tsmFiles []string) ([]string, error)

CompactFull writes multiple smaller TSM files into 1 or more larger files.

func (*Compactor) DisableCompactions added in v1.1.0

func (c *Compactor) DisableCompactions()

DisableSnapshots disables the compactor from performing compactions.

func (*Compactor) DisableSnapshots added in v1.1.0

func (c *Compactor) DisableSnapshots()

DisableSnapshots disables the compactor from performing snapshots.

func (*Compactor) EnableCompactions added in v1.1.0

func (c *Compactor) EnableCompactions()

EnableCompactions allows the compactor to perform compactions.

func (*Compactor) EnableSnapshots added in v1.1.0

func (c *Compactor) EnableSnapshots()

EnableSnapshots allows the compactor to perform snapshots.

func (*Compactor) Open added in v1.0.0

func (c *Compactor) Open()

Open initializes the Compactor.

func (*Compactor) WriteSnapshot added in v0.9.6

func (c *Compactor) WriteSnapshot(cache *Cache, formatFileName FormatFileNameFunc) ([]string, error)

WriteSnapshot writes a Cache snapshot to one or more new TSM files.

type DefaultPlanner added in v0.9.6

type DefaultPlanner struct {
	FileStore     fileStore
	ParseFileName ParseFileNameFunc
	// contains filtered or unexported fields
}

DefaultPlanner implements CompactionPlanner using a strategy to roll up multiple generations of TSM files into larger files in stages. It attempts to minimize the number of TSM files on disk while rolling up a bounder number of files.

func NewDefaultPlanner added in v1.3.0

func NewDefaultPlanner(fs fileStore, writeColdDuration time.Duration) *DefaultPlanner

func (*DefaultPlanner) ForceFull added in v1.5.0

func (c *DefaultPlanner) ForceFull()

ForceFull causes the planner to return a full compaction plan the next time a plan is requested. When ForceFull is called, level and optimize plans will not return plans until a full plan is requested and released.

func (*DefaultPlanner) FullyCompacted added in v1.3.0

func (c *DefaultPlanner) FullyCompacted() bool

FullyCompacted returns true if the shard is fully compacted.

func (*DefaultPlanner) Plan added in v0.9.6

func (c *DefaultPlanner) Plan(lastWrite time.Time) []CompactionGroup

Plan returns a set of TSM files to rewrite for level 4 or higher. The planning returns multiple groups if possible to allow compactions to run concurrently.

func (*DefaultPlanner) PlanLevel added in v0.10.0

func (c *DefaultPlanner) PlanLevel(level int) []CompactionGroup

PlanLevel returns a set of TSM files to rewrite for a specific level.

func (*DefaultPlanner) PlanOptimize added in v1.0.0

func (c *DefaultPlanner) PlanOptimize() []CompactionGroup

PlanOptimize returns all TSM files if they are in different generations in order to optimize the index across TSM files. Each returned compaction group can be compacted concurrently.

func (*DefaultPlanner) Release added in v1.3.0

func (c *DefaultPlanner) Release(groups []CompactionGroup)

Release removes the files reference in each compaction group allowing new plans to be able to use them.

func (*DefaultPlanner) SetFileStore added in v1.6.0

func (c *DefaultPlanner) SetFileStore(fs *FileStore)

type DeleteRangeWALEntry added in v0.13.0

type DeleteRangeWALEntry struct {
	Keys     [][]byte
	Min, Max int64
	// contains filtered or unexported fields
}

DeleteRangeWALEntry represents the deletion of multiple series.

func (*DeleteRangeWALEntry) Encode added in v0.13.0

func (w *DeleteRangeWALEntry) Encode(b []byte) ([]byte, error)

Encode converts the DeleteRangeWALEntry into a byte slice, appending to b.

func (*DeleteRangeWALEntry) MarshalBinary added in v0.13.0

func (w *DeleteRangeWALEntry) MarshalBinary() ([]byte, error)

MarshalBinary returns a binary representation of the entry in a new byte slice.

func (*DeleteRangeWALEntry) MarshalSize added in v1.3.0

func (w *DeleteRangeWALEntry) MarshalSize() int

func (*DeleteRangeWALEntry) Type added in v0.13.0

Type returns DeleteRangeWALEntryType.

func (*DeleteRangeWALEntry) UnmarshalBinary added in v0.13.0

func (w *DeleteRangeWALEntry) UnmarshalBinary(b []byte) error

UnmarshalBinary deserializes the byte slice into w.

type DeleteWALEntry added in v0.9.6

type DeleteWALEntry struct {
	Keys [][]byte
	// contains filtered or unexported fields
}

DeleteWALEntry represents the deletion of multiple series.

func (*DeleteWALEntry) Encode added in v0.9.6

func (w *DeleteWALEntry) Encode(dst []byte) ([]byte, error)

Encode converts the DeleteWALEntry into a byte slice, appending to dst.

func (*DeleteWALEntry) MarshalBinary added in v0.9.6

func (w *DeleteWALEntry) MarshalBinary() ([]byte, error)

MarshalBinary returns a binary representation of the entry in a new byte slice.

func (*DeleteWALEntry) MarshalSize added in v1.3.0

func (w *DeleteWALEntry) MarshalSize() int

func (*DeleteWALEntry) Type added in v0.9.6

func (w *DeleteWALEntry) Type() WalEntryType

Type returns DeleteWALEntryType.

func (*DeleteWALEntry) UnmarshalBinary added in v0.9.6

func (w *DeleteWALEntry) UnmarshalBinary(b []byte) error

UnmarshalBinary deserializes the byte slice into w.

type DigestOptions added in v1.5.0

type DigestOptions struct {
	MinTime, MaxTime int64
	MinKey, MaxKey   []byte
}

type DigestReader added in v1.5.0

type DigestReader struct {
	// contains filtered or unexported fields
}

func NewDigestReader added in v1.5.0

func NewDigestReader(r io.ReadCloser) (*DigestReader, error)

func (*DigestReader) Close added in v1.5.0

func (w *DigestReader) Close() error

func (*DigestReader) ReadTimeSpan added in v1.5.0

func (w *DigestReader) ReadTimeSpan() (string, *DigestTimeSpan, error)

type DigestTimeRange added in v1.5.0

type DigestTimeRange struct {
	Min, Max int64
	N        int
	CRC      uint32
}

type DigestTimeSpan added in v1.5.0

type DigestTimeSpan struct {
	Ranges []DigestTimeRange
}

func (*DigestTimeSpan) Add added in v1.5.0

func (t *DigestTimeSpan) Add(min, max int64, n int, crc uint32)

func (DigestTimeSpan) Len added in v1.5.0

func (a DigestTimeSpan) Len() int

func (DigestTimeSpan) Less added in v1.5.0

func (a DigestTimeSpan) Less(i, j int) bool

func (DigestTimeSpan) Swap added in v1.5.0

func (a DigestTimeSpan) Swap(i, j int)

type DigestWriter added in v1.5.0

type DigestWriter struct {
	F writeFlushCloser
	// contains filtered or unexported fields
}

DigestWriter allows for writing a digest of a shard. A digest is a condensed representation of the contents of a shard. It can be scoped to one or more series keys, ranges of times or sets of files.

func NewDigestWriter added in v1.5.0

func NewDigestWriter(w io.WriteCloser) (*DigestWriter, error)

func (*DigestWriter) Close added in v1.5.0

func (w *DigestWriter) Close() error

func (*DigestWriter) Flush added in v1.5.0

func (w *DigestWriter) Flush() error

func (*DigestWriter) WriteTimeSpan added in v1.5.0

func (w *DigestWriter) WriteTimeSpan(key string, t *DigestTimeSpan) error

type EmptyValue

type EmptyValue struct{}

EmptyValue is used when there is no appropriate other value.

func (EmptyValue) Size

func (e EmptyValue) Size() int

Size returns 0.

func (EmptyValue) String added in v0.9.6

func (e EmptyValue) String() string

String returns the empty string.

func (EmptyValue) UnixNano

func (e EmptyValue) UnixNano() int64

UnixNano returns tsdb.EOF.

func (EmptyValue) Value

func (e EmptyValue) Value() interface{}

Value returns nil.

type Engine

type Engine struct {
	WAL            *WAL
	Cache          *Cache
	Compactor      *Compactor
	CompactionPlan CompactionPlanner
	FileStore      *FileStore

	MaxPointsPerBlock int

	// CacheFlushMemorySizeThreshold specifies the minimum size threshold for
	// the cache when the engine should write a snapshot to a TSM file
	CacheFlushMemorySizeThreshold uint64

	// CacheFlushWriteColdDuration specifies the length of time after which if
	// no writes have been committed to the WAL, the engine will write
	// a snapshot of the cache to a TSM file
	CacheFlushWriteColdDuration time.Duration

	// WALEnabled determines whether writes to the WAL are enabled.  If this is false,
	// writes will only exist in the cache and can be lost if a snapshot has not occurred.
	WALEnabled bool

	// Invoked when creating a backup file "as new".
	GenerateFormatFileNameFunc func() FormatFileNameFunc
	// contains filtered or unexported fields
}

Engine represents a storage engine with compressed blocks.

func (*Engine) Backup added in v0.10.0

func (e *Engine) Backup(w io.Writer, basePath string, since time.Time) error

Backup writes a tar archive of any TSM files modified since the passed in time to the passed in writer. The basePath will be prepended to the names of the files in the archive. It will force a snapshot of the WAL first then perform the backup with a read lock against the file store. This means that new TSM files will not be able to be created in this shard while the backup is running. For shards that are still acively getting writes, this could cause the WAL to backup, increasing memory usage and evenutally rejecting writes.

func (*Engine) Close

func (e *Engine) Close() error

Close closes the engine. Subsequent calls to Close are a nop.

func (*Engine) CreateCursorIterator added in v1.6.0

func (e *Engine) CreateCursorIterator(ctx context.Context) (tsdb.CursorIterator, error)

func (*Engine) CreateIterator added in v0.11.0

func (e *Engine) CreateIterator(ctx context.Context, measurement string, opt query.IteratorOptions) (query.Iterator, error)

CreateIterator returns an iterator for the measurement based on opt.

func (*Engine) CreateSeriesIfNotExists added in v1.3.0

func (e *Engine) CreateSeriesIfNotExists(key, name []byte, tags models.Tags) error

func (*Engine) CreateSeriesListIfNotExists added in v1.3.0

func (e *Engine) CreateSeriesListIfNotExists(keys, names [][]byte, tagsSlice []models.Tags) error

func (*Engine) CreateSnapshot added in v1.0.0

func (e *Engine) CreateSnapshot() (string, error)

CreateSnapshot will create a temp directory that holds temporary hardlinks to the underylyng shard files.

func (*Engine) DeleteMeasurement

func (e *Engine) DeleteMeasurement(name []byte) error

DeleteMeasurement deletes a measurement and all related series.

func (*Engine) DeleteSeriesRange added in v0.13.0

func (e *Engine) DeleteSeriesRange(itr tsdb.SeriesIterator, min, max int64) error

DeleteSeriesRange removes the values between min and max (inclusive) from all series

func (*Engine) DeleteSeriesRangeWithPredicate added in v1.6.0

func (e *Engine) DeleteSeriesRangeWithPredicate(itr tsdb.SeriesIterator, predicate func(name []byte, tags models.Tags) (int64, int64, bool)) error

DeleteSeriesRangeWithPredicate removes the values between min and max (inclusive) from all series for which predicate() returns true. If predicate() is nil, then all values in range are removed.

func (*Engine) Digest added in v1.5.0

func (e *Engine) Digest() (io.ReadCloser, int64, error)

Digest returns a reader for the shard's digest.

func (*Engine) DiskSize added in v1.3.0

func (e *Engine) DiskSize() int64

DiskSize returns the total size in bytes of all TSM and WAL segments on disk.

func (*Engine) Export added in v1.5.0

func (e *Engine) Export(w io.Writer, basePath string, start time.Time, end time.Time) error

func (*Engine) ForEachMeasurementName added in v1.3.0

func (e *Engine) ForEachMeasurementName(fn func(name []byte) error) error

ForEachMeasurementName iterates over each measurement name in the engine.

func (*Engine) Free added in v1.4.0

func (e *Engine) Free() error

Free releases any resources held by the engine to free up memory or CPU.

func (*Engine) HasTagKey added in v1.3.0

func (e *Engine) HasTagKey(name, key []byte) (bool, error)

func (*Engine) Import added in v1.3.0

func (e *Engine) Import(r io.Reader, basePath string) error

Import reads a tar archive generated by Backup() and adds each file matching basePath as a new TSM file. This obtains a write lock so no operations can be performed while Importing. If the import is successful, a full compaction is scheduled.

func (*Engine) IsIdle added in v1.3.0

func (e *Engine) IsIdle() bool

IsIdle returns true if the cache is empty, there are no running compactions and the shard is fully compacted.

func (*Engine) IteratorCost added in v1.4.0

func (e *Engine) IteratorCost(measurement string, opt query.IteratorOptions) (query.IteratorCost, error)

IteratorCost produces the cost of an iterator.

func (*Engine) KeyCursor added in v0.10.0

func (e *Engine) KeyCursor(ctx context.Context, key []byte, t int64, ascending bool) *KeyCursor

KeyCursor returns a KeyCursor for the given key starting at time t.

func (*Engine) LastModified added in v1.2.0

func (e *Engine) LastModified() time.Time

LastModified returns the time when this shard was last modified.

func (*Engine) LoadMetadataIndex

func (e *Engine) LoadMetadataIndex(shardID uint64, index tsdb.Index) error

LoadMetadataIndex loads the shard metadata into memory.

Note, it not safe to call LoadMetadataIndex concurrently. LoadMetadataIndex should only be called when initialising a new Engine.

func (*Engine) MeasurementExists added in v1.3.0

func (e *Engine) MeasurementExists(name []byte) (bool, error)

func (*Engine) MeasurementFieldSet added in v1.5.0

func (e *Engine) MeasurementFieldSet() *tsdb.MeasurementFieldSet

MeasurementFieldSet returns the measurement field set.

func (*Engine) MeasurementFields added in v0.11.0

func (e *Engine) MeasurementFields(measurement []byte) *tsdb.MeasurementFields

MeasurementFields returns the measurement fields for a measurement.

func (*Engine) MeasurementNamesByRegex added in v1.3.0

func (e *Engine) MeasurementNamesByRegex(re *regexp.Regexp) ([][]byte, error)

func (*Engine) MeasurementTagKeysByExpr added in v1.3.0

func (e *Engine) MeasurementTagKeysByExpr(name []byte, expr influxql.Expr) (map[string]struct{}, error)

func (*Engine) MeasurementsSketches added in v1.3.0

func (e *Engine) MeasurementsSketches() (estimator.Sketch, estimator.Sketch, error)

MeasurementsSketches returns sketches that describe the cardinality of the measurements in this shard and measurements that were in this shard, but have been tombstoned.

func (*Engine) Open

func (e *Engine) Open() error

Open opens and initializes the engine.

func (*Engine) Path

func (e *Engine) Path() string

Path returns the path the engine was opened with.

func (*Engine) Restore added in v1.0.0

func (e *Engine) Restore(r io.Reader, basePath string) error

Restore reads a tar archive generated by Backup(). Only files that match basePath will be copied into the directory. This obtains a write lock so no operations can be performed while restoring.

func (*Engine) ScheduleFullCompaction added in v1.5.0

func (e *Engine) ScheduleFullCompaction() error

ScheduleFullCompaction will force the engine to fully compact all data stored. This will cancel and running compactions and snapshot any data in the cache to TSM files. This is an expensive operation.

func (*Engine) SeriesN added in v1.3.0

func (e *Engine) SeriesN() int64

SeriesN returns the unique number of series in the index.

func (*Engine) SeriesSketches added in v1.3.0

func (e *Engine) SeriesSketches() (estimator.Sketch, estimator.Sketch, error)

SeriesSketches returns sketches that describe the cardinality of the series in this shard and series that were in this shard, but have been tombstoned.

func (*Engine) SetCompactionsEnabled added in v1.0.0

func (e *Engine) SetCompactionsEnabled(enabled bool)

SetCompactionsEnabled enables compactions on the engine. When disabled all running compactions are aborted and new compactions stop running.

func (*Engine) SetEnabled added in v1.0.0

func (e *Engine) SetEnabled(enabled bool)

SetEnabled sets whether the engine is enabled.

func (*Engine) SetFieldName added in v1.3.0

func (e *Engine) SetFieldName(measurement []byte, name string)

func (*Engine) ShouldCompactCache added in v0.10.0

func (e *Engine) ShouldCompactCache(t time.Time) bool

ShouldCompactCache returns true if the Cache is over its flush threshold or if the passed in lastWriteTime is older than the write cold threshold.

func (*Engine) Statistics added in v1.0.0

func (e *Engine) Statistics(tags map[string]string) []models.Statistic

Statistics returns statistics for periodic monitoring.

func (*Engine) TagKeyCardinality added in v1.3.0

func (e *Engine) TagKeyCardinality(name, key []byte) int

func (*Engine) Type added in v1.6.0

func (e *Engine) Type(series []byte) (models.FieldType, error)

Type returns FieldType for a series. If the series does not exist, ErrUnkownFieldType is returned.

func (*Engine) WithLogger added in v1.2.0

func (e *Engine) WithLogger(log *zap.Logger)

WithLogger sets the logger for the engine.

func (*Engine) WritePoints

func (e *Engine) WritePoints(points []models.Point) error

WritePoints writes metadata and point data into the engine. It returns an error if new points are added to an existing key.

func (*Engine) WriteSnapshot added in v0.10.0

func (e *Engine) WriteSnapshot() error

WriteSnapshot will snapshot the cache and write a new TSM file with its contents, releasing the snapshot when done.

func (*Engine) WriteTo

func (e *Engine) WriteTo(w io.Writer) (n int64, err error)

WriteTo is not implemented.

type EngineStatistics added in v1.0.0

type EngineStatistics struct {
	CacheCompactions        int64 // Counter of cache compactions that have ever run.
	CacheCompactionsActive  int64 // Gauge of cache compactions currently running.
	CacheCompactionErrors   int64 // Counter of cache compactions that have failed due to error.
	CacheCompactionDuration int64 // Counter of number of wall nanoseconds spent in cache compactions.

	TSMCompactions        [3]int64 // Counter of TSM compactions (by level) that have ever run.
	TSMCompactionsActive  [3]int64 // Gauge of TSM compactions (by level) currently running.
	TSMCompactionErrors   [3]int64 // Counter of TSM compcations (by level) that have failed due to error.
	TSMCompactionDuration [3]int64 // Counter of number of wall nanoseconds spent in TSM compactions (by level).
	TSMCompactionsQueue   [3]int64 // Gauge of TSM compactions queues (by level).

	TSMOptimizeCompactions        int64 // Counter of optimize compactions that have ever run.
	TSMOptimizeCompactionsActive  int64 // Gauge of optimize compactions currently running.
	TSMOptimizeCompactionErrors   int64 // Counter of optimize compactions that have failed due to error.
	TSMOptimizeCompactionDuration int64 // Counter of number of wall nanoseconds spent in optimize compactions.
	TSMOptimizeCompactionsQueue   int64 // Gauge of optimize compactions queue.

	TSMFullCompactions        int64 // Counter of full compactions that have ever run.
	TSMFullCompactionsActive  int64 // Gauge of full compactions currently running.
	TSMFullCompactionErrors   int64 // Counter of full compactions that have failed due to error.
	TSMFullCompactionDuration int64 // Counter of number of wall nanoseconds spent in full compactions.
	TSMFullCompactionsQueue   int64 // Gauge of full compactions queue.
}

EngineStatistics maintains statistics for the engine.

type FileStat added in v0.9.6

type FileStat struct {
	Path             string
	HasTombstone     bool
	Size             uint32
	LastModified     int64
	MinTime, MaxTime int64
	MinKey, MaxKey   []byte
}

FileStat holds information about a TSM file on disk.

func (FileStat) ContainsKey added in v0.9.6

func (f FileStat) ContainsKey(key []byte) bool

ContainsKey returns true if the min and max keys of the file overlap the arguments min and max.

func (FileStat) OverlapsKeyRange added in v0.9.6

func (f FileStat) OverlapsKeyRange(min, max []byte) bool

OverlapsKeyRange returns true if the min and max keys of the file overlap the arguments min and max.

func (FileStat) OverlapsTimeRange added in v0.9.6

func (f FileStat) OverlapsTimeRange(min, max int64) bool

OverlapsTimeRange returns true if the time range of the file intersect min and max.

type FileStore added in v0.9.6

type FileStore struct {
	// contains filtered or unexported fields
}

FileStore is an abstraction around multiple TSM files.

func NewFileStore added in v0.9.6

func NewFileStore(dir string) *FileStore

NewFileStore returns a new instance of FileStore based on the given directory.

func (*FileStore) Apply added in v1.5.0

func (f *FileStore) Apply(fn func(r TSMFile) error) error

func (*FileStore) BlockCount added in v0.10.0

func (f *FileStore) BlockCount(path string, idx int) int

BlockCount returns number of values stored in the block at location idx in the file at path. If path does not match any file in the store, 0 is returned. If idx is out of range for the number of blocks in the file, 0 is returned.

func (*FileStore) Close added in v0.9.6

func (f *FileStore) Close() error

Close closes the file store.

func (*FileStore) Cost added in v1.4.0

func (f *FileStore) Cost(key []byte, min, max int64) query.IteratorCost

func (*FileStore) Count added in v0.9.6

func (f *FileStore) Count() int

Count returns the number of TSM files currently loaded.

func (*FileStore) CreateSnapshot added in v1.0.0

func (f *FileStore) CreateSnapshot() (string, error)

CreateSnapshot creates hardlinks for all tsm and tombstone files in the path provided.

func (*FileStore) CurrentGeneration added in v0.9.6

func (f *FileStore) CurrentGeneration() int

CurrentGeneration returns the current generation of the TSM files.

func (*FileStore) Delete added in v0.9.6

func (f *FileStore) Delete(keys [][]byte) error

Delete removes the keys from the set of keys available in this file.

func (*FileStore) DeleteRange added in v0.13.0

func (f *FileStore) DeleteRange(keys [][]byte, min, max int64) error

DeleteRange removes the values for keys between timestamps min and max. This should only be used with smaller batches of series keys.

func (*FileStore) DiskSizeBytes added in v1.3.0

func (f *FileStore) DiskSizeBytes() int64

func (*FileStore) Files added in v0.11.0

func (f *FileStore) Files() []TSMFile

Files returns the slice of TSM files currently loaded. This is only used for tests, and the files aren't guaranteed to stay valid in the presense of compactions.

func (*FileStore) Free added in v1.4.0

func (f *FileStore) Free() error

Free releases any resources held by the FileStore. The resources will be re-acquired if necessary if they are needed after freeing them.

func (*FileStore) KeyCursor added in v0.9.6

func (f *FileStore) KeyCursor(ctx context.Context, key []byte, t int64, ascending bool) *KeyCursor

KeyCursor returns a KeyCursor for key and t across the files in the FileStore.

func (*FileStore) Keys added in v0.9.6

func (f *FileStore) Keys() map[string]byte

Keys returns all keys and types for all files in the file store.

func (*FileStore) LastModified added in v0.9.6

func (f *FileStore) LastModified() time.Time

LastModified returns the last time the file store was updated with new TSM files or a delete.

func (*FileStore) NextGeneration added in v0.9.6

func (f *FileStore) NextGeneration() int

NextGeneration increments the max file ID and returns the new value.

func (*FileStore) Open added in v0.9.6

func (f *FileStore) Open() error

Open loads all the TSM files in the configured directory.

func (*FileStore) Read added in v0.9.6

func (f *FileStore) Read(key []byte, t int64) ([]Value, error)

Read returns the slice of values for the given key and the given timestamp, if any file matches those constraints.

func (*FileStore) Replace added in v0.9.6

func (f *FileStore) Replace(oldFiles, newFiles []string) error

Replace replaces oldFiles with newFiles.

func (*FileStore) ReplaceWithCallback added in v1.3.4

func (f *FileStore) ReplaceWithCallback(oldFiles, newFiles []string, updatedFn func(r []TSMFile)) error

ReplaceWithCallback replaces oldFiles with newFiles and calls updatedFn with the files to be added the FileStore.

func (*FileStore) Statistics added in v1.0.0

func (f *FileStore) Statistics(tags map[string]string) []models.Statistic

Statistics returns statistics for periodic monitoring.

func (*FileStore) Stats added in v0.9.6

func (f *FileStore) Stats() []FileStat

Stats returns the stats of the underlying files, preferring the cached version if it is still valid.

func (*FileStore) TSMReader added in v1.4.0

func (f *FileStore) TSMReader(path string) *TSMReader

Reader returns a TSMReader for path if one is currently managed by the FileStore. Otherwise it returns nil. If it returns a file, you must call Unref on it when you are done, and never use it after that.

func (*FileStore) Type added in v0.9.6

func (f *FileStore) Type(key []byte) (byte, error)

Type returns the type of values store at the block for key.

func (*FileStore) WalkKeys added in v0.12.0

func (f *FileStore) WalkKeys(seek []byte, fn func(key []byte, typ byte) error) error

WalkKeys calls fn for every key in every TSM file known to the FileStore. If the key exists in multiple files, it will be invoked for each file.

func (*FileStore) WithLogger added in v1.2.0

func (f *FileStore) WithLogger(log *zap.Logger)

WithLogger sets the logger on the file store.

func (*FileStore) WithObserver added in v1.6.0

func (f *FileStore) WithObserver(obs tsdb.FileStoreObserver)

WithObserver sets the observer for the file store.

type FileStoreStatistics added in v1.0.0

type FileStoreStatistics struct {
	DiskBytes int64
	FileCount int64
}

FileStoreStatistics keeps statistics about the file store.

type FloatDecoder

type FloatDecoder struct {
	// contains filtered or unexported fields
}

FloatDecoder decodes a byte slice into multiple float64 values.

func (*FloatDecoder) Error

func (it *FloatDecoder) Error() error

Error returns the current decoding error.

func (*FloatDecoder) Next

func (it *FloatDecoder) Next() bool

Next returns true if there are remaining values to read.

func (*FloatDecoder) SetBytes added in v0.13.0

func (it *FloatDecoder) SetBytes(b []byte) error

SetBytes initializes the decoder with b. Must call before calling Next().

func (*FloatDecoder) Values

func (it *FloatDecoder) Values() float64

Values returns the current float64 value.

type FloatEncoder

type FloatEncoder struct {
	// contains filtered or unexported fields
}

FloatEncoder encodes multiple float64s into a byte slice.

func NewFloatEncoder

func NewFloatEncoder() *FloatEncoder

NewFloatEncoder returns a new FloatEncoder.

func (*FloatEncoder) Bytes

func (s *FloatEncoder) Bytes() ([]byte, error)

Bytes returns a copy of the underlying byte buffer used in the encoder.

func (*FloatEncoder) Flush added in v1.2.3

func (s *FloatEncoder) Flush()

Flush indicates there are no more values to encode.

func (*FloatEncoder) Reset added in v1.1.0

func (s *FloatEncoder) Reset()

Reset sets the encoder back to its initial state.

func (*FloatEncoder) Write added in v1.2.3

func (s *FloatEncoder) Write(v float64)

Write encodes v to the underlying buffer.

type FloatValue

type FloatValue struct {
	// contains filtered or unexported fields
}

FloatValue represents a float64 value.

func DecodeFloatBlock added in v0.9.6

func DecodeFloatBlock(block []byte, a *[]FloatValue) ([]FloatValue, error)

DecodeFloatBlock decodes the float block from the byte slice and appends the float values to a.

func (FloatValue) Size

func (v FloatValue) Size() int

Size returns the number of bytes necessary to represent the value and its timestamp.

func (FloatValue) String added in v0.9.6

func (v FloatValue) String() string

String returns the string representation of the value and its timestamp.

func (FloatValue) UnixNano

func (v FloatValue) UnixNano() int64

UnixNano returns the timestamp of the value.

func (FloatValue) Value

func (v FloatValue) Value() interface{}

Value returns the underlying float64 value.

type FloatValues added in v0.11.0

type FloatValues []FloatValue

FloatValues represents a slice of Float values.

func (FloatValues) Deduplicate added in v0.11.0

func (a FloatValues) Deduplicate() FloatValues

Deduplicate returns a new slice with any values that have the same timestamp removed. The Value that appears last in the slice is the one that is kept. The returned Values are sorted if necessary.

func (FloatValues) Encode added in v1.2.3

func (a FloatValues) Encode(buf []byte) ([]byte, error)

func (FloatValues) Exclude added in v1.0.0

func (a FloatValues) Exclude(min, max int64) FloatValues

Exclude returns the subset of values not in [min, max]. The values must be deduplicated and sorted before calling Exclude or the results are undefined.

func (FloatValues) FindRange added in v1.4.0

func (a FloatValues) FindRange(min, max int64) (int, int)

FindRange returns the positions where min and max would be inserted into the array. If a[0].UnixNano() > max or a[len-1].UnixNano() < min then FindRange returns (-1, -1) indicating the array is outside the [min, max]. The values must be deduplicated and sorted before calling Exclude or the results are undefined.

func (FloatValues) Include added in v1.0.0

func (a FloatValues) Include(min, max int64) FloatValues

Include returns the subset values between min and max inclusive. The values must be deduplicated and sorted before calling Exclude or the results are undefined.

func (FloatValues) Len added in v0.11.0

func (a FloatValues) Len() int

Sort methods

func (FloatValues) Less added in v0.11.0

func (a FloatValues) Less(i, j int) bool

func (FloatValues) MaxTime added in v1.0.0

func (a FloatValues) MaxTime() int64

func (FloatValues) Merge added in v1.0.0

func (a FloatValues) Merge(b FloatValues) FloatValues

Merge overlays b to top of a. If two values conflict with the same timestamp, b is used. Both a and b must be sorted in ascending order.

func (FloatValues) MinTime added in v1.0.0

func (a FloatValues) MinTime() int64

func (FloatValues) Size added in v1.0.0

func (a FloatValues) Size() int

func (FloatValues) Swap added in v0.11.0

func (a FloatValues) Swap(i, j int)

type FormatFileNameFunc added in v1.6.0

type FormatFileNameFunc func(generation, sequence int) string

FormatFileNameFunc is executed when generating a new TSM filename. Source filenames are provided via src.

type IndexEntry

type IndexEntry struct {
	// The min and max time of all points stored in the block.
	MinTime, MaxTime int64

	// The absolute position in the file where this block is located.
	Offset int64

	// The size in bytes of the block in the file.
	Size uint32
}

IndexEntry is the index information for a given block in a TSM file.

func (*IndexEntry) AppendTo added in v0.11.0

func (e *IndexEntry) AppendTo(b []byte) []byte

AppendTo writes a binary-encoded version of IndexEntry to b, allocating and returning a new slice, if necessary.

func (*IndexEntry) Contains

func (e *IndexEntry) Contains(t int64) bool

Contains returns true if this IndexEntry may contain values for the given time. The min and max times are inclusive.

func (*IndexEntry) OverlapsTimeRange added in v0.9.6

func (e *IndexEntry) OverlapsTimeRange(min, max int64) bool

OverlapsTimeRange returns true if the given time ranges are completely within the entry's time bounds.

func (*IndexEntry) String added in v0.9.6

func (e *IndexEntry) String() string

String returns a string representation of the entry.

func (*IndexEntry) UnmarshalBinary

func (e *IndexEntry) UnmarshalBinary(b []byte) error

UnmarshalBinary decodes an IndexEntry from a byte slice.

type IndexWriter

type IndexWriter interface {
	// Add records a new block entry for a key in the index.
	Add(key []byte, blockType byte, minTime, maxTime int64, offset int64, size uint32)

	// Entries returns all index entries for a key.
	Entries(key []byte) []IndexEntry

	// KeyCount returns the count of unique keys in the index.
	KeyCount() int

	// Size returns the size of a the current index in bytes.
	Size() uint32

	// MarshalBinary returns a byte slice encoded version of the index.
	MarshalBinary() ([]byte, error)

	// WriteTo writes the index contents to a writer.
	WriteTo(w io.Writer) (int64, error)

	Close() error

	Remove() error
}

IndexWriter writes a TSMIndex.

func NewDiskIndexWriter added in v1.4.0

func NewDiskIndexWriter(f *os.File) IndexWriter

NewIndexWriter returns a new IndexWriter.

func NewIndexWriter added in v0.13.0

func NewIndexWriter() IndexWriter

NewIndexWriter returns a new IndexWriter.

type IntegerDecoder added in v0.11.0

type IntegerDecoder struct {
	// contains filtered or unexported fields
}

IntegerDecoder decodes a byte slice into int64s.

func (*IntegerDecoder) Error added in v0.11.0

func (d *IntegerDecoder) Error() error

Error returns the last error encountered by the decoder.

func (*IntegerDecoder) Next added in v0.11.0

func (d *IntegerDecoder) Next() bool

Next returns true if there are any values remaining to be decoded.

func (*IntegerDecoder) Read added in v0.11.0

func (d *IntegerDecoder) Read() int64

Read returns the next value from the decoder.

func (*IntegerDecoder) SetBytes added in v0.12.0

func (d *IntegerDecoder) SetBytes(b []byte)

SetBytes sets the underlying byte slice of the decoder.

type IntegerEncoder added in v0.11.0

type IntegerEncoder struct {
	// contains filtered or unexported fields
}

IntegerEncoder encodes int64s into byte slices.

func NewIntegerEncoder added in v0.11.0

func NewIntegerEncoder(sz int) IntegerEncoder

NewIntegerEncoder returns a new integer encoder with an initial buffer of values sized at sz.

func (*IntegerEncoder) Bytes added in v0.11.0

func (e *IntegerEncoder) Bytes() ([]byte, error)

Bytes returns a copy of the underlying buffer.

func (*IntegerEncoder) Flush added in v1.2.3

func (e *IntegerEncoder) Flush()

Flush is no-op

func (*IntegerEncoder) Reset added in v1.1.0

func (e *IntegerEncoder) Reset()

Reset sets the encoder back to its initial state.

func (*IntegerEncoder) Write added in v0.11.0

func (e *IntegerEncoder) Write(v int64)

Write encodes v to the underlying buffers.

type IntegerValue added in v0.11.0

type IntegerValue struct {
	// contains filtered or unexported fields
}

IntegerValue represents an int64 value.

func DecodeIntegerBlock added in v0.11.0

func DecodeIntegerBlock(block []byte, a *[]IntegerValue) ([]IntegerValue, error)

DecodeIntegerBlock decodes the integer block from the byte slice and appends the integer values to a.

func (IntegerValue) Size added in v0.11.0

func (v IntegerValue) Size() int

Size returns the number of bytes necessary to represent the value and its timestamp.

func (IntegerValue) String added in v0.11.0

func (v IntegerValue) String() string

String returns the string representation of the value and its timestamp.

func (IntegerValue) UnixNano added in v0.11.0

func (v IntegerValue) UnixNano() int64

UnixNano returns the timestamp of the value.

func (IntegerValue) Value added in v0.11.0

func (v IntegerValue) Value() interface{}

Value returns the underlying int64 value.

type IntegerValues added in v0.11.0

type IntegerValues []IntegerValue

IntegerValues represents a slice of Integer values.

func (IntegerValues) Deduplicate added in v0.11.0

func (a IntegerValues) Deduplicate() IntegerValues

Deduplicate returns a new slice with any values that have the same timestamp removed. The Value that appears last in the slice is the one that is kept. The returned Values are sorted if necessary.

func (IntegerValues) Encode added in v1.2.3

func (a IntegerValues) Encode(buf []byte) ([]byte, error)

func (IntegerValues) Exclude added in v1.0.0

func (a IntegerValues) Exclude(min, max int64) IntegerValues

Exclude returns the subset of values not in [min, max]. The values must be deduplicated and sorted before calling Exclude or the results are undefined.

func (IntegerValues) FindRange added in v1.4.0

func (a IntegerValues) FindRange(min, max int64) (int, int)

FindRange returns the positions where min and max would be inserted into the array. If a[0].UnixNano() > max or a[len-1].UnixNano() < min then FindRange returns (-1, -1) indicating the array is outside the [min, max]. The values must be deduplicated and sorted before calling Exclude or the results are undefined.

func (IntegerValues) Include added in v1.0.0

func (a IntegerValues) Include(min, max int64) IntegerValues

Include returns the subset values between min and max inclusive. The values must be deduplicated and sorted before calling Exclude or the results are undefined.

func (IntegerValues) Len added in v0.11.0

func (a IntegerValues) Len() int

Sort methods

func (IntegerValues) Less added in v0.11.0

func (a IntegerValues) Less(i, j int) bool

func (IntegerValues) MaxTime added in v1.0.0

func (a IntegerValues) MaxTime() int64

func (IntegerValues) Merge added in v1.0.0

Merge overlays b to top of a. If two values conflict with the same timestamp, b is used. Both a and b must be sorted in ascending order.

func (IntegerValues) MinTime added in v1.0.0

func (a IntegerValues) MinTime() int64

func (IntegerValues) Size added in v1.0.0

func (a IntegerValues) Size() int

func (IntegerValues) Swap added in v0.11.0

func (a IntegerValues) Swap(i, j int)

type KeyCursor added in v0.9.6

type KeyCursor struct {
	// contains filtered or unexported fields
}

KeyCursor allows iteration through keys in a set of files within a FileStore.

func (*KeyCursor) Close added in v0.10.0

func (c *KeyCursor) Close()

Close removes all references on the cursor.

func (*KeyCursor) Next added in v0.9.6

func (c *KeyCursor) Next()

Next moves the cursor to the next position. Data should be read by the ReadBlock functions.

func (*KeyCursor) ReadBooleanBlock added in v0.11.0

func (c *KeyCursor) ReadBooleanBlock(buf *[]BooleanValue) ([]BooleanValue, error)

ReadBooleanBlock reads the next block as a set of boolean values.

func (*KeyCursor) ReadFloatBlock added in v0.11.0

func (c *KeyCursor) ReadFloatBlock(buf *[]FloatValue) ([]FloatValue, error)

ReadFloatBlock reads the next block as a set of float values.

func (*KeyCursor) ReadIntegerBlock added in v0.11.0

func (c *KeyCursor) ReadIntegerBlock(buf *[]IntegerValue) ([]IntegerValue, error)

ReadIntegerBlock reads the next block as a set of integer values.

func (*KeyCursor) ReadStringBlock added in v0.11.0

func (c *KeyCursor) ReadStringBlock(buf *[]StringValue) ([]StringValue, error)

ReadStringBlock reads the next block as a set of string values.

func (*KeyCursor) ReadUnsignedBlock added in v1.4.0

func (c *KeyCursor) ReadUnsignedBlock(buf *[]UnsignedValue) ([]UnsignedValue, error)

ReadUnsignedBlock reads the next block as a set of unsigned values.

type KeyIterator added in v0.9.6

type KeyIterator interface {
	// Next returns true if there are any values remaining in the iterator.
	Next() bool

	// Read returns the key, time range, and raw data for the next block,
	// or any error that occurred.
	Read() (key []byte, minTime int64, maxTime int64, data []byte, err error)

	// Close closes the iterator.
	Close() error

	// Err returns any errors encountered during iteration.
	Err() error

	// EstimatedIndexSize returns the estimated size of the index that would
	// be required to store all the series and entries in the KeyIterator.
	EstimatedIndexSize() int
}

KeyIterator allows iteration over set of keys and values in sorted order.

func NewCacheKeyIterator added in v0.9.6

func NewCacheKeyIterator(cache *Cache, size int, interrupt chan struct{}) KeyIterator

NewCacheKeyIterator returns a new KeyIterator from a Cache.

func NewTSMKeyIterator added in v0.9.6

func NewTSMKeyIterator(size int, fast bool, interrupt chan struct{}, readers ...*TSMReader) (KeyIterator, error)

NewTSMKeyIterator returns a new TSM key iterator from readers. size indicates the maximum number of values to encode in a single block.

type ParseFileNameFunc added in v1.6.0

type ParseFileNameFunc func(name string) (generation, sequence int, err error)

ParseFileNameFunc is executed when parsing a TSM filename into generation & sequence.

var ParseFileName ParseFileNameFunc = func(name string) (int, int, error) {
	base := filepath.Base(name)
	idx := strings.Index(base, ".")
	if idx == -1 {
		return 0, 0, fmt.Errorf("file %s is named incorrectly", name)
	}

	id := base[:idx]

	idx = strings.Index(id, "-")
	if idx == -1 {
		return 0, 0, fmt.Errorf("file %s is named incorrectly", name)
	}

	generation, err := strconv.ParseUint(id[:idx], 10, 32)
	if err != nil {
		return 0, 0, fmt.Errorf("file %s is named incorrectly", name)
	}

	sequence, err := strconv.ParseUint(id[idx+1:], 10, 32)
	if err != nil {
		return 0, 0, fmt.Errorf("file %s is named incorrectly", name)
	}

	return int(generation), int(sequence), nil
}

ParseFileName is used to parse the filenames of TSM files.

type StringDecoder

type StringDecoder struct {
	// contains filtered or unexported fields
}

StringDecoder decodes a byte slice into strings.

func (*StringDecoder) Error

func (e *StringDecoder) Error() error

Error returns the last error encountered by the decoder.

func (*StringDecoder) Next

func (e *StringDecoder) Next() bool

Next returns true if there are any values remaining to be decoded.

func (*StringDecoder) Read

func (e *StringDecoder) Read() string

Read returns the next value from the decoder.

func (*StringDecoder) SetBytes added in v0.13.0

func (e *StringDecoder) SetBytes(b []byte) error

SetBytes initializes the decoder with bytes to read from. This must be called before calling any other method.

type StringEncoder

type StringEncoder struct {
	// contains filtered or unexported fields
}

StringEncoder encodes multiple strings into a byte slice.

func NewStringEncoder

func NewStringEncoder(sz int) StringEncoder

NewStringEncoder returns a new StringEncoder with an initial buffer ready to hold sz bytes.

func (*StringEncoder) Bytes

func (e *StringEncoder) Bytes() ([]byte, error)

Bytes returns a copy of the underlying buffer.

func (*StringEncoder) Flush added in v1.2.3

func (e *StringEncoder) Flush()

Flush is no-op

func (*StringEncoder) Reset added in v1.1.0

func (e *StringEncoder) Reset()

Reset sets the encoder back to its initial state.

func (*StringEncoder) Write

func (e *StringEncoder) Write(s string)

Write encodes s to the underlying buffer.

type StringValue

type StringValue struct {
	// contains filtered or unexported fields
}

StringValue represents a string value.

func DecodeStringBlock added in v0.9.6

func DecodeStringBlock(block []byte, a *[]StringValue) ([]StringValue, error)

DecodeStringBlock decodes the string block from the byte slice and appends the string values to a.

func (StringValue) Size

func (v StringValue) Size() int

Size returns the number of bytes necessary to represent the value and its timestamp.

func (StringValue) String

func (v StringValue) String() string

String returns the string representation of the value and its timestamp.

func (StringValue) UnixNano

func (v StringValue) UnixNano() int64

UnixNano returns the timestamp of the value.

func (StringValue) Value

func (v StringValue) Value() interface{}

Value returns the underlying string value.

type StringValues added in v0.11.0

type StringValues []StringValue

StringValues represents a slice of String values.

func (StringValues) Deduplicate added in v0.11.0

func (a StringValues) Deduplicate() StringValues

Deduplicate returns a new slice with any values that have the same timestamp removed. The Value that appears last in the slice is the one that is kept. The returned Values are sorted if necessary.

func (StringValues) Encode added in v1.2.3

func (a StringValues) Encode(buf []byte) ([]byte, error)

func (StringValues) Exclude added in v1.0.0

func (a StringValues) Exclude(min, max int64) StringValues

Exclude returns the subset of values not in [min, max]. The values must be deduplicated and sorted before calling Exclude or the results are undefined.

func (StringValues) FindRange added in v1.4.0

func (a StringValues) FindRange(min, max int64) (int, int)

FindRange returns the positions where min and max would be inserted into the array. If a[0].UnixNano() > max or a[len-1].UnixNano() < min then FindRange returns (-1, -1) indicating the array is outside the [min, max]. The values must be deduplicated and sorted before calling Exclude or the results are undefined.

func (StringValues) Include added in v1.0.0

func (a StringValues) Include(min, max int64) StringValues

Include returns the subset values between min and max inclusive. The values must be deduplicated and sorted before calling Exclude or the results are undefined.

func (StringValues) Len added in v0.11.0

func (a StringValues) Len() int

Sort methods

func (StringValues) Less added in v0.11.0

func (a StringValues) Less(i, j int) bool

func (StringValues) MaxTime added in v1.0.0

func (a StringValues) MaxTime() int64

func (StringValues) Merge added in v1.0.0

Merge overlays b to top of a. If two values conflict with the same timestamp, b is used. Both a and b must be sorted in ascending order.

func (StringValues) MinTime added in v1.0.0

func (a StringValues) MinTime() int64

func (StringValues) Size added in v1.0.0

func (a StringValues) Size() int

func (StringValues) Swap added in v0.11.0

func (a StringValues) Swap(i, j int)

type TSMFile added in v0.9.6

type TSMFile interface {
	// Path returns the underlying file path for the TSMFile.  If the file
	// has not be written or loaded from disk, the zero value is returned.
	Path() string

	// Read returns all the values in the block where time t resides.
	Read(key []byte, t int64) ([]Value, error)

	// ReadAt returns all the values in the block identified by entry.
	ReadAt(entry *IndexEntry, values []Value) ([]Value, error)
	ReadFloatBlockAt(entry *IndexEntry, values *[]FloatValue) ([]FloatValue, error)
	ReadIntegerBlockAt(entry *IndexEntry, values *[]IntegerValue) ([]IntegerValue, error)
	ReadUnsignedBlockAt(entry *IndexEntry, values *[]UnsignedValue) ([]UnsignedValue, error)
	ReadStringBlockAt(entry *IndexEntry, values *[]StringValue) ([]StringValue, error)
	ReadBooleanBlockAt(entry *IndexEntry, values *[]BooleanValue) ([]BooleanValue, error)

	// Entries returns the index entries for all blocks for the given key.
	Entries(key []byte) []IndexEntry
	ReadEntries(key []byte, entries *[]IndexEntry) []IndexEntry

	// Returns true if the TSMFile may contain a value with the specified
	// key and time.
	ContainsValue(key []byte, t int64) bool

	// Contains returns true if the file contains any values for the given
	// key.
	Contains(key []byte) bool

	// OverlapsTimeRange returns true if the time range of the file intersect min and max.
	OverlapsTimeRange(min, max int64) bool

	// OverlapsKeyRange returns true if the key range of the file intersects min and max.
	OverlapsKeyRange(min, max []byte) bool

	// TimeRange returns the min and max time across all keys in the file.
	TimeRange() (int64, int64)

	// TombstoneRange returns ranges of time that are deleted for the given key.
	TombstoneRange(key []byte) []TimeRange

	// KeyRange returns the min and max keys in the file.
	KeyRange() ([]byte, []byte)

	// KeyCount returns the number of distinct keys in the file.
	KeyCount() int

	// Seek returns the position in the index with the key <= key.
	Seek(key []byte) int

	// KeyAt returns the key located at index position idx.
	KeyAt(idx int) ([]byte, byte)

	// Type returns the block type of the values stored for the key.  Returns one of
	// BlockFloat64, BlockInt64, BlockBoolean, BlockString.  If key does not exist,
	// an error is returned.
	Type(key []byte) (byte, error)

	// BatchDelete return a BatchDeleter that allows for multiple deletes in batches
	// and group commit or rollback.
	BatchDelete() BatchDeleter

	// Delete removes the keys from the set of keys available in this file.
	Delete(keys [][]byte) error

	// DeleteRange removes the values for keys between timestamps min and max.
	DeleteRange(keys [][]byte, min, max int64) error

	// HasTombstones returns true if file contains values that have been deleted.
	HasTombstones() bool

	// TombstoneFiles returns the tombstone filestats if there are any tombstones
	// written for this file.
	TombstoneFiles() []FileStat

	// Close closes the underlying file resources.
	Close() error

	// Size returns the size of the file on disk in bytes.
	Size() uint32

	// Rename renames the existing TSM file to a new name and replaces the mmap backing slice using the new
	// file name.  Index and Reader state are not re-initialized.
	Rename(path string) error

	// Remove deletes the file from the filesystem.
	Remove() error

	// InUse returns true if the file is currently in use by queries.
	InUse() bool

	// Ref records that this file is actively in use.
	Ref()

	// Unref records that this file is no longer in use.
	Unref()

	// Stats returns summary information about the TSM file.
	Stats() FileStat

	// BlockIterator returns an iterator pointing to the first block in the file and
	// allows sequential iteration to each and every block.
	BlockIterator() *BlockIterator

	// Free releases any resources held by the FileStore to free up system resources.
	Free() error
}

TSMFile represents an on-disk TSM file.

type TSMIndex

type TSMIndex interface {
	// Delete removes the given keys from the index.
	Delete(keys [][]byte)

	// DeleteRange removes the given keys with data between minTime and maxTime from the index.
	DeleteRange(keys [][]byte, minTime, maxTime int64)

	// ContainsKey returns true if the given key may exist in the index.  This func is faster than
	// Contains but, may return false positives.
	ContainsKey(key []byte) bool

	// Contains return true if the given key exists in the index.
	Contains(key []byte) bool

	// ContainsValue returns true if key and time might exist in this file.  This function could
	// return true even though the actual point does not exists.  For example, the key may
	// exist in this file, but not have a point exactly at time t.
	ContainsValue(key []byte, timestamp int64) bool

	// Entries returns all index entries for a key.
	Entries(key []byte) []IndexEntry

	// ReadEntries reads the index entries for key into entries.
	ReadEntries(key []byte, entries *[]IndexEntry) []IndexEntry

	// Entry returns the index entry for the specified key and timestamp.  If no entry
	// matches the key and timestamp, nil is returned.
	Entry(key []byte, timestamp int64) *IndexEntry

	// Key returns the key in the index at the given position, using entries to avoid allocations.
	Key(index int, entries *[]IndexEntry) ([]byte, byte, []IndexEntry)

	// KeyAt returns the key in the index at the given position.
	KeyAt(index int) ([]byte, byte)

	// KeyCount returns the count of unique keys in the index.
	KeyCount() int

	// Seek returns the position in the index where key <= value in the index.
	Seek(key []byte) int

	// OverlapsTimeRange returns true if the time range of the file intersect min and max.
	OverlapsTimeRange(min, max int64) bool

	// OverlapsKeyRange returns true if the min and max keys of the file overlap the arguments min and max.
	OverlapsKeyRange(min, max []byte) bool

	// Size returns the size of the current index in bytes.
	Size() uint32

	// TimeRange returns the min and max time across all keys in the file.
	TimeRange() (int64, int64)

	// TombstoneRange returns ranges of time that are deleted for the given key.
	TombstoneRange(key []byte) []TimeRange

	// KeyRange returns the min and max keys in the file.
	KeyRange() ([]byte, []byte)

	// Type returns the block type of the values stored for the key.  Returns one of
	// BlockFloat64, BlockInt64, BlockBool, BlockString.  If key does not exist,
	// an error is returned.
	Type(key []byte) (byte, error)

	// UnmarshalBinary populates an index from an encoded byte slice
	// representation of an index.
	UnmarshalBinary(b []byte) error

	// Close closes the index and releases any resources.
	Close() error
}

TSMIndex represent the index section of a TSM file. The index records all blocks, their locations, sizes, min and max times.

type TSMReader added in v0.9.6

type TSMReader struct {
	// contains filtered or unexported fields
}

TSMReader is a reader for a TSM file.

func NewTSMReader

func NewTSMReader(f *os.File) (*TSMReader, error)

NewTSMReader returns a new TSMReader from the given file.

func (*TSMReader) BatchDelete added in v1.5.0

func (r *TSMReader) BatchDelete() BatchDeleter

BatchDelete returns a BatchDeleter. Only a single goroutine may run a BatchDelete at a time. Callers must either Commit or Rollback the operation.

func (*TSMReader) BlockIterator added in v0.10.0

func (t *TSMReader) BlockIterator() *BlockIterator

BlockIterator returns a BlockIterator for the underlying TSM file.

func (*TSMReader) Close added in v0.9.6

func (t *TSMReader) Close() error

Close closes the TSMReader.

func (*TSMReader) Contains added in v0.9.6

func (t *TSMReader) Contains(key []byte) bool

Contains returns whether the given key is present in the index.

func (*TSMReader) ContainsValue added in v0.9.6

func (t *TSMReader) ContainsValue(key []byte, ts int64) bool

ContainsValue returns true if key and time might exists in this file. This function could return true even though the actual point does not exist. For example, the key may exist in this file, but not have a point exactly at time t.

func (*TSMReader) Delete added in v0.9.6

func (t *TSMReader) Delete(keys [][]byte) error

Delete deletes blocks indicated by keys.

func (*TSMReader) DeleteRange added in v0.13.0

func (t *TSMReader) DeleteRange(keys [][]byte, minTime, maxTime int64) error

DeleteRange removes the given points for keys between minTime and maxTime. The series keys passed in must be sorted.

func (*TSMReader) Entries added in v0.9.6

func (t *TSMReader) Entries(key []byte) []IndexEntry

Entries returns all index entries for key.

func (*TSMReader) Free added in v1.4.0

func (t *TSMReader) Free() error

func (*TSMReader) HasTombstones added in v0.9.6

func (t *TSMReader) HasTombstones() bool

HasTombstones return true if there are any tombstone entries recorded.

func (*TSMReader) InUse added in v1.0.0

func (t *TSMReader) InUse() bool

InUse returns whether the TSMReader currently has any active references.

func (*TSMReader) IndexSize added in v0.9.6

func (t *TSMReader) IndexSize() uint32

IndexSize returns the size of the index in bytes.

func (*TSMReader) Key added in v0.9.6

func (t *TSMReader) Key(index int, entries *[]IndexEntry) ([]byte, byte, []IndexEntry)

Key returns the key and the underlying entry at the numeric index.

func (*TSMReader) KeyAt added in v0.10.0

func (t *TSMReader) KeyAt(idx int) ([]byte, byte)

KeyAt returns the key and key type at position idx in the index.

func (*TSMReader) KeyCount added in v0.10.0

func (t *TSMReader) KeyCount() int

KeyCount returns the count of unique keys in the TSMReader.

func (*TSMReader) KeyRange added in v0.9.6

func (t *TSMReader) KeyRange() ([]byte, []byte)

KeyRange returns the min and max key across all keys in the file.

func (*TSMReader) LastModified added in v0.9.6

func (t *TSMReader) LastModified() int64

LastModified returns the last time the underlying file was modified.

func (*TSMReader) OverlapsKeyRange added in v1.5.0

func (t *TSMReader) OverlapsKeyRange(min, max []byte) bool

OverlapsKeyRange returns true if the key range of the file intersect min and max.

func (*TSMReader) OverlapsTimeRange added in v1.5.0

func (t *TSMReader) OverlapsTimeRange(min, max int64) bool

OverlapsTimeRange returns true if the time range of the file intersect min and max.

func (*TSMReader) Path added in v0.9.6

func (t *TSMReader) Path() string

Path returns the path of the file the TSMReader was initialized with.

func (*TSMReader) Read added in v0.9.6

func (t *TSMReader) Read(key []byte, timestamp int64) ([]Value, error)

Read returns the values corresponding to the block at the given key and timestamp.

func (*TSMReader) ReadAll added in v0.9.6

func (t *TSMReader) ReadAll(key []byte) ([]Value, error)

ReadAll returns all values for a key in all blocks.

func (*TSMReader) ReadAt added in v0.9.6

func (t *TSMReader) ReadAt(entry *IndexEntry, vals []Value) ([]Value, error)

ReadAt returns the values corresponding to the given index entry.

func (*TSMReader) ReadBooleanBlockAt added in v0.11.0

func (t *TSMReader) ReadBooleanBlockAt(entry *IndexEntry, vals *[]BooleanValue) ([]BooleanValue, error)

ReadBooleanBlockAt returns the boolean values corresponding to the given index entry.

func (*TSMReader) ReadBytes added in v1.3.0

func (t *TSMReader) ReadBytes(e *IndexEntry, b []byte) (uint32, []byte, error)

func (*TSMReader) ReadEntries added in v0.12.0

func (t *TSMReader) ReadEntries(key []byte, entries *[]IndexEntry) []IndexEntry

ReadEntries reads the index entries for key into entries.

func (*TSMReader) ReadFloatBlockAt added in v0.11.0

func (t *TSMReader) ReadFloatBlockAt(entry *IndexEntry, vals *[]FloatValue) ([]FloatValue, error)

ReadFloatBlockAt returns the float values corresponding to the given index entry.

func (*TSMReader) ReadIntegerBlockAt added in v0.11.0

func (t *TSMReader) ReadIntegerBlockAt(entry *IndexEntry, vals *[]IntegerValue) ([]IntegerValue, error)

ReadIntegerBlockAt returns the integer values corresponding to the given index entry.

func (*TSMReader) ReadStringBlockAt added in v0.11.0

func (t *TSMReader) ReadStringBlockAt(entry *IndexEntry, vals *[]StringValue) ([]StringValue, error)

ReadStringBlockAt returns the string values corresponding to the given index entry.

func (*TSMReader) ReadUnsignedBlockAt added in v1.4.0

func (t *TSMReader) ReadUnsignedBlockAt(entry *IndexEntry, vals *[]UnsignedValue) ([]UnsignedValue, error)

ReadUnsignedBlockAt returns the unsigned integer values corresponding to the given index entry.

func (*TSMReader) Ref added in v1.0.0

func (t *TSMReader) Ref()

Ref records a usage of this TSMReader. If there are active references when the reader is closed or removed, the reader will remain open until there are no more references.

func (*TSMReader) Remove added in v0.9.6

func (t *TSMReader) Remove() error

Remove removes any underlying files stored on disk for this reader.

func (*TSMReader) Rename added in v1.0.0

func (t *TSMReader) Rename(path string) error

Rename renames the underlying file to the new path.

func (*TSMReader) Seek added in v1.5.0

func (t *TSMReader) Seek(key []byte) int

func (*TSMReader) Size added in v0.9.6

func (t *TSMReader) Size() uint32

Size returns the size of the underlying file in bytes.

func (*TSMReader) Stats added in v0.9.6

func (t *TSMReader) Stats() FileStat

Stats returns the FileStat for the TSMReader's underlying file.

func (*TSMReader) TimeRange added in v0.9.6

func (t *TSMReader) TimeRange() (int64, int64)

TimeRange returns the min and max time across all keys in the file.

func (*TSMReader) TombstoneFiles added in v0.10.0

func (t *TSMReader) TombstoneFiles() []FileStat

TombstoneFiles returns any tombstone files associated with this TSM file.

func (*TSMReader) TombstoneRange added in v0.13.0

func (t *TSMReader) TombstoneRange(key []byte) []TimeRange

TombstoneRange returns ranges of time that are deleted for the given key.

func (*TSMReader) Type added in v0.9.6

func (t *TSMReader) Type(key []byte) (byte, error)

Type returns the type of values stored at the given key.

func (*TSMReader) Unref added in v1.0.0

func (t *TSMReader) Unref()

Unref removes a usage record of this TSMReader. If the Reader was closed by another goroutine while there were active references, the file will be closed and remove

func (*TSMReader) WithObserver added in v1.6.0

func (t *TSMReader) WithObserver(obs tsdb.FileStoreObserver)

WithObserver sets the observer for the TSM reader.

type TSMWriter

type TSMWriter interface {
	// Write writes a new block for key containing and values.  Writes append
	// blocks in the order that the Write function is called.  The caller is
	// responsible for ensuring keys and blocks are sorted appropriately.
	// Values are encoded as a full block.  The caller is responsible for
	// ensuring a fixed number of values are encoded in each block as well as
	// ensuring the Values are sorted. The first and last timestamp values are
	// used as the minimum and maximum values for the index entry.
	Write(key []byte, values Values) error

	// WriteBlock writes a new block for key containing the bytes in block.  WriteBlock appends
	// blocks in the order that the WriteBlock function is called.  The caller is
	// responsible for ensuring keys and blocks are sorted appropriately, and that the
	// block and index information is correct for the block.  The minTime and maxTime
	// timestamp values are used as the minimum and maximum values for the index entry.
	WriteBlock(key []byte, minTime, maxTime int64, block []byte) error

	// WriteIndex finishes the TSM write streams and writes the index.
	WriteIndex() error

	// Flushes flushes all pending changes to the underlying file resources.
	Flush() error

	// Close closes any underlying file resources.
	Close() error

	// Size returns the current size in bytes of the file.
	Size() uint32

	Remove() error
}

TSMWriter writes TSM formatted key and values.

func NewTSMWriter

func NewTSMWriter(w io.Writer) (TSMWriter, error)

NewTSMWriter returns a new TSMWriter writing to w.

func NewTSMWriterWithDiskBuffer added in v1.4.3

func NewTSMWriterWithDiskBuffer(w io.Writer) (TSMWriter, error)

NewTSMWriterWithDiskBuffer returns a new TSMWriter writing to w and will use a disk based buffer for the TSM index if possible.

type TimeDecoder

type TimeDecoder struct {
	// contains filtered or unexported fields
}

TimeDecoder decodes a byte slice into timestamps.

func (*TimeDecoder) Error

func (d *TimeDecoder) Error() error

Error returns the last error encountered by the decoder.

func (*TimeDecoder) Init added in v0.13.0

func (d *TimeDecoder) Init(b []byte)

Init initializes the decoder with bytes to read from.

func (*TimeDecoder) Next

func (d *TimeDecoder) Next() bool

Next returns true if there are any timestamps remaining to be decoded.

func (*TimeDecoder) Read

func (d *TimeDecoder) Read() int64

Read returns the next timestamp from the decoder.

type TimeEncoder

type TimeEncoder interface {
	Write(t int64)
	Bytes() ([]byte, error)
	Reset()
}

TimeEncoder encodes time.Time to byte slices.

func NewTimeEncoder

func NewTimeEncoder(sz int) TimeEncoder

NewTimeEncoder returns a TimeEncoder with an initial buffer ready to hold sz bytes.

type TimeRange added in v0.13.0

type TimeRange struct {
	Min, Max int64
}

TimeRange holds a min and max timestamp.

func (TimeRange) Overlaps added in v1.3.7

func (t TimeRange) Overlaps(min, max int64) bool

type Tombstone added in v0.13.0

type Tombstone struct {
	// Key is the tombstoned series key.
	Key []byte

	// Min and Max are the min and max unix nanosecond time ranges of Key that are deleted.  If
	// the full range is deleted, both values are -1.
	Min, Max int64
}

Tombstone represents an individual deletion.

type Tombstoner added in v0.9.6

type Tombstoner struct {

	// Path is the location of the file to record tombstone. This should be the
	// full path to a TSM file.
	Path string

	FilterFn func(k []byte) bool
	// contains filtered or unexported fields
}

Tombstoner records tombstones when entries are deleted.

func NewTombstoner added in v1.6.0

func NewTombstoner(path string, filterFn func(k []byte) bool) *Tombstoner

NewTombstoner constructs a Tombstoner for the given path. FilterFn can be nil.

func (*Tombstoner) Add added in v0.9.6

func (t *Tombstoner) Add(keys [][]byte) error

Add adds the all keys, across all timestamps, to the tombstone.

func (*Tombstoner) AddRange added in v0.13.0

func (t *Tombstoner) AddRange(keys [][]byte, min, max int64) error

AddRange adds all keys to the tombstone specifying only the data between min and max to be removed.

func (*Tombstoner) Delete added in v0.9.6

func (t *Tombstoner) Delete() error

Delete removes all the tombstone files from disk.

func (*Tombstoner) Flush added in v1.5.0

func (t *Tombstoner) Flush() error

func (*Tombstoner) HasTombstones added in v0.9.6

func (t *Tombstoner) HasTombstones() bool

HasTombstones return true if there are any tombstone entries recorded.

func (*Tombstoner) Rollback added in v1.5.0

func (t *Tombstoner) Rollback() error

func (*Tombstoner) TombstoneFiles added in v0.10.0

func (t *Tombstoner) TombstoneFiles() []FileStat

TombstoneFiles returns any tombstone files associated with Tombstoner's TSM file.

func (*Tombstoner) Walk added in v1.0.0

func (t *Tombstoner) Walk(fn func(t Tombstone) error) error

Walk calls fn for every Tombstone under the Tombstoner.

func (*Tombstoner) WithObserver added in v1.6.0

func (t *Tombstoner) WithObserver(obs tsdb.FileStoreObserver)

WithObserver sets a FileStoreObserver for when the tombstone file is written.

type UnsignedValue added in v1.4.0

type UnsignedValue struct {
	// contains filtered or unexported fields
}

UnsignedValue represents an int64 value.

func DecodeUnsignedBlock added in v1.4.0

func DecodeUnsignedBlock(block []byte, a *[]UnsignedValue) ([]UnsignedValue, error)

DecodeUnsignedBlock decodes the unsigned integer block from the byte slice and appends the unsigned integer values to a.

func (UnsignedValue) Size added in v1.4.0

func (v UnsignedValue) Size() int

Size returns the number of bytes necessary to represent the value and its timestamp.

func (UnsignedValue) String added in v1.4.0

func (v UnsignedValue) String() string

String returns the string representation of the value and its timestamp.

func (UnsignedValue) UnixNano added in v1.4.0

func (v UnsignedValue) UnixNano() int64

UnixNano returns the timestamp of the value.

func (UnsignedValue) Value added in v1.4.0

func (v UnsignedValue) Value() interface{}

Value returns the underlying int64 value.

type UnsignedValues added in v1.4.0

type UnsignedValues []UnsignedValue

UnsignedValues represents a slice of Unsigned values.

func (UnsignedValues) Deduplicate added in v1.4.0

func (a UnsignedValues) Deduplicate() UnsignedValues

Deduplicate returns a new slice with any values that have the same timestamp removed. The Value that appears last in the slice is the one that is kept. The returned Values are sorted if necessary.

func (UnsignedValues) Encode added in v1.4.0

func (a UnsignedValues) Encode(buf []byte) ([]byte, error)

func (UnsignedValues) Exclude added in v1.4.0

func (a UnsignedValues) Exclude(min, max int64) UnsignedValues

Exclude returns the subset of values not in [min, max]. The values must be deduplicated and sorted before calling Exclude or the results are undefined.

func (UnsignedValues) FindRange added in v1.4.0

func (a UnsignedValues) FindRange(min, max int64) (int, int)

FindRange returns the positions where min and max would be inserted into the array. If a[0].UnixNano() > max or a[len-1].UnixNano() < min then FindRange returns (-1, -1) indicating the array is outside the [min, max]. The values must be deduplicated and sorted before calling Exclude or the results are undefined.

func (UnsignedValues) Include added in v1.4.0

func (a UnsignedValues) Include(min, max int64) UnsignedValues

Include returns the subset values between min and max inclusive. The values must be deduplicated and sorted before calling Exclude or the results are undefined.

func (UnsignedValues) Len added in v1.4.0

func (a UnsignedValues) Len() int

Sort methods

func (UnsignedValues) Less added in v1.4.0

func (a UnsignedValues) Less(i, j int) bool

func (UnsignedValues) MaxTime added in v1.4.0

func (a UnsignedValues) MaxTime() int64

func (UnsignedValues) Merge added in v1.4.0

Merge overlays b to top of a. If two values conflict with the same timestamp, b is used. Both a and b must be sorted in ascending order.

func (UnsignedValues) MinTime added in v1.4.0

func (a UnsignedValues) MinTime() int64

func (UnsignedValues) Size added in v1.4.0

func (a UnsignedValues) Size() int

func (UnsignedValues) Swap added in v1.4.0

func (a UnsignedValues) Swap(i, j int)

type Value

type Value interface {
	// UnixNano returns the timestamp of the value in nanoseconds since unix epoch.
	UnixNano() int64

	// Value returns the underlying value.
	Value() interface{}

	// Size returns the number of bytes necessary to represent the value and its timestamp.
	Size() int

	// String returns the string representation of the value and its timestamp.
	String() string
	// contains filtered or unexported methods
}

Value represents a TSM-encoded value.

func DecodeBlock

func DecodeBlock(block []byte, vals []Value) ([]Value, error)

DecodeBlock takes a byte slice and decodes it into values of the appropriate type based on the block.

func NewBooleanValue added in v1.1.0

func NewBooleanValue(t int64, v bool) Value

NewBooleanValue returns a new boolean value.

func NewFloatValue added in v1.1.0

func NewFloatValue(t int64, v float64) Value

NewFloatValue returns a new float value.

func NewIntegerValue added in v1.1.0

func NewIntegerValue(t int64, v int64) Value

NewIntegerValue returns a new integer value.

func NewStringValue added in v1.1.0

func NewStringValue(t int64, v string) Value

NewStringValue returns a new string value.

func NewUnsignedValue added in v1.4.0

func NewUnsignedValue(t int64, v uint64) Value

NewUnsignedValue returns a new unsigned integer value.

func NewValue

func NewValue(t int64, value interface{}) Value

NewValue returns a new Value with the underlying type dependent on value.

type Values

type Values []Value

Values represents a slice of values.

func (Values) Deduplicate

func (a Values) Deduplicate() Values

Deduplicate returns a new slice with any values that have the same timestamp removed. The Value that appears last in the slice is the one that is kept. The returned Values are sorted if necessary.

func (Values) Encode

func (a Values) Encode(buf []byte) ([]byte, error)

Encode converts the values to a byte slice. If there are no values, this function panics.

func (Values) Exclude added in v1.0.0

func (a Values) Exclude(min, max int64) Values

Exclude returns the subset of values not in [min, max]. The values must be deduplicated and sorted before calling Exclude or the results are undefined.

func (Values) FindRange added in v1.4.0

func (a Values) FindRange(min, max int64) (int, int)

FindRange returns the positions where min and max would be inserted into the array. If a[0].UnixNano() > max or a[len-1].UnixNano() < min then FindRange returns (-1, -1) indicating the array is outside the [min, max]. The values must be deduplicated and sorted before calling Exclude or the results are undefined.

func (Values) Include added in v1.0.0

func (a Values) Include(min, max int64) Values

Include returns the subset values between min and max inclusive. The values must be deduplicated and sorted before calling Exclude or the results are undefined.

func (Values) InfluxQLType added in v0.9.6

func (a Values) InfluxQLType() (influxql.DataType, error)

InfluxQLType returns the influxql.DataType the values map to.

func (Values) Len

func (a Values) Len() int

Sort methods

func (Values) Less

func (a Values) Less(i, j int) bool

func (Values) MaxTime

func (a Values) MaxTime() int64

func (Values) Merge added in v1.0.0

func (a Values) Merge(b Values) Values

Merge overlays b to top of a. If two values conflict with the same timestamp, b is used. Both a and b must be sorted in ascending order.

func (Values) MinTime

func (a Values) MinTime() int64

func (Values) Size added in v0.9.6

func (a Values) Size() int

func (Values) Swap

func (a Values) Swap(i, j int)

type WAL added in v0.9.6

type WAL struct {

	// SegmentSize is the file size at which a segment file will be rotated
	SegmentSize int
	// contains filtered or unexported fields
}

WAL represents the write-ahead log used for writing TSM files.

func NewWAL added in v0.9.6

func NewWAL(path string) *WAL

NewWAL initializes a new WAL at the given directory.

func (*WAL) Close added in v0.9.6

func (l *WAL) Close() error

Close will finish any flush that is currently in progress and close file handles.

func (*WAL) CloseSegment added in v0.9.6

func (l *WAL) CloseSegment() error

CloseSegment closes the current segment if it is non-empty and opens a new one.

func (*WAL) ClosedSegments added in v0.9.6

func (l *WAL) ClosedSegments() ([]string, error)

ClosedSegments returns a slice of the names of the closed segment files.

func (*WAL) Delete added in v0.9.6

func (l *WAL) Delete(keys [][]byte) (int, error)

Delete deletes the given keys, returning the segment ID for the operation.

func (*WAL) DeleteRange added in v0.13.0

func (l *WAL) DeleteRange(keys [][]byte, min, max int64) (int, error)

DeleteRange deletes the given keys within the given time range, returning the segment ID for the operation.

func (*WAL) DiskSizeBytes added in v1.3.0

func (l *WAL) DiskSizeBytes() int64

func (*WAL) LastWriteTime added in v0.9.6

func (l *WAL) LastWriteTime() time.Time

LastWriteTime is the last time anything was written to the WAL.

func (*WAL) Open added in v0.9.6

func (l *WAL) Open() error

Open opens and initializes the Log. Open can recover from previous unclosed shutdowns.

func (*WAL) Path added in v0.9.6

func (l *WAL) Path() string

Path returns the directory the log was initialized with.

func (*WAL) Remove added in v0.9.6

func (l *WAL) Remove(files []string) error

Remove deletes the given segment file paths from disk and cleans up any associated objects.

func (*WAL) Statistics added in v1.0.0

func (l *WAL) Statistics(tags map[string]string) []models.Statistic

Statistics returns statistics for periodic monitoring.

func (*WAL) WithLogger added in v1.2.0

func (l *WAL) WithLogger(log *zap.Logger)

WithLogger sets the WAL's logger.

func (*WAL) WriteMulti added in v1.3.0

func (l *WAL) WriteMulti(values map[string][]Value) (int, error)

WriteMulti writes the given values to the WAL. It returns the WAL segment ID to which the points were written. If an error is returned the segment ID should be ignored.

type WALEntry added in v0.9.6

type WALEntry interface {
	Type() WalEntryType
	Encode(dst []byte) ([]byte, error)
	MarshalBinary() ([]byte, error)
	UnmarshalBinary(b []byte) error
	MarshalSize() int
}

WALEntry is record stored in each WAL segment. Each entry has a type and an opaque, type dependent byte slice data attribute.

type WALSegmentReader added in v0.9.6

type WALSegmentReader struct {
	// contains filtered or unexported fields
}

WALSegmentReader reads WAL segments.

func NewWALSegmentReader added in v0.9.6

func NewWALSegmentReader(r io.ReadCloser) *WALSegmentReader

NewWALSegmentReader returns a new WALSegmentReader reading from r.

func (*WALSegmentReader) Close added in v0.9.6

func (r *WALSegmentReader) Close() error

Close closes the underlying io.Reader.

func (*WALSegmentReader) Count added in v0.9.6

func (r *WALSegmentReader) Count() int64

Count returns the total number of bytes read successfully from the segment, as of the last call to Read(). The segment is guaranteed to be valid up to and including this number of bytes.

func (*WALSegmentReader) Error added in v0.9.6

func (r *WALSegmentReader) Error() error

Error returns the last error encountered by the reader.

func (*WALSegmentReader) Next added in v0.9.6

func (r *WALSegmentReader) Next() bool

Next indicates if there is a value to read.

func (*WALSegmentReader) Read added in v0.9.6

func (r *WALSegmentReader) Read() (WALEntry, error)

Read returns the next entry in the reader.

func (*WALSegmentReader) Reset added in v1.3.6

func (r *WALSegmentReader) Reset(rc io.ReadCloser)

type WALSegmentWriter added in v0.9.6

type WALSegmentWriter struct {
	// contains filtered or unexported fields
}

WALSegmentWriter writes WAL segments.

func NewWALSegmentWriter added in v0.9.6

func NewWALSegmentWriter(w io.WriteCloser) *WALSegmentWriter

NewWALSegmentWriter returns a new WALSegmentWriter writing to w.

func (*WALSegmentWriter) Flush added in v1.3.0

func (w *WALSegmentWriter) Flush() error

func (*WALSegmentWriter) Write added in v0.9.6

func (w *WALSegmentWriter) Write(entryType WalEntryType, compressed []byte) error

Write writes entryType and the buffer containing compressed entry data.

type WALStatistics added in v1.0.0

type WALStatistics struct {
	OldBytes     int64
	CurrentBytes int64
	WriteOK      int64
	WriteErr     int64
}

WALStatistics maintains statistics about the WAL.

type WalEntryType added in v0.9.6

type WalEntryType byte

WalEntryType is a byte written to a wal segment file that indicates what the following compressed block contains.

const (
	// WriteWALEntryType indicates a write entry.
	WriteWALEntryType WalEntryType = 0x01

	// DeleteWALEntryType indicates a delete entry.
	DeleteWALEntryType WalEntryType = 0x02

	// DeleteRangeWALEntryType indicates a delete range entry.
	DeleteRangeWALEntryType WalEntryType = 0x03
)

type WriteWALEntry added in v0.9.6

type WriteWALEntry struct {
	Values map[string][]Value
	// contains filtered or unexported fields
}

WriteWALEntry represents a write of points.

func (*WriteWALEntry) Encode added in v0.9.6

func (w *WriteWALEntry) Encode(dst []byte) ([]byte, error)

Encode converts the WriteWALEntry into a byte stream using dst if it is large enough. If dst is too small, the slice will be grown to fit the encoded entry.

func (*WriteWALEntry) MarshalBinary added in v0.9.6

func (w *WriteWALEntry) MarshalBinary() ([]byte, error)

MarshalBinary returns a binary representation of the entry in a new byte slice.

func (*WriteWALEntry) MarshalSize added in v1.3.0

func (w *WriteWALEntry) MarshalSize() int

func (*WriteWALEntry) Type added in v0.9.6

func (w *WriteWALEntry) Type() WalEntryType

Type returns WriteWALEntryType.

func (*WriteWALEntry) UnmarshalBinary added in v0.9.6

func (w *WriteWALEntry) UnmarshalBinary(b []byte) error

UnmarshalBinary deserializes the byte slice into w.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL