Search in sources :

Example 16 with DeletionTime

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

the class CompactionsTest method writeSSTableWithRangeTombstoneMaskingOneColumn.

public static void writeSSTableWithRangeTombstoneMaskingOneColumn(ColumnFamilyStore cfs, TableMetadata table, int[] dks) {
    for (int dk : dks) {
        RowUpdateBuilder deletedRowUpdateBuilder = new RowUpdateBuilder(table, 1, Util.dk(Integer.toString(dk)));
        // Range tombstone covers this (timestamp 2 > 1)
        deletedRowUpdateBuilder.clustering("01").add("val", "a");
        Clustering<?> startClustering = Clustering.make(ByteBufferUtil.bytes("0"));
        Clustering<?> endClustering = Clustering.make(ByteBufferUtil.bytes("b"));
        deletedRowUpdateBuilder.addRangeTombstone(new RangeTombstone(Slice.make(startClustering, endClustering), new DeletionTime(2, (int) (System.currentTimeMillis() / 1000))));
        deletedRowUpdateBuilder.build().applyUnsafe();
        RowUpdateBuilder notYetDeletedRowUpdateBuilder = new RowUpdateBuilder(table, 3, Util.dk(Integer.toString(dk)));
        // Range tombstone doesn't cover this (timestamp 3 > 2)
        notYetDeletedRowUpdateBuilder.clustering("02").add("val", "a");
        notYetDeletedRowUpdateBuilder.build().applyUnsafe();
    }
    cfs.forceBlockingFlush();
}
Also used : RowUpdateBuilder(org.apache.cassandra.db.RowUpdateBuilder) DeletionTime(org.apache.cassandra.db.DeletionTime) RangeTombstone(org.apache.cassandra.db.RangeTombstone)

Example 17 with DeletionTime

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

the class RowFilterTest method testCQLFilterClose.

@Test
public void testCQLFilterClose() {
    // CASSANDRA-15126
    TableMetadata metadata = TableMetadata.builder("testks", "testcf").addPartitionKeyColumn("pk", Int32Type.instance).addStaticColumn("s", Int32Type.instance).addRegularColumn("r", Int32Type.instance).build();
    ColumnMetadata s = metadata.getColumn(new ColumnIdentifier("s", true));
    ColumnMetadata r = metadata.getColumn(new ColumnIdentifier("r", true));
    ByteBuffer one = Int32Type.instance.decompose(1);
    RowFilter filter = RowFilter.NONE.withNewExpressions(new ArrayList<>());
    filter.add(s, Operator.NEQ, one);
    AtomicBoolean closed = new AtomicBoolean();
    UnfilteredPartitionIterator iter = filter.filter(new SingletonUnfilteredPartitionIterator(new UnfilteredRowIterator() {

        public DeletionTime partitionLevelDeletion() {
            return null;
        }

        public EncodingStats stats() {
            return null;
        }

        public TableMetadata metadata() {
            return metadata;
        }

        public boolean isReverseOrder() {
            return false;
        }

        public RegularAndStaticColumns columns() {
            return null;
        }

        public DecoratedKey partitionKey() {
            return null;
        }

        public boolean hasNext() {
            return false;
        }

        public Unfiltered next() {
            return null;
        }

        public Row staticRow() {
            return BTreeRow.create(Clustering.STATIC_CLUSTERING, LivenessInfo.EMPTY, Row.Deletion.LIVE, BTree.singleton(new BufferCell(s, 1, Cell.NO_TTL, Cell.NO_DELETION_TIME, one, null)));
        }

        public void close() {
            closed.set(true);
        }
    }), 1);
    Assert.assertFalse(iter.hasNext());
    Assert.assertTrue(closed.get());
    filter = RowFilter.NONE.withNewExpressions(new ArrayList<>());
    filter.add(r, Operator.NEQ, one);
    closed.set(false);
    iter = filter.filter(new SingletonUnfilteredPartitionIterator(new UnfilteredRowIterator() {

        boolean hasNext = true;

        public DeletionTime partitionLevelDeletion() {
            return null;
        }

        public EncodingStats stats() {
            return null;
        }

        public TableMetadata metadata() {
            return metadata;
        }

        public boolean isReverseOrder() {
            return false;
        }

        public RegularAndStaticColumns columns() {
            return null;
        }

        public DecoratedKey partitionKey() {
            return null;
        }

        public Row staticRow() {
            return Rows.EMPTY_STATIC_ROW;
        }

        public boolean hasNext() {
            boolean r = hasNext;
            hasNext = false;
            return r;
        }

        public Unfiltered next() {
            return BTreeRow.create(Clustering.EMPTY, LivenessInfo.EMPTY, Row.Deletion.LIVE, BTree.singleton(new BufferCell(r, 1, Cell.NO_TTL, Cell.NO_DELETION_TIME, one, null)));
        }

        public void close() {
            closed.set(true);
        }
    }), 1);
    Assert.assertFalse(iter.hasNext());
    Assert.assertTrue(closed.get());
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) DeletionTime(org.apache.cassandra.db.DeletionTime) DecoratedKey(org.apache.cassandra.db.DecoratedKey) ArrayList(java.util.ArrayList) UnfilteredPartitionIterator(org.apache.cassandra.db.partitions.UnfilteredPartitionIterator) SingletonUnfilteredPartitionIterator(org.apache.cassandra.db.partitions.SingletonUnfilteredPartitionIterator) BufferCell(org.apache.cassandra.db.rows.BufferCell) ByteBuffer(java.nio.ByteBuffer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EncodingStats(org.apache.cassandra.db.rows.EncodingStats) ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier) BTreeRow(org.apache.cassandra.db.rows.BTreeRow) Row(org.apache.cassandra.db.rows.Row) SingletonUnfilteredPartitionIterator(org.apache.cassandra.db.partitions.SingletonUnfilteredPartitionIterator) Unfiltered(org.apache.cassandra.db.rows.Unfiltered) RegularAndStaticColumns(org.apache.cassandra.db.RegularAndStaticColumns) Test(org.junit.Test)

Example 18 with DeletionTime

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

the class RowsTest method copy.

@Test
public void copy() {
    int now = FBUtilities.nowInSeconds();
    long ts = secondToTs(now);
    Row.Builder originalBuilder = BTreeRow.unsortedBuilder();
    originalBuilder.newRow(c1);
    LivenessInfo liveness = LivenessInfo.create(ts, now);
    originalBuilder.addPrimaryKeyLivenessInfo(liveness);
    DeletionTime complexDeletion = new DeletionTime(ts - 1, now);
    originalBuilder.addComplexDeletion(m, complexDeletion);
    List<Cell<?>> expectedCells = Lists.newArrayList(BufferCell.live(v, secondToTs(now), BB1), BufferCell.live(m, secondToTs(now), BB1, CellPath.create(BB1)), BufferCell.live(m, secondToTs(now), BB2, CellPath.create(BB2)));
    expectedCells.forEach(originalBuilder::addCell);
    // We need to use ts-1 so the deletion doesn't shadow what we've created
    Row.Deletion rowDeletion = new Row.Deletion(new DeletionTime(ts - 1, now), false);
    originalBuilder.addRowDeletion(rowDeletion);
    RowBuilder builder = new RowBuilder();
    Rows.copy(originalBuilder.build(), builder);
    Assert.assertEquals(c1, builder.clustering);
    Assert.assertEquals(liveness, builder.livenessInfo);
    Assert.assertEquals(rowDeletion, builder.deletionTime);
    Assert.assertEquals(Lists.newArrayList(Pair.create(m, complexDeletion)), builder.complexDeletions);
    Assert.assertEquals(Sets.newHashSet(expectedCells), Sets.newHashSet(builder.cells));
}
Also used : DeletionTime(org.apache.cassandra.db.DeletionTime) LivenessInfo(org.apache.cassandra.db.LivenessInfo) Test(org.junit.Test)

Example 19 with DeletionTime

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

the class RowsTest method collectStats.

@Test
public void collectStats() {
    int now = FBUtilities.nowInSeconds();
    long ts = secondToTs(now);
    Row.Builder builder = BTreeRow.unsortedBuilder();
    builder.newRow(c1);
    LivenessInfo liveness = LivenessInfo.create(ts, now);
    builder.addPrimaryKeyLivenessInfo(liveness);
    DeletionTime complexDeletion = new DeletionTime(ts - 1, now);
    builder.addComplexDeletion(m, complexDeletion);
    List<Cell<?>> expectedCells = Lists.newArrayList(BufferCell.live(v, ts, BB1), BufferCell.live(m, ts, BB1, CellPath.create(BB1)), BufferCell.live(m, ts, BB2, CellPath.create(BB2)));
    expectedCells.forEach(builder::addCell);
    // We need to use ts-1 so the deletion doesn't shadow what we've created
    Row.Deletion rowDeletion = new Row.Deletion(new DeletionTime(ts - 1, now), false);
    builder.addRowDeletion(rowDeletion);
    StatsCollector collector = new StatsCollector();
    Rows.collectStats(builder.build(), collector);
    Assert.assertEquals(Lists.newArrayList(liveness), collector.liveness);
    Assert.assertEquals(Sets.newHashSet(rowDeletion.time(), complexDeletion), Sets.newHashSet(collector.deletions));
    Assert.assertEquals(Sets.newHashSet(expectedCells), Sets.newHashSet(collector.cells));
    Assert.assertEquals(2, collector.columnCount);
    Assert.assertFalse(collector.hasLegacyCounterShards);
}
Also used : DeletionTime(org.apache.cassandra.db.DeletionTime) LivenessInfo(org.apache.cassandra.db.LivenessInfo) Test(org.junit.Test)

Example 20 with DeletionTime

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

the class RowsTest method createBuilder.

private static Row.Builder createBuilder(Clustering<?> c, int now, ByteBuffer vVal, ByteBuffer mKey, ByteBuffer mVal) {
    long ts = secondToTs(now);
    Row.Builder builder = BTreeRow.unsortedBuilder();
    builder.newRow(c);
    builder.addPrimaryKeyLivenessInfo(LivenessInfo.create(ts, now));
    if (vVal != null) {
        builder.addCell(BufferCell.live(v, ts, vVal));
    }
    if (mKey != null && mVal != null) {
        builder.addComplexDeletion(m, new DeletionTime(ts - 1, now));
        builder.addCell(BufferCell.live(m, ts, mVal, CellPath.create(mKey)));
    }
    return builder;
}
Also used : 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