Search in sources :

Example 21 with DeletionTime

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

the class RowsTest method merge.

@Test
public void merge() {
    int now1 = FBUtilities.nowInSeconds();
    Row.Builder existingBuilder = createBuilder(c1, now1, BB1, BB1, BB1);
    int now2 = now1 + 1;
    long ts2 = secondToTs(now2);
    Cell<?> expectedVCell = BufferCell.live(v, ts2, BB2);
    Cell<?> expectedMCell = BufferCell.live(m, ts2, BB2, CellPath.create(BB1));
    DeletionTime expectedComplexDeletionTime = new DeletionTime(ts2 - 1, now2);
    Row.Builder updateBuilder = createBuilder(c1, now2, null, null, null);
    updateBuilder.addCell(expectedVCell);
    updateBuilder.addComplexDeletion(m, expectedComplexDeletionTime);
    updateBuilder.addCell(expectedMCell);
    RowBuilder builder = new RowBuilder();
    long td = Rows.merge(existingBuilder.build(), updateBuilder.build(), builder);
    Assert.assertEquals(c1, builder.clustering);
    Assert.assertEquals(LivenessInfo.create(ts2, now2), builder.livenessInfo);
    Assert.assertEquals(Lists.newArrayList(Pair.create(m, new DeletionTime(ts2 - 1, now2))), builder.complexDeletions);
    Assert.assertEquals(2, builder.cells.size());
    Assert.assertEquals(Lists.newArrayList(expectedVCell, expectedMCell), Lists.newArrayList(builder.cells));
    Assert.assertEquals(ts2 - secondToTs(now1), td);
}
Also used : DeletionTime(org.apache.cassandra.db.DeletionTime) Test(org.junit.Test)

Example 22 with DeletionTime

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

the class RowsTest method mergeComplexDeletionSupersededByRowDeletion.

@Test
public void mergeComplexDeletionSupersededByRowDeletion() {
    int now1 = FBUtilities.nowInSeconds();
    Row.Builder existingBuilder = createBuilder(c1, now1, null, null, null);
    int now2 = now1 + 1;
    Row.Builder updateBuilder = createBuilder(c1, now2, null, BB1, BB1);
    int now3 = now2 + 1;
    Row.Deletion expectedDeletion = new Row.Deletion(new DeletionTime(secondToTs(now3), now3), false);
    updateBuilder.addRowDeletion(expectedDeletion);
    RowBuilder builder = new RowBuilder();
    Rows.merge(existingBuilder.build(), updateBuilder.build(), builder);
    Assert.assertEquals(expectedDeletion, builder.deletionTime);
    Assert.assertEquals(Collections.emptyList(), builder.complexDeletions);
    Assert.assertEquals(Collections.emptyList(), builder.cells);
}
Also used : DeletionTime(org.apache.cassandra.db.DeletionTime) Test(org.junit.Test)

Example 23 with DeletionTime

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

the class RowsTest method mergeRowDeletionSupercedesLiveness.

/**
 * If a row's deletion time deletes a row's liveness info, the new row should have it's
 * liveness info set to empty
 */
@Test
public void mergeRowDeletionSupercedesLiveness() {
    int now1 = FBUtilities.nowInSeconds();
    Row.Builder existingBuilder = createBuilder(c1, now1, null, null, null);
    int now2 = now1 + 1;
    Row.Builder updateBuilder = createBuilder(c1, now2, BB1, BB1, BB1);
    int now3 = now2 + 1;
    Row.Deletion expectedDeletion = new Row.Deletion(new DeletionTime(secondToTs(now3), now3), false);
    updateBuilder.addRowDeletion(expectedDeletion);
    RowBuilder builder = new RowBuilder();
    Rows.merge(existingBuilder.build(), updateBuilder.build(), builder);
    Assert.assertEquals(expectedDeletion, builder.deletionTime);
    Assert.assertEquals(LivenessInfo.EMPTY, builder.livenessInfo);
    Assert.assertEquals(Collections.emptyList(), builder.complexDeletions);
    Assert.assertEquals(Collections.emptyList(), builder.cells);
}
Also used : DeletionTime(org.apache.cassandra.db.DeletionTime) Test(org.junit.Test)

Example 24 with DeletionTime

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

the class ThrottledUnfilteredIteratorTest method verifyThrottleIterator.

private void verifyThrottleIterator(List<Unfiltered> expectedUnfiltereds, UnfilteredRowIterator rowIteratorForThrottle, ThrottledUnfilteredIterator throttledIterator, int throttle) {
    List<Unfiltered> output = new ArrayList<>();
    boolean isRevered = rowIteratorForThrottle.isReverseOrder();
    boolean isFirst = true;
    while (throttledIterator.hasNext()) {
        UnfilteredRowIterator splittedIterator = throttledIterator.next();
        assertMetadata(rowIteratorForThrottle, splittedIterator, isFirst);
        List<Unfiltered> splittedUnfiltereds = new ArrayList<>();
        splittedIterator.forEachRemaining(splittedUnfiltereds::add);
        int remain = expectedUnfiltereds.size() - output.size();
        int expectedSize = remain >= throttle ? throttle : remain;
        if (splittedUnfiltereds.size() != expectedSize) {
            assertEquals(expectedSize + 1, splittedUnfiltereds.size());
            // the extra unfilter must be close bound marker
            Unfiltered last = splittedUnfiltereds.get(expectedSize);
            assertTrue(last.isRangeTombstoneMarker());
            RangeTombstoneMarker marker = (RangeTombstoneMarker) last;
            assertFalse(marker.isBoundary());
            assertTrue(marker.isClose(isRevered));
        }
        output.addAll(splittedUnfiltereds);
        if (isFirst)
            isFirst = false;
    }
    int index = 0;
    RangeTombstoneMarker openMarker = null;
    for (int i = 0; i < expectedUnfiltereds.size(); i++) {
        Unfiltered expected = expectedUnfiltereds.get(i);
        Unfiltered data = output.get(i);
        // verify that all tombstone are paired
        if (data.isRangeTombstoneMarker()) {
            RangeTombstoneMarker marker = (RangeTombstoneMarker) data;
            if (marker.isClose(isRevered)) {
                assertNotNull(openMarker);
                openMarker = null;
            }
            if (marker.isOpen(isRevered)) {
                assertNull(openMarker);
                openMarker = marker;
            }
        }
        if (expected.equals(data)) {
            index++;
        } else // because of created closeMarker and openMarker
        {
            assertNotNull(openMarker);
            DeletionTime openDeletionTime = openMarker.openDeletionTime(isRevered);
            // only boundary or row will create extra closeMarker and openMarker
            if (expected.isRangeTombstoneMarker()) {
                RangeTombstoneMarker marker = (RangeTombstoneMarker) expected;
                assertTrue(marker.isBoundary());
                RangeTombstoneBoundaryMarker boundary = (RangeTombstoneBoundaryMarker) marker;
                assertEquals(boundary.createCorrespondingCloseMarker(isRevered), data);
                assertEquals(boundary.createCorrespondingOpenMarker(isRevered), output.get(index + 1));
                assertEquals(openDeletionTime, boundary.endDeletionTime());
                openMarker = boundary.createCorrespondingOpenMarker(isRevered);
            } else {
                RangeTombstoneBoundMarker closeMarker = RangeTombstoneBoundMarker.exclusiveClose(isRevered, expected.clustering(), openDeletionTime);
                RangeTombstoneBoundMarker nextOpenMarker = RangeTombstoneBoundMarker.inclusiveOpen(isRevered, expected.clustering(), openDeletionTime);
                assertEquals(closeMarker, data);
                assertEquals(nextOpenMarker, output.get(index + 1));
                openMarker = nextOpenMarker;
            }
            index += 2;
        }
    }
    assertNull(openMarker);
    assertEquals(output.size(), index);
}
Also used : DeletionTime(org.apache.cassandra.db.DeletionTime) ArrayList(java.util.ArrayList)

Example 25 with DeletionTime

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

the class CompactionIteratorTest method parse.

private List<Unfiltered> parse(String input, UnfilteredRowsGenerator generator) {
    Matcher m = Pattern.compile("D(\\d+)\\|").matcher(input);
    if (m.lookingAt()) {
        int del = Integer.parseInt(m.group(1));
        input = input.substring(m.end());
        List<Unfiltered> list = generator.parse(input, NOW - 1);
        deletionTimes.put(list, new DeletionTime(del, del));
        return list;
    } else
        return generator.parse(input, NOW - 1);
}
Also used : Matcher(java.util.regex.Matcher) DeletionTime(org.apache.cassandra.db.DeletionTime)

Aggregations

DeletionTime (org.apache.cassandra.db.DeletionTime)32 Test (org.junit.Test)21 UnfilteredPartitionIterator (org.apache.cassandra.db.partitions.UnfilteredPartitionIterator)10 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)8 PartitionIterator (org.apache.cassandra.db.partitions.PartitionIterator)8 EndpointsForRange (org.apache.cassandra.locator.EndpointsForRange)8 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)8 Mutation (org.apache.cassandra.db.Mutation)7 RangeTombstone (org.apache.cassandra.db.RangeTombstone)7 Row (org.apache.cassandra.db.rows.Row)7 LivenessInfo (org.apache.cassandra.db.LivenessInfo)6 BTreeRow (org.apache.cassandra.db.rows.BTreeRow)6 ArrayList (java.util.ArrayList)5 ReadCommand (org.apache.cassandra.db.ReadCommand)4 ComplexColumnData (org.apache.cassandra.db.rows.ComplexColumnData)4 RowIterator (org.apache.cassandra.db.rows.RowIterator)4 TestableReadRepair (org.apache.cassandra.service.reads.repair.TestableReadRepair)4 ByteBuffer (java.nio.ByteBuffer)2 List (java.util.List)2 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)2