Documentation ¶
Index ¶
- Constants
- Variables
- func EncodePostingsRaw(e *encoding.Encbuf, offs []uint32) error
- func ReadPostingsOffsetTable(bs ByteSlice, off uint64, ...) error
- type BufferWriter
- func (fw *BufferWriter) AddPadding(size int) error
- func (fw *BufferWriter) Buffer() ([]byte, io.Closer, error)
- func (fw *BufferWriter) Close() error
- func (fw *BufferWriter) Flush() error
- func (fw *BufferWriter) Pos() uint64
- func (fw *BufferWriter) Read(buf []byte) (int, error)
- func (fw *BufferWriter) ReadFrom(r io.Reader) (int64, error)
- func (fw *BufferWriter) Remove() error
- func (fw *BufferWriter) Reset()
- func (fw *BufferWriter) Write(bufs ...[]byte) error
- func (fw *BufferWriter) WriteAt(buf []byte, pos uint64) error
- type ByteSlice
- type Decoder
- func (dec *Decoder) LabelNamesOffsetsFor(b []byte) ([]uint32, error)
- func (dec *Decoder) LabelValueFor(ctx context.Context, b []byte, label string) (string, error)
- func (dec *Decoder) Postings(b []byte) (int, index.Postings, error)
- func (dec *Decoder) PostingsFromDecbuf(d encoding.Decbuf) (int, index.Postings, error)
- func (dec *Decoder) Series(b []byte, builder *labels.ScratchBuilder, chks *[]chunks.Meta) error
- type PostingsEncoder
- type Range
- type Reader
- func (r *Reader) Close() error
- func (r *Reader) LabelNames(_ context.Context, matchers ...*labels.Matcher) ([]string, error)
- func (r *Reader) LabelNamesFor(ctx context.Context, ids ...storage.SeriesRef) ([]string, error)
- func (r *Reader) LabelValueFor(ctx context.Context, id storage.SeriesRef, label string) (string, error)
- func (r *Reader) LabelValues(ctx context.Context, name string, matchers ...*labels.Matcher) ([]string, error)
- func (r *Reader) Postings(ctx context.Context, name string, values ...string) (index.Postings, error)
- func (r *Reader) PostingsForLabelMatching(ctx context.Context, name string, match func(string) bool) index.Postings
- func (r *Reader) PostingsForMatchers(ctx context.Context, ms ...*labels.Matcher) (index.Postings, error)
- func (r *Reader) PostingsRanges() (map[labels.Label]Range, error)
- func (r *Reader) Series(id storage.SeriesRef, builder *labels.ScratchBuilder, chks *[]chunks.Meta) error
- func (r *Reader) ShardedPostings(p index.Postings, shardIndex, shardCount uint64) index.Postings
- func (r *Reader) Size() int64
- func (r *Reader) SortedLabelValues(ctx context.Context, name string, matchers ...*labels.Matcher) ([]string, error)
- func (r *Reader) SortedPostings(p index.Postings) index.Postings
- func (r *Reader) SymbolTableSize() uint64
- func (r *Reader) Symbols() StringIter
- func (r *Reader) Version() int
- type RealByteSlice
- type StringIter
- type Symbols
- type TOC
- type Writer
Constants ¶
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 TenantLabel = "__loki_tenant__" )
Variables ¶
var AllPostingsKey = labels.Label{}
Functions ¶
func EncodePostingsRaw ¶
EncodePostingsRaw uses the "basic" postings list encoding format with no compression: <BE uint32 len X><BE uint32 0><BE uint32 1>...<BE uint32 X-1>.
func ReadPostingsOffsetTable ¶
func ReadPostingsOffsetTable(bs ByteSlice, off uint64, f func(name, value []byte, postingsOffset uint64, labelOffset int) error) error
ReadPostingsOffsetTable reads the postings offset table and at the given position calls f for each found entry. The name and value parameters passed to f reuse the backing memory of the underlying byte slice, so they shouldn't be persisted without previously copying them. 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 NewBufferWriter ¶
func NewBufferWriter() *BufferWriter
NewBufferWriter returns a new BufferWriter. todo: pooling memory
func (*BufferWriter) AddPadding ¶
func (fw *BufferWriter) AddPadding(size int) 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) Remove ¶
func (fw *BufferWriter) Remove() error
func (*BufferWriter) Reset ¶
func (fw *BufferWriter) Reset()
func (*BufferWriter) Write ¶
func (fw *BufferWriter) Write(bufs ...[]byte) error
type Decoder ¶
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 ¶
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 ¶
LabelValueFor decodes a label for a given series.
func (*Decoder) PostingsFromDecbuf ¶
PostingsFromDecbuf returns a postings list for d and its number of elements.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
func NewReader ¶
NewReader returns a new index reader on the given byte slice. It automatically handles different format versions.
func (*Reader) LabelNames ¶
LabelNames returns all the unique label names present in the index. TODO(twilkie) implement support for matchers.
func (*Reader) LabelNamesFor ¶
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(ctx context.Context, 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(ctx context.Context, 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) PostingsForLabelMatching ¶
func (*Reader) PostingsForMatchers ¶
func (r *Reader) PostingsForMatchers(ctx context.Context, ms ...*labels.Matcher) (index.Postings, error)
PostingsForMatchers assembles a single postings iterator against the index reader based on the given matchers. The resulting postings are not ordered by series.
func (*Reader) PostingsRanges ¶
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, builder *labels.ScratchBuilder, chks *[]chunks.Meta) error
Series reads the series with the given ID and writes its labels and chunks into builder and chks.
func (*Reader) ShardedPostings ¶
ShardedPostings returns a postings list filtered by the provided shardIndex out of shardCount.
func (*Reader) SortedLabelValues ¶
func (r *Reader) SortedLabelValues(ctx context.Context, 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) SortedPostings ¶
SortedPostings returns the given postings list reordered so that the backing series are sorted.
func (*Reader) SymbolTableSize ¶
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.
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 ¶
NewSymbols returns a Symbols object for symbol lookups.
func (Symbols) Iter ¶
func (s Symbols) Iter() StringIter
type TOC ¶
type TOC struct { Symbols uint64 Series uint64 LabelIndices uint64 LabelIndicesTable uint64 Postings uint64 PostingsTable uint64 }
TOC represents the index Table Of Contents that states where each section of the index starts.
func NewTOCFromByteSlice ¶
NewTOCFromByteSlice returns a parsed TOC from the 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 ¶
NewWriter creates a new index writer using the default encoder. See NewWriterWithEncoder.
func NewWriterWithEncoder ¶
func NewWriterWithEncoder(encoder PostingsEncoder) (*Writer, error)
NewWriter returns a new Writer to the given filename. It serializes data in format version 2. It uses the given encoder to encode each postings list.