Skip to content

Commit 2594672

Browse files
committed
fix(config): remove inactive RocksDB options
Preserve the shipped RocksDB options that were effective before this change. Remove the inactive blocksize plumbing and table setters without activating the unverified table configuration. Keep the existing shared cache object for separate configuration design and validation. Closes #49
1 parent 4a21592 commit 2594672

8 files changed

Lines changed: 85 additions & 32 deletions

File tree

common/src/main/java/org/tron/common/setting/RocksDbSettings.java

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import lombok.Getter;
77
import lombok.extern.slf4j.Slf4j;
88
import org.rocksdb.BlockBasedTableConfig;
9-
import org.rocksdb.BloomFilter;
109
import org.rocksdb.ComparatorOptions;
1110
import org.rocksdb.InfoLogLevel;
1211
import org.rocksdb.LRUCache;
@@ -30,8 +29,6 @@ public class RocksDbSettings {
3029
@Getter
3130
private int compactThreads;
3231
@Getter
33-
private long blockSize;
34-
@Getter
3532
private long maxBytesForLevelBase;
3633
@Getter
3734
private double maxBytesForLevelMultiplier;
@@ -67,7 +64,7 @@ private RocksDbSettings() {
6764

6865
public static RocksDbSettings getDefaultSettings() {
6966
RocksDbSettings defaultSettings = new RocksDbSettings();
70-
return defaultSettings.withLevelNumber(7).withBlockSize(64).withCompactThreads(32)
67+
return defaultSettings.withLevelNumber(7).withCompactThreads(32)
7168
.withTargetFileSizeBase(256).withMaxBytesForLevelMultiplier(10)
7269
.withTargetFileSizeMultiplier(1)
7370
.withMaxBytesForLevelBase(256).withMaxOpenFiles(5000).withEnableStatistics(false);
@@ -78,16 +75,14 @@ public static RocksDbSettings getSettings() {
7875
}
7976

8077
public static RocksDbSettings initCustomSettings(int levelNumber, int compactThreads,
81-
int blockSize, long maxBytesForLevelBase,
82-
double maxBytesForLevelMultiplier, int level0FileNumCompactionTrigger,
83-
long targetFileSizeBase,
78+
long maxBytesForLevelBase, double maxBytesForLevelMultiplier,
79+
int level0FileNumCompactionTrigger, long targetFileSizeBase,
8480
int targetFileSizeMultiplier, int maxOpenFiles) {
8581
rocksDbSettings = new RocksDbSettings()
8682
.withMaxOpenFiles(maxOpenFiles)
8783
.withEnableStatistics(false)
8884
.withLevelNumber(levelNumber)
8985
.withCompactThreads(compactThreads)
90-
.withBlockSize(blockSize)
9186
.withMaxBytesForLevelBase(maxBytesForLevelBase)
9287
.withMaxBytesForLevelMultiplier(maxBytesForLevelMultiplier)
9388
.withLevel0FileNumCompactionTrigger(level0FileNumCompactionTrigger)
@@ -98,12 +93,11 @@ public static RocksDbSettings initCustomSettings(int levelNumber, int compactThr
9893

9994
public static void loggingSettings() {
10095
logger.info(
101-
"level number: {}, CompactThreads: {}, Blocksize:{}, maxBytesForLevelBase: {},"
96+
"level number: {}, CompactThreads: {}, maxBytesForLevelBase: {},"
10297
+ " withMaxBytesForLevelMultiplier: {}, level0FileNumCompactionTrigger: {}, "
10398
+ "withTargetFileSizeBase: {}, withTargetFileSizeMultiplier: {}, maxOpenFiles: {}",
10499
rocksDbSettings.getLevelNumber(),
105-
rocksDbSettings.getCompactThreads(), rocksDbSettings.getBlockSize(),
106-
rocksDbSettings.getMaxBytesForLevelBase(),
100+
rocksDbSettings.getCompactThreads(), rocksDbSettings.getMaxBytesForLevelBase(),
107101
rocksDbSettings.getMaxBytesForLevelMultiplier(),
108102
rocksDbSettings.getLevel0FileNumCompactionTrigger(),
109103
rocksDbSettings.getTargetFileSizeBase(), rocksDbSettings.getTargetFileSizeMultiplier(),
@@ -120,11 +114,6 @@ public RocksDbSettings withCompactThreads(int compactThreads) {
120114
return this;
121115
}
122116

123-
public RocksDbSettings withBlockSize(long blockSize) {
124-
this.blockSize = blockSize * 1024;
125-
return this;
126-
}
127-
128117
public RocksDbSettings withMaxBytesForLevelBase(long maxBytesForLevelBase) {
129118
this.maxBytesForLevelBase = maxBytesForLevelBase * 1024 * 1024;
130119
return this;
@@ -159,6 +148,7 @@ public RocksDbSettings withTargetFileSizeMultiplier(int targetFileSizeMultiplier
159148
this.targetFileSizeMultiplier = targetFileSizeMultiplier;
160149
return this;
161150
}
151+
162152
public static LRUCache getCache() {
163153
return cache;
164154
}
@@ -211,13 +201,7 @@ protected void log(InfoLogLevel infoLogLevel, String logMsg) {
211201
options.setTargetFileSizeBase(settings.getTargetFileSizeBase());
212202

213203
// table options
214-
final BlockBasedTableConfig tableCfg;
215-
options.setTableFormatConfig(tableCfg = new BlockBasedTableConfig());
216-
tableCfg.setBlockSize(settings.getBlockSize());
217-
tableCfg.setBlockCache(RocksDbSettings.getCache());
218-
tableCfg.setCacheIndexAndFilterBlocks(true);
219-
tableCfg.setPinL0FilterAndIndexBlocksInCache(true);
220-
tableCfg.setFilter(new BloomFilter(10, false));
204+
options.setTableFormatConfig(new BlockBasedTableConfig());
221205
if (Constant.MARKET_PAIR_PRICE_TO_ORDER.equals(dbName)) {
222206
ComparatorOptions comparatorOptions = new ComparatorOptions();
223207
options.setComparator(new MarketOrderPriceComparatorForRocksDB(comparatorOptions));

common/src/main/java/org/tron/core/config/args/StorageConfig.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ public static class DbSettingsConfig {
8686

8787
private int levelNumber = 7;
8888
private int compactThreads = 0; // 0 = auto: max(availableProcessors, 1)
89-
private int blocksize = 16;
9089
private long maxBytesForLevelBase = 256;
9190
private double maxBytesForLevelMultiplier = 10;
9291
private int level0FileNumCompactionTrigger = 2;

common/src/main/resources/reference.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ storage {
108108
dbSettings = {
109109
levelNumber = 7 // Number of RocksDB levels.
110110
compactThreads = 0 // 0 = auto: max(availableProcessors, 1)
111-
blocksize = 16 // n * KB
112111
maxBytesForLevelBase = 256 // n * MB
113112
maxBytesForLevelMultiplier = 10 // Level size multiplier.
114113
level0FileNumCompactionTrigger = 2 // L0 files that trigger compaction.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* java-tron is free software: you can redistribute it and/or modify
3+
* it under the terms of the GNU General Public License as published by
4+
* the Free Software Foundation, either version 3 of the License, or
5+
* (at your option) any later version.
6+
*
7+
* java-tron is distributed in the hope that it will be useful,
8+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
* GNU General Public License for more details.
11+
*
12+
* You should have received a copy of the GNU General Public License
13+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
14+
*/
15+
16+
package org.tron.common.setting;
17+
18+
import static org.junit.Assert.assertTrue;
19+
20+
import java.nio.charset.StandardCharsets;
21+
import java.nio.file.Files;
22+
import java.nio.file.Path;
23+
import java.util.Comparator;
24+
import java.util.stream.Stream;
25+
import org.junit.Rule;
26+
import org.junit.Test;
27+
import org.junit.rules.TemporaryFolder;
28+
import org.rocksdb.Options;
29+
import org.rocksdb.RocksDB;
30+
31+
public class RocksDbSettingsTest {
32+
33+
@Rule
34+
public TemporaryFolder temporaryFolder = new TemporaryFolder();
35+
36+
@Test
37+
public void shouldKeepNativeBlockTableDefaults() throws Exception {
38+
Path database = temporaryFolder.newFolder("rocksdb").toPath();
39+
40+
try (Options options = RocksDbSettings.getOptionsByDbName("test")) {
41+
try (RocksDB ignored = RocksDB.open(options, database.toString())) {
42+
// Opening the DB materializes the table factory and persists its native settings.
43+
}
44+
}
45+
46+
Path optionsFile;
47+
try (Stream<Path> files = Files.list(database)) {
48+
optionsFile = files
49+
.filter(path -> path.getFileName().toString().startsWith("OPTIONS-"))
50+
.max(Comparator.comparing(path -> path.getFileName().toString()))
51+
.orElseThrow(() -> new AssertionError("RocksDB OPTIONS file not found"));
52+
}
53+
String nativeOptions = new String(Files.readAllBytes(optionsFile), StandardCharsets.UTF_8);
54+
55+
assertTrue(nativeOptions.contains("block_size=4096"));
56+
assertTrue(nativeOptions.contains("pin_l0_filter_and_index_blocks_in_cache=false"));
57+
assertTrue(nativeOptions.contains("filter_policy=nullptr"));
58+
}
59+
}

common/src/test/java/org/tron/core/config/args/StorageConfigTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public void testDbSettingsDefaults() {
6868
// compactThreads default is 0 in reference.conf, auto-expanded by postProcess()
6969
assertEquals(StrictMathWrapper.max(Runtime.getRuntime().availableProcessors(), 1),
7070
ds.getCompactThreads());
71-
assertEquals(16, ds.getBlocksize());
7271
assertEquals(256, ds.getMaxBytesForLevelBase());
7372
assertEquals(10, ds.getMaxBytesForLevelMultiplier(), 0.01);
7473
assertEquals(2, ds.getLevel0FileNumCompactionTrigger());

framework/src/main/java/org/tron/core/config/args/Args.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,9 @@ private static void applyStorageConfig(StorageConfig sc) {
228228
StorageConfig.DbSettingsConfig dbs = sc.getDbSettings();
229229
PARAMETER.rocksDBCustomSettings = RocksDbSettings
230230
.initCustomSettings(dbs.getLevelNumber(), dbs.getCompactThreads(),
231-
dbs.getBlocksize(), dbs.getMaxBytesForLevelBase(),
232-
dbs.getMaxBytesForLevelMultiplier(), dbs.getLevel0FileNumCompactionTrigger(),
233-
dbs.getTargetFileSizeBase(), dbs.getTargetFileSizeMultiplier(),
234-
dbs.getMaxOpenFiles());
231+
dbs.getMaxBytesForLevelBase(), dbs.getMaxBytesForLevelMultiplier(),
232+
dbs.getLevel0FileNumCompactionTrigger(), dbs.getTargetFileSizeBase(),
233+
dbs.getTargetFileSizeMultiplier(), dbs.getMaxOpenFiles());
235234
RocksDbSettings.loggingSettings();
236235

237236
// Dynamic nested objects use StorageConfig's raw storage sub-tree
@@ -1315,4 +1314,3 @@ private static Map<String, String[]> getOptionGroup() {
13151314
return optionGroupMap;
13161315
}
13171316
}
1318-

framework/src/main/resources/config.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ storage {
2626
dbSettings = {
2727
levelNumber = 7
2828
# compactThreads = 32
29-
blocksize = 64 // n * KB
3029
maxBytesForLevelBase = 256 // n * MB
3130
maxBytesForLevelMultiplier = 10
3231
level0FileNumCompactionTrigger = 4

framework/src/test/java/org/tron/core/config/ConfigurationTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.tron.common.crypto.ECKey;
3636
import org.tron.common.utils.ByteArray;
3737
import org.tron.core.Wallet;
38+
import org.tron.core.config.args.StorageConfig;
3839

3940
@Slf4j
4041
public class ConfigurationTest {
@@ -91,4 +92,19 @@ public void getConfigurationWhenOnlyConfFileName() {
9192
assertTrue(config.hasPath("seed.node"));
9293
assertTrue(config.hasPath("genesis.block"));
9394
}
95+
96+
@Test
97+
public void defaultConfigShouldPreserveEffectiveRocksDbSettings() {
98+
Config config = Configuration.getByFileName("config.conf");
99+
StorageConfig.DbSettingsConfig settings = StorageConfig.fromConfig(config).getDbSettings();
100+
101+
assertFalse(config.hasPath("storage.dbSettings.blocksize"));
102+
assertEquals(7, settings.getLevelNumber());
103+
assertEquals(256, settings.getMaxBytesForLevelBase());
104+
assertEquals(10, settings.getMaxBytesForLevelMultiplier(), 0.01);
105+
assertEquals(4, settings.getLevel0FileNumCompactionTrigger());
106+
assertEquals(256, settings.getTargetFileSizeBase());
107+
assertEquals(1, settings.getTargetFileSizeMultiplier());
108+
assertEquals(5000, settings.getMaxOpenFiles());
109+
}
94110
}

0 commit comments

Comments
 (0)