Skip to content

Commit 154cca1

Browse files
committed
fix(db): configure BlockBasedTableConfig before setTableFormatConfig
1 parent 0871079 commit 154cca1

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,15 @@ protected void log(InfoLogLevel infoLogLevel, String logMsg) {
211211
options.setTargetFileSizeBase(settings.getTargetFileSizeBase());
212212

213213
// table options
214-
final BlockBasedTableConfig tableCfg;
215-
options.setTableFormatConfig(tableCfg = new BlockBasedTableConfig());
214+
// NOTE: setTableFormatConfig() snapshots the config into a native TableFactory immediately,
215+
// so it MUST be the last call - any tableCfg.setXxx() after it would be silently ignored.
216+
final BlockBasedTableConfig tableCfg = new BlockBasedTableConfig();
216217
tableCfg.setBlockSize(settings.getBlockSize());
217218
tableCfg.setBlockCache(RocksDbSettings.getCache());
218219
tableCfg.setCacheIndexAndFilterBlocks(true);
219220
tableCfg.setPinL0FilterAndIndexBlocksInCache(true);
220221
tableCfg.setFilter(new BloomFilter(10, false));
222+
options.setTableFormatConfig(tableCfg);
221223
if (Constant.MARKET_PAIR_PRICE_TO_ORDER.equals(dbName)) {
222224
ComparatorOptions comparatorOptions = new ComparatorOptions();
223225
options.setComparator(new MarketOrderPriceComparatorForRocksDB(comparatorOptions));

plugins/src/main/java/common/org/tron/plugins/utils/DBUtils.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,15 @@ public static Options newDefaultRocksDbOptions(boolean forBulkLoad, String name)
115115
1, Runtime.getRuntime().availableProcessors()));
116116
options.setLevel0FileNumCompactionTrigger(4);
117117
options.setLevelCompactionDynamicLevelBytes(true);
118-
final BlockBasedTableConfig tableCfg;
119-
options.setTableFormatConfig(tableCfg = new BlockBasedTableConfig());
118+
// NOTE: setTableFormatConfig() snapshots the config into a native TableFactory immediately,
119+
// so it MUST be the last call - any tableCfg.setXxx() after it would be silently ignored.
120+
final BlockBasedTableConfig tableCfg = new BlockBasedTableConfig();
120121
tableCfg.setBlockSize(64 * 1024);
121122
tableCfg.setBlockCacheSize(32 * 1024 * 1024);
122123
tableCfg.setCacheIndexAndFilterBlocks(true);
123124
tableCfg.setPinL0FilterAndIndexBlocksInCache(true);
124125
tableCfg.setFilter(new BloomFilter(10, false));
126+
options.setTableFormatConfig(tableCfg);
125127
if (forBulkLoad) {
126128
options.prepareForBulkLoad();
127129
}

0 commit comments

Comments
 (0)