use of org.apache.cassandra.db.migration.UpdateColumnFamily 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;
}
}
use of org.apache.cassandra.db.migration.UpdateColumnFamily in project eiger by wlloyd.
the class DefsTest method testDropIndex.
@Test
public void testDropIndex() throws IOException, ExecutionException, InterruptedException, ConfigurationException {
// insert some data. save the sstable descriptor so we can make sure it's marked for delete after the drop
RowMutation rm = new RowMutation("Keyspace6", ByteBufferUtil.bytes("k1"));
rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("notbirthdate")), ByteBufferUtil.bytes(1L), 0);
rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(1L), 0);
rm.apply();
ColumnFamilyStore cfs = Table.open("Keyspace6").getColumnFamilyStore("Indexed1");
cfs.forceBlockingFlush();
ColumnFamilyStore indexedCfs = cfs.indexManager.getIndexForColumn(cfs.indexManager.getIndexedColumns().iterator().next()).getIndexCfs();
Descriptor desc = indexedCfs.getSSTables().iterator().next().descriptor;
// drop the index
// abusing rename to clone
CFMetaData meta = CFMetaData.rename(cfs.metadata, cfs.metadata.cfName);
ColumnDefinition cdOld = meta.getColumn_metadata().values().iterator().next();
ColumnDefinition cdNew = new ColumnDefinition(cdOld.name, cdOld.getValidator(), null, null, null);
meta.columnMetadata(Collections.singletonMap(cdOld.name, cdNew));
UpdateColumnFamily update = new UpdateColumnFamily(meta.toAvro());
update.apply();
// check
assert cfs.indexManager.getIndexedColumns().isEmpty();
SSTableDeletingTask.waitForDeletions();
assert !new File(desc.filenameFor(Component.DATA)).exists();
}
use of org.apache.cassandra.db.migration.UpdateColumnFamily in project eiger by wlloyd.
the class DropIndexStatement method generateMutation.
public UpdateColumnFamily generateMutation(String keyspace) throws InvalidRequestException, ConfigurationException, IOException {
CfDef cfDef = null;
KSMetaData ksm = Schema.instance.getTableDefinition(keyspace);
for (CFMetaData cfm : ksm.cfMetaData().values()) {
cfDef = getUpdatedCFDef(cfm.toAvro());
if (cfDef != null)
break;
}
if (cfDef == null)
throw new InvalidRequestException("Index '" + index + "' could not be found in any of the ColumnFamilies of keyspace '" + keyspace + "'");
return new UpdateColumnFamily(cfDef);
}
Aggregations