Skip to content

Commit ee124d2

Browse files
samueldlightfootnetudima
authored andcommitted
Fix flaky test2DeleteRangeWithOverlapingBoundAndSameTimestampCompaction
The two deletes use the same CQL timestamp, so compaction should merge their overlapping range tombstones into a single open/close pair (no boundary markers). However, DeletionTime also includes local_delete_time (wall-clock seconds), which may differ between deletes if a second boundary is crossed during the flush. Differing local_delete_time causes the merger to treat them as distinct deletions, producing boundary markers instead. Using executeInternalWithNowInSec with a fixed nowInSec ensures both deletes get identical DeletionTime values. patch by Sam Lightfoot; reviewed by Dmitry Konstantinov,Brandon Williams for CASSANDRA-21163
1 parent 817f0b8 commit ee124d2

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

test/unit/org/apache/cassandra/db/compaction/simple/CompactionDeleteRowRangeTest.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.junit.Test;
2323

24+
import org.apache.cassandra.cql3.QueryProcessor;
2425
import org.apache.cassandra.cql3.UntypedResultSet;
2526
import org.apache.cassandra.db.ColumnFamilyStore;
2627
import org.apache.cassandra.db.Keyspace;
@@ -32,6 +33,7 @@
3233
import org.apache.cassandra.db.rows.UnfilteredRowIterator;
3334
import org.apache.cassandra.io.sstable.ISSTableScanner;
3435
import org.apache.cassandra.io.sstable.format.SSTableReader;
36+
import org.apache.cassandra.utils.FBUtilities;
3537

3638
import static org.apache.cassandra.utils.TestHelper.verifyAndPrint;
3739
import static org.junit.Assert.assertEquals;
@@ -330,8 +332,13 @@ public void test2DeleteRangeWithOverlapingBoundAndSameTimestampCompaction() thro
330332
ColumnFamilyStore cfs = Keyspace.open(keyspace).getColumnFamilyStore(table);
331333
cfs.disableAutoCompaction();
332334

335+
// Use a fixed nowInSec for both deletes so they get the same local_delete_time,
336+
// ensuring compaction merges the overlapping range tombstones deterministically.
337+
long nowInSec = FBUtilities.nowInSeconds();
338+
333339
// Delete
334-
execute("DELETE FROM " + table + " using timestamp 2 WHERE pk = ? AND ck1 = ? AND ck2 <= ?;",
340+
QueryProcessor.executeInternalWithNowInSec("DELETE FROM " + table + " using timestamp 2 WHERE pk = ? AND ck1 = ? AND ck2 <= ?;",
341+
nowInSec,
335342
Long.valueOf(0), //pk
336343
Long.valueOf(0), //ck1
337344
Integer.valueOf(3) //ck2
@@ -340,7 +347,8 @@ public void test2DeleteRangeWithOverlapingBoundAndSameTimestampCompaction() thro
340347
cfs.forceBlockingFlush(ColumnFamilyStore.FlushReason.USER_FORCED);
341348

342349
// Delete
343-
execute("DELETE FROM " + table + " using timestamp 2 WHERE pk = ? AND ck1 = ? AND ck2 >= ?;",
350+
QueryProcessor.executeInternalWithNowInSec("DELETE FROM " + table + " using timestamp 2 WHERE pk = ? AND ck1 = ? AND ck2 >= ?;",
351+
nowInSec,
344352
Long.valueOf(0), //pk
345353
Long.valueOf(0), //ck1
346354
Integer.valueOf(0) //ck2
@@ -367,13 +375,13 @@ public void test2DeleteRangeWithOverlapingBoundAndSameTimestampCompaction() thro
367375
assertTrue(partition.staticRow().isEmpty());
368376
Unfiltered tombstoneMarker = partition.next();
369377
assertTrue(tombstoneMarker.isRangeTombstoneMarker());
370-
assertTrue(!((RangeTombstoneMarker)tombstoneMarker).isBoundary());
378+
assertFalse(((RangeTombstoneMarker) tombstoneMarker).isBoundary());
371379
assertTrue(((RangeTombstoneBoundMarker)tombstoneMarker).openIsInclusive(false));
372380
assertEquals(2, ((RangeTombstoneBoundMarker)tombstoneMarker).deletionTime().markedForDeleteAt());
373381

374382
tombstoneMarker = partition.next();
375383
assertTrue(tombstoneMarker.isRangeTombstoneMarker());
376-
assertTrue(!((RangeTombstoneMarker)tombstoneMarker).isBoundary());
384+
assertFalse(((RangeTombstoneMarker) tombstoneMarker).isBoundary());
377385
assertTrue(((RangeTombstoneMarker)tombstoneMarker).closeIsInclusive(false));
378386
assertEquals(2, ((RangeTombstoneBoundMarker)tombstoneMarker).deletionTime().markedForDeleteAt());
379387
assertFalse(partition.hasNext());

0 commit comments

Comments
 (0)