bolt

package
v1.85.2 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithNoSync

func ContextWithNoSync(ctx context.Context) context.Context

ContextWithNoSync returns a context that asks bolt-backed stores to commit the writes it accompanies without waiting for fsync.

Relaxed commits trade durability for throughput: a synced commit costs an fsync (milliseconds on hosts where it maps to a full flush, such as macOS), a relaxed one costs microseconds. Process death loses nothing — pages sit in the OS cache — but an OS crash or power loss may discard commits made since the last synced write, and, as with any bbolt NoSync usage, may require recovery from the previous meta page. Reserve it for bulk-loading data that can be rebuilt.

Durability is restored by the next write on the same database path whose context does not carry the request: its commit fsyncs everything before it. Bulk loaders should therefore write their completion marker with a plain context, so the marker's durability implies the durability of the data it vouches for.

The request is honored per write operation, applies to every store sharing the database path, and is invisible to non-bolt implementations of document.Service.

func NoSyncRequested

func NoSyncRequested(ctx context.Context) bool

NoSyncRequested reports whether ctx carries the relaxed-durability request installed by ContextWithNoSync.

Types

type Store

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

Store implements a document.Service backed by a local, embedded bolt DB. It additionally provides a method to efficiently delete all contents of a collection: DeleteAll.

func New

func New(dbPath string, collectionID string) (*Store, error)

New allocates store for a new Store and initializes it with the given dbPath and collectionID.

func NewWithMarshaler

func NewWithMarshaler(
	dbPath string, collectionID string, marshaler docmarshal.Marshaler,
) (*Store, error)

NewWithMarshaler allocates a new Store using the given marshaler for encoding stored documents. Callers that need the storage marshaler to match the wire marshaler used elsewhere (for type-strict CAS preconditions to round-trip identically) should pass the wire marshaler here.

func (*Store) ApplyBatch

func (s *Store) ApplyBatch(
	ctx context.Context, ops []document.BatchOp,
) ([]document.BatchOpResult, error)

ApplyBatch satisfies document.BatchWriter. Every op is applied in a single read-write transaction, so a batch costs one commit — and one fsync, unless ctx requests otherwise — instead of one per operation.

func (*Store) Close

func (s *Store) Close() error

Close releases this Store's reference to the shared *bolt.DB. The underlying handle is closed (and evicted from the package-level dbs cache) only when the last Store referencing the path closes, so sibling Stores opened against the same dbPath keep working.

func (*Store) Create

func (s *Store) Create(
	ctx context.Context, ID string, doc any,
) error

Create satisfies document.Service.

func (*Store) Delete

func (s *Store) Delete(
	ctx context.Context, ID string,
) error

Delete satisfies document.Service.

func (*Store) Drop

func (s *Store) Drop(ctx context.Context) error

Drop satisfies document.DroppableService.

func (*Store) Get

func (s *Store) Get(
	ctx context.Context, ID string, doc any,
) error

Get satisfies document.Service.

func (*Store) List

func (s *Store) List(ctx context.Context, filters []document.Filter) (
	document.Iterator, error,
)

List satisfies document.Service.

func (*Store) Set

func (s *Store) Set(
	ctx context.Context, ID string, doc any,
) error

Set satisfies document.Service.

func (*Store) Update

func (s *Store) Update(
	ctx context.Context, ID string, updates []document.Update,
	preconds ...document.Precondition,
) error

Update satisfies document.Service.

Jump to

Keyboard shortcuts

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