Search in sources :

Example 6 with LivenessInfo

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

the class BTreeRow method filter.

public Row filter(ColumnFilter filter, DeletionTime activeDeletion, boolean setActiveDeletionToRow, TableMetadata metadata) {
    Map<ByteBuffer, DroppedColumn> droppedColumns = metadata.droppedColumns;
    boolean mayFilterColumns = !filter.fetchesAllColumns(isStatic()) || !filter.allFetchedColumnsAreQueried();
    // When merging sstable data in Row.Merger#merge(), rowDeletion is removed if it doesn't supersede activeDeletion.
    boolean mayHaveShadowed = !activeDeletion.isLive() && !deletion.time().supersedes(activeDeletion);
    if (!mayFilterColumns && !mayHaveShadowed && droppedColumns.isEmpty())
        return this;
    LivenessInfo newInfo = primaryKeyLivenessInfo;
    Deletion newDeletion = deletion;
    if (mayHaveShadowed) {
        if (activeDeletion.deletes(newInfo.timestamp()))
            newInfo = LivenessInfo.EMPTY;
        // note that mayHaveShadowed means the activeDeletion shadows the row deletion. So if don't have setActiveDeletionToRow,
        // the row deletion is shadowed and we shouldn't return it.
        newDeletion = setActiveDeletionToRow ? Deletion.regular(activeDeletion) : Deletion.LIVE;
    }
    Columns columns = filter.fetchedColumns().columns(isStatic());
    Predicate<ColumnMetadata> inclusionTester = columns.inOrderInclusionTester();
    Predicate<ColumnMetadata> queriedByUserTester = filter.queriedColumns().columns(isStatic()).inOrderInclusionTester();
    final LivenessInfo rowLiveness = newInfo;
    return transformAndFilter(newInfo, newDeletion, (cd) -> {
        ColumnMetadata column = cd.column();
        if (!inclusionTester.test(column))
            return null;
        DroppedColumn dropped = droppedColumns.get(column.name.bytes);
        if (column.isComplex())
            return ((ComplexColumnData) cd).filter(filter, mayHaveShadowed ? activeDeletion : DeletionTime.LIVE, dropped, rowLiveness);
        Cell<?> cell = (Cell<?>) cd;
        // We include the cell unless it is 1) shadowed, 2) for a dropped column or 3) skippable.
        // And a cell is skippable if it is for a column that is not queried by the user and its timestamp
        // is lower than the row timestamp (see #10657 or SerializationHelper.includes() for details).
        boolean isForDropped = dropped != null && cell.timestamp() <= dropped.droppedTime;
        boolean isShadowed = mayHaveShadowed && activeDeletion.deletes(cell);
        boolean isSkippable = !queriedByUserTester.test(column);
        if (isForDropped || isShadowed || (isSkippable && cell.timestamp() < rowLiveness.timestamp()))
            return null;
        // between sstables and memtables data, i.e resulting in a digest mismatch.
        return isSkippable ? cell.withSkippedValue() : cell;
    });
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) DroppedColumn(org.apache.cassandra.schema.DroppedColumn) Columns(org.apache.cassandra.db.Columns) ByteBuffer(java.nio.ByteBuffer) LivenessInfo(org.apache.cassandra.db.LivenessInfo)

Example 7 with LivenessInfo

use of org.apache.cassandra.db.LivenessInfo 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 8 with LivenessInfo

use of org.apache.cassandra.db.LivenessInfo 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)

Aggregations

LivenessInfo (org.apache.cassandra.db.LivenessInfo)8 DeletionTime (org.apache.cassandra.db.DeletionTime)6 Test (org.junit.Test)5 ByteBuffer (java.nio.ByteBuffer)1 Columns (org.apache.cassandra.db.Columns)1 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)1 DroppedColumn (org.apache.cassandra.schema.DroppedColumn)1