From 2ef75dfc8facf8f25f57e9d2d67cbeb9e4fb04fb Mon Sep 17 00:00:00 2001 From: Danno Ferrin Date: Wed, 19 Feb 2020 10:43:12 -0700 Subject: [PATCH] Reduce recaching in Transaction Log Bloom Filter Cache Do a cursory cache check at start up (file is present and correct size) instead of re-generating the cache at startup. Signed-off-by: Danno Ferrin --- .../besu/ethereum/api/query/TransactionLogBloomCacher.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/TransactionLogBloomCacher.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/TransactionLogBloomCacher.java index c8e6cc6286e..bafbf05fdf4 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/TransactionLogBloomCacher.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/TransactionLogBloomCacher.java @@ -51,6 +51,7 @@ public class TransactionLogBloomCacher { public static final int BLOCKS_PER_BLOOM_CACHE = 100_000; private static final int BLOOM_BITS_LENGTH = 256; + private static final int EXPECTED_BLOOM_FILE_SIZE = BLOCKS_PER_BLOOM_CACHE * BLOOM_BITS_LENGTH; public static final String CURRENT = "current"; private final Map cachedSegments; @@ -201,7 +202,10 @@ private void ensurePreviousSegmentsArePresent(final long blockNumber) { try { if (!cachedSegments.getOrDefault(currentSegment, false)) { final long startBlock = currentSegment * BLOCKS_PER_BLOOM_CACHE; - generateLogBloomCache(startBlock, startBlock + BLOCKS_PER_BLOOM_CACHE); + final File cacheFile = calculateCacheFileName(startBlock, cacheDir); + if (!cacheFile.isFile() || cacheFile.length() != EXPECTED_BLOOM_FILE_SIZE) { + generateLogBloomCache(startBlock, startBlock + BLOCKS_PER_BLOOM_CACHE); + } cachedSegments.put(currentSegment, true); } } finally {