Skip to content

Commit

Permalink
Remove multidb db-split, use pebble-flg only (Fantom-foundation#86)
Browse files Browse the repository at this point in the history
* Remove db presets switching

* Remove db cache by table

* Replace multidb producer with a fake one

* Remove db routing table

* Remove genesis-processing specific cache settings

* Remove db migration

* Move async-flushed producers from SupportedDBs into MakeMultiProducer

* Remove old db migrations

* Reduce usages of DBProducer in gossip/evm stores

* Remove multidb producer

* Fix flushing closed lachesis-N pebble database on stop (flg instead of fsh)

* Fix losing HighestBefore events in vecflushable

Fixed error:
panic: panic of Vector clock: Event A=2:2:875e5a not found

* Use always pebble-flg (check dirty flag even for imports/exports)
  • Loading branch information
Jan Kalina authored Jan 25, 2024
1 parent 9eac240 commit d3eb92a
Show file tree
Hide file tree
Showing 29 changed files with 285 additions and 1,815 deletions.
2 changes: 1 addition & 1 deletion cmd/opera/launcher/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func checkEvm(ctx *cli.Context) error {

cfg := makeAllConfigs(ctx)

rawDbs := makeDirectDBsProducer(cfg)
rawDbs := makeDBsProducer(cfg)
gdb := makeGossipStore(rawDbs, cfg)
defer gdb.Close()

Expand Down
95 changes: 5 additions & 90 deletions cmd/opera/launcher/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,6 @@ var (
Name: "exitwhensynced.epoch",
Usage: "Exits after synchronisation reaches the required epoch",
}

DBMigrationModeFlag = cli.StringFlag{
Name: "db.migration.mode",
Usage: "MultiDB migration mode ('reformat' or 'rebuild')",
}
DBPresetFlag = cli.StringFlag{
Name: "db.preset",
Usage: "DBs layout preset ('pbl-1' or 'ldb-1' or 'legacy-ldb' or 'legacy-pbl')",
}
)

type GenesisTemplate struct {
Expand Down Expand Up @@ -416,92 +407,17 @@ func gossipStoreConfigWithFlags(ctx *cli.Context, src gossip.StoreConfig) (gossi
return cfg, nil
}

func setDBConfig(ctx *cli.Context, cfg integration.DBsConfig, cacheRatio cachescale.Func) integration.DBsConfig {
if ctx.GlobalIsSet(DBPresetFlag.Name) {
preset := ctx.GlobalString(DBPresetFlag.Name)
cfg = setDBConfigStr(cfg, cacheRatio, preset)
}
if ctx.GlobalIsSet(DBMigrationModeFlag.Name) {
cfg.MigrationMode = ctx.GlobalString(DBMigrationModeFlag.Name)
}
return cfg
}

func setStateDBConfig(datadir string) statedb.Config {
cfg := statedb.Config{
Directory: filepath.Join(datadir, "carmen"),
}
return cfg
}

func setDBConfigStr(cfg integration.DBsConfig, cacheRatio cachescale.Func, preset string) integration.DBsConfig {
switch preset {
case "pbl-1":
cfg = integration.Pbl1DBsConfig(cacheRatio.U64, uint64(utils.MakeDatabaseHandles()))
case "ldb-1":
cfg = integration.Ldb1DBsConfig(cacheRatio.U64, uint64(utils.MakeDatabaseHandles()))
case "legacy-ldb":
cfg = integration.LdbLegacyDBsConfig(cacheRatio.U64, uint64(utils.MakeDatabaseHandles()))
case "legacy-pbl":
cfg = integration.PblLegacyDBsConfig(cacheRatio.U64, uint64(utils.MakeDatabaseHandles()))
default:
utils.Fatalf("--%s must be 'pbl-1', 'ldb-1', 'legacy-pbl' or 'legacy-ldb'", DBPresetFlag.Name)
}
// sanity check
if preset != reversePresetName(cfg.Routing) {
log.Error("Preset name cannot be reversed")
}
return cfg
}

func reversePresetName(cfg integration.RoutingConfig) string {
pbl1 := integration.Pbl1RoutingConfig()
ldb1 := integration.Ldb1RoutingConfig()
ldbLegacy := integration.LdbLegacyRoutingConfig()
pblLegacy := integration.PblLegacyRoutingConfig()
if cfg.Equal(pbl1) {
return "pbl-1"
}
if cfg.Equal(ldb1) {
return "ldb-1"
}
if cfg.Equal(ldbLegacy) {
return "legacy-ldb"
}
if cfg.Equal(pblLegacy) {
return "legacy-pbl"
}
return ""
}

func memorizeDBPreset(cfg *config) {
preset := reversePresetName(cfg.DBs.Routing)
pPath := path.Join(cfg.Node.DataDir, "chaindata", "preset")
if len(preset) != 0 {
futils.FilePut(pPath, []byte(preset), true)
} else {
_ = os.Remove(pPath)
}
}

func setDBConfigDefault(cfg config, cacheRatio cachescale.Func) config {
if len(cfg.DBs.Routing.Table) == 0 && len(cfg.DBs.GenesisCache.Table) == 0 && len(cfg.DBs.RuntimeCache.Table) == 0 {
// Substitute memorized db preset from datadir, unless already set
datadirPreset := futils.FileGet(path.Join(cfg.Node.DataDir, "chaindata", "preset"))
if len(datadirPreset) != 0 {
cfg.DBs = setDBConfigStr(cfg.DBs, cacheRatio, string(datadirPreset))
}
}
// apply default for DB config if it wasn't touched by config file or flags, and there's no datadir's default value
dbDefault := integration.DefaultDBsConfig(cacheRatio.U64, uint64(utils.MakeDatabaseHandles()))
if len(cfg.DBs.Routing.Table) == 0 {
cfg.DBs.Routing = dbDefault.Routing
}
if len(cfg.DBs.GenesisCache.Table) == 0 {
cfg.DBs.GenesisCache = dbDefault.GenesisCache
}
if len(cfg.DBs.RuntimeCache.Table) == 0 {
cfg.DBs.RuntimeCache = dbDefault.RuntimeCache
func setDBConfig(cfg config, cacheRatio cachescale.Func) config {
cfg.DBs.RuntimeCache = integration.DBCacheConfig{
Cache: cacheRatio.U64(480 * opt.MiB),
Fdlimit: uint64(utils.MakeDatabaseHandles())*480/1400 + 1,
}
return cfg
}
Expand Down Expand Up @@ -587,7 +503,6 @@ func mayMakeAllConfigs(ctx *cli.Context) (*config, error) {
return nil, err
}
cfg.Node = nodeConfigWithFlags(ctx, cfg.Node)
cfg.DBs = setDBConfig(ctx, cfg.DBs, cacheRatio)
cfg.OperaStore.StateDB = setStateDBConfig(cfg.Node.DataDir)

if overrideMinGasPrice := ctx.GlobalUint64(overrideMinGasPriceFlag.Name); overrideMinGasPrice != 0 {
Expand Down Expand Up @@ -625,7 +540,7 @@ func mayMakeAllConfigs(ctx *cli.Context) (*config, error) {
setTxPool(ctx, &cfg.TxPool)

// Process DBs defaults in the end because they are applied only in absence of config or flags
cfg = setDBConfigDefault(cfg, cacheRatio)
cfg = setDBConfig(cfg, cacheRatio)

if err := cfg.Opera.Validate(); err != nil {
return nil, err
Expand Down
Loading

0 comments on commit d3eb92a

Please sign in to comment.