diff --git a/database/pebbledb/batch.go b/database/pebbledb/batch.go index a14666749bc9..2037a537e493 100644 --- a/database/pebbledb/batch.go +++ b/database/pebbledb/batch.go @@ -33,12 +33,12 @@ func (db *Database) NewBatch() database.Batch { func (b *batch) Put(key, value []byte) error { b.size += len(key) + len(value) + pebbleByteOverHead - return b.batch.Set(key, value, pebble.Sync) + return b.batch.Set(key, value, b.db.writeOptions) } func (b *batch) Delete(key []byte) error { b.size += len(key) + pebbleByteOverHead - return b.batch.Delete(key, pebble.Sync) + return b.batch.Delete(key, b.db.writeOptions) } func (b *batch) Size() int { @@ -67,7 +67,7 @@ func (b *batch) Write() error { } b.written = true - return updateError(b.batch.Commit(pebble.Sync)) + return updateError(b.batch.Commit(b.db.writeOptions)) } func (b *batch) Reset() { diff --git a/database/pebbledb/db.go b/database/pebbledb/db.go index 1de9c2ce5de5..8d4080bb8832 100644 --- a/database/pebbledb/db.go +++ b/database/pebbledb/db.go @@ -43,6 +43,7 @@ var ( MemTableSize: defaultCacheSize / 4, MaxOpenFiles: 4096, MaxConcurrentCompactions: 1, + Sync: true, } ) @@ -51,6 +52,7 @@ type Database struct { pebbleDB *pebble.DB closed bool openIterators set.Set[*iter] + writeOptions *pebble.WriteOptions } type Config struct { @@ -61,6 +63,7 @@ type Config struct { MemTableSize uint64 `json:"memTableSize"` MaxOpenFiles int `json:"maxOpenFiles"` MaxConcurrentCompactions int `json:"maxConcurrentCompactions"` + Sync bool `json:"sync"` } // TODO: Add metrics @@ -93,6 +96,7 @@ func New(file string, configBytes []byte, log logging.Logger, _ prometheus.Regis return &Database{ pebbleDB: db, openIterators: set.Set[*iter]{}, + writeOptions: &pebble.WriteOptions{Sync: cfg.Sync}, }, err } @@ -167,7 +171,7 @@ func (db *Database) Put(key []byte, value []byte) error { return database.ErrClosed } - return updateError(db.pebbleDB.Set(key, value, pebble.Sync)) + return updateError(db.pebbleDB.Set(key, value, db.writeOptions)) } func (db *Database) Delete(key []byte) error { @@ -178,7 +182,7 @@ func (db *Database) Delete(key []byte) error { return database.ErrClosed } - return updateError(db.pebbleDB.Delete(key, pebble.Sync)) + return updateError(db.pebbleDB.Delete(key, db.writeOptions)) } func (db *Database) Compact(start []byte, end []byte) error {