badgerimpl

package
v0.42.4-access-txerr-b... Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2025 License: AGPL-3.0 Imports: 11 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToDB

func ToDB(db *badger.DB) storage.DB

func ToReader

func ToReader(db *badger.DB) storage.Reader

ToReader is a helper function to convert a *badger.DB to a Reader

func WithReaderBatchWriter

func WithReaderBatchWriter(db *badger.DB, fn func(storage.ReaderBatchWriter) error) error

Types

type ReaderBatchWriter

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

ReaderBatchWriter is for reading and writing to a storage backend. It is useful for performing a related sequence of reads and writes, after which you would like to modify some non-database state if the sequence completed successfully (via AddCallback). If you are not using AddCallback, avoid using ReaderBatchWriter: use Reader and Writer directly. ReaderBatchWriter is not safe for concurrent use.

func NewReaderBatchWriter

func NewReaderBatchWriter(db *badger.DB) *ReaderBatchWriter

func (*ReaderBatchWriter) AddCallback

func (b *ReaderBatchWriter) AddCallback(callback func(error))

AddCallback adds a callback to execute after the batch has been flush regardless the batch update is succeeded or failed. The error parameter is the error returned by the batch update.

func (*ReaderBatchWriter) BadgerWriteBatch

func (b *ReaderBatchWriter) BadgerWriteBatch() *badger.WriteBatch

BadgerWriteBatch returns the badger write batch

func (*ReaderBatchWriter) Close added in v0.41.0

func (b *ReaderBatchWriter) Close() error

Close releases memory of the batch and no error is returned. This can be called as a defer statement immediately after creating Batch to reduce risk of unbounded memory consumption. No errors are expected during normal operation.

func (*ReaderBatchWriter) Commit

func (b *ReaderBatchWriter) Commit() error

Commit flushes the batch to the database. No errors expected during normal operation

func (*ReaderBatchWriter) Delete

func (b *ReaderBatchWriter) Delete(key []byte) error

Delete deletes the value for the given key. Deletes are blind all will succeed even if the given key does not exist.

It is safe to modify the contents of the arguments after Delete returns. No errors expected during normal operation

func (*ReaderBatchWriter) DeleteByRange

func (b *ReaderBatchWriter) DeleteByRange(globalReader storage.Reader, startPrefix, endPrefix []byte) error

DeleteByRange removes all keys with a prefix that falls within the range [start, end], both inclusive. It returns error if endPrefix < startPrefix no other errors are expected during normal operation

func (*ReaderBatchWriter) GlobalReader

func (b *ReaderBatchWriter) GlobalReader() storage.Reader

GlobalReader returns a database-backed reader which reads the latest committed global database state ("read-committed isolation"). This reader will not read un-committed writes written to ReaderBatchWriter.Writer until the write batch is committed. This reader may observe different values for the same key on subsequent reads.

func (*ReaderBatchWriter) Lock added in v0.41.0

func (b *ReaderBatchWriter) Lock(lock *sync.Mutex)

Lock tries to acquire the lock for the batch. if the lock is already acquired by this same batch from other pending db operations, then it will not be blocked and can continue updating the batch, which prevents a re-entrant deadlock. CAUTION: The caller must ensure that no other references exist for the input lock.

func (*ReaderBatchWriter) Set

func (b *ReaderBatchWriter) Set(key, value []byte) error

Set sets the value for the given key. It overwrites any previous value for that key; a DB is not a multi-map.

It is safe to modify the contents of the arguments after Set returns. No errors expected during normal operation

func (*ReaderBatchWriter) Writer

func (b *ReaderBatchWriter) Writer() storage.Writer

Writer returns a writer associated with a batch of writes. The batch is pending until it is committed. When we `Write` into the batch, that write operation is added to the pending batch, but not committed. The commit operation is atomic w.r.t. the batch; either all writes are applied to the database, or no writes are. Note: - The writer cannot be used concurrently for writing.

Jump to

Keyboard shortcuts

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