sijie closed pull request #886: Add command line tool to manually recover
ledgers
URL: https://github.com/apache/bookkeeper/pull/886
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
index aacd7a21f..2e1dc1797 100644
---
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
+++
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
@@ -567,6 +567,7 @@ Options getOptions() {
lOpts.addOption("l", "ledgerid", true, "Ledger ID");
lOpts.addOption("fe", "firstentryid", true, "First EntryID");
lOpts.addOption("le", "lastentryid", true, "Last EntryID");
+ lOpts.addOption("r", "force-recovery", false, "Ensure the ledger
is properly closed before reading");
}
@Override
@@ -582,7 +583,8 @@ String getDescription() {
@Override
String getUsage() {
return "readledger [-msg] -ledgerid <ledgerid> "
- + "[-firstentryid <firstentryid> [-lastentryid
<lastentryid>]]";
+ + "[-firstentryid <firstentryid> [-lastentryid
<lastentryid>]] "
+ + "[-force-recovery]";
}
@Override
@@ -594,9 +596,10 @@ int runCmd(CommandLine cmdLine) throws Exception {
}
final long firstEntry = getOptionLongValue(cmdLine,
"firstentryid", 0);
- final long lastEntry = getOptionLongValue(cmdLine, "lastentryid",
-1);
+ long lastEntry = getOptionLongValue(cmdLine, "lastentryid", -1);
boolean printMsg = cmdLine.hasOption("m");
+ boolean forceRecovery = cmdLine.hasOption("r");
ClientConfiguration conf = new ClientConfiguration();
conf.addConfiguration(bkConf);
@@ -604,13 +607,22 @@ int runCmd(CommandLine cmdLine) throws Exception {
BookKeeperAdmin bk = null;
try {
bk = new BookKeeperAdmin(conf);
+ if (forceRecovery) {
+ // Force the opening of the ledger to trigger recovery
+ try (LedgerHandle lh = bk.openLedger(ledgerId)) {
+ if (lastEntry == -1 || lastEntry >
lh.getLastAddConfirmed()) {
+ lastEntry = lh.getLastAddConfirmed();
+ }
+ }
+ }
+
Iterator<LedgerEntry> entries = bk.readEntries(ledgerId,
firstEntry, lastEntry).iterator();
while (entries.hasNext()) {
LedgerEntry entry = entries.next();
formatEntry(entry, printMsg);
}
} catch (Exception e) {
- LOG.error("Error reading entries from ledger {}", ledgerId,
e.getCause());
+ LOG.error("Error reading entries from ledger {}", ledgerId, e);
return -1;
} finally {
if (bk != null) {
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services