-
Notifications
You must be signed in to change notification settings - Fork 886
Replace benchmark DB wrapper #4112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5f66f03
4ecbe0e
9bfeb2e
e936495
9608f1e
b023c67
6894b7d
483446c
2e8b204
230bc09
90f7ba9
8949ec4
14ba233
3f16720
5e9b9bf
06773cd
0cf7aac
d7a8bf6
e0488ea
eb47e30
750050b
d809f25
aa2a7e4
2a626f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,14 +3,17 @@ package cryptosim | |
| import ( | ||
| "context" | ||
| "fmt" | ||
| "path/filepath" | ||
| "runtime" | ||
| "time" | ||
|
|
||
| "github.com/sei-protocol/sei-chain/sei-db/bench/wrappers" | ||
| "golang.org/x/time/rate" | ||
|
|
||
| "github.com/sei-protocol/sei-chain/sei-db/common/keys" | ||
| crand "github.com/sei-protocol/sei-chain/sei-db/common/rand" | ||
| "github.com/sei-protocol/sei-chain/sei-db/common/utils" | ||
| "golang.org/x/time/rate" | ||
| "github.com/sei-protocol/sei-chain/sei-db/controller" | ||
| "github.com/sei-protocol/sei-chain/sei-db/state_db/giga" | ||
| ) | ||
|
|
||
| const ( | ||
|
|
@@ -133,23 +136,50 @@ func NewCryptoSim( | |
| fmt.Printf("Running cryptosim benchmark from data directory: %s\n", config.DataDir) | ||
| fmt.Printf("Logs are being routed to: %s\n", config.LogDir) | ||
|
|
||
| var dbConfig any | ||
| switch config.Backend { | ||
| case wrappers.FlatKV: | ||
| dbConfig = config.FlatKVConfig | ||
| case wrappers.SSComposite, wrappers.CompositeDual_SSComposite: | ||
| dbConfig = config.StateStoreConfig | ||
| case wrappers.SSHistoricalOffload: | ||
| dbConfig = config.HistoricalOffload | ||
| config.FlatKVConfig.DataDir = config.DataDir | ||
| config.StateStoreConfig.EVMDBDirectory = filepath.Join( | ||
| config.DataDir, "state_store", "evm", config.StateStoreConfig.Backend) | ||
|
|
||
| // Every store the state DB opens is pruned by the collector started below, so each one stands its | ||
| // own pruner down. This is the same handover bootstrap.GigaStorageManager performs for a node. | ||
| config.FlatKVConfig.ExternalPruning = true | ||
| config.StateStoreConfig.ExternalPruning = true | ||
|
|
||
| // giga.NewStateDB is the node's own entry point, and the only one that leaves the state WAL | ||
| // outside the live state DB: it opens the WAL itself and writes each block to it ahead of the | ||
| // commit. A live state DB opened directly would own its WAL and write it inline instead. | ||
| db, err := giga.NewStateDB(ctx, config.FlatKVConfig, config.StateStoreConfig, config.CheckpointConfig) | ||
|
seidroid[bot] marked this conversation as resolved.
|
||
| if err != nil { | ||
| cancel() | ||
| return nil, fmt.Errorf("failed to open the state DB: %w", err) | ||
| } | ||
|
|
||
| db, err := wrappers.NewDBImpl(ctx, config.Backend, config.DataDir, dbConfig) | ||
| // Nothing the state DB opens prunes itself on this path: the state WAL, and the historical state | ||
| // DB when it is enabled, shrink only when a collector tells them to. | ||
| garbageCollector, err := controller.NewStorageGarbageCollector( | ||
| ctx, config.PruningConfig, db.PrunableStores()) | ||
| if err != nil { | ||
| cancel() | ||
| return nil, fmt.Errorf("failed to create database: %w", err) | ||
| if closeErr := db.Close(); closeErr != nil { | ||
| fmt.Printf("failed to close the state DB during error recovery: %v\n", closeErr) | ||
| } | ||
| return nil, fmt.Errorf("failed to start the storage garbage collector: %w", err) | ||
| } | ||
|
|
||
| metrics := NewCryptosimMetrics(ctx, db.GetPhaseTimer(), config) | ||
| // Every construction failure past this point releases through here. The state DB holds the state | ||
| // WAL directory's exclusive lock, so a handle left open makes an in-process retry fail to open the | ||
| // WAL rather than only leaking descriptors. | ||
| releaseStorage := func() { | ||
| cancel() | ||
| if closeErr := garbageCollector.Close(); closeErr != nil { | ||
| fmt.Printf("failed to close the garbage collector during error recovery: %v\n", closeErr) | ||
| } | ||
| if closeErr := db.Close(); closeErr != nil { | ||
| fmt.Printf("failed to close the state DB during error recovery: %v\n", closeErr) | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cleanup skips open state viewMedium Severity
Additional Locations (2)Reviewed by Cursor Bugbot for commit 2a626f5. Configure here. |
||
|
|
||
| metrics := NewCryptosimMetrics(ctx, db.SC().GetPhaseTimer(), config) | ||
| // Server start deferred until after DataGenerator loads DB state and sets gauges, | ||
| // avoiding rate() spikes when restarting with a preserved DB. | ||
|
|
||
|
|
@@ -160,24 +190,15 @@ func NewCryptoSim( | |
|
|
||
| start := time.Now() | ||
|
|
||
| database, err := NewDatabase(config, db, metrics, 0) | ||
| database, err := NewDatabase(config, db, garbageCollector, metrics) | ||
| if err != nil { | ||
| cancel() | ||
| if closeErr := db.Close(); closeErr != nil { | ||
| fmt.Printf("failed to close database during error recovery: %v\n", closeErr) | ||
| } | ||
| releaseStorage() | ||
| return nil, fmt.Errorf("failed to create database: %w", err) | ||
| } | ||
|
|
||
| dataGenerator, err := NewDataGenerator(config, database, rand, metrics) | ||
| if err != nil { | ||
| cancel() | ||
| if closeErr := db.Close(); closeErr != nil { | ||
| fmt.Printf("failed to close database during error recovery: %v\n", closeErr) | ||
| } | ||
| return nil, fmt.Errorf("failed to create data generator: %w", err) | ||
| } | ||
| database.nextBlockNumber = dataGenerator.InitialNextBlockNumber() | ||
| fmt.Printf("Next block number: %s.\n", int64Commas(database.nextBlockNumber)) | ||
|
|
||
| dataGenerator := NewDataGenerator(config, database, rand, metrics) | ||
| threadCount := int(config.ThreadsPerCore)*runtime.NumCPU() + config.ConstantThreadCount | ||
| if threadCount < 1 { | ||
| threadCount = 1 | ||
|
|
@@ -195,7 +216,7 @@ func NewCryptoSim( | |
| recieptsChan = make(chan *block, config.RecieptChannelCapacity) | ||
| _, err := NewRecieptStoreSimulator(ctx, config, recieptsChan, metrics, rand.Clone(false)) | ||
| if err != nil { | ||
| cancel() | ||
| releaseStorage() | ||
| return nil, fmt.Errorf("failed to create receipt store simulator: %w", err) | ||
| } | ||
| metrics.startReceiptChannelDepthSampling(recieptsChan, config.BackgroundMetricsScrapeInterval) | ||
|
|
@@ -230,6 +251,7 @@ func NewCryptoSim( | |
|
|
||
| err = c.setup() | ||
| if err != nil { | ||
| releaseStorage() | ||
| return nil, fmt.Errorf("failed to setup benchmark: %w", err) | ||
| } | ||
|
|
||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[suggestion] These two assignments overwrite
FlatKVConfig.DataDirandStateStoreConfig.EVMDBDirectoryunconditionally, so a value set for either in a config file is silently ignored (LoadConfigFromFileusesDisallowUnknownFields, soEVMDBDirectoryis accepted and then discarded rather than rejected). Overwriting only when the supplied value is empty would keep both knobs meaningful.Two related loose ends while you are here:
DefaultGigaStorageConfigputs flatkv atdata/state_commit/flatkvand SS atdata/state_store/evm/{backend}, whereas this puts flatkv at the data-dir root and nests SS inside it. Functionally harmless (traverseSnapshotsskips non-snapshot dirs), but it makes per-storeduand separate-device mounts awkward on a harness whose point is to reproduce node storage behaviour.StateStoreConfig.DBDirectoryis not read on the giga path (openSSuses onlyEVMDBDirectory), yetconfig/basic-config.json— documented as listing every knob at its default — still advertises it. Worth dropping alongside theEVMDBDirectoryentry this PR already removed.