Search in sources :

Example 1 with AddColumnFamily

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

the class DefsTest method addNewCfWithNullComment.

@Test
public void addNewCfWithNullComment() throws ConfigurationException, IOException, ExecutionException, InterruptedException {
    final String ks = "Keyspace1";
    final String cf = "BrandNewCfWithNull";
    KSMetaData original = Schema.instance.getTableDefinition(ks);
    CFMetaData newCf = addTestCF(original.name, cf, null);
    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);
}
Also used : AddColumnFamily(org.apache.cassandra.db.migration.AddColumnFamily) Test(org.junit.Test)

Example 2 with AddColumnFamily

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

the class DefsTest method testMigrations.

@Test
public void testMigrations() throws IOException, ConfigurationException {
    // do a save. make sure it doesn't mess with the defs version.
    UUID prior = Schema.instance.getVersion();
    UUID ver0 = UUIDGen.makeType1UUIDFromHost(FBUtilities.getBroadcastAddress());
    DefsTable.dumpToStorage(ver0);
    assert Schema.instance.getVersion().equals(prior);
    // add a cf.
    CFMetaData newCf1 = addTestCF("Keyspace1", "MigrationCf_1", "Migration CF");
    Migration m1 = new AddColumnFamily(newCf1);
    m1.apply();
    UUID ver1 = m1.getVersion();
    assert Schema.instance.getVersion().equals(ver1);
    // drop it.
    Migration m3 = new DropColumnFamily("Keyspace1", "MigrationCf_1");
    m3.apply();
    UUID ver3 = m3.getVersion();
    assert Schema.instance.getVersion().equals(ver3);
    // now lets load the older migrations to see if that code works.
    Collection<IColumn> serializedMigrations = Migration.getLocalMigrations(ver1, ver3);
    assert serializedMigrations.size() == 2;
    // test deserialization of the migrations.
    Migration[] reconstituded = new Migration[2];
    int i = 0;
    for (IColumn col : serializedMigrations) {
        UUID version = UUIDGen.getUUID(col.name());
        reconstituded[i] = Migration.deserialize(col.value(), MessagingService.version_);
        assert version.equals(reconstituded[i].getVersion());
        i++;
    }
    assert m1.getClass().equals(reconstituded[0].getClass());
    assert m3.getClass().equals(reconstituded[1].getClass());
    // verify that the row mutations are the same. rather than exposing the private fields, serialize and verify.
    assert m1.serialize().equals(reconstituded[0].serialize());
    assert m3.serialize().equals(reconstituded[1].serialize());
}
Also used : Migration(org.apache.cassandra.db.migration.Migration) AddColumnFamily(org.apache.cassandra.db.migration.AddColumnFamily) DropColumnFamily(org.apache.cassandra.db.migration.DropColumnFamily) Test(org.junit.Test)

Example 3 with AddColumnFamily

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

the class MeteredFlusherTest method testManyMemtables.

@Test
public void testManyMemtables() throws IOException, ConfigurationException {
    Table table = Table.open("Keyspace1");
    for (int i = 0; i < 100; i++) {
        CFMetaData metadata = new CFMetaData(table.name, "_CF" + i, ColumnFamilyType.Standard, UTF8Type.instance, null);
        new AddColumnFamily(metadata).apply();
    }
    ByteBuffer name = ByteBufferUtil.bytes("c");
    for (int j = 0; j < 200; j++) {
        for (int i = 0; i < 100; i++) {
            RowMutation rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("key" + j));
            ColumnFamily cf = ColumnFamily.create("Keyspace1", "_CF" + i);
            // don't cheat by allocating this outside of the loop; that defeats the purpose of deliberately using lots of memory
            ByteBuffer value = ByteBuffer.allocate(100000);
            cf.addColumn(new Column(name, value));
            rm.add(cf);
            rm.applyUnsafe();
        }
    }
    int flushes = 0;
    for (ColumnFamilyStore cfs : ColumnFamilyStore.all()) {
        if (cfs.getColumnFamilyName().startsWith("_CF"))
            flushes += cfs.getMemtableSwitchCount();
    }
    assert flushes > 0;
}
Also used : AddColumnFamily(org.apache.cassandra.db.migration.AddColumnFamily) CFMetaData(org.apache.cassandra.config.CFMetaData) ByteBuffer(java.nio.ByteBuffer) AddColumnFamily(org.apache.cassandra.db.migration.AddColumnFamily) Test(org.junit.Test)

Example 4 with AddColumnFamily

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

the class DefsTest method createEmptyKsAddNewCf.

@Test
public void createEmptyKsAddNewCf() throws ConfigurationException, IOException, ExecutionException, InterruptedException {
    assert Schema.instance.getTableDefinition("EmptyKeyspace") == null;
    KSMetaData newKs = KSMetaData.testMetadata("EmptyKeyspace", SimpleStrategy.class, KSMetaData.optsWithRF(5));
    new AddKeyspace(newKs).apply();
    assert Schema.instance.getTableDefinition("EmptyKeyspace") != null;
    CFMetaData newCf = addTestCF("EmptyKeyspace", "AddedLater", "A new CF to add to an empty KS");
    //should not exist until apply
    assert !Schema.instance.getTableDefinition(newKs.name).cfMetaData().containsKey(newCf.cfName);
    //add the new CF to the empty space
    new AddColumnFamily(newCf).apply();
    assert Schema.instance.getTableDefinition(newKs.name).cfMetaData().containsKey(newCf.cfName);
    assert Schema.instance.getTableDefinition(newKs.name).cfMetaData().get(newCf.cfName).equals(newCf);
    // now read and write to it.
    DecoratedKey dk = Util.dk("key0");
    RowMutation rm = new RowMutation(newKs.name, dk.key);
    rm.add(new QueryPath(newCf.cfName, null, ByteBufferUtil.bytes("col0")), ByteBufferUtil.bytes("value0"), 1L);
    rm.apply();
    ColumnFamilyStore store = Table.open(newKs.name).getColumnFamilyStore(newCf.cfName);
    assert store != null;
    store.forceBlockingFlush();
    ColumnFamily cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath(newCf.cfName), 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) AddKeyspace(org.apache.cassandra.db.migration.AddKeyspace) 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 5 with AddColumnFamily

use of org.apache.cassandra.db.migration.AddColumnFamily 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)

Aggregations

AddColumnFamily (org.apache.cassandra.db.migration.AddColumnFamily)5 Test (org.junit.Test)5 DropColumnFamily (org.apache.cassandra.db.migration.DropColumnFamily)3 QueryPath (org.apache.cassandra.db.filter.QueryPath)2 UpdateColumnFamily (org.apache.cassandra.db.migration.UpdateColumnFamily)2 ByteBuffer (java.nio.ByteBuffer)1 CFMetaData (org.apache.cassandra.config.CFMetaData)1 AddKeyspace (org.apache.cassandra.db.migration.AddKeyspace)1 Migration (org.apache.cassandra.db.migration.Migration)1