2020import java .util .Map .Entry ;
2121import java .util .Properties ;
2222import java .util .concurrent .CompletableFuture ;
23+ import java .util .concurrent .atomic .AtomicBoolean ;
2324import lombok .extern .slf4j .Slf4j ;
2425import org .apache .commons .lang3 .ArrayUtils ;
2526import org .bouncycastle .util .encoders .Hex ;
@@ -76,6 +77,7 @@ public class TxCacheDB implements DB<byte[], byte[]>, Flusher {
7677 private final Path cacheFile1 ;
7778 private final Path cacheProperties ;
7879 private final Path cacheDir ;
80+ private AtomicBoolean isValid = new AtomicBoolean (false );
7981
8082 public TxCacheDB (String name , RecentTransactionStore recentTransactionStore ) {
8183 this .name = name ;
@@ -135,6 +137,7 @@ private void initCache() {
135137
136138 public void init () {
137139 if (recovery ()) {
140+ isValid .set (true );
138141 return ;
139142 }
140143 long size = recentTransactionStore .size ();
@@ -156,6 +159,7 @@ public void init() {
156159 logger .info ("Load cache from recentTransactionStore, filter: {}, filter-fpp: {}, cost: {} ms." ,
157160 bloomFilters [1 ].approximateElementCount (), bloomFilters [1 ].expectedFpp (),
158161 System .currentTimeMillis () - start );
162+ isValid .set (true );
159163 }
160164
161165 @ Override
@@ -235,8 +239,10 @@ public Iterator<Entry<byte[], byte[]>> iterator() {
235239 }
236240
237241 @ Override
238- public void flush (Map <WrappedByteArray , WrappedByteArray > batch ) {
242+ public synchronized void flush (Map <WrappedByteArray , WrappedByteArray > batch ) {
243+ isValid .set (false );
239244 batch .forEach ((k , v ) -> this .put (k .getBytes (), v .getBytes ()));
245+ isValid .set (true );
240246 }
241247
242248 @ Override
@@ -298,6 +304,9 @@ private boolean handleException(Throwable e) {
298304 }
299305
300306 private void dump () {
307+ if (!isValid .get ()) {
308+ logger .info ("bloomFilters is not valid." );
309+ }
301310 FileUtil .createDirIfNotExists (this .cacheDir .toString ());
302311 logger .info ("dump bloomFilters start." );
303312 CompletableFuture <Void > task0 = CompletableFuture .runAsync (
0 commit comments