common

package
v1.8.8-0...-edaca3c Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package common contains shared transaction and B-tree management helpers used by SOP.

Index

Constants

View Source
const DefaultInitialSlotsCapacity = 256

DefaultInitialSlotsCapacity is the optimal initial capacity for node Slots. This balances memory efficiency (95%+ savings vs pre-allocating SlotLength) with minimal resize overhead (0-2 resizes for typical node sizes via Go's doubling strategy).

Variables

This section is empty.

Functions

func CursorOnOpenedBtree

func CursorOnOpenedBtree[TK btree.Ordered, TV any](ctx context.Context, name string, t sop.Transaction) (btree.BtreeInterface[TK, TV], error)

func NewBtree

func NewBtree[TK btree.Ordered, TV any](ctx context.Context, si sop.StoreOptions, t sop.Transaction, comparer btree.ComparerFunc[TK]) (btree.BtreeInterface[TK, TV], error)

NewBtree will create a new B-Tree instance with data persisted to backend storage upon commit. If the store exists, it opens it and validates compatibility with the provided options. The creation of the store is fully transactional; if the transaction rolls back, the store will not be created. When creating a new store, a root node ID is preassigned for commit-time merging.

func OpenBtree

func OpenBtree[TK btree.Ordered, TV any](ctx context.Context, name string, t sop.Transaction, comparer btree.ComparerFunc[TK]) (btree.BtreeInterface[TK, TV], error)

OpenBtree will open an existing B-Tree instance & prepare it for use in a transaction. Requires an active transaction. Returns an error if the store does not exist.

func OpenBtreeCursor

func OpenBtreeCursor[TK btree.Ordered, TV any](ctx context.Context, name string, t sop.Transaction, comparer btree.ComparerFunc[TK]) (btree.BtreeInterface[TK, TV], error)

func ResetOnIdleTimers

func ResetOnIdleTimers()

ResetOnIdleTimers resets the last run times for onIdle tasks. This is intended for testing purposes only.

Types

type NodeRepository

type NodeRepository interface {
	// Get retrieves a node by its logical ID.
	Get(ctx context.Context, logicalID sop.UUID, target interface{}) (interface{}, error)
	// Add marks a node as new in the repository.
	Add(nodeID sop.UUID, node interface{})
	// Update modifies an existing node in the repository.
	Update(nodeID sop.UUID, node interface{})
	// Remove marks a node as removed in the repository.
	Remove(nodeID sop.UUID)
}

NodeRepository is the interface that wraps the basic Get, Add, Update, Remove methods.

type StoreInterface

type StoreInterface[TK btree.Ordered, TV any] struct {
	btree.StoreInterface[TK, TV]
	// contains filtered or unexported fields
}

StoreInterface contains different repositories needed/used by B-Tree to manage/access its data/objects.

type Transaction

type Transaction struct {
	StoreRepository sop.StoreRepository

	// Handle replication related error.
	HandleReplicationRelatedError func(ctx context.Context, ioError error, rollbackError error, rollbackSucceeded bool)
	// contains filtered or unexported fields
}

Transaction implements the sop's TwoPhaseTransaction interface.

func NewTwoPhaseCommitTransaction

func NewTwoPhaseCommitTransaction(mode sop.TransactionMode, commitMaxDuration time.Duration,
	blobStore sop.BlobStore, storeRepository sop.StoreRepository, registry sop.Registry, l2Cache sop.L2Cache, transactionLog sop.TransactionLog) (*Transaction, error)

NewTwoPhaseCommitTransaction creates a new two-phase commit controller. commitMaxDuration limits commit duration; logging enables crash-safe recovery via a transaction log. Note: commitMaxDuration is the internal safety cap for commit and lock TTLs; the effective limit is min(ctx deadline, commitMaxDuration).

func (*Transaction) Begin

func (t *Transaction) Begin(ctx context.Context) error

func (*Transaction) Close

func (t *Transaction) Close() error

Close releases resources held by the transaction (e.g., registry file handles).

func (*Transaction) CommitMaxDuration

func (t *Transaction) CommitMaxDuration() time.Duration

CommitMaxDuration returns the configured maximum commit duration for this transaction. This is used as the internal cap and lock TTL; the effective runtime cap is min(ctx deadline, this duration).

func (*Transaction) GetID

func (t *Transaction) GetID() sop.UUID

func (*Transaction) GetMode

func (t *Transaction) GetMode() sop.TransactionMode

GetMode returns the transaction's mode (read-only, write, or no-check).

func (*Transaction) GetStoreRepository

func (t *Transaction) GetStoreRepository() sop.StoreRepository

Returns this transaction's StoreRepository.

func (*Transaction) GetStores

func (t *Transaction) GetStores(ctx context.Context) ([]string, error)

func (*Transaction) HasBegun

func (t *Transaction) HasBegun() bool

Transaction has begun if it is has begun & not yet committed/rolled back.

func (*Transaction) OnCommit

func (t *Transaction) OnCommit(callback func(ctx context.Context) error)

OnCommit registers a callback to be executed after a successful commit.

func (*Transaction) Phase1Commit

func (t *Transaction) Phase1Commit(ctx context.Context) error

Phase1Commit performs the first phase of 2PC for writer transactions: - validates state, takes locks, refetches/merges on contention, - persists value blobs and prepares node mutations without finalizing registry updates.

func (*Transaction) Phase2Commit

func (t *Transaction) Phase2Commit(ctx context.Context) error

Phase2Commit completes the commit: - applies registry updates (root changes, added/updated nodes), - populates caches, removes logs, and unlocks resources; on failure attempts priority rollback and surfaces the error.

func (*Transaction) Rollback

func (t *Transaction) Rollback(ctx context.Context, err error) error

Rollback aborts the transaction and attempts to undo work recorded in the log. It also invokes replication error handlers to enable failover.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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