spill

package
v0.0.0-...-5bdcda0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package spill provides a memory-mapped spill buffer for dirty pages.

Index

Constants

View Source
const DefaultInitialCap = 1024

DefaultInitialCap is the default initial capacity (number of pages) per segment.

View Source
const DefaultMaxSegments = math.MaxInt32

DefaultMaxSegments is the maximum number of segments (limits total capacity).

Variables

View Source
var ErrBufferFull = &spillError{"buffer full (max segments reached)"}

Error types

Functions

This section is empty.

Types

type Bitmap

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

Bitmap tracks slot allocation using a bitset. Uses uint64 words for efficient 64-bit operations.

func NewBitmap

func NewBitmap(numSlots uint32) *Bitmap

NewBitmap creates a bitmap capable of tracking the given number of slots.

func (*Bitmap) Allocate

func (b *Bitmap) Allocate() (uint32, bool)

Allocate finds and marks a free slot. Returns the slot index or (MaxUint32, false) if no free slot is available.

func (*Bitmap) Capacity

func (b *Bitmap) Capacity() uint32

Capacity returns the total number of slots.

func (*Bitmap) Clear

func (b *Bitmap) Clear()

Clear resets all slots to free.

func (*Bitmap) Count

func (b *Bitmap) Count() uint32

Count returns the number of allocated slots.

func (*Bitmap) Extend

func (b *Bitmap) Extend(newCap uint32)

Extend increases the bitmap capacity to accommodate more slots.

func (*Bitmap) Free

func (b *Bitmap) Free(slot uint32)

Free marks a slot as available.

func (*Bitmap) IsAllocated

func (b *Bitmap) IsAllocated(slot uint32) bool

IsAllocated returns true if the slot is marked as allocated.

type Buffer

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

Buffer is a memory-mapped file used to spill dirty pages. This reduces heap pressure by storing dirty pages in mmap'd memory rather than Go-allocated heap memory. Uses multiple segments to allow growth without invalidating existing slices.

func New

func New(path string, pageSize, initialCap uint32) (*Buffer, error)

New creates or reopens a spill buffer at the given path. The pageSize determines the size of each slot. initialCap is the initial capacity in number of pages per segment.

func (*Buffer) Allocate

func (b *Buffer) Allocate() ([]byte, *Slot, error)

Allocate allocates a slot and returns the page data slice and slot info. Automatically extends by adding new segments if needed.

func (*Buffer) AllocatedCount

func (b *Buffer) AllocatedCount() uint32

AllocatedCount returns the number of allocated slots.

func (*Buffer) Capacity

func (b *Buffer) Capacity() uint32

Capacity returns the total capacity in number of pages.

func (*Buffer) Clear

func (b *Buffer) Clear()

Clear releases all slots without closing the buffer.

func (*Buffer) Close

func (b *Buffer) Close(deleteFile bool) error

Close closes the spill buffer. If deleteFile is true, the underlying files are also deleted.

func (*Buffer) Get

func (b *Buffer) Get(slot *Slot) []byte

Get returns the page data for a given slot.

func (*Buffer) PageSize

func (b *Buffer) PageSize() uint32

PageSize returns the page size of this buffer.

func (*Buffer) Release

func (b *Buffer) Release(slot *Slot)

Release returns a slot to the pool.

func (*Buffer) ReleaseBulk

func (b *Buffer) ReleaseBulk(slots []*Slot)

ReleaseBulk returns multiple slots to the pool.

type Slot

type Slot struct {
	Pgno       uint32 // Original page number (set by caller)
	SegmentIdx uint16 // Which segment
	SlotIdx    uint16 // Index within segment
}

Slot represents an allocated slot in the spill buffer.

Jump to

Keyboard shortcuts

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