use of org.apache.cassandra.db.filter.QueryPath in project eiger by wlloyd.
the class TimeSortTest method testTimeSort.
@Test
public void testTimeSort() throws IOException, ExecutionException, InterruptedException {
Table table = Table.open("Keyspace1");
ColumnFamilyStore cfStore = table.getColumnFamilyStore("StandardLong1");
for (int i = 900; i < 1000; ++i) {
RowMutation rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes(Integer.toString(i)));
for (int j = 0; j < 8; ++j) {
rm.add(new QueryPath("StandardLong1", null, getBytes(j * 2)), ByteBufferUtil.bytes("a"), j * 2);
}
rm.apply();
}
validateTimeSort(table);
cfStore.forceBlockingFlush();
validateTimeSort(table);
// interleave some new data to test memtable + sstable
DecoratedKey key = Util.dk("900");
RowMutation rm = new RowMutation("Keyspace1", key.key);
for (int j = 0; j < 4; ++j) {
rm.add(new QueryPath("StandardLong1", null, getBytes(j * 2 + 1)), ByteBufferUtil.bytes("b"), j * 2 + 1);
}
rm.apply();
// and some overwrites
rm = new RowMutation("Keyspace1", key.key);
rm.add(new QueryPath("StandardLong1", null, getBytes(0)), ByteBufferUtil.bytes("c"), 100);
rm.add(new QueryPath("StandardLong1", null, getBytes(10)), ByteBufferUtil.bytes("c"), 100);
rm.apply();
// verify
ColumnFamily cf = cfStore.getColumnFamily(key, new QueryPath("StandardLong1"), getBytes(0), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1000);
Collection<IColumn> columns = cf.getSortedColumns();
assertEquals(12, columns.size());
Iterator<IColumn> iter = columns.iterator();
IColumn column;
for (int j = 0; j < 8; j++) {
column = iter.next();
assert column.name().equals(getBytes(j));
}
TreeSet<ByteBuffer> columnNames = new TreeSet<ByteBuffer>(LongType.instance);
columnNames.add(getBytes(10));
columnNames.add(getBytes(0));
cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(Util.dk("900"), new QueryPath("StandardLong1"), columnNames));
assert "c".equals(ByteBufferUtil.string(cf.getColumn(getBytes(0)).value()));
assert "c".equals(ByteBufferUtil.string(cf.getColumn(getBytes(10)).value()));
}
use of org.apache.cassandra.db.filter.QueryPath in project eiger by wlloyd.
the class CompactionsPurgeTest method testMinorCompactionPurge.
@Test
public void testMinorCompactionPurge() throws IOException, ExecutionException, InterruptedException {
CompactionManager.instance.disableAutoCompaction();
Table table = Table.open(TABLE2);
String cfName = "Standard1";
ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName);
RowMutation rm;
for (int k = 1; k <= 2; ++k) {
DecoratedKey key = Util.dk("key" + k);
// inserts
rm = new RowMutation(TABLE2, key.key);
for (int i = 0; i < 10; i++) {
rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0);
}
rm.apply();
cfs.forceBlockingFlush();
// deletes
for (int i = 0; i < 10; i++) {
rm = new RowMutation(TABLE2, key.key);
rm.delete(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), 1);
rm.apply();
}
cfs.forceBlockingFlush();
}
DecoratedKey key1 = Util.dk("key1");
DecoratedKey key2 = Util.dk("key2");
// flush, remember the current sstable and then resurrect one column
// for first key. Then submit minor compaction on remembered sstables.
cfs.forceBlockingFlush();
Collection<SSTableReader> sstablesIncomplete = cfs.getSSTables();
rm = new RowMutation(TABLE2, key1.key);
rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(5))), ByteBufferUtil.EMPTY_BYTE_BUFFER, 2);
rm.apply();
cfs.forceBlockingFlush();
new CompactionTask(cfs, sstablesIncomplete, Integer.MAX_VALUE).execute(null);
// verify that minor compaction does not GC when key is present
// in a non-compacted sstable
ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(key1, new QueryPath(cfName)));
assert cf.getColumnCount() == 10;
// verify that minor compaction does GC when key is provably not
// present in a non-compacted sstable
cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(key2, new QueryPath(cfName)));
assert cf == null;
}
use of org.apache.cassandra.db.filter.QueryPath in project eiger by wlloyd.
the class CompactionsPurgeTest method testMajorCompactionPurge.
@Test
public void testMajorCompactionPurge() throws IOException, ExecutionException, InterruptedException {
CompactionManager.instance.disableAutoCompaction();
Table table = Table.open(TABLE1);
String cfName = "Standard1";
ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName);
DecoratedKey key = Util.dk("key1");
RowMutation rm;
// inserts
rm = new RowMutation(TABLE1, key.key);
for (int i = 0; i < 10; i++) {
rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0);
}
rm.apply();
cfs.forceBlockingFlush();
// deletes
for (int i = 0; i < 10; i++) {
rm = new RowMutation(TABLE1, key.key);
rm.delete(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), 1);
rm.apply();
}
cfs.forceBlockingFlush();
// resurrect one column
rm = new RowMutation(TABLE1, key.key);
rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(5))), ByteBufferUtil.EMPTY_BYTE_BUFFER, 2);
rm.apply();
cfs.forceBlockingFlush();
// major compact and test that all columns but the resurrected one is completely gone
CompactionManager.instance.submitMaximal(cfs, Integer.MAX_VALUE).get();
cfs.invalidateCachedRow(key);
ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(key, new QueryPath(cfName)));
assertColumns(cf, "5");
assert cf.getColumn(ByteBufferUtil.bytes(String.valueOf(5))) != null;
}
use of org.apache.cassandra.db.filter.QueryPath in project eiger by wlloyd.
the class CompactionsPurgeTest method testCompactionPurgeOneFile.
@Test
public void testCompactionPurgeOneFile() throws IOException, ExecutionException, InterruptedException {
CompactionManager.instance.disableAutoCompaction();
Table table = Table.open(TABLE1);
String cfName = "Standard2";
ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName);
DecoratedKey key = Util.dk("key1");
RowMutation rm;
// inserts
rm = new RowMutation(TABLE1, key.key);
for (int i = 0; i < 5; i++) {
rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0);
}
rm.apply();
// deletes
for (int i = 0; i < 5; i++) {
rm = new RowMutation(TABLE1, key.key);
rm.delete(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), 1);
rm.apply();
}
cfs.forceBlockingFlush();
// inserts & deletes were in the same memtable -> only deletes in sstable
assert cfs.getSSTables().size() == 1 : cfs.getSSTables();
// compact and test that the row is completely gone
Util.compactAll(cfs).get();
assert cfs.getSSTables().isEmpty();
ColumnFamily cf = table.getColumnFamilyStore(cfName).getColumnFamily(QueryFilter.getIdentityFilter(key, new QueryPath(cfName)));
assert cf == null : cf;
}
use of org.apache.cassandra.db.filter.QueryPath in project eiger by wlloyd.
the class CompactionsTest method testEchoedRow.
@Test
public void testEchoedRow() throws IOException, ExecutionException, InterruptedException {
// This test check that EchoedRow doesn't skipp rows: see CASSANDRA-2653
Table table = Table.open(TABLE1);
ColumnFamilyStore store = table.getColumnFamilyStore("Standard2");
// disable compaction while flushing
store.disableAutoCompaction();
// at least to trigger what was causing CASSANDRA-2653
for (int i = 1; i < 5; i++) {
DecoratedKey key = Util.dk(String.valueOf(i));
RowMutation rm = new RowMutation(TABLE1, key.key);
rm.add(new QueryPath("Standard2", null, ByteBufferUtil.bytes(String.valueOf(i))), ByteBufferUtil.EMPTY_BYTE_BUFFER, i);
rm.apply();
if (i % 2 == 0)
store.forceBlockingFlush();
}
Collection<SSTableReader> toCompact = store.getSSTables();
assert toCompact.size() == 2;
// to make sure we use EchoedRow, otherwise it won't be used because purge can be done.
for (int i = 1; i < 5; i++) {
DecoratedKey key = Util.dk(String.valueOf(i));
RowMutation rm = new RowMutation(TABLE1, key.key);
rm.add(new QueryPath("Standard2", null, ByteBufferUtil.bytes(String.valueOf(i))), ByteBufferUtil.EMPTY_BYTE_BUFFER, i);
rm.apply();
}
store.forceBlockingFlush();
SSTableReader tmpSSTable = null;
for (SSTableReader sstable : store.getSSTables()) if (!toCompact.contains(sstable))
tmpSSTable = sstable;
assert tmpSSTable != null;
// Force compaction on first sstables. Since each row is in only one sstable, we will be using EchoedRow.
Util.compact(store, toCompact, false);
assertEquals(2, store.getSSTables().size());
// Now, we remove the sstable that was just created to force the use of EchoedRow (so that it doesn't hide the problem)
store.markCompacted(Collections.singleton(tmpSSTable));
assertEquals(1, store.getSSTables().size());
// Now assert we do have the 4 keys
assertEquals(4, Util.getRangeSlice(store).size());
}
Aggregations