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


##########
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 ?



##########
bookkeeper-server/src/test/java/org/apache/bookkeeper/client/TestFencing.java:
##########
@@ -87,6 +94,61 @@ public void testBasicFencing() throws Exception {
                    readlh.getLastAddConfirmed() == 
writelh.getLastAddConfirmed());
     }
 
+    @Test
+    public void testWriteAfterDeleted() throws Exception {
+        LedgerHandle writeLedger;
+        writeLedger = bkc.createLedger(digestType, "password".getBytes());
+
+        String tmp = "BookKeeper is cool!";
+        for (int i = 0; i < 10; i++) {
+            long entryId = writeLedger.addEntry(tmp.getBytes());
+            LOG.info("entryId: {}", entryId);
+        }
+
+        // Fence and delete.
+        BookKeeperTestClient bkc2 = new BookKeeperTestClient(baseClientConf, 
new TestStatsProvider());
+        LedgerHandle readLedger = bkc2.openLedger(writeLedger.getId(), 
digestType, "password".getBytes());
+        bkc2.deleteLedger(readLedger.ledgerId);
+
+        // Waiting for GC.
+        for (ServerTester server : servers) {
+            triggerGC(server.getServer().getBookie());
+        }
+
+        try {
+            long entryId = writeLedger.addEntry(tmp.getBytes());
+            LOG.info("Not expected: entryId: {}", entryId);
+            LOG.error("Should have thrown an exception");
+            fail("Should have thrown an exception when trying to write");
+        } catch (Exception e) {
+            e.printStackTrace();

Review Comment:
   Please use logger and catch the expected exception



-- 
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