Slice.isEmpty() returns false for some empty slices patch by Sylvain Lebresne; reviewed by Branimir Lambov for CASSANDRA-13305
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/31dec3d5 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/31dec3d5 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/31dec3d5 Branch: refs/heads/trunk Commit: 31dec3d548ae2c76d7c8bf4bffa9d506f670f756 Parents: 60d3292 Author: Sylvain Lebresne <sylv...@datastax.com> Authored: Thu Mar 9 11:58:40 2017 +0100 Committer: Sylvain Lebresne <sylv...@datastax.com> Committed: Thu Mar 9 11:58:40 2017 +0100 ---------------------------------------------------------------------- CHANGES.txt | 1 + src/java/org/apache/cassandra/db/Slice.java | 2 +- .../cql3/validation/operations/DeleteTest.java | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/31dec3d5/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 0979852..1876922 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 3.0.13 + * Slice.isEmpty() returns false for some empty slices (CASSANDRA-13305) * Add formatted row output to assertEmpty in CQL Tester (CASSANDRA-13238) Merged from 2.2: * Fix GRANT/REVOKE when keyspace isn't specified (CASSANDRA-13053) http://git-wip-us.apache.org/repos/asf/cassandra/blob/31dec3d5/src/java/org/apache/cassandra/db/Slice.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/db/Slice.java b/src/java/org/apache/cassandra/db/Slice.java index 7fde45e..3c645dc 100644 --- a/src/java/org/apache/cassandra/db/Slice.java +++ b/src/java/org/apache/cassandra/db/Slice.java @@ -160,7 +160,7 @@ public class Slice public static boolean isEmpty(ClusteringComparator comparator, Slice.Bound start, Slice.Bound end) { assert start.isStart() && end.isEnd(); - return comparator.compare(end, start) < 0; + return comparator.compare(end, start) <= 0; } /** http://git-wip-us.apache.org/repos/asf/cassandra/blob/31dec3d5/test/unit/org/apache/cassandra/cql3/validation/operations/DeleteTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/DeleteTest.java b/test/unit/org/apache/cassandra/cql3/validation/operations/DeleteTest.java index 09098ac..9d7d4a3 100644 --- a/test/unit/org/apache/cassandra/cql3/validation/operations/DeleteTest.java +++ b/test/unit/org/apache/cassandra/cql3/validation/operations/DeleteTest.java @@ -1292,6 +1292,24 @@ public class DeleteTest extends CQLTester } /** + * Test for CASSANDRA-13305 + */ + @Test + public void testWithEmptyRange() throws Throwable + { + createTable("CREATE TABLE %s (k text, a int, b int, PRIMARY KEY (k, a, b))"); + + // Both of the following should be doing nothing, but before #13305 this inserted broken ranges. We do it twice + // and the follow-up delete mainly as a way to show the bug as the combination of this will trigger an assertion + // in RangeTombstoneList pre-#13305 showing that something wrong happened. + execute("DELETE FROM %s WHERE k = ? AND a >= ? AND a < ?", "a", 1, 1); + execute("DELETE FROM %s WHERE k = ? AND a >= ? AND a < ?", "a", 1, 1); + + execute("DELETE FROM %s WHERE k = ? AND a >= ? AND a < ?", "a", 0, 2); + } + + + /** * Checks if the memtable is empty or not * @return {@code true} if the memtable is empty, {@code false} otherwise. */