Skip to content

Commit 14922c4

Browse files
committed
fix(config): remove inactive RocksDB options
Preserve the shipped RocksDB configuration and public block-size API while removing table setters that never reached the native table factory. Document that blocksize is currently ineffective and verify native behavior. Keep the existing shared cache object for separate configuration design and validation. Closes #6939
1 parent 4a21592 commit 14922c4

4 files changed

Lines changed: 78 additions & 8 deletions

File tree

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

Lines changed: 1 addition & 8 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;
@@ -211,13 +210,7 @@ protected void log(InfoLogLevel infoLogLevel, String logMsg) {
211210
options.setTargetFileSizeBase(settings.getTargetFileSizeBase());
212211

213212
// 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));
213+
options.setTableFormatConfig(new BlockBasedTableConfig());
221214
if (Constant.MARKET_PAIR_PRICE_TO_ORDER.equals(dbName)) {
222215
ComparatorOptions comparatorOptions = new ComparatorOptions();
223216
options.setComparator(new MarketOrderPriceComparatorForRocksDB(comparatorOptions));

‎common/src/main/resources/reference.conf‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ storage {
108108
dbSettings = {
109109
levelNumber = 7 // Number of RocksDB levels.
110110
compactThreads = 0 // 0 = auto: max(availableProcessors, 1)
111+
# Currently retained for compatibility but not applied to native RocksDB table options.
111112
blocksize = 16 // n * KB
112113
maxBytesForLevelBase = 256 // n * MB
113114
maxBytesForLevelMultiplier = 10 // Level size multiplier.
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+
}

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

Lines changed: 17 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,20 @@ 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+
assertTrue(config.hasPath("storage.dbSettings.blocksize"));
102+
assertEquals(64, settings.getBlocksize());
103+
assertEquals(7, settings.getLevelNumber());
104+
assertEquals(256, settings.getMaxBytesForLevelBase());
105+
assertEquals(10, settings.getMaxBytesForLevelMultiplier(), 0.01);
106+
assertEquals(4, settings.getLevel0FileNumCompactionTrigger());
107+
assertEquals(256, settings.getTargetFileSizeBase());
108+
assertEquals(1, settings.getTargetFileSizeMultiplier());
109+
assertEquals(5000, settings.getMaxOpenFiles());
110+
}
94111
}

0 commit comments

Comments
 (0)