Search in sources :

Example 6 with ColumnFamily

use of org.apache.cassandra.db.ColumnFamily 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;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) Table(org.apache.cassandra.db.Table) DecoratedKey(org.apache.cassandra.db.DecoratedKey) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) RowMutation(org.apache.cassandra.db.RowMutation) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Example 7 with ColumnFamily

use of org.apache.cassandra.db.ColumnFamily 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;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) Table(org.apache.cassandra.db.Table) DecoratedKey(org.apache.cassandra.db.DecoratedKey) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) RowMutation(org.apache.cassandra.db.RowMutation) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Example 8 with ColumnFamily

use of org.apache.cassandra.db.ColumnFamily 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;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) Table(org.apache.cassandra.db.Table) DecoratedKey(org.apache.cassandra.db.DecoratedKey) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) RowMutation(org.apache.cassandra.db.RowMutation) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Example 9 with ColumnFamily

use of org.apache.cassandra.db.ColumnFamily in project eiger by wlloyd.

the class SSTableUtils method createCF.

public static ColumnFamily createCF(long mfda, int ldt, IColumn... cols) {
    ColumnFamily cf = ColumnFamily.create(TABLENAME, CFNAME);
    cf.delete(ldt, mfda);
    for (IColumn col : cols) cf.addColumn(col);
    return cf;
}
Also used : IColumn(org.apache.cassandra.db.IColumn) ColumnFamily(org.apache.cassandra.db.ColumnFamily)

Example 10 with ColumnFamily

use of org.apache.cassandra.db.ColumnFamily in project eiger by wlloyd.

the class RowResolverTest method testResolveSupersetNewer.

@Test
public void testResolveSupersetNewer() {
    ColumnFamily cf1 = ColumnFamily.create("Keyspace1", "Standard1");
    cf1.addColumn(column("c1", "v1", 0));
    ColumnFamily cf2 = ColumnFamily.create("Keyspace1", "Standard1");
    cf2.addColumn(column("c1", "v2", 1));
    ColumnFamily resolved = RowRepairResolver.resolveSuperset(Arrays.asList(cf1, cf2));
    assertColumns(resolved, "c1");
    assertColumns(ColumnFamily.diff(cf1, resolved), "c1");
    assertNull(ColumnFamily.diff(cf2, resolved));
}
Also used : ColumnFamily(org.apache.cassandra.db.ColumnFamily) TableTest(org.apache.cassandra.db.TableTest) Test(org.junit.Test)

Aggregations

ColumnFamily (org.apache.cassandra.db.ColumnFamily)36 Test (org.junit.Test)26 QueryPath (org.apache.cassandra.db.filter.QueryPath)14 File (java.io.File)11 SSTableUtils.tempSSTableFile (org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile)11 SSTableReader (org.apache.cassandra.io.sstable.SSTableReader)10 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)8 DecoratedKey (org.apache.cassandra.db.DecoratedKey)8 IColumn (org.apache.cassandra.db.IColumn)8 TableTest (org.apache.cassandra.db.TableTest)7 PrintStream (java.io.PrintStream)6 RowMutation (org.apache.cassandra.db.RowMutation)6 Table (org.apache.cassandra.db.Table)6 QueryFilter (org.apache.cassandra.db.filter.QueryFilter)6 SSTableWriter (org.apache.cassandra.io.sstable.SSTableWriter)6 FileReader (java.io.FileReader)5 ExpiringColumn (org.apache.cassandra.db.ExpiringColumn)4 JSONArray (org.json.simple.JSONArray)4 JSONObject (org.json.simple.JSONObject)4 ByteBuffer (java.nio.ByteBuffer)3