Search in sources :

Example 11 with FilteredPartition

use of org.apache.cassandra.db.partitions.FilteredPartition in project cassandra by apache.

the class CleanupTransientTest method testCleanup.

@Test
public void testCleanup() throws Exception {
    Keyspace keyspace = Keyspace.open(KEYSPACE1);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF_STANDARD1);
    // insert data and verify we get it back w/ range query
    fillCF(cfs, "val", LOOPS);
    // record max timestamps of the sstables pre-cleanup
    List<Long> expectedMaxTimestamps = getMaxTimestampList(cfs);
    assertEquals(LOOPS, Util.getAll(Util.cmd(cfs).build()).size());
    // with two tokens RF=2/1 and the sstable not repaired this should do nothing
    CompactionManager.instance.performCleanup(cfs, 2);
    // ensure max timestamp of the sstables are retained post-cleanup
    assert expectedMaxTimestamps.equals(getMaxTimestampList(cfs));
    // check data is still there
    assertEquals(LOOPS, Util.getAll(Util.cmd(cfs).build()).size());
    // Get an exact count of how many partitions are in the fully replicated range and should
    // be retained
    int fullCount = 0;
    RangesAtEndpoint localRanges = StorageService.instance.getLocalReplicas(keyspace.getName()).filter(Replica::isFull);
    for (FilteredPartition partition : Util.getAll(Util.cmd(cfs).build())) {
        Token token = partition.partitionKey().getToken();
        for (Replica r : localRanges) {
            if (r.range().contains(token))
                fullCount++;
        }
    }
    SSTableReader sstable = cfs.getLiveSSTables().iterator().next();
    sstable.descriptor.getMetadataSerializer().mutateRepairMetadata(sstable.descriptor, 1, null, false);
    sstable.reloadSSTableMetadata();
    // This should remove approximately 50% of the data, specifically whatever was transiently replicated
    CompactionManager.instance.performCleanup(cfs, 2);
    // ensure max timestamp of the sstables are retained post-cleanup
    assert expectedMaxTimestamps.equals(getMaxTimestampList(cfs));
    // check less data is there, all transient data should be gone since the table was repaired
    assertEquals(fullCount, Util.getAll(Util.cmd(cfs).build()).size());
}
Also used : RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) FilteredPartition(org.apache.cassandra.db.partitions.FilteredPartition) Token(org.apache.cassandra.dht.Token) Replica(org.apache.cassandra.locator.Replica) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) Test(org.junit.Test)

Example 12 with FilteredPartition

use of org.apache.cassandra.db.partitions.FilteredPartition in project cassandra by apache.

the class QueryPagerTest method rangeNamesQueryTest.

public void rangeNamesQueryTest(boolean testPagingState, ProtocolVersion protocolVersion) {
    ReadCommand command = rangeNamesQuery("k0", "k5", 100, "c1", "c4", "c8");
    QueryPager pager = command.getPager(null, protocolVersion);
    assertFalse(pager.isExhausted());
    List<FilteredPartition> partitions = query(pager, 3 * 3);
    for (int i = 1; i <= 3; i++) assertRow(partitions.get(i - 1), "k" + i, "c1", "c4", "c8");
    assertFalse(pager.isExhausted());
    pager = maybeRecreate(pager, command, testPagingState, protocolVersion);
    assertFalse(pager.isExhausted());
    partitions = query(pager, 3 * 3, 2 * 3);
    for (int i = 4; i <= 5; i++) assertRow(partitions.get(i - 4), "k" + i, "c1", "c4", "c8");
    assertTrue(pager.isExhausted());
}
Also used : QueryPager(org.apache.cassandra.service.pager.QueryPager) FilteredPartition(org.apache.cassandra.db.partitions.FilteredPartition)

Example 13 with FilteredPartition

use of org.apache.cassandra.db.partitions.FilteredPartition in project cassandra by apache.

the class QueryPagerTest method multiQueryTest.

public void multiQueryTest(boolean testPagingState, ProtocolVersion protocolVersion) {
    ReadQuery command = SinglePartitionReadCommand.Group.create(new ArrayList<SinglePartitionReadCommand>() {

        {
            add(sliceQuery("k1", "c2", "c6", 10));
            add(sliceQuery("k4", "c3", "c5", 10));
        }
    }, DataLimits.NONE);
    QueryPager pager = command.getPager(null, protocolVersion);
    assertFalse(pager.isExhausted());
    List<FilteredPartition> partition = query(pager, 3);
    assertRow(partition.get(0), "k1", "c2", "c3", "c4");
    assertFalse(pager.isExhausted());
    pager = maybeRecreate(pager, command, testPagingState, protocolVersion);
    assertFalse(pager.isExhausted());
    partition = query(pager, 4);
    assertRow(partition.get(0), "k1", "c5", "c6");
    assertRow(partition.get(1), "k4", "c3", "c4");
    assertFalse(pager.isExhausted());
    pager = maybeRecreate(pager, command, testPagingState, protocolVersion);
    assertFalse(pager.isExhausted());
    partition = query(pager, 3, 1);
    assertRow(partition.get(0), "k4", "c5");
    assertTrue(pager.isExhausted());
}
Also used : QueryPager(org.apache.cassandra.service.pager.QueryPager) FilteredPartition(org.apache.cassandra.db.partitions.FilteredPartition)

Example 14 with FilteredPartition

use of org.apache.cassandra.db.partitions.FilteredPartition in project cassandra by apache.

the class QueryPagerTest method query.

private static List<FilteredPartition> query(QueryPager pager, int toQuery, int expectedSize) {
    StringBuilder sb = new StringBuilder();
    List<FilteredPartition> partitionList = new ArrayList<>();
    int rows = 0;
    try (ReadExecutionController executionController = pager.executionController();
        PartitionIterator iterator = pager.fetchPageInternal(toQuery, executionController)) {
        while (iterator.hasNext()) {
            try (RowIterator rowIter = iterator.next()) {
                FilteredPartition partition = FilteredPartition.create(rowIter);
                sb.append(partition);
                partitionList.add(partition);
                rows += partition.rowCount();
            }
        }
    }
    assertEquals(sb.toString(), expectedSize, rows);
    return partitionList;
}
Also used : PartitionIterator(org.apache.cassandra.db.partitions.PartitionIterator) RowIterator(org.apache.cassandra.db.rows.RowIterator) FilteredPartition(org.apache.cassandra.db.partitions.FilteredPartition)

Example 15 with FilteredPartition

use of org.apache.cassandra.db.partitions.FilteredPartition in project cassandra by apache.

the class QueryPagerTest method reversedSliceQueryTest.

public void reversedSliceQueryTest(boolean testPagingState, ProtocolVersion protocolVersion) {
    ReadCommand command = sliceQuery("k0", "c1", "c8", true, 10);
    QueryPager pager = command.getPager(null, protocolVersion);
    assertFalse(pager.isExhausted());
    List<FilteredPartition> partition = query(pager, 3);
    assertRow(partition.get(0), "k0", "c6", "c7", "c8");
    assertFalse(pager.isExhausted());
    pager = maybeRecreate(pager, command, testPagingState, protocolVersion);
    assertFalse(pager.isExhausted());
    partition = query(pager, 3);
    assertRow(partition.get(0), "k0", "c3", "c4", "c5");
    assertFalse(pager.isExhausted());
    pager = maybeRecreate(pager, command, testPagingState, protocolVersion);
    assertFalse(pager.isExhausted());
    partition = query(pager, 3, 2);
    assertRow(partition.get(0), "k0", "c1", "c2");
    assertTrue(pager.isExhausted());
}
Also used : QueryPager(org.apache.cassandra.service.pager.QueryPager) FilteredPartition(org.apache.cassandra.db.partitions.FilteredPartition)

Aggregations

FilteredPartition (org.apache.cassandra.db.partitions.FilteredPartition)15 QueryPager (org.apache.cassandra.service.pager.QueryPager)9 Test (org.junit.Test)6 RowIterator (org.apache.cassandra.db.rows.RowIterator)3 SinglePartitionReadCommand (org.apache.cassandra.db.SinglePartitionReadCommand)2 PartitionIterator (org.apache.cassandra.db.partitions.PartitionIterator)2 Row (org.apache.cassandra.db.rows.Row)2 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)2 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)2 TableMetadata (org.apache.cassandra.schema.TableMetadata)2 ArrayList (java.util.ArrayList)1 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)1 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)1 ConsistencyLevel (org.apache.cassandra.db.ConsistencyLevel)1 DecoratedKey (org.apache.cassandra.db.DecoratedKey)1 Directories (org.apache.cassandra.db.Directories)1 Keyspace (org.apache.cassandra.db.Keyspace)1 ReadExecutionController (org.apache.cassandra.db.ReadExecutionController)1 ClusteringIndexSliceFilter (org.apache.cassandra.db.filter.ClusteringIndexSliceFilter)1 PartitionUpdate (org.apache.cassandra.db.partitions.PartitionUpdate)1