tsdb: github.com/prometheus/tsdb/index Index | Files

package index

import "github.com/prometheus/tsdb/index"

Index

Package Files

index.go postings.go

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
)

func AllPostingsKey Uses

func AllPostingsKey() (name, value string)

AllPostingsKey returns the label key that is used to store the postings list of all existing IDs.

func ExpandPostings Uses

func ExpandPostings(p Postings) (res []uint64, err error)

ExpandPostings returns the postings expanded as a slice.

func NewStringTuples Uses

func NewStringTuples(entries []string, length int) (*stringTuples, error)

func ReadOffsetTable Uses

func ReadOffsetTable(bs ByteSlice, off uint64, f func([]string, uint64) 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.

func ReadSymbols Uses

func ReadSymbols(bs ByteSlice, version int, off int) ([]string, map[uint32]string, error)

ReadSymbols reads the symbol table fully into memory and allocates proper strings for them. Strings backed by the mmap'd memory would cause memory faults if applications keep using them after the reader is closed.

type ByteSlice Uses

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

ByteSlice abstracts a byte slice.

type Decoder Uses

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) Postings Uses

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

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

func (*Decoder) Series Uses

func (dec *Decoder) Series(b []byte, lbls *labels.Labels, chks *[]chunks.Meta) error

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

type ListPostings Uses

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

ListPostings implements the Postings interface over a plain list.

func (*ListPostings) At Uses

func (it *ListPostings) At() uint64

func (*ListPostings) Err Uses

func (it *ListPostings) Err() error

func (*ListPostings) Next Uses

func (it *ListPostings) Next() bool

func (*ListPostings) Seek Uses

func (it *ListPostings) Seek(x uint64) bool

type MemPostings Uses

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 Uses

func NewMemPostings() *MemPostings

NewMemPostings returns a memPostings that's ready for reads and writes.

func NewUnorderedMemPostings Uses

func NewUnorderedMemPostings() *MemPostings

NewUnorderedMemPostings returns a memPostings that is not safe to be read from until ensureOrder was called once.

func (*MemPostings) Add Uses

func (p *MemPostings) Add(id uint64, lset labels.Labels)

Add a label set to the postings index.

func (*MemPostings) All Uses

func (p *MemPostings) All() Postings

All returns a postings list over all documents ever added.

func (*MemPostings) Delete Uses

func (p *MemPostings) Delete(deleted map[uint64]struct{})

Delete removes all ids in the given map from the postings lists.

func (*MemPostings) EnsureOrder Uses

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 Uses

func (p *MemPostings) Get(name, value string) Postings

Get returns a postings list for the given label pair.

func (*MemPostings) Iter Uses

func (p *MemPostings) Iter(f func(labels.Label, Postings) error) error

Iter calls f for each postings list. It aborts if f returns an error and returns it.

func (*MemPostings) SortedKeys Uses

func (p *MemPostings) SortedKeys() []labels.Label

SortedKeys returns a list of sorted label keys of the postings.

type Postings Uses

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 uint64) bool

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

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

Postings provides iterative access over a postings list.

func EmptyPostings Uses

func EmptyPostings() Postings

EmptyPostings returns a postings list that's always empty. NOTE: Returning EmptyPostings sentinel when index.Postings struct has no postings is recommended. It triggers optimized flow in other functions like Intersect, Without etc.

func ErrPostings Uses

func ErrPostings(err error) Postings

ErrPostings returns new postings that immediately error.

func Intersect Uses

func Intersect(its ...Postings) Postings

Intersect returns a new postings list over the intersection of the input postings.

func Merge Uses

func Merge(its ...Postings) Postings

Merge returns a new iterator over the union of the input iterators.

func NewListPostings Uses

func NewListPostings(list []uint64) Postings

func Without Uses

func Without(full, drop Postings) Postings

Without returns a new postings list that contains all elements from the full list that are not in the drop list.

type Range Uses

type Range struct {
    Start, End int64
}

Range marks a byte range.

type Reader Uses

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

func NewFileReader Uses

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

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

func NewReader Uses

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) Close Uses

func (r *Reader) Close() error

Close the reader and its underlying resources.

func (*Reader) LabelIndices Uses

func (r *Reader) LabelIndices() ([][]string, error)

LabelIndices returns a slice of label names for which labels or label tuples value indices exist. NOTE: This is deprecated. Use `LabelNames()` instead.

func (*Reader) LabelNames Uses

func (r *Reader) LabelNames() ([]string, error)

LabelNames returns all the unique label names present in the index.

func (*Reader) LabelValues Uses

func (r *Reader) LabelValues(names ...string) (StringTuples, error)

LabelValues returns value tuples that exist for the given label name tuples.

func (*Reader) Postings Uses

func (r *Reader) Postings(name, value string) (Postings, error)

Postings returns a postings list for the given label pair.

func (*Reader) PostingsRanges Uses

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 Uses

func (r *Reader) Series(id uint64, lbls *labels.Labels, chks *[]chunks.Meta) error

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

func (*Reader) Size Uses

func (r *Reader) Size() int64

Size returns the size of an index file.

func (*Reader) SortedPostings Uses

func (r *Reader) SortedPostings(p Postings) Postings

SortedPostings returns the given postings list reordered so that the backing series are sorted.

func (*Reader) SymbolTableSize Uses

func (r *Reader) SymbolTableSize() uint64

SymbolTableSize returns the symbol table size in bytes.

func (*Reader) Symbols Uses

func (r *Reader) Symbols() (map[string]struct{}, error)

Symbols returns a set of symbols that exist within the index.

func (*Reader) Version Uses

func (r *Reader) Version() int

Version returns the file format version of the underlying index.

type StringTuples Uses

type StringTuples interface {
    // Total number of tuples in the list.
    Len() int
    // At returns the tuple at position i.
    At(i int) ([]string, error)
}

StringTuples provides access to a sorted list of string tuples.

type TOC Uses

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 Uses

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

NewTOCFromByteSlice return parsed TOC from given index byte slice.

type Writer Uses

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

Writer implements the IndexWriter interface for the standard serialization format.

func NewWriter Uses

func NewWriter(fn string) (*Writer, error)

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

func (*Writer) AddSeries Uses

func (w *Writer) AddSeries(ref uint64, lset labels.Labels, chunks ...chunks.Meta) error

AddSeries adds the series one at a time along with its chunks.

func (*Writer) AddSymbols Uses

func (w *Writer) AddSymbols(sym map[string]struct{}) error

func (*Writer) Close Uses

func (w *Writer) Close() error

func (*Writer) WriteLabelIndex Uses

func (w *Writer) WriteLabelIndex(names []string, values []string) error

func (*Writer) WritePostings Uses

func (w *Writer) WritePostings(name, value string, it Postings) error

Package index imports 20 packages (graph) and is imported by 5 packages. Updated 2019-07-21. Refresh now. Tools for package owners.