diff --git a/database/pebbledb/batch_test.go b/database/pebbledb/batch_test.go index 0670caceecae..98ab0e28eb35 100644 --- a/database/pebbledb/batch_test.go +++ b/database/pebbledb/batch_test.go @@ -17,7 +17,7 @@ func TestBatch(t *testing.T) { require := require.New(t) dirName := t.TempDir() - db, err := New(dirName, DefaultSyncWrites, nil, logging.NoLog{}, prometheus.NewRegistry()) + db, err := New(dirName, nil, logging.NoLog{}, prometheus.NewRegistry()) require.NoError(err) batchIntf := db.NewBatch() diff --git a/database/pebbledb/db.go b/database/pebbledb/db.go index d020fb7d0425..8d4080bb8832 100644 --- a/database/pebbledb/db.go +++ b/database/pebbledb/db.go @@ -35,8 +35,6 @@ var ( errInvalidOperation = errors.New("invalid operation") - DefaultSyncWrites = true - DefaultConfig = Config{ CacheSize: defaultCacheSize, BytesPerSync: 512 * units.KiB, @@ -45,6 +43,7 @@ var ( MemTableSize: defaultCacheSize / 4, MaxOpenFiles: 4096, MaxConcurrentCompactions: 1, + Sync: true, } ) @@ -64,10 +63,11 @@ type Config struct { MemTableSize uint64 `json:"memTableSize"` MaxOpenFiles int `json:"maxOpenFiles"` MaxConcurrentCompactions int `json:"maxConcurrentCompactions"` + Sync bool `json:"sync"` } // TODO: Add metrics -func New(file string, useSyncWrites bool, configBytes []byte, log logging.Logger, _ prometheus.Registerer) (database.Database, error) { +func New(file string, configBytes []byte, log logging.Logger, _ prometheus.Registerer) (database.Database, error) { cfg := DefaultConfig if len(configBytes) > 0 { if err := json.Unmarshal(configBytes, &cfg); err != nil { @@ -89,7 +89,6 @@ func New(file string, useSyncWrites bool, configBytes []byte, log logging.Logger log.Info( "opening pebble", - zap.Bool("useSyncWrites", useSyncWrites), zap.Reflect("config", cfg), ) @@ -97,7 +96,7 @@ func New(file string, useSyncWrites bool, configBytes []byte, log logging.Logger return &Database{ pebbleDB: db, openIterators: set.Set[*iter]{}, - writeOptions: &pebble.WriteOptions{Sync: useSyncWrites}, + writeOptions: &pebble.WriteOptions{Sync: cfg.Sync}, }, err } diff --git a/database/pebbledb/db_test.go b/database/pebbledb/db_test.go index 56a750415b1a..f230152b30b3 100644 --- a/database/pebbledb/db_test.go +++ b/database/pebbledb/db_test.go @@ -16,7 +16,7 @@ import ( func newDB(t testing.TB) *Database { folder := t.TempDir() - db, err := New(folder, DefaultSyncWrites, nil, logging.NoLog{}, prometheus.NewRegistry()) + db, err := New(folder, nil, logging.NoLog{}, prometheus.NewRegistry()) require.NoError(t, err) return db.(*Database) } diff --git a/node/node.go b/node/node.go index a2570297e4f8..504dbdf7a6e1 100644 --- a/node/node.go +++ b/node/node.go @@ -781,7 +781,7 @@ func (n *Node) initDatabase() error { n.DB = memdb.New() case pebbledb.Name: dbPath := filepath.Join(n.Config.DatabaseConfig.Path, "pebble") - n.DB, err = pebbledb.New(dbPath, pebbledb.DefaultSyncWrites, n.Config.DatabaseConfig.Config, n.Log, dbRegisterer) + n.DB, err = pebbledb.New(dbPath, n.Config.DatabaseConfig.Config, n.Log, dbRegisterer) if err != nil { return fmt.Errorf("couldn't create %s at %s: %w", pebbledb.Name, dbPath, err) }