storage

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package storage implements the local segment log backing stream persistence: append-only segment files with a sparse in-memory index, plus retention-aware pruning.

Index

Constants

This section is empty.

Variables

View Source
var ErrOutOfRange = errors.New("storage: sequence out of range")

ErrOutOfRange is returned when reading before the first or after the last available sequence.

Functions

This section is empty.

Types

type Log

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

Log is a sequence of segments covering a contiguous seq range.

func OpenLog

func OpenLog(dir string, opts Options) (*Log, error)

OpenLog opens (or creates) a log in dir.

func (*Log) Append

func (l *Log) Append(msg protocol.Message) (uint64, error)

Append writes a message and returns its assigned sequence number.

func (*Log) Bytes

func (l *Log) Bytes() int64

Bytes returns the total on-disk size of the log.

func (*Log) BytesLocked

func (l *Log) BytesLocked() int64

func (*Log) Close

func (l *Log) Close() error

Close closes every segment file.

func (*Log) DeleteBefore

func (l *Log) DeleteBefore(keepFrom uint64) error

DeleteBefore removes every record with seq < keepFrom by dropping whole segments. Segments partially inside the range keep all records (the tail segment is never split).

func (*Log) FirstSeq

func (l *Log) FirstSeq() uint64

FirstSeq returns the lowest available sequence (0 for an empty log).

func (*Log) LastSeq

func (l *Log) LastSeq() uint64

LastSeq returns the highest written sequence (0 for an empty log).

func (*Log) Read

func (l *Log) Read(fromSeq, max uint64) ([]Record, error)

Read returns up to max records starting at fromSeq.

func (*Log) Sync

func (l *Log) Sync() error

Sync flushes all open segments.

func (*Log) TrimOverBytes

func (l *Log) TrimOverBytes(target int64) (int64, error)

TrimOverBytes deletes oldest whole segments until the log fits under target bytes. The newest segment is never dropped, so the returned size may still exceed target. It returns the freed bytes.

type Options

type Options struct {
	Dir      string
	MaxBytes int64 // max bytes per segment (0 = 64 MiB)
}

Options configures a Log.

type Record

type Record struct {
	Seq     uint64
	Message protocol.Message
}

Record is one stored message.

Jump to

Keyboard shortcuts

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