Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions sei-db/db_engine/pebbledb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ type pebbleDB struct {

var _ types.KeyValueDB = (*pebbleDB)(nil)

// Open opens (or creates) a Pebble-backed DB at path, returning a KeyValueDB
// Open opens (or creates) a Pebble-backed DB at path, returning a KeyValueDB.
// ctx is unused: metrics collection is stopped by Close, not by cancellation.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[suggestion] ctx is now entirely unused in Open — it was only ever wired to the metrics goroutine's cancellation. Documenting a parameter as ignored leaves a trap rather than removing it: every one of the ~16 call sites (s.ctx in flatkv/store.go:761, t.Context() in several tests, context.Background() elsewhere) still reads as if cancelling that context releases the DB's background work, and it no longer does. Since Close is now the single choke point for stopping collection, dropping the parameter from the signature would make that invariant unmissable instead of a comment callers have to find. If you prefer to keep the signature stable for now, consider renaming it _ context.Context so the compiler-visible intent matches the comment.

Relatedly, metricsCancel is still typed context.CancelFunc (line 24) though it no longer comes from a context; plain func() would match what it now holds.

func Open(
ctx context.Context,
config *PebbleDBConfig,
Expand Down Expand Up @@ -85,14 +86,14 @@ func Open(
return nil, err
}

ctx, cancel := context.WithCancel(ctx)
var metricsCancel func()
if config.EnableMetrics {
NewPebbleMetrics(ctx, db, filepath.Base(config.DataDir), config.MetricsScrapeInterval)
metricsCancel = NewPebbleMetrics(db, filepath.Base(config.DataDir), config.MetricsScrapeInterval)
}

return &pebbleDB{
db: db,
metricsCancel: cancel,
metricsCancel: metricsCancel,
operationMetrics: NewOperationMetrics(config.EnableReadWriteMetrics, filepath.Base(config.DataDir)),
}, nil
}
Expand Down
7 changes: 2 additions & 5 deletions sei-db/db_engine/pebbledb/mvcc/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,8 @@ func OpenDB(dataDir string, config config.StateStoreConfig) (types.StateStore, e
database.asyncWriteWG.Add(1)
go database.writeAsyncInBackground()

// Start background metrics collection for Pebble-internal stats
// (compaction, flush, sstable, memtable, WAL, cache).
metricsCtx, metricsCancel := context.WithCancel(context.Background())
database.metricsCancel = metricsCancel
pebbledbmetrics.NewPebbleMetrics(metricsCtx, db, dbName, 10*time.Second)
// Refresh Pebble-internal stats (compaction, flush, sstable, memtable, WAL, cache).
database.metricsCancel = pebbledbmetrics.NewPebbleMetrics(db, dbName, 10*time.Second)

return database, nil
}
Expand Down
Loading
Loading