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);
}
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, now3 + 1);
Assert.assertEquals(expectedDeletion, builder.deletionTime);
Assert.assertEquals(Collections.emptyList(), builder.complexDeletions);
Assert.assertEquals(Collections.emptyList(), builder.cells);
}
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, now3 + 1);
Assert.assertEquals(expectedDeletion, builder.deletionTime);
Assert.assertEquals(LivenessInfo.EMPTY, builder.livenessInfo);
Assert.assertEquals(Collections.emptyList(), builder.complexDeletions);
Assert.assertEquals(Collections.emptyList(), builder.cells);
}
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, now2 + 1);
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);
}
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(now);
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);
}
Aggregations