Skip to content

Commit

Permalink
add batch
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangchiqing committed Oct 18, 2024
1 parent 1341a02 commit b5cb99c
Show file tree
Hide file tree
Showing 5 changed files with 23 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)
}
1 change: 1 addition & 0 deletions storage/operation/badgerimpl/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type ReaderBatchWriter struct {
}

var _ storage.ReaderBatchWriter = (*ReaderBatchWriter)(nil)
var _ storage.Batch = (*ReaderBatchWriter)(nil)

func (b *ReaderBatchWriter) GlobalReader() storage.Reader {
return b.globalReader
Expand Down
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)
}
1 change: 1 addition & 0 deletions storage/operation/pebbleimpl/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type ReaderBatchWriter struct {
}

var _ storage.ReaderBatchWriter = (*ReaderBatchWriter)(nil)
var _ storage.Batch = (*ReaderBatchWriter)(nil)

func (b *ReaderBatchWriter) GlobalReader() storage.Reader {
return b.globalReader
Expand Down
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 b5cb99c

Please sign in to comment.