You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@bookkeeper.apache.org by gi...@git.apache.org on 2017/06/29 15:31:59 UTC

[GitHub] sijie commented on a change in pull request #205: Issue 208: Improve ledger fence logic

sijie commented on a change in pull request #205: Issue 208: Improve ledger fence logic
URL: https://github.com/apache/bookkeeper/pull/205#discussion_r124834567
 
 

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/LedgerDescriptorImpl.java
 ##########
 @@ -81,6 +85,52 @@ ByteBuf getExplicitLac() {
         return ledgerStorage.getExplicitLac(ledgerId);
     }
 
+    synchronized SettableFuture<Boolean> fenceAndLogInJournal(Journal journal) throws IOException {
+        boolean success = this.setFenced();
+        if(success) {
+            // fenced for first time, we should add the key to journal ensure we can rebuild.
+            return logFenceEntryInJournal(journal);
+        } else {
+            // If we reach here, it means this ledger has been fenced before.
+            // However, fencing might still be in progress.
+            if(logFenceResult == null || fenceEntryPersisted.get()){
+                // Either ledger's fenced state is recovered from Journal
+                // Or Log fence entry in Journal succeed
+                SettableFuture<Boolean> result = SettableFuture.create();
+                result.set(true);
+                return result;
+            } else if (logFenceResult.isDone()) {
+                // We failed to log fence entry in Journal, try again.
+                return logFenceEntryInJournal(journal);
+            }
+            // Fencing is in progress
+            return logFenceResult;
+        }
+    }
+
+    /**
+     * Log the fence ledger entry in Journal so that we can rebuild the state.
+     * @param journal log the fence entry in the Journal
+     * @return A future which will be satisfied when add entry to journal complete
+     */
+    private SettableFuture<Boolean> logFenceEntryInJournal(Journal journal) {
+        SettableFuture<Boolean> result;
+        synchronized (this) {
+            result = logFenceResult = SettableFuture.create();
 
 Review comment:
   Because the fence is failed , line 102 is the else branch of line 96..
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services