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


##########
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:
   If the ledger only has 100 entries, but the input param `lastEntry` is 
10000, it will still read 100-10000 entries. 
   There are two ways to solve it.
   1. remove the `lastEntry == -1` judgment, once meet BKNoSuchEntryException, 
end the loop.
   2. Add more limitations for the loop. (lastEntry == -1 || nextEntryId <= 
lastEntry && nextEntryId <= LAC), we can use bookieClient.readLac() to get the 
LAC.



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