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();
}
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());
}
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));
}
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);
}
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;
}
Aggregations