Documentation ¶
Index ¶
- Constants
- func AllPostingsKey() (name, value string)
- func ExpandPostings(p Postings) (res []storage.SeriesRef, err error)
- func FindIntersectingPostings(p Postings, candidates []Postings) (indexes []int, err error)
- func IsEmptyPostingsType(p Postings) bool
- func ReadPostingsOffsetTable(bs ByteSlice, off uint64, ...) error
- type ByteSlice
- type Decoder
- func (dec *Decoder) LabelNamesOffsetsFor(b []byte) ([]uint32, error)
- func (dec *Decoder) LabelValueFor(b []byte, label string) (string, error)
- func (dec *Decoder) Postings(b []byte) (int, Postings, error)
- func (dec *Decoder) Series(b []byte, builder *labels.ScratchBuilder, chks *[]chunks.Meta) error
- type FileWriter
- func (fw *FileWriter) AddPadding(size int) error
- func (fw *FileWriter) Close() error
- func (fw *FileWriter) Flush() error
- func (fw *FileWriter) Pos() uint64
- func (fw *FileWriter) Remove() error
- func (fw *FileWriter) Write(bufs ...[]byte) error
- func (fw *FileWriter) WriteAt(buf []byte, pos uint64) error
- type ListPostings
- type MemPostings
- func (p *MemPostings) Add(id storage.SeriesRef, lset labels.Labels)
- func (p *MemPostings) All() Postings
- func (p *MemPostings) Delete(deleted map[storage.SeriesRef]struct{})
- func (p *MemPostings) EnsureOrder()
- func (p *MemPostings) Get(name, value string) Postings
- func (p *MemPostings) Iter(f func(labels.Label, Postings) error) error
- func (p *MemPostings) LabelNames() []string
- func (p *MemPostings) LabelValues(name string) []string
- func (p *MemPostings) SortedKeys() []labels.Label
- func (p *MemPostings) Stats(label string) *PostingsStats
- func (p *MemPostings) Symbols() StringIter
- type Postings
- type PostingsStats
- type Range
- type Reader
- func (r *Reader) Close() error
- func (r *Reader) LabelNames(matchers ...*labels.Matcher) ([]string, error)
- func (r *Reader) LabelNamesFor(ids ...storage.SeriesRef) ([]string, error)
- func (r *Reader) LabelValueFor(id storage.SeriesRef, label string) (string, error)
- func (r *Reader) LabelValues(name string, matchers ...*labels.Matcher) ([]string, error)
- func (r *Reader) Postings(name string, values ...string) (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) Size() int64
- func (r *Reader) SortedLabelValues(name string, matchers ...*labels.Matcher) ([]string, error)
- func (r *Reader) SortedPostings(p Postings) Postings
- func (r *Reader) SymbolTableSize() uint64
- func (r *Reader) Symbols() StringIter
- func (r *Reader) Version() int
- type Stat
- 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 )
Variables ¶
This section is empty.
Functions ¶
func AllPostingsKey ¶
func AllPostingsKey() (name, value string)
AllPostingsKey returns the label key that is used to store the postings list of all existing IDs.
func ExpandPostings ¶
ExpandPostings returns the postings expanded as a slice.
func FindIntersectingPostings ¶
FindIntersectingPostings checks the intersection of p and candidates[i] for each i in candidates, if intersection is non empty, then i is added to the indexes returned. Returned indexes are not sorted.
func IsEmptyPostingsType ¶
IsEmptyPostingsType returns true if the postings are an empty postings list. When this function returns false, it doesn't mean that the postings isn't empty (it could be an empty intersection of two non-empty postings, for example).
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 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.
type FileWriter ¶
type FileWriter struct {
// contains filtered or unexported fields
}
func NewFileWriter ¶
func NewFileWriter(name string) (*FileWriter, error)
func (*FileWriter) AddPadding ¶
func (fw *FileWriter) AddPadding(size int) error
AddPadding adds zero byte padding until the file size is a multiple size.
func (*FileWriter) Close ¶
func (fw *FileWriter) Close() error
func (*FileWriter) Flush ¶
func (fw *FileWriter) Flush() error
func (*FileWriter) Pos ¶
func (fw *FileWriter) Pos() uint64
func (*FileWriter) Remove ¶
func (fw *FileWriter) Remove() error
func (*FileWriter) Write ¶
func (fw *FileWriter) Write(bufs ...[]byte) error
type ListPostings ¶
type ListPostings struct {
// contains filtered or unexported fields
}
ListPostings implements the Postings interface over a plain list.
func (*ListPostings) At ¶
func (it *ListPostings) At() storage.SeriesRef
func (*ListPostings) Err ¶
func (it *ListPostings) Err() error
func (*ListPostings) Next ¶
func (it *ListPostings) Next() bool
type MemPostings ¶
type MemPostings struct {
// contains filtered or unexported fields
}
MemPostings holds postings list for series ID per label pair. They may be written to out of order. EnsureOrder() must be called once before any reads are done. This allows for quick unordered batch fills on startup.
func NewMemPostings ¶
func NewMemPostings() *MemPostings
NewMemPostings returns a memPostings that's ready for reads and writes.
func NewUnorderedMemPostings ¶
func NewUnorderedMemPostings() *MemPostings
NewUnorderedMemPostings returns a memPostings that is not safe to be read from until EnsureOrder() was called once.
func (*MemPostings) Add ¶
func (p *MemPostings) Add(id storage.SeriesRef, lset labels.Labels)
Add a label set to the postings index.
func (*MemPostings) All ¶
func (p *MemPostings) All() Postings
All returns a postings list over all documents ever added.
func (*MemPostings) Delete ¶
func (p *MemPostings) Delete(deleted map[storage.SeriesRef]struct{})
Delete removes all ids in the given map from the postings lists.
func (*MemPostings) EnsureOrder ¶
func (p *MemPostings) EnsureOrder()
EnsureOrder ensures that all postings lists are sorted. After it returns all further calls to add and addFor will insert new IDs in a sorted manner.
func (*MemPostings) Get ¶
func (p *MemPostings) Get(name, value string) Postings
Get returns a postings list for the given label pair.
func (*MemPostings) Iter ¶
Iter calls f for each postings list. It aborts if f returns an error and returns it.
func (*MemPostings) LabelNames ¶
func (p *MemPostings) LabelNames() []string
LabelNames returns all the unique label names.
func (*MemPostings) LabelValues ¶
func (p *MemPostings) LabelValues(name string) []string
LabelValues returns label values for the given name.
func (*MemPostings) SortedKeys ¶
func (p *MemPostings) SortedKeys() []labels.Label
SortedKeys returns a list of sorted label keys of the postings.
func (*MemPostings) Stats ¶
func (p *MemPostings) Stats(label string) *PostingsStats
Stats calculates the cardinality statistics from postings.
func (*MemPostings) Symbols ¶
func (p *MemPostings) Symbols() StringIter
Symbols returns an iterator over all unique name and value strings, in order.
type Postings ¶
type Postings interface { // Next advances the iterator and returns true if another value was found. Next() bool // Seek advances the iterator to value v or greater and returns // true if a value was found. Seek(v storage.SeriesRef) bool // At returns the value at the current iterator position. At() storage.SeriesRef // Err returns the last error of the iterator. Err() error }
Postings provides iterative access over a postings list.
func EmptyPostings ¶
func EmptyPostings() Postings
EmptyPostings returns a postings list that's always empty. NOTE: Returning EmptyPostings sentinel when Postings struct has no postings is recommended. It triggers optimized flow in other functions like Intersect, Without etc.
func ErrPostings ¶
ErrPostings returns new postings that immediately error.
func NewListPostings ¶
type PostingsStats ¶
type PostingsStats struct { CardinalityMetricsStats []Stat CardinalityLabelStats []Stat LabelValueStats []Stat LabelValuePairsStats []Stat NumLabelPairs int }
PostingsStats contains cardinality based statistics for postings.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
func NewFileReader ¶
NewFileReader returns a new index reader against the given index file.
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 ¶
LabelValueFor returns label value for the given label name in the series referred to by ID.
func (*Reader) LabelValues ¶
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) 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) SortedLabelValues ¶
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 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.
func NewStringListIter ¶
func NewStringListIter(s []string) StringIter
NewStringListIter returns a StringIter for the given 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 index Table Of Content that states where each section of index starts.
func NewTOCFromByteSlice ¶
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 ¶
NewWriter returns a new Writer to the given filename. It serializes data in format version 2.