feat(store/v2): support rocks out of the box (#21649)

This commit is contained in:
Marko 2024-09-11 16:36:51 +02:00 committed by GitHub
parent aa8bf41eb9
commit 72620a5776
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 74 additions and 4 deletions

View File

@ -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'

View File

@ -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

View File

@ -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
}