From 9c245797b27da16486c3afbd8c090147157eaec3 Mon Sep 17 00:00:00 2001 From: zhangkai Date: Sun, 20 Nov 2022 21:39:54 +0800 Subject: [PATCH] Merge PR: optimiz fss flag (#2769) * fast storage is default true and set by the data * add fast-storage tips when start the node * hidden flag discard-fast-storage * print iavl.IsFastStorage when start node * Update Makefile * restore and hide the old flag Co-authored-by: KamiD <44460798+KamiD@users.noreply.github.com> --- Makefile | 2 +- app/app.go | 3 +++ app/repair_state.go | 5 +---- app/utils/sanity/start.go | 10 ---------- cmd/exchaind/repair_data.go | 6 +----- cmd/exchaind/replay.go | 3 +++ libs/cosmos-sdk/server/start.go | 4 +++- libs/cosmos-sdk/server/start_okchain.go | 3 +++ libs/iavl/mutable_tree_oec.go | 5 +++-- 9 files changed, 18 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 53c8785abd..27883a8446 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ IGNORE_CHECK_GO=false install_rocksdb_version:=$(ROCKSDB_VERSION) -Version=v1.6.5.5 +Version=v1.6.5.6 CosmosSDK=v0.39.2 Tendermint=v0.33.9 Iavl=v0.14.3 diff --git a/app/app.go b/app/app.go index ab355d7194..1ac12f0bef 100644 --- a/app/app.go +++ b/app/app.go @@ -7,6 +7,7 @@ import ( "os" "sync" + "github.com/okex/exchain/app/utils/appstatus" "github.com/spf13/cobra" "github.com/spf13/viper" "google.golang.org/grpc/encoding" @@ -858,9 +859,11 @@ func PreRun(ctx *server.Context, cmd *cobra.Command) error { // init tx signature cache tmtypes.InitSignatureCache() + iavl.SetEnableFastStorage(appstatus.IsFastStorageStrategy()) // set external package flags server.SetExternalPackageValue(cmd) + ctx.Logger.Info("The database storage strategy", "fast-storage", iavl.GetEnableFastStorage()) // set the dynamic config appconfig.RegisterDynamicConfig(ctx.Logger.With("module", "config")) diff --git a/app/repair_state.go b/app/repair_state.go index 4fa10f3f77..744f1007a1 100644 --- a/app/repair_state.go +++ b/app/repair_state.go @@ -61,10 +61,7 @@ func repairStateOnStart(ctx *server.Context) { orgEnableFlatKV := viper.GetBool(flatkv.FlagEnable) iavl.EnableAsyncCommit = false viper.Set(flatkv.FlagEnable, false) - if appstatus.IsFastStorageStrategy() && - viper.GetBool(iavl.FlagIavlEnableFastStorage) { - iavl.SetEnableFastStorage(true) - } + iavl.SetEnableFastStorage(appstatus.IsFastStorageStrategy()) // repair state RepairState(ctx, true) diff --git a/app/utils/sanity/start.go b/app/utils/sanity/start.go index 7c2a57ffe0..43b54bf70b 100644 --- a/app/utils/sanity/start.go +++ b/app/utils/sanity/start.go @@ -1,14 +1,10 @@ package sanity import ( - "fmt" - apptype "github.com/okex/exchain/app/types" - "github.com/okex/exchain/app/utils/appstatus" "github.com/okex/exchain/libs/cosmos-sdk/server" cosmost "github.com/okex/exchain/libs/cosmos-sdk/store/types" sdk "github.com/okex/exchain/libs/cosmos-sdk/types" - "github.com/okex/exchain/libs/iavl" "github.com/okex/exchain/libs/tendermint/consensus" "github.com/okex/exchain/libs/tendermint/state" "github.com/okex/exchain/libs/tendermint/types" @@ -87,12 +83,6 @@ var ( configA: stringItem{name: apptype.FlagNodeMode, expect: string(apptype.ArchiveNode)}, configB: boolItem{name: watcher.FlagFastQuery, expect: true}, }, - { - configA: boolItem{name: iavl.FlagIavlEnableFastStorage, expect: true}, - configB: funcItem{name: "Upgraded to fast IAVL", expect: false, f: appstatus.IsFastStorageStrategy}, - tips: fmt.Sprintf("Upgrade to IAVL fast storage may take several hours, "+ - "you can use exchaind fss create command to upgrade, or unset --%v", iavl.FlagIavlEnableFastStorage), - }, } checkRangeItems = []rangeItem{ diff --git a/cmd/exchaind/repair_data.go b/cmd/exchaind/repair_data.go index bde18883b3..fbf1b9de7a 100644 --- a/cmd/exchaind/repair_data.go +++ b/cmd/exchaind/repair_data.go @@ -14,7 +14,6 @@ import ( tmtypes "github.com/okex/exchain/libs/tendermint/types" types2 "github.com/okex/exchain/x/evm/types" "github.com/spf13/cobra" - "github.com/spf13/viper" ) func repairStateCmd(ctx *server.Context) *cobra.Command { @@ -37,14 +36,11 @@ func repairStateCmd(ctx *server.Context) *cobra.Command { cmd.Flags().Bool(trace.FlagEnableAnalyzer, false, "Enable auto open log analyzer") cmd.Flags().BoolVar(&types2.TrieUseCompositeKey, types2.FlagTrieUseCompositeKey, true, "Use composite key to store contract state") cmd.Flags().Int(sm.FlagDeliverTxsExecMode, 0, "execution mode for deliver txs, (0:serial[default], 1:deprecated, 2:parallel)") - cmd.Flags().Bool(tmiavl.FlagIavlEnableFastStorage, false, "Enable fast storage") cmd.Flags().String(sdk.FlagDBBackend, tmtypes.DBBackend, "Database backend: goleveldb | rocksdb") return cmd } func setExternalPackageValue() { - enableFastStorage := viper.GetBool(tmiavl.FlagIavlEnableFastStorage) || - appstatus.IsFastStorageStrategy() - tmiavl.SetEnableFastStorage(enableFastStorage) + tmiavl.SetEnableFastStorage(appstatus.IsFastStorageStrategy()) } diff --git a/cmd/exchaind/replay.go b/cmd/exchaind/replay.go index 1c0c59a831..47bd429c45 100644 --- a/cmd/exchaind/replay.go +++ b/cmd/exchaind/replay.go @@ -14,12 +14,14 @@ import ( "github.com/gogo/protobuf/jsonpb" "github.com/okex/exchain/app/config" okexchain "github.com/okex/exchain/app/types" + "github.com/okex/exchain/app/utils/appstatus" "github.com/okex/exchain/app/utils/sanity" "github.com/okex/exchain/libs/cosmos-sdk/baseapp" "github.com/okex/exchain/libs/cosmos-sdk/client/lcd" "github.com/okex/exchain/libs/cosmos-sdk/codec" "github.com/okex/exchain/libs/cosmos-sdk/server" sdk "github.com/okex/exchain/libs/cosmos-sdk/types" + "github.com/okex/exchain/libs/iavl" "github.com/okex/exchain/libs/system/trace" abci "github.com/okex/exchain/libs/tendermint/abci/types" tcmd "github.com/okex/exchain/libs/tendermint/cmd/tendermint/commands" @@ -66,6 +68,7 @@ func replayCmd(ctx *server.Context, registerAppFlagFn func(cmd *cobra.Command), fmt.Println(err) return err } + iavl.SetEnableFastStorage(appstatus.IsFastStorageStrategy()) server.SetExternalPackageValue(cmd) types.InitSignatureCache() return nil diff --git a/libs/cosmos-sdk/server/start.go b/libs/cosmos-sdk/server/start.go index 6f0f04a312..e81f67141b 100644 --- a/libs/cosmos-sdk/server/start.go +++ b/libs/cosmos-sdk/server/start.go @@ -320,7 +320,9 @@ func SetExternalPackageValue(cmd *cobra.Command) { tmiavl.HeightOrphansCacheSize = viper.GetInt(tmiavl.FlagIavlHeightOrphansCacheSize) tmiavl.MaxCommittedHeightNum = viper.GetInt(tmiavl.FlagIavlMaxCommittedHeightNum) tmiavl.EnableAsyncCommit = viper.GetBool(tmiavl.FlagIavlEnableAsyncCommit) - tmiavl.SetEnableFastStorage(viper.GetBool(tmiavl.FlagIavlEnableFastStorage)) + if viper.GetBool(tmiavl.FlagIavlDiscardFastStorage) { + tmiavl.SetEnableFastStorage(false) + } tmiavl.SetFastNodeCacheSize(viper.GetInt(tmiavl.FlagIavlFastStorageCacheSize)) system.EnableGid = viper.GetBool(system.FlagEnableGid) diff --git a/libs/cosmos-sdk/server/start_okchain.go b/libs/cosmos-sdk/server/start_okchain.go index 7c7f06d23e..d7eb1e6087 100644 --- a/libs/cosmos-sdk/server/start_okchain.go +++ b/libs/cosmos-sdk/server/start_okchain.go @@ -206,7 +206,10 @@ func RegisterServerFlags(cmd *cobra.Command) *cobra.Command { cmd.Flags().Int(tmiavl.FlagIavlHeightOrphansCacheSize, 8, "Max orphan version to cache in memory") cmd.Flags().Int(tmiavl.FlagIavlMaxCommittedHeightNum, 30, "Max committed version to cache in memory") cmd.Flags().Bool(tmiavl.FlagIavlEnableAsyncCommit, true, "Enable async commit") + cmd.Flags().Bool(tmiavl.FlagIavlDiscardFastStorage, false, "Discard fast storage") + cmd.Flags().MarkHidden(tmiavl.FlagIavlDiscardFastStorage) cmd.Flags().Bool(tmiavl.FlagIavlEnableFastStorage, false, "Enable fast storage") + cmd.Flags().MarkHidden(tmiavl.FlagIavlEnableFastStorage) cmd.Flags().Int(tmiavl.FlagIavlFastStorageCacheSize, 10000000, "Max size of iavl fast storage cache") cmd.Flags().Bool(abci.FlagDisableABCIQueryMutex, true, "Disable local client query mutex for better concurrency") cmd.Flags().Bool(abci.FlagDisableCheckTx, false, "Disable checkTx for test") diff --git a/libs/iavl/mutable_tree_oec.go b/libs/iavl/mutable_tree_oec.go index 1cac6de6d6..602a25e0b3 100644 --- a/libs/iavl/mutable_tree_oec.go +++ b/libs/iavl/mutable_tree_oec.go @@ -17,8 +17,9 @@ const ( FlagIavlHeightOrphansCacheSize = "iavl-height-orphans-cache-size" FlagIavlMaxCommittedHeightNum = "iavl-max-committed-height-num" FlagIavlEnableAsyncCommit = "iavl-enable-async-commit" - FlagIavlEnableFastStorage = "iavl-enable-fast-storage" FlagIavlFastStorageCacheSize = "iavl-fast-storage-cache-size" + FlagIavlEnableFastStorage = "iavl-enable-fast-storage" + FlagIavlDiscardFastStorage = "discard-fast-storage" ) var ( @@ -33,7 +34,7 @@ var ( EnableAsyncCommit = false EnablePruningHistoryState = true CommitGapHeight int64 = 100 - enableFastStorage = false + enableFastStorage = true fastNodeCacheSize = 10000000 )