index

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2024 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MagicIndex 4 bytes at the head of an index file.
	MagicIndex = 0xBAAAD700
	// HeaderLen represents number of bytes reserved of index for header.
	HeaderLen = 5

	// FormatV1 represents 1 version of index.
	FormatV1 = 1
	// FormatV2 represents 2 version of index.
	FormatV2 = 2

	IndexFilename = "index"

	SegmentsIndexWriterBufSize = 2 * 0x1000 // small for segments
	BlocksIndexWriterBufSize   = 1 << 22    // large for blocks
)

Variables

This section is empty.

Functions

func PutBufferWriterToPool

func PutBufferWriterToPool(fw *BufferWriter)

func ReadOffsetTable

func ReadOffsetTable(bs ByteSlice, off uint64, f func([]string, uint64, int) error) error

ReadOffsetTable reads an offset table and at the given position calls f for each found entry. If f returns an error it stops decoding and returns the received error.

Types

type BufferWriter

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

func GetBufferWriterFromPool

func GetBufferWriterFromPool() *BufferWriter

func NewBufferWriter

func NewBufferWriter() *BufferWriter

NewBufferWriter returns a new BufferWriter. todo: pooling memory

func (*BufferWriter) AddPadding

func (fw *BufferWriter) AddPadding(size int) error

func (*BufferWriter) Buffer

func (fw *BufferWriter) Buffer() ([]byte, io.Closer, error)

func (*BufferWriter) Close

func (fw *BufferWriter) Close() error

func (*BufferWriter) Flush

func (fw *BufferWriter) Flush() error

func (*BufferWriter) Pos

func (fw *BufferWriter) Pos() uint64

func (*BufferWriter) Read

func (fw *BufferWriter) Read(buf []byte) (int, error)

func (*BufferWriter) ReadFrom

func (fw *BufferWriter) ReadFrom(r io.Reader) (int64, error)

func (*BufferWriter) Remove

func (fw *BufferWriter) Remove() error

func (*BufferWriter) Reset

func (fw *BufferWriter) Reset()

func (*BufferWriter) Write

func (fw *BufferWriter) Write(bufs ...[]byte) error

func (*BufferWriter) WriteAt

func (fw *BufferWriter) WriteAt(buf []byte, pos uint64) error

type ByteSlice

type ByteSlice interface {
	Len() int
	Range(start, end int) []byte
}

ByteSlice abstracts a byte slice.

type Decoder

type Decoder struct {
	LookupSymbol func(uint32) (string, error)
}

Decoder provides decoding methods for the v1 and v2 index file format.

It currently does not contain decoding methods for all entry types but can be extended by them if there's demand.

func (*Decoder) LabelNamesOffsetsFor

func (dec *Decoder) LabelNamesOffsetsFor(b []byte) ([]uint32, error)

LabelNamesOffsetsFor decodes the offsets of the name symbols for a given series. They are returned in the same order they're stored, which should be sorted lexicographically.

func (*Decoder) LabelValueFor

func (dec *Decoder) LabelValueFor(b []byte, label string) (string, error)

LabelValueFor decodes a label for a given series.

func (*Decoder) Postings

func (dec *Decoder) Postings(b []byte) (int, index.Postings, error)

Postings returns a postings list for b and its number of elements.

func (*Decoder) Series

func (dec *Decoder) Series(b []byte, lbls *phlaremodel.Labels, chks *[]index.ChunkMeta, group bool, by ...string) (uint64, error)

Series decodes a series entry from the given byte slice into lset and chks.

type Metadata

type Metadata struct {
	From, Through int64
	Checksum      uint32
}

Metadata is TSDB-level metadata

func (*Metadata) EnsureBounds

func (m *Metadata) EnsureBounds(from, through int64)

type Range

type Range struct {
	Start, End int64
}

Range marks a byte range.

type Reader

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

func NewFileReader

func NewFileReader(path string) (*Reader, error)

NewFileReader returns a new index reader against the given index file.

func NewReader

func NewReader(b ByteSlice) (*Reader, error)

NewReader returns a new index reader on the given byte slice. It automatically handles different format versions.

func (*Reader) Bounds

func (r *Reader) Bounds() (int64, int64)

func (*Reader) Checksum

func (r *Reader) Checksum() uint32

func (*Reader) Close

func (r *Reader) Close() error

Close the reader and its underlying resources.

func (*Reader) FileInfo

func (r *Reader) FileInfo() block.File

FileInfo returns some general stats about the underlying file

func (*Reader) LabelNames

func (r *Reader) LabelNames(matchers ...*labels.Matcher) ([]string, error)

LabelNames returns all the unique label names present in the index. TODO(twilkie) implement support for matchers

func (*Reader) LabelNamesFor

func (r *Reader) LabelNamesFor(ids ...storage.SeriesRef) ([]string, error)

LabelNamesFor returns all the label names for the series referred to by IDs. The names returned are sorted.

func (*Reader) LabelValueFor

func (r *Reader) LabelValueFor(id storage.SeriesRef, label string) (string, error)

LabelValueFor returns label value for the given label name in the series referred to by ID.

func (*Reader) LabelValues

func (r *Reader) LabelValues(name string, matchers ...*labels.Matcher) ([]string, error)

LabelValues returns value tuples that exist for the given label name. It is not safe to use the return value beyond the lifetime of the byte slice passed into the Reader. TODO(replay): Support filtering by matchers

func (*Reader) Postings

func (r *Reader) Postings(name string, shard *index.ShardAnnotation, values ...string) (index.Postings, error)

func (*Reader) PostingsRanges

func (r *Reader) PostingsRanges() (map[labels.Label]Range, error)

PostingsRanges returns a new map of byte range in the underlying index file for all postings lists.

func (*Reader) Series

func (r *Reader) Series(id storage.SeriesRef, lbls *phlaremodel.Labels, chks *[]index.ChunkMeta) (uint64, error)

Series reads the series with the given ID and writes its labels and chunks into lbls and chks.

func (*Reader) SeriesBy

func (r *Reader) SeriesBy(id storage.SeriesRef, lbls *phlaremodel.Labels, chks *[]index.ChunkMeta, by ...string) (uint64, error)

SeriesBy is like Series but allows to group labels by name. This avoid looking up all label symbols for requested series.

func (*Reader) Size

func (r *Reader) Size() int64

Size returns the size of an index file.

func (*Reader) SortedLabelValues

func (r *Reader) SortedLabelValues(name string, matchers ...*labels.Matcher) ([]string, error)

SortedLabelValues returns value tuples that exist for the given label name. It is not safe to use the return value beyond the lifetime of the byte slice passed into the Reader.

func (*Reader) SymbolTableSize

func (r *Reader) SymbolTableSize() uint64

SymbolTableSize returns the symbol table size in bytes.

func (*Reader) Symbols

func (r *Reader) Symbols() StringIter

Symbols returns an iterator over the symbols that exist within the index.

func (*Reader) Version

func (r *Reader) Version() int

Version returns the file format version of the underlying index.

type RealByteSlice

type RealByteSlice []byte

func (RealByteSlice) Len

func (b RealByteSlice) Len() int

func (RealByteSlice) Range

func (b RealByteSlice) Range(start, end int) []byte

func (RealByteSlice) Sub

func (b RealByteSlice) Sub(start, end int) ByteSlice

type StringIter

type StringIter interface {
	// Next advances the iterator and returns true if another value was found.
	Next() bool

	// At returns the value at the current iterator position.
	At() string

	// Err returns the last error of the iterator.
	Err() error
}

StringIter iterates over a sorted list of strings.

type Symbols

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

func NewSymbols

func NewSymbols(bs ByteSlice, version, off int) (*Symbols, error)

NewSymbols returns a Symbols object for symbol lookups.

func (Symbols) Iter

func (s Symbols) Iter() StringIter

func (Symbols) Lookup

func (s Symbols) Lookup(o uint32) (string, error)

func (Symbols) ReverseLookup

func (s Symbols) ReverseLookup(sym string) (uint32, error)

func (Symbols) Size

func (s Symbols) Size() int

type TOC

type TOC struct {
	Symbols            uint64
	Series             uint64
	LabelIndices       uint64
	LabelIndicesTable  uint64
	Postings           uint64
	PostingsTable      uint64
	FingerprintOffsets uint64
	Metadata           Metadata
}

TOC represents index Table Of Content that states where each section of index starts.

func NewTOCFromByteSlice

func NewTOCFromByteSlice(bs ByteSlice) (*TOC, error)

NewTOCFromByteSlice return parsed TOC from given index byte slice.

type Writer

type Writer struct {
	Version int
	// contains filtered or unexported fields
}

Writer implements the IndexWriter interface for the standard serialization format.

func NewWriter

func NewWriter(ctx context.Context, bufferSize int) (*Writer, error)

NewWriter returns a new Writer to the given filename. It serializes data in format version 2.

func (*Writer) AddSeries

func (w *Writer) AddSeries(ref storage.SeriesRef, lset phlaremodel.Labels, fp model.Fingerprint, chunks ...index.ChunkMeta) error

AddSeries adds the series one at a time along with its chunks. Requires a specific fingerprint to be passed in the case where the "desired" fingerprint differs from what labels.Hash() produces. For example, multitenant TSDBs embed a tenant label, but the actual series has no such label and so the derived fingerprint differs.

func (*Writer) AddSymbol

func (w *Writer) AddSymbol(sym string) error

func (*Writer) Close

func (w *Writer) Close() error

func (*Writer) ReleaseIndex

func (w *Writer) ReleaseIndex() []byte

todo better name, nicer api

func (*Writer) ReleaseIndexBuffer

func (w *Writer) ReleaseIndexBuffer() *BufferWriter

todo better name, nicer api

Jump to

Keyboard shortcuts

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