Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.rocksdb.BlockBasedTableConfig;
import org.rocksdb.BloomFilter;
import org.rocksdb.ComparatorOptions;
import org.rocksdb.InfoLogLevel;
import org.rocksdb.LRUCache;
Expand Down Expand Up @@ -211,13 +210,7 @@ protected void log(InfoLogLevel infoLogLevel, String logMsg) {
options.setTargetFileSizeBase(settings.getTargetFileSizeBase());

// table options
final BlockBasedTableConfig tableCfg;
options.setTableFormatConfig(tableCfg = new BlockBasedTableConfig());
tableCfg.setBlockSize(settings.getBlockSize());
tableCfg.setBlockCache(RocksDbSettings.getCache());
tableCfg.setCacheIndexAndFilterBlocks(true);
tableCfg.setPinL0FilterAndIndexBlocksInCache(true);
tableCfg.setFilter(new BloomFilter(10, false));
options.setTableFormatConfig(new BlockBasedTableConfig());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[NIT] Remove options.setTableFormatConfig(new BlockBasedTableConfig()); ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retain an entry point for modifying the configuration; this is a change that will require separate verification in the future.

if (Constant.MARKET_PAIR_PRICE_TO_ORDER.equals(dbName)) {
ComparatorOptions comparatorOptions = new ComparatorOptions();
options.setComparator(new MarketOrderPriceComparatorForRocksDB(comparatorOptions));
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ storage {
dbSettings = {
levelNumber = 7 // Number of RocksDB levels.
compactThreads = 0 // 0 = auto: max(availableProcessors, 1)
blocksize = 16 // n * KB
blocksize = 16 // n * KB. Currently retained for compatibility but not applied to native RocksDB table options.
maxBytesForLevelBase = 256 // n * MB
maxBytesForLevelMultiplier = 10 // Level size multiplier.
level0FileNumCompactionTrigger = 2 // L0 files that trigger compaction.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* java-tron is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* java-tron is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.tron.common.setting;

import static org.junit.Assert.assertTrue;

import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
import java.util.stream.Stream;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.rocksdb.Options;
import org.rocksdb.RocksDB;

public class RocksDbSettingsTest {

@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();

@Test
public void shouldKeepNativeBlockTableDefaults() throws Exception {
Path database = temporaryFolder.newFolder("rocksdb").toPath();

try (Options options = RocksDbSettings.getOptionsByDbName("test")) {
try (RocksDB ignored = RocksDB.open(options, database.toString())) {
// Opening the DB materializes the table factory and persists its native settings.
}
}

Path optionsFile;
try (Stream<Path> files = Files.list(database)) {
optionsFile = files
.filter(path -> path.getFileName().toString().startsWith("OPTIONS-"))
.max(Comparator.comparing(path -> path.getFileName().toString()))
.orElseThrow(() -> new AssertionError("RocksDB OPTIONS file not found"));
}
String nativeOptions = new String(Files.readAllBytes(optionsFile), StandardCharsets.UTF_8);

assertTrue(nativeOptions.contains("block_size=4096"));
assertTrue(nativeOptions.contains("pin_l0_filter_and_index_blocks_in_cache=false"));
assertTrue(nativeOptions.contains("filter_policy=nullptr"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.tron.common.crypto.ECKey;
import org.tron.common.utils.ByteArray;
import org.tron.core.Wallet;
import org.tron.core.config.args.StorageConfig;

@Slf4j
public class ConfigurationTest {
Expand Down Expand Up @@ -91,4 +92,20 @@ public void getConfigurationWhenOnlyConfFileName() {
assertTrue(config.hasPath("seed.node"));
assertTrue(config.hasPath("genesis.block"));
}

@Test
public void defaultConfigShouldPreserveEffectiveRocksDbSettings() {
Config config = Configuration.getByFileName("config.conf");
StorageConfig.DbSettingsConfig settings = StorageConfig.fromConfig(config).getDbSettings();

assertTrue(config.hasPath("storage.dbSettings.blocksize"));
assertEquals(64, settings.getBlocksize());
assertEquals(7, settings.getLevelNumber());
assertEquals(256, settings.getMaxBytesForLevelBase());
assertEquals(10, settings.getMaxBytesForLevelMultiplier(), 0.01);
assertEquals(4, settings.getLevel0FileNumCompactionTrigger());
assertEquals(256, settings.getTargetFileSizeBase());
assertEquals(1, settings.getTargetFileSizeMultiplier());
assertEquals(5000, settings.getMaxOpenFiles());
}
}
Loading