storage

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package storage provides a filesystem based storage layer for tony system api.

Storage manages

  • mappings of virtual document paths to and from the filesyste

  • indexing of virtual document nodes

  • storage of diffs associated with virtual document nodes

  • transactions of multi-participant diffs

  • compaction of diffs

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Storage

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

Storage provides filesystem-based storage for logd.

func Open

func Open(root string, umask int, logger *slog.Logger) (*Storage, error)

Open opens or creates a Storage instance with the given root directory. The root directory will be created if it doesn't exist. umask is applied to directory permissions (e.g., 022 for 0755 -> 0755). If logger is nil, slog.Default() will be used. compactorConfig is optional - if nil, a default config with divisor 2 and NeverRemove is used.

func (*Storage) Close added in v0.0.10

func (s *Storage) Close() error

func (*Storage) GetCurrentCommit added in v0.0.10

func (s *Storage) GetCurrentCommit() (int64, error)

GetCurrentCommit returns the current commit number.

func (*Storage) GetTx added in v0.0.10

func (s *Storage) GetTx(txID int64) (tx.Tx, error)

GetTx gets an existing transaction by transaction ID. This is the primary way participants coordinate - they all receive the same transaction ID and get the same transaction.

Example:

// Multiple parallel HTTP handlers all receive the same txID
tx, err := storage.GetTx(txID)
if err != nil {
    // handle error
}

// Each participant gets their own patcher handle
patcher := tx.NewPatcher(kp, m, p)
result := patcher.Commit()

func (*Storage) NewTx added in v0.0.10

func (s *Storage) NewTx(participantCount int, meta *api.PatchMeta) (tx.Tx, error)

NewTx creates a new transaction with the specified number of participants. Returns a transaction that participants can get via GetTx or get a patcher via NewPatcher().

Example usage (typical pattern for parallel HTTP handlers):

// Create transaction
tx, err := storage.NewTx(participantCount, meta)
if err != nil {
    // handle error
}

// Each participant gets their own patcher handle
patcher := tx.NewPatcher(kp, m, p)
result := patcher.WaitForCompletion()

func (*Storage) ReadStateAt added in v0.0.10

func (s *Storage) ReadStateAt(kp string, commit int64) (*ir.Node, error)

ReadStateAt reads the state for a given kpath at a specific commit count. Searches for the most recent snapshot and applies patches from that point forward.

func (*Storage) SwitchAndSnapshot added in v0.0.15

func (s *Storage) SwitchAndSnapshot() error

SwitchAndSnapshot switches the active log and creates a snapshot of the inactive log. The snapshot is created for the current commit at the time of switching. This should be called periodically (e.g., based on log size or time) to enable snapshot-based read optimization and eventual compaction. Protected by switchMu to prevent concurrent switching while snapshot is being written.

Directories

Path Synopsis
Package index provides hierarchical path-based indexing for storage.
Package index provides hierarchical path-based indexing for storage.
internal
dlog
Package dlog provides double-buffered write-ahead logging.
Package dlog provides double-buffered write-ahead logging.
patches
Package patches provides streaming patch application for snapshots.
Package patches provides streaming patch application for snapshots.
seq
Package seq provides atomic sequence counters.
Package seq provides atomic sequence counters.
snap
Package snap provides event-based snapshot storage.
Package snap provides event-based snapshot storage.
Package tx provides transaction coordination for multi-participant updates.
Package tx provides transaction coordination for multi-participant updates.

Jump to

Keyboard shortcuts

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