batch

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyEmpty           = errors.New("key cannot be empty")
	ErrBatchClosed        = errors.New("batch closed")
	ErrValueTooLarge      = errors.New("value exceeds inline threshold; use SetPointer")
	ErrMissingValueReader = errors.New("value reader unavailable")
)

Functions

func Release

func Release(b *Batch)

Release resets and returns the batch to the pool.

Types

type Batch

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

Batch accumulates writes and deletes before committing them.

func Acquire

func Acquire(reader ValueReader, threshold int) *Batch

Acquire returns a reusable Batch from the pool.

func New

func New(reader ValueReader, threshold int) *Batch

New creates a new Batch.

func (*Batch) AppendPointerViewNoTouchTrustedSorted added in v0.4.0

func (b *Batch) AppendPointerViewNoTouchTrustedSorted(key []byte, ptr page.ValuePtr)

AppendPointerViewNoTouchTrustedSorted appends a pointer Put without input validation, touched-segment tracking, or key-order checks. Caller must guarantee: batch is open, key is non-empty, ptr is a value-log pointer, and appended keys are already non-decreasing.

func (*Batch) ByteSize

func (b *Batch) ByteSize() int

ByteSize returns the approximate size of the batch.

func (*Batch) Close

func (b *Batch) Close() error

Close returns the batch to the pool.

func (*Batch) Delete

func (b *Batch) Delete(key []byte) error

Delete adds or replaces a delete operation.

func (*Batch) DeleteView

func (b *Batch) DeleteView(key []byte) error

DeleteView is an internal-performance helper that records a Delete without copying the key bytes. Callers must treat key as immutable until the batch is committed (Write/WriteSync) or closed.

func (*Batch) EntriesCap added in v0.4.0

func (b *Batch) EntriesCap() int

EntriesCap returns the current capacity of the internal entry buffer.

func (*Batch) HasValueLogPointers added in v0.4.0

func (b *Batch) HasValueLogPointers() bool

HasValueLogPointers reports whether this batch contains any value-log pointer operations.

func (*Batch) NoteTouchedValueLogFileID added in v0.4.0

func (b *Batch) NoteTouchedValueLogFileID(fileID uint32)

NoteTouchedValueLogFileID is an internal helper that records a touched value-log segment without appending a batch entry.

func (*Batch) Ops

func (b *Batch) Ops() map[string]Entry

Ops returns the map of operations. WARNING: This constructs the map on demand. Duplicate keys in the batch are resolved so the last one wins.

func (*Batch) Replay

func (b *Batch) Replay(fn func(Entry) error) error

Replay iterates over the batch entries.

func (*Batch) Reserve added in v0.2.0

func (b *Batch) Reserve(n int)

Reserve grows internal buffers to accommodate roughly n entries without reallocation. It is intended as a best-effort performance hint for high-throughput internal callers (e.g. flush).

func (*Batch) Reset

func (b *Batch) Reset()

Reset clears the batch for reuse without releasing its internal buffers.

func (*Batch) Set

func (b *Batch) Set(key, value []byte) error

Set adds or replaces a key/value operation.

func (*Batch) SetInlineThresholdResolver added in v0.4.0

func (b *Batch) SetInlineThresholdResolver(resolver func([]byte) int)

SetInlineThresholdResolver installs an optional per-key threshold resolver used by Set/SetView/SetOps inline-size checks.

func (*Batch) SetOps

func (b *Batch) SetOps(ops []Entry) error

SetOps merges a slice of operations into the batch.

func (*Batch) SetPointer

func (b *Batch) SetPointer(key []byte, ptr page.ValuePtr) error

SetPointer adds a pointer directly to the batch (used by Compaction).

func (*Batch) SetPointerView added in v0.2.0

func (b *Batch) SetPointerView(key []byte, ptr page.ValuePtr) error

SetPointerView is an internal-performance helper that records a pointer Put without copying the key bytes. Callers must treat key as immutable until the batch is committed (Write/WriteSync) or closed.

This is intentionally not part of the public batch.Interface; it is a best-effort optimization used by higher-level layers (e.g. cached flush streaming).

func (*Batch) SetPointerViewNoTouch added in v0.4.0

func (b *Batch) SetPointerViewNoTouch(key []byte, ptr page.ValuePtr) error

SetPointerViewNoTouch is an internal-performance helper that records a pointer Put without copying key bytes and without tracking touched value-log segments. Callers must separately provide touched segment hints when commit publication needs them.

func (*Batch) SetView

func (b *Batch) SetView(key, value []byte) error

SetView is an internal-performance helper that records a Put without copying key/value bytes. Callers must treat key/value as immutable until the batch is committed (Write/WriteSync) or closed.

func (*Batch) SortedEntries

func (b *Batch) SortedEntries() []Entry

SortedEntries returns the operations sorted by key. Duplicate keys are resolved (last write wins). This modifies the internal entries slice (sorts and compacts).

func (*Batch) TouchedValueLogSegments added in v0.4.0

func (b *Batch) TouchedValueLogSegments() []uint32

TouchedValueLogSegments reports the value-log segments that were touched by pointer puts in this batch. The returned slice is sorted for deterministic commit/publish behavior.

In the small-set fast path, the returned slice aliases internal batch storage and remains valid only until the batch is mutated, reset, or released. Callers must treat the result as read-only.

type Entry

type Entry struct {
	Type     OpType
	Key      []byte
	Value    []byte        // For inline values
	ValuePtr page.ValuePtr // For large values
	IsPtr    bool          // True if ValuePtr is valid
}

Entry represents a single operation in the batch.

type Interface

type Interface interface {
	Set(key, value []byte) error
	Delete(key []byte) error
	SetOps(ops []Entry) error
	Write() error
	WriteSync() error
	Close() error
	Replay(func(Entry) error) error
	GetByteSize() (int, error)
}

Interface defines the contract for a batch operation.

type OpType

type OpType uint8

OpType represents the type of operation (Put or Delete).

const (
	OpPut OpType = iota
	OpDelete
)

type ValueReader added in v0.3.0

type ValueReader interface {
	Read(ptr page.ValuePtr) ([]byte, error)
	ReadUnsafe(ptr page.ValuePtr) ([]byte, error)
}

ValueReader resolves value pointers for Replay callers that require full values.

Jump to

Keyboard shortcuts

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