Documentation
¶
Index ¶
- func ContextWithNoSync(ctx context.Context) context.Context
- func NoSyncRequested(ctx context.Context) bool
- type Store
- func (s *Store) ApplyBatch(ctx context.Context, ops []document.BatchOp) ([]document.BatchOpResult, error)
- func (s *Store) Close() error
- func (s *Store) Create(ctx context.Context, ID string, doc any) error
- func (s *Store) Delete(ctx context.Context, ID string) error
- func (s *Store) Drop(ctx context.Context) error
- func (s *Store) Get(ctx context.Context, ID string, doc any) error
- func (s *Store) List(ctx context.Context, filters []document.Filter) (document.Iterator, error)
- func (s *Store) Set(ctx context.Context, ID string, doc any) error
- func (s *Store) Update(ctx context.Context, ID string, updates []document.Update, ...) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithNoSync ¶
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 ¶
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 ¶
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 ¶
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.