@ -56,6 +56,7 @@ public class TransactionLogBloomCacher {
private final Map < Long , Boolean > cachedSegments ;
private final Map < Long , Boolean > cachedSegments ;
private final Lock submissionLock = new ReentrantLock ( ) ;
private final Lock submissionLock = new ReentrantLock ( ) ;
private final Lock populateLastFragmentLock = new ReentrantLock ( ) ;
private final EthScheduler scheduler ;
private final EthScheduler scheduler ;
private final Blockchain blockchain ;
private final Blockchain blockchain ;
@ -170,9 +171,12 @@ public class TransactionLogBloomCacher {
private boolean populateLatestSegment ( ) {
private boolean populateLatestSegment ( ) {
try {
try {
long blockNumber = blockchain . getChainHeadBlockNumber ( ) ;
if ( populateLastFragmentLock . tryLock ( 100 , TimeUnit . MILLISECONDS ) ) {
try {
final File currentFile = calculateCacheFileName ( CURRENT , cacheDir ) ;
final File currentFile = calculateCacheFileName ( CURRENT , cacheDir ) ;
final long segmentNumber = blockNumber / BLOCKS_PER_BLOOM_CACHE ;
final long segmentNumber = blockchain . getChainHeadBlockNumber ( ) / BLOCKS_PER_BLOOM_CACHE ;
long blockNumber = segmentNumber / BLOCKS_PER_BLOOM_CACHE ;
try ( final OutputStream out = new FileOutputStream ( currentFile ) ) {
try ( final OutputStream out = new FileOutputStream ( currentFile ) ) {
fillCacheFile ( segmentNumber * BLOCKS_PER_BLOOM_CACHE , blockNumber , out ) ;
fillCacheFile ( segmentNumber * BLOCKS_PER_BLOOM_CACHE , blockNumber , out ) ;
}
}
@ -189,8 +193,14 @@ public class TransactionLogBloomCacher {
return true ;
return true ;
} catch ( final IOException e ) {
} catch ( final IOException e ) {
LOG . error ( "Unhandled caching exception." , e ) ;
LOG . error ( "Unhandled caching exception." , e ) ;
return false ;
} finally {
populateLastFragmentLock . unlock ( ) ;
}
}
}
} catch ( final InterruptedException e ) {
// ignore
}
return false ;
}
}
private void ensurePreviousSegmentsArePresent ( final long blockNumber ) {
private void ensurePreviousSegmentsArePresent ( final long blockNumber ) {