diff --git a/CHANGELOG.md b/CHANGELOG.md index 7206a732110b..88c07345c297 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,17 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Improvements + +* (store) [#14189](https://github.com/cosmos/cosmos-sdk/pull/14189) Add config `iavl-lazy-loading` to enable lazy loading of iavl store, to improve start up time of archive nodes, add method `SetLazyLoading` to `CommitMultiStore` interface. + * A new field has been added to the app.toml. This alllows nodes with larger databases to startup quicker + + ```toml + # IAVLLazyLoading enable/disable the lazy loading of iavl store. + # Default is false. + iavl-lazy-loading = "" + ``` + ### Bug Fixes - (store) [#14798](https://github.com/cosmos/cosmos-sdk/pull/14798) Copy btree to avoid the problem of modify while iteration. diff --git a/baseapp/options.go b/baseapp/options.go index 59b6a2dcc3d8..84b57e2e92e5 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -69,6 +69,11 @@ func SetIAVLDisableFastNode(disable bool) func(*BaseApp) { return func(bapp *BaseApp) { bapp.cms.SetIAVLDisableFastNode(disable) } } +// SetIAVLLazyLoading enables/disables lazy loading of the IAVL store. +func SetIAVLLazyLoading(lazyLoading bool) func(*BaseApp) { + return func(bapp *BaseApp) { bapp.cms.SetLazyLoading(lazyLoading) } +} + // SetInterBlockCache provides a BaseApp option function that sets the // inter-block cache. func SetInterBlockCache(cache sdk.MultiStorePersistentCache) func(*BaseApp) { diff --git a/go.mod b/go.mod index 4b8102bdb91a..24d71a15008b 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/cosmos/cosmos-proto v1.0.0-alpha7 github.com/cosmos/cosmos-sdk/db v1.0.0-beta.1 github.com/cosmos/go-bip39 v1.0.0 - github.com/cosmos/iavl v0.19.5-rc.1 + github.com/cosmos/iavl v0.19.5-rc.2 github.com/cosmos/ledger-cosmos-go v0.12.2 github.com/gogo/gateway v1.1.0 github.com/gogo/protobuf v1.3.2 diff --git a/go.sum b/go.sum index a226b5ec89f2..bef8f811b0c8 100644 --- a/go.sum +++ b/go.sum @@ -240,8 +240,8 @@ github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4Y= github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw= -github.com/cosmos/iavl v0.19.5-rc.1 h1:4PjF2PdScyPbN1WbXpiQU21YtyonnrMU31xN74g8Rkg= -github.com/cosmos/iavl v0.19.5-rc.1/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= +github.com/cosmos/iavl v0.19.5-rc.2 h1:kd97TVlTZWpyM17PjMtXJg0ONCvuCHhG/oU8XXytvK4= +github.com/cosmos/iavl v0.19.5-rc.2/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76 h1:DdzS1m6o/pCqeZ8VOAit/gyATedRgjvkVI+UCrLpyuU= github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76/go.mod h1:0mkLWIoZuQ7uBoospo5Q9zIpqq6rYCPJDSUdeCJvPM8= github.com/cosmos/ledger-cosmos-go v0.12.2 h1:/XYaBlE2BJxtvpkHiBm97gFGSGmYGKunKyF3nNqAXZA= diff --git a/server/config/config.go b/server/config/config.go index fe84b28271d0..40087b149603 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -91,6 +91,9 @@ type BaseConfig struct { // IAVLDisableFastNode enables or disables the fast sync node. IAVLDisableFastNode bool `mapstructure:"iavl-disable-fastnode"` + // IAVLLazyLoading enable/disable the lazy loading of iavl store. + IAVLLazyLoading bool `mapstructure:"iavl-lazy-loading"` + // AppDBBackend defines the type of Database to use for the application and snapshots databases. // An empty string indicates that the Tendermint config's DBBackend value should be used. AppDBBackend string `mapstructure:"app-db-backend"` @@ -285,6 +288,7 @@ func DefaultConfig() *Config { IndexEvents: make([]string, 0), IAVLCacheSize: 781250, // 50 MB IAVLDisableFastNode: false, + IAVLLazyLoading: false, AppDBBackend: "", }, Telemetry: telemetry.Config{ diff --git a/server/config/toml.go b/server/config/toml.go index 57fdafa3262a..920201b330e4 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -78,6 +78,10 @@ iavl-cache-size = {{ .BaseConfig.IAVLCacheSize }} # Default is false. iavl-disable-fastnode = {{ .BaseConfig.IAVLDisableFastNode }} +# EXPERIMENTAL: IAVLLazyLoading enable/disable the lazy loading of iavl store. +# Default is false. +iavl-lazy-loading = {{ .BaseConfig.IAVLLazyLoading }} + # AppDBBackend defines the database backend type to use for the application and snapshots DBs. # An empty string indicates that a fallback will be used. # First fallback is the deprecated compile-time types.DBBackend value. diff --git a/server/mock/store.go b/server/mock/store.go index d427806f72e9..17e20de54e00 100644 --- a/server/mock/store.go +++ b/server/mock/store.go @@ -134,6 +134,10 @@ func (ms multiStore) SetIAVLDisableFastNode(disable bool) { panic("not implemented") } +func (ms multiStore) SetLazyLoading(bool) { + panic("not implemented") +} + func (ms multiStore) SetInitialVersion(version int64) error { panic("not implemented") } diff --git a/server/start.go b/server/start.go index 402c88d7479e..b10518f2efb6 100644 --- a/server/start.go +++ b/server/start.go @@ -58,6 +58,7 @@ const ( FlagMinRetainBlocks = "min-retain-blocks" FlagIAVLCacheSize = "iavl-cache-size" FlagDisableIAVLFastNode = "iavl-disable-fastnode" + FlagIAVLLazyLoading = "iavl-lazy-loading" // state sync-related flags FlagStateSyncSnapshotInterval = "state-sync.snapshot-interval" diff --git a/server/util.go b/server/util.go index e211bd245844..1834da6c3384 100644 --- a/server/util.go +++ b/server/util.go @@ -457,5 +457,6 @@ func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) { baseapp.SetSnapshot(snapshotStore, snapshotOptions), baseapp.SetIAVLCacheSize(cast.ToInt(appOpts.Get(FlagIAVLCacheSize))), baseapp.SetIAVLDisableFastNode(cast.ToBool(appOpts.Get(FlagDisableIAVLFastNode))), + baseapp.SetIAVLLazyLoading(cast.ToBool(appOpts.Get(FlagIAVLLazyLoading))), } } diff --git a/store/iavl/store.go b/store/iavl/store.go index 45a9e6496389..3cf6c1dedbf2 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -239,6 +239,11 @@ func (st *Store) LoadVersionForOverwriting(targetVersion int64) (int64, error) { return st.tree.LoadVersionForOverwriting(targetVersion) } +// LazyLoadVersionForOverwriting is the lazy version of LoadVersionForOverwriting. +func (st *Store) LazyLoadVersionForOverwriting(targetVersion int64) (int64, error) { + return st.tree.LazyLoadVersionForOverwriting(targetVersion) +} + // Implements types.KVStore. func (st *Store) Iterator(start, end []byte) types.Iterator { iterator, err := st.tree.Iterator(start, end, true) diff --git a/store/iavl/tree.go b/store/iavl/tree.go index 81350fc34a8b..f8e2843f61c6 100644 --- a/store/iavl/tree.go +++ b/store/iavl/tree.go @@ -35,6 +35,7 @@ type ( Iterator(start, end []byte, ascending bool) (types.Iterator, error) AvailableVersions() []int LoadVersionForOverwriting(targetVersion int64) (int64, error) + LazyLoadVersionForOverwriting(targetVersion int64) (int64, error) } // immutableTree is a simple wrapper around a reference to an iavl.ImmutableTree @@ -104,3 +105,7 @@ func (it *immutableTree) AvailableVersions() []int { func (it *immutableTree) LoadVersionForOverwriting(targetVersion int64) (int64, error) { panic("cannot call 'LoadVersionForOverwriting' on an immutable IAVL tree") } + +func (it *immutableTree) LazyLoadVersionForOverwriting(targetVersion int64) (int64, error) { + panic("cannot call 'LazyLoadVersionForOverwriting' on an immutable IAVL tree") +} diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index d02944d95800..3b5fede4321d 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -966,7 +966,12 @@ func (rs *Store) RollbackToVersion(target int64) error { // If the store is wrapped with an inter-block cache, we must first unwrap // it to get the underlying IAVL store. store = rs.GetCommitKVStore(key) - _, err := store.(*iavl.Store).LoadVersionForOverwriting(target) + var err error + if rs.lazyLoading { + _, err = store.(*iavl.Store).LazyLoadVersionForOverwriting(target) + } else { + _, err = store.(*iavl.Store).LoadVersionForOverwriting(target) + } if err != nil { return err } diff --git a/store/types/store.go b/store/types/store.go index ef5ff36c8c42..7ad4da2cc0a3 100644 --- a/store/types/store.go +++ b/store/types/store.go @@ -188,6 +188,9 @@ type CommitMultiStore interface { // SetIAVLDisableFastNode enables/disables fastnode feature on iavl. SetIAVLDisableFastNode(disable bool) + // SetIAVLLazyLoading enable/disable lazy loading on iavl. + SetLazyLoading(lazyLoading bool) + // RollbackToVersion rollback the db to specific version(height). RollbackToVersion(version int64) error