Skip to content

Commit

Permalink
use pebble nosync by default (#3581)
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyonur authored Dec 10, 2024
1 parent 1dc4192 commit f6a5c1c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions database/pebbledb/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down
8 changes: 6 additions & 2 deletions database/pebbledb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var (
MemTableSize: defaultCacheSize / 4,
MaxOpenFiles: 4096,
MaxConcurrentCompactions: 1,
Sync: true,
}
)

Expand All @@ -51,6 +52,7 @@ type Database struct {
pebbleDB *pebble.DB
closed bool
openIterators set.Set[*iter]
writeOptions *pebble.WriteOptions
}

type Config struct {
Expand All @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit f6a5c1c

Please sign in to comment.