sijie commented on a change in pull request #1121: [Merge Yahoo repo]: 
AsyncReadLastEntry should trigger callback with error when ledger is empty
URL: https://github.com/apache/bookkeeper/pull/1121#discussion_r168349715
 
 

 ##########
 File path: 
bookkeeper-server/src/main/java/org/apache/bookkeeper/client/ReadOnlyLedgerHandle.java
 ##########
 @@ -178,4 +180,25 @@ public String toString() {
     protected void initializeExplicitLacFlushPolicy() {
         explicitLacFlushPolicy = 
ExplicitLacFlushPolicy.VOID_EXPLICITLAC_FLUSH_POLICY;
     }
+
+    @Override
+    public void asyncReadLastEntry(ReadCallback cb, Object ctx) {
+        asyncReadLastConfirmed(new ReadLastConfirmedCallback() {
+            @Override
+            public void readLastConfirmedComplete(int rc, long lastConfirmed, 
Object ctx) {
+                if (rc == BKException.Code.OK) {
+                    if (lastConfirmed < 0) {
+                        // Ledger was empty, so there is no last entry to read
+                        cb.readComplete(BKException.Code.NoSuchEntryException, 
ReadOnlyLedgerHandle.this, null, ctx);
+                    } else {
+                        asyncReadEntriesInternal(lastConfirmed, lastConfirmed, 
cb, ctx);
+                    }
+                } else {
+                    LOG.error("ReadException in asyncReadLastEntry, ledgerId: 
{}, lac: {}, rc:{}",
+                        lastConfirmed, ledgerId, rc);
+                    cb.readComplete(BKException.Code.ReadException, 
ReadOnlyLedgerHandle.this, null, ctx);
 
 Review comment:
   cb.readCpomplete(rc, ...)
   
   you can pass the rc through to the application.

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

Reply via email to