Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions pebble.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ type PebbleDB struct {

var _ DB = (*PebbleDB)(nil)

const flushThreshold = 3_500_000_000 // ~3.5 GB

func NewPebbleDB(name, dir string, opts Options) (DB, error) {
do := &pebble.Options{
Logger: &fatalLogger{}, // pebble info logs are messing up the logs
Expand Down Expand Up @@ -306,6 +308,15 @@ func (b *pebbleDBBatch) Set(key, value []byte) error {
if b.batch == nil {
return errBatchClosed
}

// Prevent Pebble batch from exceeding 4 GB hard limit
if b.batch.Len() > flushThreshold {
if err := b.batch.Commit(pebble.Sync); err != nil {
return err
}
b.batch.Reset()
}

return b.batch.Set(key, value, nil)
}

Expand All @@ -317,6 +328,15 @@ func (b *pebbleDBBatch) Delete(key []byte) error {
if b.batch == nil {
return errBatchClosed
}

// Prevent Pebble batch from exceeding 4 GB hard limit
if b.batch.Len() > flushThreshold {
if err := b.batch.Commit(pebble.Sync); err != nil {
return err
}
b.batch.Reset()
}

return b.batch.Delete(key, nil)
}

Expand Down