Skip to content

Commit

Permalink
add batch
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangchiqing committed Oct 28, 2024
1 parent 784dbd1 commit 402c14d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions storage/operation/badgerimpl/dbstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ func (b *dbStore) Reader() storage.Reader {
func (b *dbStore) WithReaderBatchWriter(fn func(storage.ReaderBatchWriter) error) error {
return WithReaderBatchWriter(b.db, fn)
}

func (b *dbStore) NewBatch() storage.Batch {
return NewReaderBatchWriter(b.db)
}
4 changes: 4 additions & 0 deletions storage/operation/pebbleimpl/dbstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ func (b *dbStore) Reader() storage.Reader {
func (b *dbStore) WithReaderBatchWriter(fn func(storage.ReaderBatchWriter) error) error {
return WithReaderBatchWriter(b.db, fn)
}

func (b *dbStore) NewBatch() storage.Batch {
return NewReaderBatchWriter(b.db)
}
13 changes: 13 additions & 0 deletions storage/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ type DB interface {
// atomic batch updates to the database.
// Any error returned are considered fatal and the batch is not committed.
WithReaderBatchWriter(func(ReaderBatchWriter) error) error

// NewBatch create a new batch for writing.
NewBatch() Batch
}

// Batch is an interface for a batch of writes to a storage backend.
// The batch is pending until it is committed.
// Useful for dynamically adding writes to the batch
type Batch interface {
ReaderBatchWriter

// Commit applies the batched updates to the database.
Commit() error
}

// OnlyWriter is an adapter to convert a function that takes a Writer
Expand Down

0 comments on commit 402c14d

Please sign in to comment.