Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -188,35 +188,36 @@ private boolean readledger(ServerConfiguration serverConf, ReadLedgerFlags flags
BookieClient bookieClient = new BookieClientImpl(conf, eventLoopGroup, UnpooledByteBufAllocator.DEFAULT,
executor, scheduler, NullStatsLogger.INSTANCE,
bk.getBookieAddressResolver());

LongStream.range(flags.firstEntryId, lastEntry).forEach(entryId -> {
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);

try {
future.get();
} catch (Exception e) {
LOG.error("Error future.get while reading entries from ledger {}", flags.ledgerId, e);
}
});

// if firstEntryId == lastEntryId == -1, it will cause an infinite loop
if (lastEntry >= 0) {
LongStream.rangeClosed(flags.firstEntryId, lastEntry).forEach(entryId -> {
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);

try {
future.get();
} catch (Exception e) {
LOG.error("Error future.get while reading entries from ledger {}", flags.ledgerId, e);
}
});
}
eventLoopGroup.shutdownGracefully();
executor.shutdown();
bookieClient.close();
Expand Down