pager

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: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPageOutOfBounds = errors.New("page index out of bounds") // Added declaration
	ErrFileSize        = errors.New("file size is not a multiple of page size")
	ErrReadOnly        = errors.New("pager is read-only")
)

Functions

This section is empty.

Types

type Pager

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

Pager manages the index.db file using chunked mmap.

func Open

func Open(path string, chunkSize int64) (*Pager, error)

Open opens the pager at the given path. If the file doesn't exist, it creates it. chunkSize determines the size of each mmap region.

func OpenReadOnly

func OpenReadOnly(path string, chunkSize int64) (*Pager, error)

OpenReadOnly opens an existing pager at path without modifying the underlying file.

The returned pager does not support Alloc/GetForWrite/Write/Sync.

func (*Pager) Alloc

func (p *Pager) Alloc(count int) (uint64, error)

Alloc allocates `count` new pages and returns the ID of the first one. It grows the file if necessary.

func (*Pager) Close

func (p *Pager) Close() error

Close closes the pager and unmaps memory.

func (*Pager) Get

func (p *Pager) Get(pageID uint64) ([]byte, error)

Get returns the byte slice for the given page ID. CAUTION: The returned slice points directly to mmapped memory. Do not hold references to it after closing the pager.

func (*Pager) GetForWrite

func (p *Pager) GetForWrite(pageID uint64) ([]byte, error)

GetForWrite returns the byte slice for the given page ID and marks the chunk dirty.

func (*Pager) IsVerified

func (p *Pager) IsVerified(pageID uint64) bool

IsVerified returns true if the page has passed CRC verification. Thread-safe (protected by p.mu in caller, or we can add internal locking if needed, but Pager methods usually hold lock). Currently Pager.Get holds RLock.

func (*Pager) MarkUnverified

func (p *Pager) MarkUnverified(pageID uint64)

MarkUnverified marks a page as unverified (dirty/reused).

func (*Pager) MarkVerified

func (p *Pager) MarkVerified(pageID uint64)

MarkVerified marks a page as verified.

func (*Pager) PageCount

func (p *Pager) PageCount() uint64

PageCount returns the current logical number of pages.

func (*Pager) ReadPage

func (p *Pager) ReadPage(pageID uint64) ([]byte, error)

ReadPage returns a copy of the page data. Safe for concurrent use including checksum verification.

func (*Pager) SetPageCount

func (p *Pager) SetPageCount(count uint64)

SetPageCount updates the logical page count. Should be called by the DB layer after recovery.

func (*Pager) SetVerifyOnRead

func (p *Pager) SetVerifyOnRead(always bool)

SetVerifyOnRead enables or disables checksum verification on every read.

func (*Pager) Sync

func (p *Pager) Sync() error

Sync msyncs the memory maps to disk.

func (*Pager) Truncate

func (p *Pager) Truncate(targetPages uint64) error

Truncate resizes the file to the specified number of pages. Safety: Shrinking is forbidden. Only growing is allowed.

func (*Pager) VerifyOnRead

func (p *Pager) VerifyOnRead() bool

VerifyOnRead reports whether checksum verification should happen on every read.

func (*Pager) Write

func (p *Pager) Write(pageID uint64, data []byte) error

Write copies data into the page. The data slice must be exactly PageSize bytes (or less, but we usually write full pages).

Jump to

Keyboard shortcuts

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