This is an automated email from the ASF dual-hosted git repository.
sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
The following commit(s) were added to refs/heads/master by this push:
new 9ab3045 Add command line tool to manually recover ledgers
9ab3045 is described below
commit 9ab30454343118e6c80ca3f3eb13d01e511c89fc
Author: Sijie Guo <[email protected]>
AuthorDate: Tue Dec 19 18:40:37 2017 -0800
Add command line tool to manually recover ledgers
Descriptions of the changes in this PR:
This is a change ported from yahoo/bookkeeperf4957610.
Author: Sijie Guo <[email protected]>
Author: Matteo Merli <[email protected]>
Reviewers: Enrico Olivelli <[email protected]>
This closes #886 from sijie/manually_recover_ledgers
---
.../java/org/apache/bookkeeper/bookie/BookieShell.java | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
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 aacd7a2..2e1dc17 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 @@ public class BookieShell implements Tool {
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 @@ public class BookieShell implements Tool {
@Override
String getUsage() {
return "readledger [-msg] -ledgerid <ledgerid> "
- + "[-firstentryid <firstentryid> [-lastentryid
<lastentryid>]]";
+ + "[-firstentryid <firstentryid> [-lastentryid
<lastentryid>]] "
+ + "[-force-recovery]";
}
@Override
@@ -594,9 +596,10 @@ public class BookieShell implements Tool {
}
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 @@ public class BookieShell implements Tool {
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) {
--
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].