diff --git a/CHANGES.txt b/CHANGES.txt index 0e759b720f..422f66e306 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -30,6 +30,7 @@ * Fix streaming not holding ref when stream error (CASSANDRA-9295) * Fix canonical view returning early opened SSTables (CASSANDRA-9396) Merged from 2.0: + * Fix bad condition in RangeTombstoneList (CASSANDRA-9485) * Fix potential StackOverflow when setting CrcCheckChance over JMX (CASSANDRA-9488) * Fix null static columns in pages after the first, paged reversed queries (CASSANDRA-8502) diff --git a/src/java/org/apache/cassandra/db/RangeTombstoneList.java b/src/java/org/apache/cassandra/db/RangeTombstoneList.java index c0ab42b396..bd6e669b4a 100644 --- a/src/java/org/apache/cassandra/db/RangeTombstoneList.java +++ b/src/java/org/apache/cassandra/db/RangeTombstoneList.java @@ -146,7 +146,7 @@ public class RangeTombstoneList implements Iterable, IMeasurable /** * Adds a new range tombstone. * - * This method will be faster if the new tombstone sort after all the currently existing ones (this is a common use case), + * This method will be faster if the new tombstone sort after all the currently existing ones (this is a common use case), * but it doesn't assume it. */ public void add(Composite start, Composite end, long markedAt, int delTime) @@ -160,7 +160,7 @@ public class RangeTombstoneList implements Iterable, IMeasurable int c = comparator.compare(ends[size-1], start); // Fast path if we add in sorted order - if (c <= 0) + if (c < 0) { addInternal(size, start, end, markedAt, delTime); } diff --git a/test/unit/org/apache/cassandra/db/RangeTombstoneListTest.java b/test/unit/org/apache/cassandra/db/RangeTombstoneListTest.java index 712cfa22be..7dc7300760 100644 --- a/test/unit/org/apache/cassandra/db/RangeTombstoneListTest.java +++ b/test/unit/org/apache/cassandra/db/RangeTombstoneListTest.java @@ -31,7 +31,6 @@ import org.apache.cassandra.utils.ByteBufferUtil; public class RangeTombstoneListTest { private static final Comparator cmp = new SimpleDenseCellNameType(IntegerType.instance); - private static final Random rand = new Random(); @Test public void testDiff() @@ -462,7 +461,23 @@ public class RangeTombstoneListTest assertEquals(6, l.maxMarkedAt()); } - private RangeTombstoneList makeRandom(int size, int maxItSize, int maxItDistance, int maxMarkedAt) + @Test + public void insertSameTest() + { + // Simple test that adding the same element multiple time ends up + // with that element only a single time (CASSANDRA-9485) + + RangeTombstoneList l = new RangeTombstoneList(cmp, 0); + l.add(rt(4, 4, 5, 100)); + l.add(rt(4, 4, 6, 110)); + l.add(rt(4, 4, 4, 90)); + + Iterator iter = l.iterator(); + assertRT(rt(4, 4, 6, 110), iter.next()); + assert !iter.hasNext(); + } + + private RangeTombstoneList makeRandom(Random rand, int size, int maxItSize, int maxItDistance, int maxMarkedAt) { RangeTombstoneList l = new RangeTombstoneList(cmp, size); @@ -495,10 +510,13 @@ public class RangeTombstoneListTest int MAX_IT_DISTANCE = 10; int MAX_MARKEDAT = 10; + long seed = System.nanoTime(); + Random rand = new Random(seed); + for (int i = 0; i < TEST_COUNT; i++) { - RangeTombstoneList l1 = makeRandom(rand.nextInt(MAX_LIST_SIZE) + 1, rand.nextInt(MAX_IT_SIZE) + 1, rand.nextInt(MAX_IT_DISTANCE) + 1, rand.nextInt(MAX_MARKEDAT) + 1); - RangeTombstoneList l2 = makeRandom(rand.nextInt(MAX_LIST_SIZE) + 1, rand.nextInt(MAX_IT_SIZE) + 1, rand.nextInt(MAX_IT_DISTANCE) + 1, rand.nextInt(MAX_MARKEDAT) + 1); + RangeTombstoneList l1 = makeRandom(rand, rand.nextInt(MAX_LIST_SIZE) + 1, rand.nextInt(MAX_IT_SIZE) + 1, rand.nextInt(MAX_IT_DISTANCE) + 1, rand.nextInt(MAX_MARKEDAT) + 1); + RangeTombstoneList l2 = makeRandom(rand, rand.nextInt(MAX_LIST_SIZE) + 1, rand.nextInt(MAX_IT_SIZE) + 1, rand.nextInt(MAX_IT_DISTANCE) + 1, rand.nextInt(MAX_MARKEDAT) + 1); RangeTombstoneList l1Initial = l1.copy(); @@ -513,6 +531,7 @@ public class RangeTombstoneListTest System.out.println("Error merging:"); System.out.println(" l1: " + toString(l1Initial)); System.out.println(" l2: " + toString(l2)); + System.out.println("Seed was: " + seed); throw e; } }