Skip to content

Commit 3f30d22

Browse files
authored
if entrySize > segmentSize ,will throw IndexOutOfBoundsException when put entry into ReadCache (apache#2982)
1 parent bbc690f commit 3f30d22

File tree

1 file changed

+7
-0
lines changed
  • bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb

1 file changed

+7
-0
lines changed

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/ReadCache.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
import org.apache.bookkeeper.util.collections.ConcurrentLongLongPairHashMap;
3636
import org.apache.bookkeeper.util.collections.ConcurrentLongLongPairHashMap.LongPair;
37+
import org.slf4j.Logger;
38+
import org.slf4j.LoggerFactory;
3739

3840
/**
3941
* Read cache implementation.
@@ -46,6 +48,7 @@
4648
* the read cache.
4749
*/
4850
public class ReadCache implements Closeable {
51+
private static final Logger log = LoggerFactory.getLogger(ReadCache.class);
4952

5053
private static final int DEFAULT_MAX_SEGMENT_SIZE = 1 * 1024 * 1024 * 1024;
5154

@@ -90,6 +93,10 @@ public void put(long ledgerId, long entryId, ByteBuf entry) {
9093
lock.readLock().lock();
9194

9295
try {
96+
if (entrySize > segmentSize) {
97+
log.warn("entrySize {} > segmentSize {}, skip update read cache!", entrySize, segmentSize);
98+
return;
99+
}
93100
int offset = currentSegmentOffset.getAndAdd(alignedSize);
94101
if (offset + entrySize > segmentSize) {
95102
// Roll-over the segment (outside the read-lock)

0 commit comments

Comments
 (0)