Skip to content

Commit 189a489

Browse files
committed
ReadLedgerCommand can't get lastEntry when specifying the ledger range and bookie addr
1 parent be1749c commit 189a489

1 file changed

Lines changed: 30 additions & 29 deletions

File tree

bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/commands/bookie/ReadLedgerCommand.java

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -188,35 +188,36 @@ private boolean readledger(ServerConfiguration serverConf, ReadLedgerFlags flags
188188
BookieClient bookieClient = new BookieClientImpl(conf, eventLoopGroup, UnpooledByteBufAllocator.DEFAULT,
189189
executor, scheduler, NullStatsLogger.INSTANCE,
190190
bk.getBookieAddressResolver());
191-
192-
LongStream.range(flags.firstEntryId, lastEntry).forEach(entryId -> {
193-
CompletableFuture<Void> future = new CompletableFuture<>();
194-
195-
bookieClient.readEntry(bookie, flags.ledgerId, entryId,
196-
(rc, ledgerId1, entryId1, buffer, ctx) -> {
197-
if (rc != BKException.Code.OK) {
198-
LOG.error("Failed to read entry {} -- {}", entryId1,
199-
BKException.getMessage(rc));
200-
future.completeExceptionally(BKException.create(rc));
201-
return;
202-
}
203-
204-
LOG.info("--------- Lid={}, Eid={} ---------",
205-
ledgerIdFormatter.formatLedgerId(flags.ledgerId), entryId);
206-
if (flags.msg) {
207-
LOG.info("Data: " + ByteBufUtil.prettyHexDump(buffer));
208-
}
209-
210-
future.complete(null);
211-
}, null, BookieProtocol.FLAG_NONE);
212-
213-
try {
214-
future.get();
215-
} catch (Exception e) {
216-
LOG.error("Error future.get while reading entries from ledger {}", flags.ledgerId, e);
217-
}
218-
});
219-
191+
// if firstEntryId == lastEntryId == -1, it will cause an infinite loop
192+
if (lastEntry >= 0) {
193+
LongStream.rangeClosed(flags.firstEntryId, lastEntry).forEach(entryId -> {
194+
CompletableFuture<Void> future = new CompletableFuture<>();
195+
196+
bookieClient.readEntry(bookie, flags.ledgerId, entryId,
197+
(rc, ledgerId1, entryId1, buffer, ctx) -> {
198+
if (rc != BKException.Code.OK) {
199+
LOG.error("Failed to read entry {} -- {}", entryId1,
200+
BKException.getMessage(rc));
201+
future.completeExceptionally(BKException.create(rc));
202+
return;
203+
}
204+
205+
LOG.info("--------- Lid={}, Eid={} ---------",
206+
ledgerIdFormatter.formatLedgerId(flags.ledgerId), entryId);
207+
if (flags.msg) {
208+
LOG.info("Data: " + ByteBufUtil.prettyHexDump(buffer));
209+
}
210+
211+
future.complete(null);
212+
}, null, BookieProtocol.FLAG_NONE);
213+
214+
try {
215+
future.get();
216+
} catch (Exception e) {
217+
LOG.error("Error future.get while reading entries from ledger {}", flags.ledgerId, e);
218+
}
219+
});
220+
}
220221
eventLoopGroup.shutdownGracefully();
221222
executor.shutdown();
222223
bookieClient.close();

0 commit comments

Comments
 (0)