Skip to content

Commit

Permalink
feat(store/v2): support rocks out of the box (cosmos#21649)
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle authored Sep 11, 2024
1 parent aa8bf41 commit 72620a5
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 4 deletions.
2 changes: 1 addition & 1 deletion server/v2/testdata/app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
10 changes: 7 additions & 3 deletions store/v2/root/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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"`
Expand Down Expand Up @@ -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
Expand Down
66 changes: 66 additions & 0 deletions store/v2/storage/rocksdb/db_noflag.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 72620a5

Please sign in to comment.