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();
}
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();
}
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();
}
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());
}
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();
}
}
}
Aggregations