jvrao commented on a change in pull request #205: Issue 208: Improve ledger fence logic URL: https://github.com/apache/bookkeeper/pull/205#discussion_r124808898
########## 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: When logFenceEntryInJournal is called in line 104, the else case says we have object logFenceResult already. Why are we creating another logFenceResult here??? ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services