-
Notifications
You must be signed in to change notification settings - Fork 79
fix(pebble.go): implement flush threshold for Pebble batch operations #275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ type PebbleDB struct { | |
| } | ||
|
|
||
| var _ DB = (*PebbleDB)(nil) | ||
| const flushThreshold = 3_500_000_000 // ~3.5 GB | ||
|
|
||
| func NewPebbleDB(name string, dir string) (*PebbleDB, error) { | ||
| opts := &pebble.Options{} | ||
|
|
@@ -250,6 +251,14 @@ func (b *pebbleDBBatch) Set(key, value []byte) error { | |
| 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() | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Batch Size Check Timing IssueThe batch size check in Additional Locations (1)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my opinion this would be unlikely to happen. Single operations normally are much smaller, just batching them can lead to the issue. |
||
| return b.batch.Set(key, value, nil) | ||
| } | ||
|
|
||
|
|
@@ -262,6 +271,14 @@ func (b *pebbleDBBatch) Delete(key []byte) error { | |
| 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) | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Batch Flush Sync Inconsistency
The automatic batch flush uses
pebble.Sync, which is inconsistent with thepebble.NoSyncused by theWrite()method. This introduces unexpected synchronous writes during batch building, potentially causing performance slowdowns and violating user expectations.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would think this is necessary due to the location the commit is called, as it "interrupts" a normal batch operation, this should not simply continue until the batch is committed.