merlimat closed pull request #1279: Fixed DbStorage write cache segment index
computation
URL: https://github.com/apache/bookkeeper/pull/1279
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/storage/ldb/WriteCache.java
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/WriteCache.java
index 1544b6d64..08ffe6732 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
@@ -94,7 +94,7 @@ public WriteCache(long maxCacheSize, int maxSegmentSize) {
this.maxCacheSize = maxCacheSize;
this.maxSegmentSize = (int) maxSegmentSize;
this.segmentOffsetMask = maxSegmentSize - 1;
- this.segmentOffsetBits = 64 -
Long.numberOfLeadingZeros(maxSegmentSize);
+ this.segmentOffsetBits = 63 -
Long.numberOfLeadingZeros(maxSegmentSize);
this.segmentsCount = 1 + (int) (maxCacheSize / maxSegmentSize);
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 75feb3252..f8b2bba44 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
@@ -30,6 +30,7 @@
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.buffer.Unpooled;
+import java.nio.charset.Charset;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;
@@ -261,4 +262,25 @@ public void testLedgerDeletion() {
cache.close();
}
+ @Test
+ public void testWriteReadsInMultipleSegments() {
+ // Create cache with max size 4 KB and each segment is 128 bytes
+ WriteCache cache = new WriteCache(4 * 1024, 128);
+
+ for (int i = 0; i < 48; i++) {
+ boolean inserted = cache.put(1, i, Unpooled.wrappedBuffer(("test-"
+ i).getBytes()));
+ assertTrue(inserted);
+ }
+
+ assertEquals(48, cache.count());
+
+ for (int i = 0; i < 48; i++) {
+ ByteBuf b = cache.get(1, i);
+
+ assertEquals("test-" + i, b.toString(Charset.forName("UTF-8")));
+ }
+
+ cache.close();
+ }
+
}
----------------------------------------------------------------
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