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

package wal

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

Index

Package Files

live_reader.go reader.go wal.go

Constants

const (
    DefaultSegmentSize = 128 * 1024 * 1024 // 128 MB

)

func NewLiveReaderMetrics Uses

func NewLiveReaderMetrics(reg prometheus.Registerer) *liveReaderMetrics

LiveReaderMetrics instatiates, registers and returns metrics to be injected at LiveReader instantiation.

func NewSegmentBufReader Uses

func NewSegmentBufReader(segs ...*Segment) *segmentBufReader

func NewSegmentsRangeReader Uses

func NewSegmentsRangeReader(sr ...SegmentRange) (io.ReadCloser, error)

NewSegmentsRangeReader returns a new reader over the given WAL segment ranges. If first or last are -1, the range is open on the respective end.

func NewSegmentsReader Uses

func NewSegmentsReader(dir string) (io.ReadCloser, error)

NewSegmentsReader returns a new reader over all segments in the directory.

func SegmentName Uses

func SegmentName(dir string, i int) string

SegmentName builds a segment name for the directory.

type CorruptionErr Uses

type CorruptionErr struct {
    Dir     string
    Segment int
    Offset  int64
    Err     error
}

CorruptionErr is an error that's returned when corruption is encountered.

func (*CorruptionErr) Error Uses

func (e *CorruptionErr) Error() string

type LiveReader Uses

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

LiveReader reads WAL records from an io.Reader. It allows reading of WALs that are still in the process of being written, and returns records as soon as they can be read.

func NewLiveReader Uses

func NewLiveReader(logger log.Logger, metrics *liveReaderMetrics, r io.Reader) *LiveReader

NewLiveReader returns a new live reader.

func (*LiveReader) Err Uses

func (r *LiveReader) Err() error

Err returns any errors encountered reading the WAL. io.EOFs are not terminal and Next can be tried again. Non-EOFs are terminal, and the reader should not be used again. It is up to the user to decide when to stop trying should io.EOF be returned.

func (*LiveReader) Next Uses

func (r *LiveReader) Next() bool

Next returns true if Record() will contain a full record. If Next returns false, you should always checked the contents of Error(). Return false guarantees there are no more records if the segment is closed and not corrupt, otherwise if Err() == io.EOF you should try again when more data has been written.

func (*LiveReader) Offset Uses

func (r *LiveReader) Offset() int64

Offset returns the number of bytes consumed from this segment.

func (*LiveReader) Record Uses

func (r *LiveReader) Record() []byte

Record returns the current record. The returned byte slice is only valid until the next call to Next.

type Reader Uses

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

Reader reads WAL records from an io.Reader.

func NewReader Uses

func NewReader(r io.Reader) *Reader

NewReader returns a new reader.

func (*Reader) Err Uses

func (r *Reader) Err() error

Err returns the last encountered error wrapped in a corruption error. If the reader does not allow to infer a segment index and offset, a total offset in the reader stream will be provided.

func (*Reader) Next Uses

func (r *Reader) Next() bool

Next advances the reader to the next records and returns true if it exists. It must not be called again after it returned false.

func (*Reader) Offset Uses

func (r *Reader) Offset() int64

Offset returns the current position of the segment being read.

func (*Reader) Record Uses

func (r *Reader) Record() []byte

Record returns the current record. The returned byte slice is only valid until the next call to Next.

func (*Reader) Segment Uses

func (r *Reader) Segment() int

Segment returns the current segment being read.

type Segment Uses

type Segment struct {
    *os.File
    // contains filtered or unexported fields
}

Segment represents a segment file.

func CreateSegment Uses

func CreateSegment(dir string, k int) (*Segment, error)

CreateSegment creates a new segment k in dir.

func OpenReadSegment Uses

func OpenReadSegment(fn string) (*Segment, error)

OpenReadSegment opens the segment with the given filename.

func OpenWriteSegment Uses

func OpenWriteSegment(logger log.Logger, dir string, k int) (*Segment, error)

OpenWriteSegment opens segment k in dir. The returned segment is ready for new appends.

func (*Segment) Dir Uses

func (s *Segment) Dir() string

Dir returns the directory of the segment.

func (*Segment) Index Uses

func (s *Segment) Index() int

Index returns the index of the segment.

type SegmentRange Uses

type SegmentRange struct {
    Dir         string
    First, Last int
}

SegmentRange groups segments by the directory and the first and last index it includes.

type WAL Uses

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

WAL is a write ahead log that stores records in segment files. It must be read from start to end once before logging new data. If an error occurs during read, the repair procedure must be called before it's safe to do further writes.

Segments are written to in pages of 32KB, with records possibly split across page boundaries. Records are never split across segments to allow full segments to be safely truncated. It also ensures that torn writes never corrupt records beyond the most recent segment.

func New Uses

func New(logger log.Logger, reg prometheus.Registerer, dir string, compress bool) (*WAL, error)

New returns a new WAL over the given directory.

func NewSize Uses

func NewSize(logger log.Logger, reg prometheus.Registerer, dir string, segmentSize int, compress bool) (*WAL, error)

NewSize returns a new WAL over the given directory. New segments are created with the specified size.

func Open Uses

func Open(logger log.Logger, reg prometheus.Registerer, dir string) (*WAL, error)

Open an existing WAL.

func (*WAL) Close Uses

func (w *WAL) Close() (err error)

Close flushes all writes and closes active segment.

func (*WAL) CompressionEnabled Uses

func (w *WAL) CompressionEnabled() bool

CompressionEnabled returns if compression is enabled on this WAL.

func (*WAL) Dir Uses

func (w *WAL) Dir() string

Dir returns the directory of the WAL.

func (*WAL) Log Uses

func (w *WAL) Log(recs ...[]byte) error

Log writes the records into the log. Multiple records can be passed at once to reduce writes and increase throughput.

func (*WAL) NextSegment Uses

func (w *WAL) NextSegment() error

NextSegment creates the next segment and closes the previous one.

func (*WAL) Repair Uses

func (w *WAL) Repair(origErr error) error

Repair attempts to repair the WAL based on the error. It discards all data after the corruption.

func (*WAL) Segments Uses

func (w *WAL) Segments() (first, last int, err error)

Segments returns the range [first, n] of currently existing segments. If no segments are found, first and n are -1.

func (*WAL) Truncate Uses

func (w *WAL) Truncate(i int) (err error)

Truncate drops all segments before i.

Package wal imports 17 packages (graph) and is imported by 8 packages. Updated 2019-08-06. Refresh now. Tools for package owners.