Skip to content

Commit

Permalink
LogBloomCache - Do uncached query if EOF is detected (#609)
Browse files Browse the repository at this point in the history
If we detect an EOF for the cache file switch over to an uncached query.

This is typically seen when filling a log filter and the new block has
not yet written out the log bloom cache to disk.  Fixed #473

Signed-off-by: Danno Ferrin <[email protected]>
  • Loading branch information
shemnon authored Mar 29, 2020
1 parent 4fa78d6 commit 04044fd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ private List<LogWithMetadata> matchingLogsCached(
try {
raf.readFully(bloomBuff);
} catch (final EOFException e) {
results.addAll(matchingLogsUncached(segmentStart + pos, segmentStart + endOffset, query));
break;
}
final LogsBloomFilter logsBloom = new LogsBloomFilter(bytesValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,14 @@ private boolean populateLatestSegment() {
try {
final File currentFile = calculateCacheFileName(CURRENT, cacheDir);

final long segmentNumber = blockchain.getChainHeadBlockNumber() / BLOCKS_PER_BLOOM_CACHE;
long blockNumber = segmentNumber / BLOCKS_PER_BLOOM_CACHE;
final long chainHeadBlockNumber = blockchain.getChainHeadBlockNumber();
final long segmentNumber = chainHeadBlockNumber / BLOCKS_PER_BLOOM_CACHE;
long blockNumber =
Math.min((segmentNumber + 1) * BLOCKS_PER_BLOOM_CACHE - 1, chainHeadBlockNumber);
try (final OutputStream out = new FileOutputStream(currentFile)) {
fillCacheFile(segmentNumber * BLOCKS_PER_BLOOM_CACHE, blockNumber, out);
}
while (blockNumber <= blockchain.getChainHeadBlockNumber()
while (blockNumber <= chainHeadBlockNumber
&& (blockNumber % BLOCKS_PER_BLOOM_CACHE != 0)) {
cacheSingleBlock(blockchain.getBlockHeader(blockNumber).orElseThrow(), currentFile);
blockNumber++;
Expand Down

0 comments on commit 04044fd

Please sign in to comment.