Search in sources :

Example 16 with UnfilteredRowIterator

use of org.apache.cassandra.db.rows.UnfilteredRowIterator in project cassandra by apache.

the class SinglePartitionSliceCommandTest method checkForS.

private void checkForS(UnfilteredPartitionIterator pi) {
    Assert.assertTrue(pi.toString(), pi.hasNext());
    UnfilteredRowIterator ri = pi.next();
    Assert.assertTrue(ri.columns().contains(s));
    Row staticRow = ri.staticRow();
    Iterator<Cell> cellIterator = staticRow.cells().iterator();
    Assert.assertTrue(staticRow.toString(metadata, true), cellIterator.hasNext());
    Cell cell = cellIterator.next();
    Assert.assertEquals(s, cell.column());
    Assert.assertEquals(ByteBufferUtil.bytesToHex(cell.value()), ByteBufferUtil.bytes("s"), cell.value());
    Assert.assertFalse(cellIterator.hasNext());
}
Also used : UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) Row(org.apache.cassandra.db.rows.Row) Cell(org.apache.cassandra.db.rows.Cell)

Example 17 with UnfilteredRowIterator

use of org.apache.cassandra.db.rows.UnfilteredRowIterator in project cassandra by apache.

the class NeverPurgeTest method verifyContainsTombstones.

private void verifyContainsTombstones(Collection<SSTableReader> sstables, int expectedTombstoneCount) throws Exception {
    // always run a major compaction before calling this
    assertTrue(sstables.size() == 1);
    SSTableReader sstable = sstables.iterator().next();
    int tombstoneCount = 0;
    try (ISSTableScanner scanner = sstable.getScanner()) {
        while (scanner.hasNext()) {
            try (UnfilteredRowIterator iter = scanner.next()) {
                if (!iter.partitionLevelDeletion().isLive())
                    tombstoneCount++;
                while (iter.hasNext()) {
                    Unfiltered atom = iter.next();
                    if (atom.isRow()) {
                        Row r = (Row) atom;
                        if (!r.deletion().isLive())
                            tombstoneCount++;
                        for (Cell c : r.cells()) if (c.isTombstone())
                            tombstoneCount++;
                    }
                }
            }
        }
    }
    assertEquals(tombstoneCount, expectedTombstoneCount);
}
Also used : ISSTableScanner(org.apache.cassandra.io.sstable.ISSTableScanner) UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Row(org.apache.cassandra.db.rows.Row) Cell(org.apache.cassandra.db.rows.Cell) Unfiltered(org.apache.cassandra.db.rows.Unfiltered)

Example 18 with UnfilteredRowIterator

use of org.apache.cassandra.db.rows.UnfilteredRowIterator in project cassandra by apache.

the class AntiCompactionTest method antiCompactTen.

public void antiCompactTen(String compactionStrategy) throws InterruptedException, IOException {
    Keyspace keyspace = Keyspace.open(KEYSPACE1);
    ColumnFamilyStore store = keyspace.getColumnFamilyStore(CF);
    store.disableAutoCompaction();
    for (int table = 0; table < 10; table++) {
        generateSStable(store, Integer.toString(table));
    }
    Collection<SSTableReader> sstables = getUnrepairedSSTables(store);
    assertEquals(store.getLiveSSTables().size(), sstables.size());
    Range<Token> range = new Range<Token>(new BytesToken("0".getBytes()), new BytesToken("4".getBytes()));
    List<Range<Token>> ranges = Arrays.asList(range);
    long repairedAt = 1000;
    UUID parentRepairSession = UUID.randomUUID();
    try (LifecycleTransaction txn = store.getTracker().tryModify(sstables, OperationType.ANTICOMPACTION);
        Refs<SSTableReader> refs = Refs.ref(sstables)) {
        CompactionManager.instance.performAnticompaction(store, ranges, refs, txn, repairedAt, NO_PENDING_REPAIR, parentRepairSession);
    }
    /*
        Anticompaction will be anti-compacting 10 SSTables but will be doing this two at a time
        so there will be no net change in the number of sstables
         */
    assertEquals(10, store.getLiveSSTables().size());
    int repairedKeys = 0;
    int nonRepairedKeys = 0;
    for (SSTableReader sstable : store.getLiveSSTables()) {
        try (ISSTableScanner scanner = sstable.getScanner()) {
            while (scanner.hasNext()) {
                try (UnfilteredRowIterator row = scanner.next()) {
                    if (sstable.isRepaired()) {
                        assertTrue(range.contains(row.partitionKey().getToken()));
                        assertEquals(repairedAt, sstable.getSSTableMetadata().repairedAt);
                        repairedKeys++;
                    } else {
                        assertFalse(range.contains(row.partitionKey().getToken()));
                        assertEquals(ActiveRepairService.UNREPAIRED_SSTABLE, sstable.getSSTableMetadata().repairedAt);
                        nonRepairedKeys++;
                    }
                }
            }
        }
    }
    assertEquals(repairedKeys, 40);
    assertEquals(nonRepairedKeys, 60);
}
Also used : UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction) BytesToken(org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) BytesToken(org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken) UUID(java.util.UUID)

Example 19 with UnfilteredRowIterator

use of org.apache.cassandra.db.rows.UnfilteredRowIterator in project cassandra by apache.

the class TTLExpiryTest method testNoExpire.

@Test
public void testNoExpire() throws InterruptedException, IOException {
    ColumnFamilyStore cfs = Keyspace.open(KEYSPACE1).getColumnFamilyStore("Standard1");
    cfs.truncateBlocking();
    cfs.disableAutoCompaction();
    MigrationManager.announceTableUpdate(cfs.metadata().unbuild().gcGraceSeconds(0).build(), true);
    long timestamp = System.currentTimeMillis();
    String key = "ttl";
    new RowUpdateBuilder(cfs.metadata(), timestamp, 1, key).add("col", ByteBufferUtil.EMPTY_BYTE_BUFFER).add("col7", ByteBufferUtil.EMPTY_BYTE_BUFFER).build().applyUnsafe();
    cfs.forceBlockingFlush();
    new RowUpdateBuilder(cfs.metadata(), timestamp, 1, key).add("col2", ByteBufferUtil.EMPTY_BYTE_BUFFER).build().applyUnsafe();
    cfs.forceBlockingFlush();
    new RowUpdateBuilder(cfs.metadata(), timestamp, 1, key).add("col3", ByteBufferUtil.EMPTY_BYTE_BUFFER).build().applyUnsafe();
    cfs.forceBlockingFlush();
    String noTTLKey = "nottl";
    new RowUpdateBuilder(cfs.metadata(), timestamp, noTTLKey).add("col311", ByteBufferUtil.EMPTY_BYTE_BUFFER).build().applyUnsafe();
    cfs.forceBlockingFlush();
    // wait for ttl to expire
    Thread.sleep(2000);
    assertEquals(4, cfs.getLiveSSTables().size());
    cfs.enableAutoCompaction(true);
    assertEquals(1, cfs.getLiveSSTables().size());
    SSTableReader sstable = cfs.getLiveSSTables().iterator().next();
    ISSTableScanner scanner = sstable.getScanner(ColumnFilter.all(cfs.metadata()), DataRange.allData(cfs.getPartitioner()));
    assertTrue(scanner.hasNext());
    while (scanner.hasNext()) {
        UnfilteredRowIterator iter = scanner.next();
        assertEquals(Util.dk(noTTLKey), iter.partitionKey());
    }
    scanner.close();
}
Also used : ISSTableScanner(org.apache.cassandra.io.sstable.ISSTableScanner) UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Test(org.junit.Test)

Aggregations

UnfilteredRowIterator (org.apache.cassandra.db.rows.UnfilteredRowIterator)19 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)11 Test (org.junit.Test)6 File (java.io.File)5 ISSTableScanner (org.apache.cassandra.io.sstable.ISSTableScanner)5 UnfilteredPartitionIterator (org.apache.cassandra.db.partitions.UnfilteredPartitionIterator)4 Row (org.apache.cassandra.db.rows.Row)4 Range (org.apache.cassandra.dht.Range)4 ByteBuffer (java.nio.ByteBuffer)3 LifecycleTransaction (org.apache.cassandra.db.lifecycle.LifecycleTransaction)3 IOException (java.io.IOException)2 UUID (java.util.UUID)2 ClusteringIndexSliceFilter (org.apache.cassandra.db.filter.ClusteringIndexSliceFilter)2 AbstractRow (org.apache.cassandra.db.rows.AbstractRow)2 Cell (org.apache.cassandra.db.rows.Cell)2 Unfiltered (org.apache.cassandra.db.rows.Unfiltered)2 BytesToken (org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken)2 Token (org.apache.cassandra.dht.Token)2 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)2 SSTableRewriter (org.apache.cassandra.io.sstable.SSTableRewriter)2