Skip to content

Commit

Permalink
add switch for transaction cache initialization optimization (#5543)
Browse files Browse the repository at this point in the history
  • Loading branch information
halibobo1205 authored Oct 17, 2023
1 parent 87db52a commit d1f0ff3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public class TxCacheDB implements DB<byte[], byte[]>, Flusher {
private final Path cacheProperties;
private final Path cacheDir;
private AtomicBoolean isValid = new AtomicBoolean(false);
private boolean txCacheInitOptimization;

@Getter
@Setter
Expand Down Expand Up @@ -128,6 +129,8 @@ public TxCacheDB(String name, RecentTransactionStore recentTransactionStore,
this.cacheFile0 = Paths.get(cacheDir.toString(), "bloomFilters_0");
this.cacheFile1 = Paths.get(cacheDir.toString(), "bloomFilters_1");
this.cacheProperties = Paths.get(cacheDir.toString(), "txCache.properties");
this.txCacheInitOptimization = CommonParameter.getInstance()
.getStorage().isTxCacheInitOptimization();

}

Expand Down Expand Up @@ -280,6 +283,12 @@ public void reset() {
}

private boolean recovery() {
if (!txCacheInitOptimization) {
logger.info("txCache init optimization is disabled, skip fast recovery mode.");
logger.info("If you want fast recovery mode,"
+ " please set `storage.txCache.initOptimization = true` in config.conf.");
return false;
}
FileUtil.createDirIfNotExists(this.cacheDir.toString());
logger.info("recovery bloomFilters start.");
CompletableFuture<Boolean> loadProperties = CompletableFuture.supplyAsync(this::loadProperties);
Expand Down
10 changes: 10 additions & 0 deletions common/src/main/java/org/tron/core/config/args/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class Storage {
private static final String CHECKPOINT_SYNC_KEY = "storage.checkpoint.sync";

private static final String CACHE_STRATEGIES = "storage.cache.strategies";
public static final String TX_CACHE_INIT_OPTIMIZATION = "storage.txCache.initOptimization";

/**
* Default values of directory
Expand Down Expand Up @@ -145,6 +146,10 @@ public class Storage {
@Setter
private int estimatedBlockTransactions;

@Getter
@Setter
private boolean txCacheInitOptimization = false;

// second cache
private final Map<CacheType, String> cacheStrategies = Maps.newConcurrentMap();

Expand Down Expand Up @@ -235,6 +240,11 @@ public static int getEstimatedTransactionsFromConfig(final Config config) {
return estimatedTransactions;
}

public static boolean getTxCacheInitOptimizationFromConfig(final Config config) {
return config.hasPath(TX_CACHE_INIT_OPTIMIZATION)
&& config.getBoolean(TX_CACHE_INIT_OPTIMIZATION);
}


public void setCacheStrategies(Config config) {
if (config.hasPath(CACHE_STRATEGIES)) {
Expand Down
2 changes: 2 additions & 0 deletions framework/src/main/java/org/tron/core/config/args/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ public static void setParam(final String[] args, final String confFileName) {

PARAMETER.storage.setEstimatedBlockTransactions(
Storage.getEstimatedTransactionsFromConfig(config));
PARAMETER.storage.setTxCacheInitOptimization(
Storage.getTxCacheInitOptimizationFromConfig(config));
PARAMETER.storage.setMaxFlushCount(Storage.getSnapshotMaxFlushCountFromConfig(config));

PARAMETER.storage.setDefaultDbOptions(config);
Expand Down
2 changes: 2 additions & 0 deletions framework/src/main/resources/config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ storage {
# the estimated number of block transactions (default 1000, min 100, max 10000).
# so the total number of cached transactions is 65536 * txCache.estimatedTransactions
# txCache.estimatedTransactions = 1000
# if true, transaction cache initialization will be faster. default false
# txCache.initOptimization = true
}

node.discovery = {
Expand Down
2 changes: 2 additions & 0 deletions framework/src/test/resources/config-test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ storage {
# the estimated number of block transactions (default 1000, min 100, max 10000).
# so the total number of cached transactions is 65536 * txCache.estimatedTransactions
txCache.estimatedTransactions = 50
# if true, transaction cache initialization will be faster. default false
txCache.initOptimization = true

}

Expand Down

0 comments on commit d1f0ff3

Please sign in to comment.