Skip to content

Commit

Permalink
move sync to cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyonur committed Dec 10, 2024
1 parent ffb2f91 commit cc83a0e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion database/pebbledb/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 4 additions & 5 deletions database/pebbledb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ var (

errInvalidOperation = errors.New("invalid operation")

DefaultSyncWrites = true

DefaultConfig = Config{
CacheSize: defaultCacheSize,
BytesPerSync: 512 * units.KiB,
Expand All @@ -45,6 +43,7 @@ var (
MemTableSize: defaultCacheSize / 4,
MaxOpenFiles: 4096,
MaxConcurrentCompactions: 1,
Sync: true,
}
)

Expand All @@ -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 {
Expand All @@ -89,15 +89,14 @@ func New(file string, useSyncWrites bool, configBytes []byte, log logging.Logger

log.Info(
"opening pebble",
zap.Bool("useSyncWrites", useSyncWrites),
zap.Reflect("config", cfg),
)

db, err := pebble.Open(file, opts)
return &Database{
pebbleDB: db,
openIterators: set.Set[*iter]{},
writeOptions: &pebble.WriteOptions{Sync: useSyncWrites},
writeOptions: &pebble.WriteOptions{Sync: cfg.Sync},
}, err
}

Expand Down
2 changes: 1 addition & 1 deletion database/pebbledb/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit cc83a0e

Please sign in to comment.