Search in sources :

Example 1 with AddKeyspace

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

the class DatabaseDescriptorTest method testTransKsMigration.

// this came as a result of CASSANDRA-995
@Test
public void testTransKsMigration() throws IOException, ConfigurationException {
    CleanupHelper.cleanupAndLeaveDirs();
    DatabaseDescriptor.loadSchemas();
    assert Schema.instance.getNonSystemTables().size() == 0;
    // add a few.
    AddKeyspace ks0 = new AddKeyspace(KSMetaData.testMetadata("ks0", SimpleStrategy.class, KSMetaData.optsWithRF(3)));
    ks0.apply();
    AddKeyspace ks1 = new AddKeyspace(KSMetaData.testMetadata("ks1", SimpleStrategy.class, KSMetaData.optsWithRF(3)));
    ks1.apply();
    assert Schema.instance.getTableDefinition("ks0") != null;
    assert Schema.instance.getTableDefinition("ks1") != null;
    Schema.instance.clearTableDefinition(Schema.instance.getTableDefinition("ks0"), new UUID(4096, 0));
    Schema.instance.clearTableDefinition(Schema.instance.getTableDefinition("ks1"), new UUID(4096, 0));
    assert Schema.instance.getTableDefinition("ks0") == null;
    assert Schema.instance.getTableDefinition("ks1") == null;
    DatabaseDescriptor.loadSchemas();
    assert Schema.instance.getTableDefinition("ks0") != null;
    assert Schema.instance.getTableDefinition("ks1") != null;
}
Also used : AddKeyspace(org.apache.cassandra.db.migration.AddKeyspace) SimpleStrategy(org.apache.cassandra.locator.SimpleStrategy) UUID(java.util.UUID) Test(org.junit.Test)

Example 2 with AddKeyspace

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

the class DefsTest method testUpdateColumnFamilyNoIndexes.

@Test
public void testUpdateColumnFamilyNoIndexes() throws ConfigurationException, IOException, ExecutionException, InterruptedException {
    // create a keyspace with a cf to update.
    CFMetaData cf = addTestCF("UpdatedCfKs", "Standard1added", "A new cf that will be updated");
    KSMetaData ksm = KSMetaData.testMetadata(cf.ksName, SimpleStrategy.class, KSMetaData.optsWithRF(1), cf);
    new AddKeyspace(ksm).apply();
    assert Schema.instance.getTableDefinition(cf.ksName) != null;
    assert Schema.instance.getTableDefinition(cf.ksName) == ksm;
    assert Schema.instance.getCFMetaData(cf.ksName, cf.cfName) != null;
    // updating certain fields should fail.
    org.apache.cassandra.db.migration.avro.CfDef cf_def = cf.toAvro();
    cf_def.column_metadata = new ArrayList<org.apache.cassandra.db.migration.avro.ColumnDef>();
    cf_def.default_validation_class = "BytesType";
    cf_def.min_compaction_threshold = 5;
    cf_def.max_compaction_threshold = 31;
    // test valid operations.
    cf_def.comment = "Modified comment";
    // doesn't get set back here.
    new UpdateColumnFamily(cf_def).apply();
    cf_def.read_repair_chance = 0.23;
    new UpdateColumnFamily(cf_def).apply();
    cf_def.gc_grace_seconds = 12;
    new UpdateColumnFamily(cf_def).apply();
    cf_def.default_validation_class = "UTF8Type";
    new UpdateColumnFamily(cf_def).apply();
    cf_def.min_compaction_threshold = 3;
    new UpdateColumnFamily(cf_def).apply();
    cf_def.max_compaction_threshold = 33;
    new UpdateColumnFamily(cf_def).apply();
    // check the cumulative affect.
    assert Schema.instance.getCFMetaData(cf.ksName, cf.cfName).getComment().equals(cf_def.comment);
    assert Schema.instance.getCFMetaData(cf.ksName, cf.cfName).getReadRepairChance() == cf_def.read_repair_chance;
    assert Schema.instance.getCFMetaData(cf.ksName, cf.cfName).getGcGraceSeconds() == cf_def.gc_grace_seconds;
    assert Schema.instance.getCFMetaData(cf.ksName, cf.cfName).getDefaultValidator() == UTF8Type.instance;
    // todo: we probably don't need to reset old values in the catches anymore.
    // make sure some invalid operations fail.
    int oldId = cf_def.id;
    try {
        cf_def.id++;
        cf.apply(cf_def);
        throw new AssertionError("Should have blown up when you used a different id.");
    } catch (ConfigurationException expected) {
        cf_def.id = oldId;
    }
    CharSequence oldStr = cf_def.name;
    try {
        cf_def.name = cf_def.name + "_renamed";
        cf.apply(cf_def);
        throw new AssertionError("Should have blown up when you used a different name.");
    } catch (ConfigurationException expected) {
        cf_def.name = oldStr;
    }
    oldStr = cf_def.keyspace;
    try {
        cf_def.keyspace = oldStr + "_renamed";
        cf.apply(cf_def);
        throw new AssertionError("Should have blown up when you used a different keyspace.");
    } catch (ConfigurationException expected) {
        cf_def.keyspace = oldStr;
    }
    try {
        cf_def.column_type = ColumnFamilyType.Super.name();
        cf.apply(cf_def);
        throw new AssertionError("Should have blwon up when you used a different cf type.");
    } catch (ConfigurationException expected) {
        cf_def.column_type = ColumnFamilyType.Standard.name();
    }
    oldStr = cf_def.comparator_type;
    try {
        cf_def.comparator_type = BytesType.class.getSimpleName();
        cf.apply(cf_def);
        throw new AssertionError("Should have blown up when you used a different comparator.");
    } catch (ConfigurationException expected) {
        cf_def.comparator_type = UTF8Type.class.getSimpleName();
    }
    try {
        cf_def.min_compaction_threshold = 34;
        cf.apply(cf_def);
        throw new AssertionError("Should have blown up when min > max.");
    } catch (ConfigurationException expected) {
        cf_def.min_compaction_threshold = 3;
    }
    try {
        cf_def.max_compaction_threshold = 2;
        cf.apply(cf_def);
        throw new AssertionError("Should have blown up when max > min.");
    } catch (ConfigurationException expected) {
        cf_def.max_compaction_threshold = 33;
    }
}
Also used : AddKeyspace(org.apache.cassandra.db.migration.AddKeyspace) UpdateColumnFamily(org.apache.cassandra.db.migration.UpdateColumnFamily) BytesType(org.apache.cassandra.db.marshal.BytesType) Test(org.junit.Test)

Example 3 with AddKeyspace

use of org.apache.cassandra.db.migration.AddKeyspace 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 4 with AddKeyspace

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

the class DefsTest method addNewKS.

@Test
public void addNewKS() throws ConfigurationException, IOException, ExecutionException, InterruptedException {
    DecoratedKey dk = Util.dk("key0");
    CFMetaData newCf = addTestCF("NewKeyspace1", "AddedStandard1", "A new cf for a new ks");
    KSMetaData newKs = KSMetaData.testMetadata(newCf.ksName, SimpleStrategy.class, KSMetaData.optsWithRF(5), newCf);
    new AddKeyspace(newKs).apply();
    assert Schema.instance.getTableDefinition(newCf.ksName) != null;
    assert Schema.instance.getTableDefinition(newCf.ksName) == newKs;
    // test reads and writes.
    RowMutation rm = new RowMutation(newCf.ksName, dk.key);
    rm.add(new QueryPath(newCf.cfName, null, ByteBufferUtil.bytes("col0")), ByteBufferUtil.bytes("value0"), 1L);
    rm.apply();
    ColumnFamilyStore store = Table.open(newCf.ksName).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) 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 AddKeyspace

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

the class DefsTest method testUpdateKeyspace.

@Test
public void testUpdateKeyspace() throws ConfigurationException, IOException, ExecutionException, InterruptedException {
    // create a keyspace to serve as existing.
    CFMetaData cf = addTestCF("UpdatedKeyspace", "AddedStandard1", "A new cf for a new ks");
    KSMetaData oldKs = KSMetaData.testMetadata(cf.ksName, SimpleStrategy.class, KSMetaData.optsWithRF(5), cf);
    new AddKeyspace(oldKs).apply();
    assert Schema.instance.getTableDefinition(cf.ksName) != null;
    assert Schema.instance.getTableDefinition(cf.ksName) == oldKs;
    // anything with cf defs should fail.
    CFMetaData cf2 = addTestCF(cf.ksName, "AddedStandard2", "A new cf for a new ks");
    KSMetaData newBadKs = KSMetaData.testMetadata(cf.ksName, SimpleStrategy.class, KSMetaData.optsWithRF(4), cf2);
    try {
        new UpdateKeyspace(newBadKs).apply();
        throw new AssertionError("Should not have been able to update a KS with a KS that described column families.");
    } catch (ConfigurationException ex) {
    // expected.
    }
    // names should match.
    KSMetaData newBadKs2 = KSMetaData.testMetadata(cf.ksName + "trash", SimpleStrategy.class, KSMetaData.optsWithRF(4));
    try {
        new UpdateKeyspace(newBadKs2).apply();
        throw new AssertionError("Should not have been able to update a KS with an invalid KS name.");
    } catch (ConfigurationException ex) {
    // expected.
    }
    KSMetaData newKs = KSMetaData.testMetadata(cf.ksName, OldNetworkTopologyStrategy.class, KSMetaData.optsWithRF(1));
    new UpdateKeyspace(newKs).apply();
    KSMetaData newFetchedKs = Schema.instance.getKSMetaData(newKs.name);
    assert newFetchedKs.strategyClass.equals(newKs.strategyClass);
    assert !newFetchedKs.strategyClass.equals(oldKs.strategyClass);
}
Also used : AddKeyspace(org.apache.cassandra.db.migration.AddKeyspace) UpdateKeyspace(org.apache.cassandra.db.migration.UpdateKeyspace) Test(org.junit.Test)

Aggregations

AddKeyspace (org.apache.cassandra.db.migration.AddKeyspace)5 Test (org.junit.Test)5 UpdateColumnFamily (org.apache.cassandra.db.migration.UpdateColumnFamily)3 QueryPath (org.apache.cassandra.db.filter.QueryPath)2 AddColumnFamily (org.apache.cassandra.db.migration.AddColumnFamily)2 DropColumnFamily (org.apache.cassandra.db.migration.DropColumnFamily)2 UUID (java.util.UUID)1 BytesType (org.apache.cassandra.db.marshal.BytesType)1 UpdateKeyspace (org.apache.cassandra.db.migration.UpdateKeyspace)1 SimpleStrategy (org.apache.cassandra.locator.SimpleStrategy)1