Skip to content

Commit da5db44

Browse files
author
yihuang
authored
Problem: sst files are ingested into too bottom level by default (#871)
* Problem: sst files are ingested into too bottom level by default Solution: - set temporary num_level when ingesting sst files * comments * revert rocksdb version change * changelog
1 parent 60ac2b6 commit da5db44

File tree

7 files changed

+49
-14
lines changed

7 files changed

+49
-14
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Changelog
22

3-
*Feb 09, 2022*
3+
*Feb 15, 2022*
44

55
## v1.0.4
66

@@ -13,7 +13,8 @@
1313

1414
- [#813](https://github.com/crypto-org-chain/cronos/pull/813) Tune up rocksdb options.
1515
- [#791](https://github.com/crypto-org-chain/cronos/pull/791) Implement versiondb and migration commands.
16-
- [#779](https://github.com/crypto-org-chain/cronos/pull/779) Add config iavl-lazy-loading to enable lazy loading of iavl store.
16+
- [#779](https://github.com/crypto-org-chain/cronos/pull/779) Add config `iavl-lazy-loading` to enable lazy loading of iavl store.
17+
- [#871](https://github.com/crypto-org-chain/cronos/pull/871) Only ingest sst files to level 3 in versiondb migration.
1718

1819
*Feb 08, 2023*
1920

integration_tests/test_versiondb.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,15 @@ def test_versiondb_migration(cronos: Cronos):
6363
print("restore versiondb for node0")
6464
sst_dir = tempfile.mkdtemp(dir=cronos.base_dir)
6565
print(cli0.changeset_build_versiondb_sst(changeset_dir, sst_dir))
66+
tmpdir = tempfile.mkdtemp(dir=cronos.base_dir)
6667
print(
6768
cli0.changeset_ingest_versiondb_sst(
68-
cli0.data_dir / "data/versiondb", sst_dir, maximum_version=latest_version
69+
tmpdir, sst_dir, maximum_version=latest_version
6970
)
7071
)
72+
versiondb_dir = cli0.data_dir / "data/versiondb"
73+
shutil.rmtree(versiondb_dir)
74+
shutil.move(tmpdir, versiondb_dir)
7175

7276
print("start all nodes")
7377
print(cronos.supervisorctl("start", "cronos_777-1-node0", "cronos_777-1-node1"))

nix/rocksdb.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ stdenv.mkDerivation rec {
2222
version = "7.9.2";
2323

2424
src = fetchFromGitHub {
25-
owner = "yihuang";
25+
owner = "facebook";
2626
repo = pname;
27-
rev = "82d63cdd7db25cce3b97f30e11000a382c116aff"; # release/v7.9.x
28-
sha256 = "sha256-ProQ5g5CqruWwnmbzD0HN4z9tgal9YCOgNiD9AHjjqo=";
27+
rev = "v${version}";
28+
sha256 = "sha256-5P7IqJ14EZzDkbjaBvbix04ceGGdlWBuVFH/5dpD5VM=";
2929
};
3030

3131
nativeBuildInputs = [ cmake ninja ];

versiondb/client/flags.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ const (
2020
flagLoadSnapshot = "load-snapshot"
2121
flagSorterChunkSize = "sorter-chunk-size"
2222
flagInitialVersion = "initial-version"
23+
flagNumLevels = "num-levels"
2324
)

versiondb/client/ingest_sst.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,19 @@ func IngestVersionDBSSTCmd() *cobra.Command {
2020
if err != nil {
2121
return err
2222
}
23-
24-
db, cfHandle, err := tsrocksdb.OpenVersionDB(dbPath)
23+
numLevels, err := cmd.Flags().GetInt(flagNumLevels)
24+
if err != nil {
25+
return err
26+
}
27+
opts := tsrocksdb.NewVersionDBOpts(false)
28+
// it's a workaround for rocksdb issue(https://github.com/facebook/rocksdb/issues/11212),
29+
// because rocksdb always ingest files into level `num_levels-1`,
30+
// the new data will take a very long time to reach that level,
31+
// level3 is the bottommost level in practice.
32+
if numLevels > 0 {
33+
opts.SetNumLevels(numLevels)
34+
}
35+
db, cfHandle, err := tsrocksdb.OpenVersionDBWithOpts(dbPath, opts)
2536
if err != nil {
2637
return err
2738
}
@@ -56,5 +67,6 @@ func IngestVersionDBSSTCmd() *cobra.Command {
5667
}
5768
cmd.Flags().Bool(flagMoveFiles, false, "move sst files instead of copy them")
5869
cmd.Flags().Int64(flagMaximumVersion, 0, "Specify the maximum version covered by the ingested files, if it's bigger than existing recorded latest version, will update it.")
70+
cmd.Flags().Int(flagNumLevels, 4, "Override the num levels in default options, when ingesting into a new db, the sst files will be ingested into level `num-levels-1`, set to 0 to not override.")
5971
return cmd
6072
}

versiondb/client/restore_app_db.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ func RestoreAppDBCmd(opts Options) *cobra.Command {
6363
if err != nil {
6464
return err
6565
}
66+
numLevels, err := cmd.Flags().GetInt(flagNumLevels)
67+
if err != nil {
68+
return err
69+
}
6670
stores, err := GetStoresOrDefault(cmd, opts.DefaultStores)
6771
if err != nil {
6872
return err
@@ -143,7 +147,15 @@ func RestoreAppDBCmd(opts Options) *cobra.Command {
143147
defer ingestOpts.Destroy()
144148
ingestOpts.SetMoveFiles(true)
145149

146-
db, err := grocksdb.OpenDb(opts.AppRocksDBOptions(false), iavlDir)
150+
opts := opts.AppRocksDBOptions(false)
151+
// it's a workaround for rocksdb issue(https://github.com/facebook/rocksdb/issues/11212),
152+
// because rocksdb always ingest files into level `num_levels-1`,
153+
// the new data will take a very long time to reach that level,
154+
// level3 is the bottommost level in practice.
155+
if numLevels > 0 {
156+
opts.SetNumLevels(numLevels)
157+
}
158+
db, err := grocksdb.OpenDb(opts, iavlDir)
147159
if err != nil {
148160
return errors.Wrap(err, "open iavl db fail")
149161
}
@@ -167,6 +179,7 @@ func RestoreAppDBCmd(opts Options) *cobra.Command {
167179
cmd.Flags().String(flagStores, "", "list of store names, default to the current store list in application")
168180
cmd.Flags().Uint64(flagSorterChunkSize, DefaultSorterChunkSizeIAVL, "uncompressed chunk size for external sorter, it decides the peak ram usage, on disk it'll be snappy compressed")
169181
cmd.Flags().Int(flagConcurrency, runtime.NumCPU(), "Number concurrent goroutines to parallelize the work")
182+
cmd.Flags().Int(flagNumLevels, 4, "Override the num levels in default options, when ingesting into a new db, the sst files will be ingested into level `num-levels-1`, set to 0 to not override.")
170183

171184
return cmd
172185
}

versiondb/tsrocksdb/opts.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,27 @@ func NewVersionDBOpts(sstFileWriter bool) *grocksdb.Options {
4646
return opts
4747
}
4848

49-
// OpenVersionDB opens versiondb, the default column family is used for metadata,
50-
// actually key-value pairs are stored on another column family named with "versiondb",
51-
// which has user-defined timestamp enabled.
52-
func OpenVersionDB(dir string) (*grocksdb.DB, *grocksdb.ColumnFamilyHandle, error) {
49+
func OpenVersionDBWithOpts(dir string, versionDBOpts *grocksdb.Options) (*grocksdb.DB, *grocksdb.ColumnFamilyHandle, error) {
5350
opts := grocksdb.NewDefaultOptions()
5451
opts.SetCreateIfMissing(true)
5552
opts.SetCreateIfMissingColumnFamilies(true)
5653
db, cfHandles, err := grocksdb.OpenDbColumnFamilies(
5754
opts, dir, []string{"default", VersionDBCFName},
58-
[]*grocksdb.Options{opts, NewVersionDBOpts(false)},
55+
[]*grocksdb.Options{opts, versionDBOpts},
5956
)
6057
if err != nil {
6158
return nil, nil, err
6259
}
6360
return db, cfHandles[1], nil
6461
}
6562

63+
// OpenVersionDB opens versiondb, the default column family is used for metadata,
64+
// actually key-value pairs are stored on another column family named with "versiondb",
65+
// which has user-defined timestamp enabled.
66+
func OpenVersionDB(dir string) (*grocksdb.DB, *grocksdb.ColumnFamilyHandle, error) {
67+
return OpenVersionDBWithOpts(dir, NewVersionDBOpts(false))
68+
}
69+
6670
// OpenVersionDBAndTrimHistory opens versiondb similar to `OpenVersionDB`,
6771
// but it also trim the versions newer than target one, can be used for rollback.
6872
func OpenVersionDBAndTrimHistory(dir string, version int64) (*grocksdb.DB, *grocksdb.ColumnFamilyHandle, error) {

0 commit comments

Comments
 (0)