Search in sources :

Example 11 with RangeTombstone

use of org.apache.cassandra.db.RangeTombstone in project cassandra by apache.

the class DataResolverTest method testRepairRangeTombstoneWithPartitionDeletion.

/**
 * Test for CASSANDRA-13719: tests that having a partition deletion shadow a range tombstone on another source
 * doesn't trigger an assertion error.
 */
@Test
public void testRepairRangeTombstoneWithPartitionDeletion() {
    EndpointsForRange replicas = makeReplicas(2);
    DataResolver resolver = new DataResolver(command, plan(replicas, ALL), readRepair, nanoTime());
    InetAddressAndPort peer1 = replicas.get(0).endpoint();
    InetAddressAndPort peer2 = replicas.get(1).endpoint();
    // 1st "stream": just a partition deletion
    UnfilteredPartitionIterator iter1 = iter(PartitionUpdate.fullPartitionDelete(cfm, dk, 10, nowInSec));
    // 2nd "stream": a range tombstone that is covered by the 1st stream
    RangeTombstone rt = tombstone("0", true, "10", true, 5, nowInSec);
    UnfilteredPartitionIterator iter2 = iter(new RowUpdateBuilder(cfm, nowInSec, 1L, dk).addRangeTombstone(rt).buildUpdate());
    resolver.preprocess(response(command, peer1, iter1));
    resolver.preprocess(response(command, peer2, iter2));
    // No results, we've only reconciled tombstones.
    try (PartitionIterator data = resolver.resolve()) {
        assertFalse(data.hasNext());
    // 2nd stream should get repaired
    }
    assertEquals(1, readRepair.sent.size());
    Mutation mutation = readRepair.getForEndpoint(peer2);
    assertRepairMetadata(mutation);
    assertRepairContainsNoColumns(mutation);
    assertRepairContainsDeletions(mutation, new DeletionTime(10, nowInSec));
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) RowUpdateBuilder(org.apache.cassandra.db.RowUpdateBuilder) UnfilteredPartitionIterator(org.apache.cassandra.db.partitions.UnfilteredPartitionIterator) PartitionIterator(org.apache.cassandra.db.partitions.PartitionIterator) DeletionTime(org.apache.cassandra.db.DeletionTime) EndpointsForRange(org.apache.cassandra.locator.EndpointsForRange) UnfilteredPartitionIterator(org.apache.cassandra.db.partitions.UnfilteredPartitionIterator) Mutation(org.apache.cassandra.db.Mutation) RangeTombstone(org.apache.cassandra.db.RangeTombstone) Test(org.junit.Test)

Example 12 with RangeTombstone

use of org.apache.cassandra.db.RangeTombstone in project cassandra by apache.

the class DataResolverTest method assertRepairContainsDeletions.

private void assertRepairContainsDeletions(Mutation mutation, DeletionTime deletionTime, RangeTombstone... rangeTombstones) {
    PartitionUpdate update = mutation.getPartitionUpdates().iterator().next();
    DeletionInfo deletionInfo = update.deletionInfo();
    if (deletionTime != null)
        assertEquals(deletionTime, deletionInfo.getPartitionDeletion());
    assertEquals(rangeTombstones.length, deletionInfo.rangeCount());
    Iterator<RangeTombstone> ranges = deletionInfo.rangeIterator(false);
    int i = 0;
    while (ranges.hasNext()) {
        RangeTombstone expected = rangeTombstones[i++];
        RangeTombstone actual = ranges.next();
        String msg = String.format("Expected %s, but got %s", expected.toString(cfm.comparator), actual.toString(cfm.comparator));
        assertEquals(msg, expected, actual);
    }
}
Also used : DeletionInfo(org.apache.cassandra.db.DeletionInfo) MutableDeletionInfo(org.apache.cassandra.db.MutableDeletionInfo) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) RangeTombstone(org.apache.cassandra.db.RangeTombstone)

Example 13 with RangeTombstone

use of org.apache.cassandra.db.RangeTombstone in project cassandra by apache.

the class DataResolverTest method testRepairRangeTombstoneBoundary.

/**
 * Test for CASSANDRA-13237, checking we don't fail (and handle correctly) the case where a RT boundary has the
 * same deletion on both side (while is useless but could be created by legacy code pre-CASSANDRA-13237 and could
 * thus still be sent).
 */
private void testRepairRangeTombstoneBoundary(int timestamp1, int timestamp2, int timestamp3) throws UnknownHostException {
    EndpointsForRange replicas = makeReplicas(2);
    DataResolver resolver = new DataResolver(command, plan(replicas, ALL), readRepair, nanoTime());
    InetAddressAndPort peer1 = replicas.get(0).endpoint();
    InetAddressAndPort peer2 = replicas.get(1).endpoint();
    // 1st "stream"
    RangeTombstone one_nine = tombstone("0", true, "9", true, timestamp1, nowInSec);
    UnfilteredPartitionIterator iter1 = iter(new RowUpdateBuilder(cfm, nowInSec, 1L, dk).addRangeTombstone(one_nine).buildUpdate());
    // 2nd "stream" (build more manually to ensure we have the boundary we want)
    RangeTombstoneBoundMarker open_one = marker("0", true, true, timestamp2, nowInSec);
    RangeTombstoneBoundaryMarker boundary_five = boundary("5", false, timestamp2, nowInSec, timestamp3, nowInSec);
    RangeTombstoneBoundMarker close_nine = marker("9", false, true, timestamp3, nowInSec);
    UnfilteredPartitionIterator iter2 = iter(dk, open_one, boundary_five, close_nine);
    resolver.preprocess(response(command, peer1, iter1));
    resolver.preprocess(response(command, peer2, iter2));
    boolean shouldHaveRepair = timestamp1 != timestamp2 || timestamp1 != timestamp3;
    // No results, we've only reconciled tombstones.
    try (PartitionIterator data = resolver.resolve()) {
        assertFalse(data.hasNext());
    }
    assertEquals(shouldHaveRepair ? 1 : 0, readRepair.sent.size());
    if (!shouldHaveRepair)
        return;
    Mutation mutation = readRepair.getForEndpoint(peer2);
    assertRepairMetadata(mutation);
    assertRepairContainsNoColumns(mutation);
    RangeTombstone expected = timestamp1 != timestamp2 ? // We've repaired the 1st part
    tombstone("0", true, "5", false, timestamp1, nowInSec) : // We've repaired the 2nd part
    tombstone("5", true, "9", true, timestamp1, nowInSec);
    assertRepairContainsDeletions(mutation, null, expected);
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) RowUpdateBuilder(org.apache.cassandra.db.RowUpdateBuilder) UnfilteredPartitionIterator(org.apache.cassandra.db.partitions.UnfilteredPartitionIterator) PartitionIterator(org.apache.cassandra.db.partitions.PartitionIterator) EndpointsForRange(org.apache.cassandra.locator.EndpointsForRange) RangeTombstoneBoundaryMarker(org.apache.cassandra.db.rows.RangeTombstoneBoundaryMarker) UnfilteredPartitionIterator(org.apache.cassandra.db.partitions.UnfilteredPartitionIterator) Mutation(org.apache.cassandra.db.Mutation) RangeTombstoneBoundMarker(org.apache.cassandra.db.rows.RangeTombstoneBoundMarker) RangeTombstone(org.apache.cassandra.db.RangeTombstone)

Example 14 with RangeTombstone

use of org.apache.cassandra.db.RangeTombstone in project cassandra by apache.

the class AbstractReadResponseTest method tombstone.

public RangeTombstone tombstone(Object start, boolean inclusiveStart, Object end, boolean inclusiveEnd, long markedForDeleteAt, int localDeletionTime) {
    ClusteringBound<?> startBound = rtBound(start, true, inclusiveStart);
    ClusteringBound<?> endBound = rtBound(end, false, inclusiveEnd);
    return new RangeTombstone(Slice.make(startBound, endBound), new DeletionTime(markedForDeleteAt, localDeletionTime));
}
Also used : DeletionTime(org.apache.cassandra.db.DeletionTime) RangeTombstone(org.apache.cassandra.db.RangeTombstone)

Aggregations

RangeTombstone (org.apache.cassandra.db.RangeTombstone)14 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)9 DeletionTime (org.apache.cassandra.db.DeletionTime)7 Mutation (org.apache.cassandra.db.Mutation)5 PartitionIterator (org.apache.cassandra.db.partitions.PartitionIterator)5 UnfilteredPartitionIterator (org.apache.cassandra.db.partitions.UnfilteredPartitionIterator)5 EndpointsForRange (org.apache.cassandra.locator.EndpointsForRange)5 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)5 Test (org.junit.Test)5 PartitionUpdate (org.apache.cassandra.db.partitions.PartitionUpdate)3 MutableDeletionInfo (org.apache.cassandra.db.MutableDeletionInfo)2 Slice (org.apache.cassandra.db.Slice)2 Relation (harry.operations.Relation)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)1 QueryOptions (org.apache.cassandra.cql3.QueryOptions)1 SingleColumnRelation (org.apache.cassandra.cql3.SingleColumnRelation)1 VariableSpecifications (org.apache.cassandra.cql3.VariableSpecifications)1 WhereClause (org.apache.cassandra.cql3.WhereClause)1