From 72620a57766094d80051576e9c680a5859e4e061 Mon Sep 17 00:00:00 2001 From: Marko Date: Wed, 11 Sep 2024 16:36:51 +0200 Subject: [PATCH] feat(store/v2): support rocks out of the box (#21649) --- server/v2/testdata/app.toml | 2 +- store/v2/root/factory.go | 10 ++-- store/v2/storage/rocksdb/db_noflag.go | 66 +++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 store/v2/storage/rocksdb/db_noflag.go diff --git a/server/v2/testdata/app.toml b/server/v2/testdata/app.toml index 3581b2ae7e63..094ac068d94a 100644 --- a/server/v2/testdata/app.toml +++ b/server/v2/testdata/app.toml @@ -25,7 +25,7 @@ minimum-gas-prices = '0stake' app-db-backend = 'goleveldb' [store.options] -# SState storage database type. Currently we support: "sqlite" and "pebble" +# SState storage database type. Currently we support: "sqlite", "pebble" and "rocksdb" ss-type = 'sqlite' # State commitment database type. Currently we support: "iavl" and "iavl-v2" sc-type = 'iavl' diff --git a/store/v2/root/factory.go b/store/v2/root/factory.go index c906c4bfecf2..4dfa01966314 100644 --- a/store/v2/root/factory.go +++ b/store/v2/root/factory.go @@ -16,6 +16,7 @@ import ( "cosmossdk.io/store/v2/pruning" "cosmossdk.io/store/v2/storage" "cosmossdk.io/store/v2/storage/pebbledb" + "cosmossdk.io/store/v2/storage/rocksdb" "cosmossdk.io/store/v2/storage/sqlite" ) @@ -34,7 +35,7 @@ const ( // app.toml config options type Options struct { - SSType SSType `mapstructure:"ss-type" toml:"ss-type" comment:"SState storage database type. Currently we support: \"sqlite\" and \"pebble\""` + SSType SSType `mapstructure:"ss-type" toml:"ss-type" comment:"SState storage database type. Currently we support: \"sqlite\", \"pebble\" and \"rocksdb\""` SCType SCType `mapstructure:"sc-type" toml:"sc-type" comment:"State commitment database type. Currently we support: \"iavl\" and \"iavl-v2\""` SSPruningOption *store.PruningOption `mapstructure:"ss-pruning-option" toml:"ss-pruning-option" comment:"Pruning options for state storage"` SCPruningOption *store.PruningOption `mapstructure:"sc-pruning-option" toml:"sc-pruning-option" comment:"Pruning options for state commitment"` @@ -103,8 +104,11 @@ func CreateRootStore(opts *FactoryOptions) (store.RootStore, error) { } ssDb, err = pebbledb.New(dir) case SSTypeRocks: - // TODO: rocksdb requires build tags so is not supported here by default - return nil, errors.New("rocksdb not supported") + dir := fmt.Sprintf("%s/data/ss/rocksdb", opts.RootDir) + if err = ensureDir(dir); err != nil { + return nil, err + } + ssDb, err = rocksdb.New(dir) } if err != nil { return nil, err diff --git a/store/v2/storage/rocksdb/db_noflag.go b/store/v2/storage/rocksdb/db_noflag.go new file mode 100644 index 000000000000..def31e437a44 --- /dev/null +++ b/store/v2/storage/rocksdb/db_noflag.go @@ -0,0 +1,66 @@ +//go:build !rocksdb +// +build !rocksdb + +package rocksdb + +import ( + corestore "cosmossdk.io/core/store" + "cosmossdk.io/store/v2" + "cosmossdk.io/store/v2/storage" +) + +var ( + _ storage.Database = (*Database)(nil) + _ store.UpgradableDatabase = (*Database)(nil) +) + +type Database struct{} + +func New(dataDir string) (*Database, error) { + return &Database{}, nil +} + +func (db *Database) Close() error { + return nil +} + +func (db *Database) NewBatch(version uint64) (store.Batch, error) { + panic("rocksdb requires a build flag") +} + +func (db *Database) SetLatestVersion(version uint64) error { + panic("rocksdb requires a build flag") +} + +func (db *Database) GetLatestVersion() (uint64, error) { + panic("rocksdb requires a build flag") +} + +func (db *Database) Has(storeKey []byte, version uint64, key []byte) (bool, error) { + panic("rocksdb requires a build flag") +} + +func (db *Database) Get(storeKey []byte, version uint64, key []byte) ([]byte, error) { + panic("rocksdb requires a build flag") +} + +// Prune prunes all versions up to and including the provided version argument. +// Internally, this performs a manual compaction, the data with older timestamp +// will be GCed by compaction. +func (db *Database) Prune(version uint64) error { + panic("rocksdb requires a build flag") +} + +func (db *Database) Iterator(storeKey []byte, version uint64, start, end []byte) (corestore.Iterator, error) { + panic("rocksdb requires a build flag") +} + +func (db *Database) ReverseIterator(storeKey []byte, version uint64, start, end []byte) (corestore.Iterator, error) { + panic("rocksdb requires a build flag") +} + +// PruneStoreKeys will do nothing for RocksDB, it will be pruned by compaction +// when the version is pruned +func (db *Database) PruneStoreKeys(_ []string, _ uint64) error { + return nil +}