Search in sources :

Example 66 with QueryPath

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

the class DefsTest method dropCf.

@Test
public void dropCf() throws ConfigurationException, IOException, ExecutionException, InterruptedException {
    DecoratedKey dk = Util.dk("dropCf");
    // sanity
    final KSMetaData ks = Schema.instance.getTableDefinition("Keyspace1");
    assert ks != null;
    final CFMetaData cfm = ks.cfMetaData().get("Standard1");
    assert cfm != null;
    // write some data, force a flush, then verify that files exist on disk.
    RowMutation rm = new RowMutation(ks.name, dk.key);
    for (int i = 0; i < 100; i++) rm.add(new QueryPath(cfm.cfName, null, ByteBufferUtil.bytes(("col" + i))), ByteBufferUtil.bytes("anyvalue"), 1L);
    rm.apply();
    ColumnFamilyStore store = Table.open(cfm.ksName).getColumnFamilyStore(cfm.cfName);
    assert store != null;
    store.forceBlockingFlush();
    store.getFlushPath(1024, Descriptor.CURRENT_VERSION);
    assert store.directories.sstableLister().list().size() > 0;
    new DropColumnFamily(ks.name, cfm.cfName).apply();
    assert !Schema.instance.getTableDefinition(ks.name).cfMetaData().containsKey(cfm.cfName);
    // any write should fail.
    rm = new RowMutation(ks.name, dk.key);
    boolean success = true;
    try {
        rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("col0")), ByteBufferUtil.bytes("value0"), 1L);
        rm.apply();
    } catch (Throwable th) {
        success = false;
    }
    assert !success : "This mutation should have failed since the CF no longer exists.";
    // verify that the files are gone.
    for (File file : store.directories.sstableLister().listFiles()) {
        if (file.getPath().endsWith("Data.db") && !new File(file.getPath().replace("Data.db", "Compacted")).exists())
            throw new AssertionError("undeleted file " + file);
    }
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) File(java.io.File) DropColumnFamily(org.apache.cassandra.db.migration.DropColumnFamily) Test(org.junit.Test)

Example 67 with QueryPath

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

the class DefsTest method dropKSUnflushed.

@Test
public void dropKSUnflushed() throws ConfigurationException, IOException, ExecutionException, InterruptedException {
    DecoratedKey dk = Util.dk("dropKs");
    // sanity
    final KSMetaData ks = Schema.instance.getTableDefinition("Keyspace3");
    assert ks != null;
    final CFMetaData cfm = ks.cfMetaData().get("Standard1");
    assert cfm != null;
    // write some data
    RowMutation rm = new RowMutation(ks.name, dk.key);
    for (int i = 0; i < 100; i++) rm.add(new QueryPath(cfm.cfName, null, ByteBufferUtil.bytes(("col" + i))), ByteBufferUtil.bytes("anyvalue"), 1L);
    rm.apply();
    new DropKeyspace(ks.name).apply();
    assert Schema.instance.getTableDefinition(ks.name) == null;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) DropKeyspace(org.apache.cassandra.db.migration.DropKeyspace) Test(org.junit.Test)

Example 68 with QueryPath

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

the class DefsTest method addNewCF.

@Test
public void addNewCF() throws ConfigurationException, IOException, ExecutionException, InterruptedException {
    final String ks = "Keyspace1";
    final String cf = "BrandNewCf";
    KSMetaData original = Schema.instance.getTableDefinition(ks);
    CFMetaData newCf = addTestCF(original.name, cf, "A New Column Family");
    assert !Schema.instance.getTableDefinition(ks).cfMetaData().containsKey(newCf.cfName);
    new AddColumnFamily(newCf).apply();
    assert Schema.instance.getTableDefinition(ks).cfMetaData().containsKey(newCf.cfName);
    assert Schema.instance.getTableDefinition(ks).cfMetaData().get(newCf.cfName).equals(newCf);
    // now read and write to it.
    DecoratedKey dk = Util.dk("key0");
    RowMutation rm = new RowMutation(ks, dk.key);
    rm.add(new QueryPath(cf, null, ByteBufferUtil.bytes("col0")), ByteBufferUtil.bytes("value0"), 1L);
    rm.apply();
    ColumnFamilyStore store = Table.open(ks).getColumnFamilyStore(cf);
    assert store != null;
    store.forceBlockingFlush();
    ColumnFamily cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath(cf), ByteBufferUtil.bytes("col0")));
    assert cfam.getColumn(ByteBufferUtil.bytes("col0")) != null;
    IColumn col = cfam.getColumn(ByteBufferUtil.bytes("col0"));
    assert ByteBufferUtil.bytes("value0").equals(col.value());
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) AddColumnFamily(org.apache.cassandra.db.migration.AddColumnFamily) UpdateColumnFamily(org.apache.cassandra.db.migration.UpdateColumnFamily) AddColumnFamily(org.apache.cassandra.db.migration.AddColumnFamily) DropColumnFamily(org.apache.cassandra.db.migration.DropColumnFamily) Test(org.junit.Test)

Example 69 with QueryPath

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

the class DefsTest method dropKS.

@Test
public void dropKS() throws ConfigurationException, IOException, ExecutionException, InterruptedException {
    DecoratedKey dk = Util.dk("dropKs");
    // sanity
    final KSMetaData ks = Schema.instance.getTableDefinition("Keyspace1");
    assert ks != null;
    final CFMetaData cfm = ks.cfMetaData().get("Standard2");
    assert cfm != null;
    // write some data, force a flush, then verify that files exist on disk.
    RowMutation rm = new RowMutation(ks.name, dk.key);
    for (int i = 0; i < 100; i++) rm.add(new QueryPath(cfm.cfName, null, ByteBufferUtil.bytes(("col" + i))), ByteBufferUtil.bytes("anyvalue"), 1L);
    rm.apply();
    ColumnFamilyStore store = Table.open(cfm.ksName).getColumnFamilyStore(cfm.cfName);
    assert store != null;
    store.forceBlockingFlush();
    assert store.directories.sstableLister().list().size() > 0;
    new DropKeyspace(ks.name).apply();
    assert Schema.instance.getTableDefinition(ks.name) == null;
    // write should fail.
    rm = new RowMutation(ks.name, dk.key);
    boolean success = true;
    try {
        rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("col0")), ByteBufferUtil.bytes("value0"), 1L);
        rm.apply();
    } catch (Throwable th) {
        success = false;
    }
    assert !success : "This mutation should have failed since the CF no longer exists.";
    // reads should fail too.
    boolean threw = false;
    try {
        Table.open(ks.name);
    } catch (Throwable th) {
        threw = true;
    }
    assert threw;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) DropKeyspace(org.apache.cassandra.db.migration.DropKeyspace) Test(org.junit.Test)

Example 70 with QueryPath

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

the class KeyCacheTest method testKeyCache.

@Test
public void testKeyCache() throws IOException, ExecutionException, InterruptedException {
    CompactionManager.instance.disableAutoCompaction();
    Table table = Table.open(TABLE1);
    ColumnFamilyStore cfs = table.getColumnFamilyStore(COLUMN_FAMILY1);
    // just to make sure that everything is clean
    CacheService.instance.invalidateKeyCache();
    // KeyCache should start at size 0 if we're caching X% of zero data.
    int keyCacheSize = CacheService.instance.keyCache.size();
    assert keyCacheSize == 0 : keyCacheSize;
    DecoratedKey key1 = Util.dk("key1");
    DecoratedKey key2 = Util.dk("key2");
    RowMutation rm;
    // inserts
    rm = new RowMutation(TABLE1, key1.key);
    rm.add(new QueryPath(COLUMN_FAMILY1, null, ByteBufferUtil.bytes("1")), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0);
    rm.apply();
    rm = new RowMutation(TABLE1, key2.key);
    rm.add(new QueryPath(COLUMN_FAMILY1, null, ByteBufferUtil.bytes("2")), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0);
    rm.apply();
    // to make sure we have SSTable
    cfs.forceBlockingFlush();
    // reads to cache key position
    cfs.getColumnFamily(QueryFilter.getSliceFilter(key1, new QueryPath(new ColumnParent(COLUMN_FAMILY1)), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 10));
    cfs.getColumnFamily(QueryFilter.getSliceFilter(key2, new QueryPath(new ColumnParent(COLUMN_FAMILY1)), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 10));
    assert CacheService.instance.keyCache.size() == 2;
    Util.compactAll(cfs).get();
    keyCacheSize = CacheService.instance.keyCache.size();
    // new SSTables, if we had 2 keys in cache previously it should become 4
    assert keyCacheSize == 4 : keyCacheSize;
    // re-read same keys to verify that key cache didn't grow further
    cfs.getColumnFamily(QueryFilter.getSliceFilter(key1, new QueryPath(new ColumnParent(COLUMN_FAMILY1)), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 10));
    cfs.getColumnFamily(QueryFilter.getSliceFilter(key2, new QueryPath(new ColumnParent(COLUMN_FAMILY1)), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 10));
    assert CacheService.instance.keyCache.size() == 4;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) ColumnParent(org.apache.cassandra.thrift.ColumnParent) Test(org.junit.Test)

Aggregations

QueryPath (org.apache.cassandra.db.filter.QueryPath)127 Test (org.junit.Test)67 ByteBuffer (java.nio.ByteBuffer)40 QueryFilter (org.apache.cassandra.db.filter.QueryFilter)22 ColumnFamily (org.apache.cassandra.db.ColumnFamily)14 RowMutation (org.apache.cassandra.db.RowMutation)12 File (java.io.File)10 SSTableReader (org.apache.cassandra.io.sstable.SSTableReader)10 IOException (java.io.IOException)8 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)8 DecoratedKey (org.apache.cassandra.db.DecoratedKey)8 Table (org.apache.cassandra.db.Table)8 SSTableUtils.tempSSTableFile (org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile)8 WrappedRunnable (org.apache.cassandra.utils.WrappedRunnable)8 ArrayList (java.util.ArrayList)5 IColumn (org.apache.cassandra.db.IColumn)5 PrintStream (java.io.PrintStream)4 UnknownHostException (java.net.UnknownHostException)4 HashSet (java.util.HashSet)4 DropColumnFamily (org.apache.cassandra.db.migration.DropColumnFamily)4