This is an automated email from the ASF dual-hosted git repository.
chenhang 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 d6d9212a64 Not wrap IOException twice form checkpoint (#3683)
d6d9212a64 is described below
commit d6d9212a64a6c9dabd69a646082718929c43b4f9
Author: wenbingshen <[email protected]>
AuthorDate: Wed Feb 15 15:15:11 2023 +0800
Not wrap IOException twice form checkpoint (#3683)
### Motivation
IOException may be wrapped by RuntimeException, so don't wrap
RuntimeException with IOException.
---
.../ldb/SingleDirectoryDbLedgerStorage.java | 12 ++----------
.../bookkeeper/bookie/storage/ldb/WriteCache.java | 5 +++--
.../bookie/storage/ldb/WriteCacheTest.java | 22 ++++++++++++++++++++--
3 files changed, 25 insertions(+), 14 deletions(-)
diff --git
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/SingleDirectoryDbLedgerStorage.java
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/SingleDirectoryDbLedgerStorage.java
index 0d18367dd7..03e29f8c8b 100644
---
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/SingleDirectoryDbLedgerStorage.java
+++
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/SingleDirectoryDbLedgerStorage.java
@@ -775,12 +775,8 @@ public class SingleDirectoryDbLedgerStorage implements
CompactableLedgerStorage
Batch batch = entryLocationIndex.newBatch();
writeCacheBeingFlushed.forEach((ledgerId, entryId, entry) -> {
- try {
- long location = entryLogger.addEntry(ledgerId, entry);
- entryLocationIndex.addLocation(batch, ledgerId, entryId,
location);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
+ long location = entryLogger.addEntry(ledgerId, entry);
+ entryLocationIndex.addLocation(batch, ledgerId, entryId,
location);
});
long entryLoggerStart = MathUtils.nowInNano();
@@ -833,10 +829,6 @@ public class SingleDirectoryDbLedgerStorage implements
CompactableLedgerStorage
recordFailedEvent(dbLedgerStorageStats.getFlushStats(), startTime);
// Leave IOExecption as it is
throw e;
- } catch (RuntimeException e) {
- recordFailedEvent(dbLedgerStorageStats.getFlushStats(), startTime);
- // Wrap unchecked exceptions
- throw new IOException(e);
} finally {
try {
isFlushOngoing.set(false);
diff --git
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/WriteCache.java
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/WriteCache.java
index 22a42c0492..10a4a198b4 100644
---
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/WriteCache.java
+++
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/WriteCache.java
@@ -26,6 +26,7 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.Unpooled;
import java.io.Closeable;
+import java.io.IOException;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.LongAdder;
import java.util.concurrent.locks.ReentrantLock;
@@ -55,7 +56,7 @@ public class WriteCache implements Closeable {
* Consumer that is used to scan the entire write cache.
*/
public interface EntryConsumer {
- void accept(long ledgerId, long entryId, ByteBuf entry);
+ void accept(long ledgerId, long entryId, ByteBuf entry) throws
IOException;
}
private final ConcurrentLongLongPairHashMap index =
ConcurrentLongLongPairHashMap.newBuilder()
@@ -218,7 +219,7 @@ public class WriteCache implements Closeable {
private static final ArrayGroupSort groupSorter = new ArrayGroupSort(2, 4);
- public void forEach(EntryConsumer consumer) {
+ public void forEach(EntryConsumer consumer) throws IOException {
sortedEntriesLock.lock();
try {
diff --git
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/storage/ldb/WriteCacheTest.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/storage/ldb/WriteCacheTest.java
index dc1ce791e8..bd622d6566 100644
---
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/storage/ldb/WriteCacheTest.java
+++
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/storage/ldb/WriteCacheTest.java
@@ -31,6 +31,7 @@ import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import io.netty.buffer.UnpooledByteBufAllocator;
import io.netty.util.ReferenceCountUtil;
+import java.io.IOException;
import java.nio.charset.Charset;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CountDownLatch;
@@ -143,7 +144,7 @@ public class WriteCacheTest {
}
@Test
- public void testEmptyCache() {
+ public void testEmptyCache() throws IOException {
WriteCache cache = new WriteCache(allocator, 1024 * 1024, 16 * 1024);
assertEquals(0, cache.count());
@@ -221,7 +222,7 @@ public class WriteCacheTest {
}
@Test
- public void testLedgerDeletion() {
+ public void testLedgerDeletion() throws IOException {
WriteCache cache = new WriteCache(allocator, 1024 * 1024, 16 * 1024);
ByteBuf entry = Unpooled.buffer(1024);
@@ -305,4 +306,21 @@ public class WriteCacheTest {
}
assertFalse(cache.hasEntry(ledgerId, 48));
}
+
+ @Test(expected = IOException.class)
+ public void testForEachIOException() throws Exception {
+ try (WriteCache cache = new WriteCache(allocator, 1024 * 1024, 16 *
1024)) {
+
+ for (int i = 0; i < 48; i++) {
+ boolean inserted = cache.put(1, i,
Unpooled.wrappedBuffer(("test-" + i).getBytes()));
+ assertTrue(inserted);
+ }
+
+ assertEquals(48, cache.count());
+
+ cache.forEach(((ledgerId, entryId, entry) -> {
+ throw new IOException("test throw IOException.");
+ }));
+ }
+ }
}