batch

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 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")
)

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(sm *slab.SlabManager, threshold int) *Batch

Acquire returns a reusable Batch from the pool.

func New

func New(sm *slab.SlabManager, threshold int) *Batch

New creates a new Batch.

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) 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) 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) 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) 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) SlabWriteBytes

func (b *Batch) SlabWriteBytes() int

SlabWriteBytes returns the number of bytes written to the slab file.

func (*Batch) SlabWriteBytesByFile

func (b *Batch) SlabWriteBytesByFile() map[uint32]int64

SlabWriteBytesByFile returns a per-slab breakdown of bytes appended during this batch. The returned map must be treated as read-only by callers.

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).

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
)

Jump to

Keyboard shortcuts

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