You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by "TakaHiR07 (via GitHub)" <gi...@apache.org> on 2023/03/20 07:45:24 UTC

[GitHub] [bookkeeper] TakaHiR07 commented on a diff in pull request #3874: [bookie-shell] fix readLedger with parameter -bookie and -ledgerid can not read any entries in ledger

TakaHiR07 commented on code in PR #3874:
URL: https://github.com/apache/bookkeeper/pull/3874#discussion_r1141730774


##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/bookie/ReadLedgerCommand.java:
##########
@@ -189,33 +188,39 @@ private boolean readledger(ServerConfiguration serverConf, ReadLedgerFlags flags
                                                                  executor, scheduler, NullStatsLogger.INSTANCE,
                                                                  bk.getBookieAddressResolver());
 
-                LongStream.range(flags.firstEntryId, lastEntry).forEach(entryId -> {
+                long nextEntryId = flags.firstEntryId;
+                while (lastEntry == -1 || nextEntryId <= lastEntry) {
                     CompletableFuture<Void> future = new CompletableFuture<>();
 
-                    bookieClient.readEntry(bookie, flags.ledgerId, entryId,
-                                           (rc, ledgerId1, entryId1, buffer, ctx) -> {
-                                               if (rc != BKException.Code.OK) {
-                                                   LOG.error("Failed to read entry {} -- {}", entryId1,
-                                                             BKException.getMessage(rc));
-                                                   future.completeExceptionally(BKException.create(rc));
-                                                   return;
-                                               }
-
-                                               LOG.info("--------- Lid={}, Eid={} ---------",
-                                                   ledgerIdFormatter.formatLedgerId(flags.ledgerId), entryId);
-                                               if (flags.msg) {
-                                                   LOG.info("Data: " + ByteBufUtil.prettyHexDump(buffer));
-                                               }
-
-                                               future.complete(null);
-                                           }, null, BookieProtocol.FLAG_NONE);
+                    long entryId = nextEntryId;
+                    bookieClient.readEntry(bookie, flags.ledgerId, nextEntryId,
+                            (rc, ledgerId1, entryId1, buffer, ctx) -> {
+                                if (rc != BKException.Code.OK) {
+                                    LOG.error("Failed to read entry {} -- {}", entryId1,
+                                            BKException.getMessage(rc));
+                                    future.completeExceptionally(BKException.create(rc));
+                                    return;
+                                }
+
+                                LOG.info("--------- Lid={}, Eid={} ---------",
+                                        ledgerIdFormatter.formatLedgerId(flags.ledgerId), entryId);
+                                if (flags.msg) {
+                                    LOG.info("Data: " + ByteBufUtil.prettyHexDump(buffer));
+                                }
+
+                                future.complete(null);
+                            }, null, BookieProtocol.FLAG_NONE);
 
                     try {
                         future.get();
                     } catch (Exception e) {
                         LOG.error("Error future.get while reading entries from ledger {}", flags.ledgerId, e);
+                        if (e.getCause() instanceof BKException.BKNoSuchEntryException && lastEntry == -1) {

Review Comment:
   Second way is more reasonable, I will implement it. 



-- 
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: commits-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org