Updated Branches: refs/heads/cassandra-1.2 dbb55ebd6 -> fcc51ea49
Integer overflow in OffHeapBitSet when bloomfilter > 2GB patch by Vijay; reviewed by jbellis for CASSANDRA-5903 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/fcc51ea4 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/fcc51ea4 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/fcc51ea4 Branch: refs/heads/cassandra-1.2 Commit: fcc51ea49bb45b5862acdb458a5c9a96880597bc Parents: dbb55eb Author: Vijay Parthasarathy <vijay2...@gmail.com> Authored: Tue Aug 20 15:30:28 2013 -0700 Committer: Vijay Parthasarathy <vijay2...@gmail.com> Committed: Tue Aug 20 15:30:28 2013 -0700 ---------------------------------------------------------------------- .../org/apache/cassandra/utils/obs/OffHeapBitSet.java | 11 +++++++++-- src/java/org/apache/cassandra/utils/obs/OpenBitSet.java | 6 +++--- 2 files changed, 12 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/fcc51ea4/src/java/org/apache/cassandra/utils/obs/OffHeapBitSet.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/utils/obs/OffHeapBitSet.java b/src/java/org/apache/cassandra/utils/obs/OffHeapBitSet.java index 1733a81..b7bb733 100644 --- a/src/java/org/apache/cassandra/utils/obs/OffHeapBitSet.java +++ b/src/java/org/apache/cassandra/utils/obs/OffHeapBitSet.java @@ -36,8 +36,15 @@ public class OffHeapBitSet implements IBitSet public OffHeapBitSet(long numBits) { // OpenBitSet.bits2words calculation is there for backward compatibility. - int byteCount = OpenBitSet.bits2words(numBits) * 8; - bytes = RefCountedMemory.allocate(byteCount); + long byteCount = OpenBitSet.bits2words(numBits) * 8L; + try + { + bytes = RefCountedMemory.allocate(byteCount); + } + catch (OutOfMemoryError e) + { + throw new RuntimeException("Out of native memory occured, You can avoid it by increasing the system ram space or by increasing bloom_filter_fp_chance."); + } // flush/clear the existing memory. clear(); } http://git-wip-us.apache.org/repos/asf/cassandra/blob/fcc51ea4/src/java/org/apache/cassandra/utils/obs/OpenBitSet.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/utils/obs/OpenBitSet.java b/src/java/org/apache/cassandra/utils/obs/OpenBitSet.java index 4fce3f8..f92cd45 100644 --- a/src/java/org/apache/cassandra/utils/obs/OpenBitSet.java +++ b/src/java/org/apache/cassandra/utils/obs/OpenBitSet.java @@ -65,7 +65,7 @@ public class OpenBitSet implements IBitSet */ public OpenBitSet(long numBits) { - wlen = bits2words(numBits); + wlen = (int) bits2words(numBits); int lastPageSize = wlen % PAGE_SIZE; int fullPageCount = wlen / PAGE_SIZE; pageCount = fullPageCount + (lastPageSize == 0 ? 0 : 1); @@ -339,8 +339,8 @@ public class OpenBitSet implements IBitSet } /** returns the number of 64 bit words it would take to hold numBits */ - public static int bits2words(long numBits) { - return (int)(((numBits-1)>>>6)+1); + public static long bits2words(long numBits) { + return (((numBits-1)>>>6)+1); } /** returns true if both sets have the same bits set */