Search in sources :

Example 21 with RowUpdateBuilder

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

the class CompactionControllerTest method applyMutation.

private void applyMutation(TableMetadata cfm, DecoratedKey key, long timestamp) {
    ByteBuffer val = ByteBufferUtil.bytes(1L);
    new RowUpdateBuilder(cfm, timestamp, key).clustering("ck").add("val", val).build().applyUnsafe();
}
Also used : RowUpdateBuilder(org.apache.cassandra.db.RowUpdateBuilder) ByteBuffer(java.nio.ByteBuffer)

Example 22 with RowUpdateBuilder

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

the class DateTieredCompactionStrategyTest method testFilterOldSSTables.

@Test
public void testFilterOldSSTables() {
    Keyspace keyspace = Keyspace.open(KEYSPACE1);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF_STANDARD1);
    cfs.disableAutoCompaction();
    ByteBuffer value = ByteBuffer.wrap(new byte[100]);
    // create 3 sstables
    int numSSTables = 3;
    for (int r = 0; r < numSSTables; r++) {
        DecoratedKey key = Util.dk(String.valueOf(r));
        new RowUpdateBuilder(cfs.metadata(), r, key.getKey()).clustering("column").add("val", value).build().applyUnsafe();
        cfs.forceBlockingFlush();
    }
    cfs.forceBlockingFlush();
    Iterable<SSTableReader> filtered;
    List<SSTableReader> sstrs = new ArrayList<>(cfs.getLiveSSTables());
    filtered = filterOldSSTables(sstrs, 0, 2);
    assertEquals("when maxSSTableAge is zero, no sstables should be filtered", sstrs.size(), Iterables.size(filtered));
    filtered = filterOldSSTables(sstrs, 1, 2);
    assertEquals("only the newest 2 sstables should remain", 2, Iterables.size(filtered));
    filtered = filterOldSSTables(sstrs, 1, 3);
    assertEquals("only the newest sstable should remain", 1, Iterables.size(filtered));
    filtered = filterOldSSTables(sstrs, 1, 4);
    assertEquals("no sstables should remain when all are too old", 0, Iterables.size(filtered));
    cfs.truncateBlocking();
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) RowUpdateBuilder(org.apache.cassandra.db.RowUpdateBuilder) Keyspace(org.apache.cassandra.db.Keyspace) DecoratedKey(org.apache.cassandra.db.DecoratedKey) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 23 with RowUpdateBuilder

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

the class DateTieredCompactionStrategyTest method testSTCSBigWindow.

@Test
public void testSTCSBigWindow() {
    Keyspace keyspace = Keyspace.open(KEYSPACE1);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF_STANDARD1);
    cfs.disableAutoCompaction();
    ByteBuffer bigValue = ByteBuffer.wrap(new byte[10000]);
    ByteBuffer value = ByteBuffer.wrap(new byte[100]);
    int numSSTables = 40;
    // create big sstabels out of half:
    long timestamp = System.currentTimeMillis();
    for (int r = 0; r < numSSTables / 2; r++) {
        for (int i = 0; i < 10; i++) {
            DecoratedKey key = Util.dk(String.valueOf(r));
            new RowUpdateBuilder(cfs.metadata(), timestamp, key.getKey()).clustering("column").add("val", bigValue).build().applyUnsafe();
        }
        cfs.forceBlockingFlush();
    }
    // and small ones:
    for (int r = 0; r < numSSTables / 2; r++) {
        DecoratedKey key = Util.dk(String.valueOf(r));
        new RowUpdateBuilder(cfs.metadata(), timestamp, key.getKey()).clustering("column").add("val", value).build().applyUnsafe();
        cfs.forceBlockingFlush();
    }
    Map<String, String> options = new HashMap<>();
    options.put(SizeTieredCompactionStrategyOptions.MIN_SSTABLE_SIZE_KEY, "1");
    DateTieredCompactionStrategy dtcs = new DateTieredCompactionStrategy(cfs, options);
    for (SSTableReader sstable : cfs.getSSTables(SSTableSet.CANONICAL)) dtcs.addSSTable(sstable);
    AbstractCompactionTask task = dtcs.getNextBackgroundTask(0);
    assertEquals(20, task.transaction.originals().size());
    task.transaction.abort();
    cfs.truncateBlocking();
}
Also used : DecoratedKey(org.apache.cassandra.db.DecoratedKey) ByteBuffer(java.nio.ByteBuffer) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) RowUpdateBuilder(org.apache.cassandra.db.RowUpdateBuilder) Keyspace(org.apache.cassandra.db.Keyspace) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Test(org.junit.Test)

Example 24 with RowUpdateBuilder

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

the class OneCompactionTest method testCompaction.

private void testCompaction(String columnFamilyName, int insertsPerTable) {
    CompactionManager.instance.disableAutoCompaction();
    Keyspace keyspace = Keyspace.open(KEYSPACE1);
    ColumnFamilyStore store = keyspace.getColumnFamilyStore(columnFamilyName);
    Set<String> inserted = new HashSet<>();
    for (int j = 0; j < insertsPerTable; j++) {
        String key = String.valueOf(j);
        new RowUpdateBuilder(store.metadata(), j, key).clustering("0").add("val", ByteBufferUtil.EMPTY_BYTE_BUFFER).build().applyUnsafe();
        inserted.add(key);
        store.forceBlockingFlush();
        assertEquals(inserted.size(), Util.getAll(Util.cmd(store).build()).size());
    }
    CompactionManager.instance.performMaximal(store, false);
    assertEquals(1, store.getLiveSSTables().size());
}
Also used : RowUpdateBuilder(org.apache.cassandra.db.RowUpdateBuilder) Keyspace(org.apache.cassandra.db.Keyspace) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) HashSet(java.util.HashSet)

Example 25 with RowUpdateBuilder

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

the class SnapshotDeletingTest method populate.

private void populate(int rowCount) {
    long timestamp = System.currentTimeMillis();
    TableMetadata cfm = Keyspace.open(KEYSPACE1).getColumnFamilyStore(CF_STANDARD1).metadata();
    for (int i = 0; i <= rowCount; i++) {
        DecoratedKey key = Util.dk(Integer.toString(i));
        for (int j = 0; j < 10; j++) {
            new RowUpdateBuilder(cfm, timestamp, 0, key.getKey()).clustering(Integer.toString(j)).add("val", ByteBufferUtil.EMPTY_BYTE_BUFFER).build().applyUnsafe();
        }
    }
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) RowUpdateBuilder(org.apache.cassandra.db.RowUpdateBuilder) DecoratedKey(org.apache.cassandra.db.DecoratedKey)

Aggregations

RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)34 Test (org.junit.Test)22 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)19 Keyspace (org.apache.cassandra.db.Keyspace)17 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)14 ByteBuffer (java.nio.ByteBuffer)12 TableMetadata (org.apache.cassandra.schema.TableMetadata)12 DecoratedKey (org.apache.cassandra.db.DecoratedKey)10 Mutation (org.apache.cassandra.db.Mutation)9 ArrayList (java.util.ArrayList)4 UntypedResultSet (org.apache.cassandra.cql3.UntypedResultSet)4 File (java.io.File)3 LifecycleTransaction (org.apache.cassandra.db.lifecycle.LifecycleTransaction)3 UUID (java.util.UUID)2 CompactionController (org.apache.cassandra.db.compaction.CompactionController)2 CompactionIterator (org.apache.cassandra.db.compaction.CompactionIterator)2 Row (org.apache.cassandra.db.rows.Row)2 WriteTimeoutException (org.apache.cassandra.exceptions.WriteTimeoutException)2 DataInputBuffer (org.apache.cassandra.io.util.DataInputBuffer)2 DataInputPlus (org.apache.cassandra.io.util.DataInputPlus)2