poorbarcode commented on code in PR #4462:
URL: https://github.com/apache/bookkeeper/pull/4462#discussion_r1674034186


##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/HandleFactoryImpl.java:
##########
@@ -21,14 +21,25 @@
 
 package org.apache.bookkeeper.bookie;
 
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
 import java.io.IOException;
+import java.time.Duration;
 import org.apache.bookkeeper.bookie.LedgerStorage.LedgerDeletionListener;
 import org.apache.bookkeeper.util.collections.ConcurrentLongHashMap;
 
 class HandleFactoryImpl implements HandleFactory, LedgerDeletionListener {
     private final ConcurrentLongHashMap<LedgerDescriptor> ledgers;
     private final ConcurrentLongHashMap<LedgerDescriptor> readOnlyLedgers;
 
+    /**
+     * Once the ledger was marked "fenced" before, the ledger was accessed by 
multi clients. One client is calling
+     * "delete" now, and other clients may call "write" continuously later. We 
mark these ledgers can not be written
+     * anymore. And maintains the state for 7 days is safety.
+     */
+    private final Cache<Long, Boolean> recentlyFencedAndDeletedLedgers = 
CacheBuilder.newBuilder()

Review Comment:
   > This is in memory, what happens if you restart the bookie?
   
   I think scenarios `1` and `2` below are fine, and scenario `3` below is not 
fine.
   
   Regarding scenario `3`, I think there are two solutions below, which is your 
preference?
   - After a bookie channel is reconnected, let all ledgers related to this 
channel change BKs ensemble.
   - Let the GC task skip the fenced ledger until it is not used for a long 
time.
   
   ---
   
   **Scenario 1: the journal log is still there**
   - Deleted the ledger.
   - Restart BK.
   - Replay journal logs.
   - Reset the ledger as fenced.
     - Since the ledger is fenced, the client will get a fenced error when it 
tries to write. 
   - Delete the ledger after a GC
     - Move the ledger into  `recentlyFencedAndDeletedLedgers`
     - Since the ledger is in the variable `recentlyFencedAndDeletedLedgers`, 
the client will get a fenced error when it tries to write.
   
   ---
   
   **Scenario 2: the journal log was removed & the client switched the ensemble 
due to pending operations failed**
   - Deleted the ledger.
     - Journal logs were removed.
   - Restart BK.
   - The client tries to switch the ensemble due to previous operation fails
     - Since the ledger metadata was removed, this operation will fail.
   
   ---
   
    **Scenario 3: the journal log was removed & the client did not switch the 
ensemble because there are no pending operations**
   - Deleted the ledger.
     - Journal logs were removed.
   - Restart BK.
   - The client reconnect successfully.
   - If the client tries to write, it will be successful.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to