This is an automated email from the ASF dual-hosted git repository.
sijie pushed a commit to branch branch-4.9
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
The following commit(s) were added to refs/heads/branch-4.9 by this push:
new f6f0f65 Fix when met unexpect entry id crashed
f6f0f65 is described below
commit f6f0f653d871792572ba504ffa80092f4803958d
Author: Yong Zhang <[email protected]>
AuthorDate: Wed Mar 27 23:35:48 2019 +0800
Fix when met unexpect entry id crashed
Fixes #2001
*Motivation*
When met a unexpect entry id, db indexes failed cleanup.
*Modifications*
Catch the exception and ignore it.
Master Issue: #2001
Reviewers: Jia Zhai <[email protected]>, Matteo Merli <[email protected]>
This closes #2002 from zymap/fixnoentryexception
(cherry picked from commit 6c3f33f55fc3754925323b1d077108331d027aaf)
Signed-off-by: Sijie Guo <[email protected]>
---
.../bookie/storage/ldb/EntryLocationIndex.java | 10 ++++++-
.../bookie/storage/ldb/EntryLocationIndexTest.java | 32 ++++++++++++++++++++++
2 files changed, 41 insertions(+), 1 deletion(-)
diff --git
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/EntryLocationIndex.java
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/EntryLocationIndex.java
index 5673883..6b01c50 100644
---
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/EntryLocationIndex.java
+++
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/EntryLocationIndex.java
@@ -216,7 +216,15 @@ public class EntryLocationIndex implements Closeable {
}
long firstEntryId = ArrayUtil.getLong(firstKeyRes.getKey(), 8);
- long lastEntryId = getLastEntryInLedgerInternal(ledgerId);
+ long lastEntryId;
+ try {
+ lastEntryId = getLastEntryInLedgerInternal(ledgerId);
+ } catch (Bookie.NoEntryException nee) {
+ if (log.isDebugEnabled()) {
+ log.debug("No last entry id found for ledger {}",
ledgerId);
+ }
+ continue;
+ }
if (log.isDebugEnabled()) {
log.debug("Deleting index for ledger {} entries ({} ->
{})",
ledgerId, firstEntryId, lastEntryId);
diff --git
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/storage/ldb/EntryLocationIndexTest.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/storage/ldb/EntryLocationIndexTest.java
index 6e83ffd..f1cefed 100644
---
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/storage/ldb/EntryLocationIndexTest.java
+++
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/storage/ldb/EntryLocationIndexTest.java
@@ -23,6 +23,7 @@ package org.apache.bookkeeper.bookie.storage.ldb;
import static org.junit.Assert.assertEquals;
import java.io.File;
+import java.io.IOException;
import org.apache.bookkeeper.conf.ServerConfiguration;
import org.apache.bookkeeper.stats.NullStatsLogger;
@@ -108,4 +109,35 @@ public class EntryLocationIndexTest {
idx.close();
}
+
+ // test non exist entry
+ @Test
+ public void testDeleteSpecialEntry() throws IOException {
+ File tmpDir = File.createTempFile("bkTest", ".dir");
+ tmpDir.delete();
+ tmpDir.mkdir();
+ tmpDir.deleteOnExit();
+
+ EntryLocationIndex idx = new EntryLocationIndex(serverConfiguration,
KeyValueStorageRocksDB.factory,
+
tmpDir.getAbsolutePath(), NullStatsLogger.INSTANCE);
+
+ // Add some dummy indexes
+ idx.addLocation(40312, -1, 1);
+ idx.addLocation(40313, 10, 2);
+ idx.addLocation(40320, 0, 3);
+
+ // Add more indexes in a different batch
+ idx.addLocation(40313, 11, 5);
+ idx.addLocation(40313, 12, 6);
+ idx.addLocation(40320, 1, 7);
+
+ // delete a non exist entry
+ idx.delete(40312);
+ idx.removeOffsetFromDeletedLedgers();
+
+ // another delete entry operation shouldn't effected
+ idx.delete(40313);
+ idx.removeOffsetFromDeletedLedgers();
+ assertEquals(0, idx.getLocation(40312, 10));
+ }
}