use of org.apache.cassandra.db.migration.DropColumnFamily 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());
}
use of org.apache.cassandra.db.migration.DropColumnFamily 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);
}
}
Aggregations