batchrepr

package
v2.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2025 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package batchrepr provides interfaces for reading and writing the binary batch representation. This batch representation is used in-memory while constructing a batch and on-disk within the write-ahead log.

Index

Constants

View Source
const (
	// HeaderLen is the length of the batch header in bytes.
	HeaderLen = 12
)

Variables

View Source
var ErrInvalidBatch = base.MarkCorruptionError(errors.New("pebble: invalid batch"))

ErrInvalidBatch indicates that a batch is invalid or otherwise corrupted.

Functions

func DecodeStr

func DecodeStr(data []byte) (odata []byte, s []byte, ok bool)

DecodeStr decodes a varint encoded string from data, returning the remainder of data and the decoded string. It returns ok=false if the varint is invalid.

TODO(jackson): This should be unexported once pebble package callers have been updated to use appropriate abstractions.

func IsEmpty

func IsEmpty(repr []byte) bool

IsEmpty returns true iff the batch contains zero keys.

func ReadSeqNum

func ReadSeqNum(repr []byte) base.SeqNum

ReadSeqNum reads the sequence number encoded within the batch. ReadSeqNum does not validate that the repr is valid. It's exported only for very performance sensitive code paths that should not necessarily read the rest of the header as well.

func SetCount

func SetCount(repr []byte, count uint32)

SetCount mutates the provided batch representation, storing the provided count in its header. The provided byte slice must already be at least HeaderLen bytes long or else SetCount will panic.

func SetSeqNum

func SetSeqNum(repr []byte, seqNum base.SeqNum)

SetSeqNum mutates the provided batch representation, storing the provided sequence number in its header. The provided byte slice must already be at least HeaderLen bytes long or else SetSeqNum will panic.

Types

type Header struct {
	// SeqNum is the sequence number at which the batch is committed. A batch
	// that has not yet committed will have a zero sequence number.
	SeqNum base.SeqNum
	// Count is the count of keys written to the batch.
	Count uint32
}

Header describes the contents of a batch header.

func ReadHeader

func ReadHeader(repr []byte) (h Header, ok bool)

ReadHeader reads the contents of the batch header. If the repr is too small to contain a valid batch header, ReadHeader returns ok=false.

func (Header) String

func (h Header) String() string

String returns a string representation of the header's contents.

type Reader

type Reader []byte

Reader iterates over the entries contained in a batch.

func Read

func Read(repr []byte) (r Reader)

Read constructs a Reader from an encoded batch representation, ignoring the contents of the Header.

func (*Reader) Next

func (r *Reader) Next() (kind base.InternalKeyKind, ukey []byte, value []byte, ok bool, err error)

Next returns the next entry in this batch, if there is one. If the reader has reached the end of the batch, Next returns ok=false and a nil error. If the batch is corrupt and the next entry is illegible, Next returns ok=false and a non-nil error.

Jump to

Keyboard shortcuts

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