Skip to content

Commit 72620a5

Browse files
authored
feat(store/v2): support rocks out of the box (#21649)
1 parent aa8bf41 commit 72620a5

3 files changed

Lines changed: 74 additions & 4 deletions

File tree

server/v2/testdata/app.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ minimum-gas-prices = '0stake'
2525
app-db-backend = 'goleveldb'
2626

2727
[store.options]
28-
# SState storage database type. Currently we support: "sqlite" and "pebble"
28+
# SState storage database type. Currently we support: "sqlite", "pebble" and "rocksdb"
2929
ss-type = 'sqlite'
3030
# State commitment database type. Currently we support: "iavl" and "iavl-v2"
3131
sc-type = 'iavl'

store/v2/root/factory.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"cosmossdk.io/store/v2/pruning"
1717
"cosmossdk.io/store/v2/storage"
1818
"cosmossdk.io/store/v2/storage/pebbledb"
19+
"cosmossdk.io/store/v2/storage/rocksdb"
1920
"cosmossdk.io/store/v2/storage/sqlite"
2021
)
2122

@@ -34,7 +35,7 @@ const (
3435

3536
// app.toml config options
3637
type Options struct {
37-
SSType SSType `mapstructure:"ss-type" toml:"ss-type" comment:"SState storage database type. Currently we support: \"sqlite\" and \"pebble\""`
38+
SSType SSType `mapstructure:"ss-type" toml:"ss-type" comment:"SState storage database type. Currently we support: \"sqlite\", \"pebble\" and \"rocksdb\""`
3839
SCType SCType `mapstructure:"sc-type" toml:"sc-type" comment:"State commitment database type. Currently we support: \"iavl\" and \"iavl-v2\""`
3940
SSPruningOption *store.PruningOption `mapstructure:"ss-pruning-option" toml:"ss-pruning-option" comment:"Pruning options for state storage"`
4041
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) {
103104
}
104105
ssDb, err = pebbledb.New(dir)
105106
case SSTypeRocks:
106-
// TODO: rocksdb requires build tags so is not supported here by default
107-
return nil, errors.New("rocksdb not supported")
107+
dir := fmt.Sprintf("%s/data/ss/rocksdb", opts.RootDir)
108+
if err = ensureDir(dir); err != nil {
109+
return nil, err
110+
}
111+
ssDb, err = rocksdb.New(dir)
108112
}
109113
if err != nil {
110114
return nil, err
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//go:build !rocksdb
2+
// +build !rocksdb
3+
4+
package rocksdb
5+
6+
import (
7+
corestore "cosmossdk.io/core/store"
8+
"cosmossdk.io/store/v2"
9+
"cosmossdk.io/store/v2/storage"
10+
)
11+
12+
var (
13+
_ storage.Database = (*Database)(nil)
14+
_ store.UpgradableDatabase = (*Database)(nil)
15+
)
16+
17+
type Database struct{}
18+
19+
func New(dataDir string) (*Database, error) {
20+
return &Database{}, nil
21+
}
22+
23+
func (db *Database) Close() error {
24+
return nil
25+
}
26+
27+
func (db *Database) NewBatch(version uint64) (store.Batch, error) {
28+
panic("rocksdb requires a build flag")
29+
}
30+
31+
func (db *Database) SetLatestVersion(version uint64) error {
32+
panic("rocksdb requires a build flag")
33+
}
34+
35+
func (db *Database) GetLatestVersion() (uint64, error) {
36+
panic("rocksdb requires a build flag")
37+
}
38+
39+
func (db *Database) Has(storeKey []byte, version uint64, key []byte) (bool, error) {
40+
panic("rocksdb requires a build flag")
41+
}
42+
43+
func (db *Database) Get(storeKey []byte, version uint64, key []byte) ([]byte, error) {
44+
panic("rocksdb requires a build flag")
45+
}
46+
47+
// Prune prunes all versions up to and including the provided version argument.
48+
// Internally, this performs a manual compaction, the data with older timestamp
49+
// will be GCed by compaction.
50+
func (db *Database) Prune(version uint64) error {
51+
panic("rocksdb requires a build flag")
52+
}
53+
54+
func (db *Database) Iterator(storeKey []byte, version uint64, start, end []byte) (corestore.Iterator, error) {
55+
panic("rocksdb requires a build flag")
56+
}
57+
58+
func (db *Database) ReverseIterator(storeKey []byte, version uint64, start, end []byte) (corestore.Iterator, error) {
59+
panic("rocksdb requires a build flag")
60+
}
61+
62+
// PruneStoreKeys will do nothing for RocksDB, it will be pruned by compaction
63+
// when the version is pruned
64+
func (db *Database) PruneStoreKeys(_ []string, _ uint64) error {
65+
return nil
66+
}

0 commit comments

Comments
 (0)