Author: jbellis Date: Tue Oct 18 17:19:11 2011 New Revision: 1185761 URL: http://svn.apache.org/viewvc?rev=1185761&view=rev Log: r/m obsolete CF/KS rename code patch by jbellis; reviewed by pyaskevich for CASSANDRA-3292
Removed: cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/db/migration/RenameColumnFamily.java cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/db/migration/RenameKeyspace.java Modified: cassandra/branches/cassandra-0.8/src/avro/internode.genavro cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/db/Table.java cassandra/branches/cassandra-0.8/test/unit/org/apache/cassandra/db/DefsTest.java Modified: cassandra/branches/cassandra-0.8/src/avro/internode.genavro URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/src/avro/internode.genavro?rev=1185761&r1=1185760&r2=1185761&view=diff ============================================================================== --- cassandra/branches/cassandra-0.8/src/avro/internode.genavro (original) +++ cassandra/branches/cassandra-0.8/src/avro/internode.genavro Tue Oct 18 17:19:11 2011 @@ -103,20 +103,6 @@ protocol InterNode { } @namespace("org.apache.cassandra.db.migration.avro") - record RenameColumnFamily { - string ksname; - int cfid; - string old_cfname; - string new_cfname; - } - - @namespace("org.apache.cassandra.db.migration.avro") - record RenameKeyspace { - string old_ksname; - string new_ksname; - } - - @namespace("org.apache.cassandra.db.migration.avro") record UpdateKeyspace { KsDef oldKs; KsDef newKs; @@ -133,6 +119,6 @@ protocol InterNode { org.apache.cassandra.utils.avro.UUID new_version; bytes row_mutation; string classname; - union { AddColumnFamily,DropColumnFamily,RenameColumnFamily,AddKeyspace,DropKeyspace,RenameKeyspace,UpdateKeyspace,UpdateColumnFamily } migration; + union { AddColumnFamily,DropColumnFamily,AddKeyspace,DropKeyspace,UpdateKeyspace,UpdateColumnFamily } migration; } } Modified: cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/db/Table.java URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/db/Table.java?rev=1185761&r1=1185760&r2=1185761&view=diff ============================================================================== --- cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/db/Table.java (original) +++ cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/db/Table.java Tue Oct 18 17:19:11 2011 @@ -369,16 +369,6 @@ public class Table columnFamilyStores.put(cfId, ColumnFamilyStore.createColumnFamilyStore(this, cfName)); } - /** basically a combined drop and add */ - public void renameCf(Integer cfId, String newName) throws IOException - { - assert columnFamilyStores.containsKey(cfId); - ColumnFamilyStore cfs = columnFamilyStores.remove(cfId); - unloadCf(cfs); - cfs.renameSSTables(newName); - initCf(cfId, newName); - } - public Row getRow(QueryFilter filter) throws IOException { ColumnFamilyStore cfStore = getColumnFamilyStore(filter.getColumnFamilyName()); Modified: cassandra/branches/cassandra-0.8/test/unit/org/apache/cassandra/db/DefsTest.java URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/test/unit/org/apache/cassandra/db/DefsTest.java?rev=1185761&r1=1185760&r2=1185761&view=diff ============================================================================== --- cassandra/branches/cassandra-0.8/test/unit/org/apache/cassandra/db/DefsTest.java (original) +++ cassandra/branches/cassandra-0.8/test/unit/org/apache/cassandra/db/DefsTest.java Tue Oct 18 17:19:11 2011 @@ -43,8 +43,6 @@ import org.apache.cassandra.db.migration import org.apache.cassandra.db.migration.DropColumnFamily; import org.apache.cassandra.db.migration.DropKeyspace; import org.apache.cassandra.db.migration.Migration; -import org.apache.cassandra.db.migration.RenameColumnFamily; -import org.apache.cassandra.db.migration.RenameKeyspace; import org.apache.cassandra.db.migration.UpdateColumnFamily; import org.apache.cassandra.db.migration.UpdateKeyspace; import org.apache.cassandra.io.SerDeUtils; @@ -213,24 +211,18 @@ public class DefsTest extends CleanupHel UUID ver1 = m1.getVersion(); assert DatabaseDescriptor.getDefsVersion().equals(ver1); - // rename it. - Migration m2 = new RenameColumnFamily("Keyspace1", "MigrationCf_1", "MigrationCf_2"); - m2.apply(); - UUID ver2 = m2.getVersion(); - assert DatabaseDescriptor.getDefsVersion().equals(ver2); - // drop it. - Migration m3 = new DropColumnFamily("Keyspace1", "MigrationCf_2"); + Migration m3 = new DropColumnFamily("Keyspace1", "MigrationCf_1"); m3.apply(); UUID ver3 = m3.getVersion(); assert DatabaseDescriptor.getDefsVersion().equals(ver3); // now lets load the older migrations to see if that code works. Collection<IColumn> serializedMigrations = Migration.getLocalMigrations(ver1, ver3); - assert serializedMigrations.size() == 3; + assert serializedMigrations.size() == 2; // test deserialization of the migrations. - Migration[] reconstituded = new Migration[3]; + Migration[] reconstituded = new Migration[2]; int i = 0; for (IColumn col : serializedMigrations) { @@ -241,13 +233,11 @@ public class DefsTest extends CleanupHel } assert m1.getClass().equals(reconstituded[0].getClass()); - assert m2.getClass().equals(reconstituded[1].getClass()); - assert m3.getClass().equals(reconstituded[2].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 m2.serialize().equals(reconstituded[1].serialize()); - assert m3.serialize().equals(reconstituded[2].serialize()); + assert m3.serialize().equals(reconstituded[1].serialize()); } @Test @@ -342,53 +332,7 @@ public class DefsTest extends CleanupHel throw new AssertionError("undeleted file " + file); } } - - @Test - public void renameCf() throws ConfigurationException, IOException, ExecutionException, InterruptedException - { - DecoratedKey dk = Util.dk("key0"); - final KSMetaData ks = DatabaseDescriptor.getTableDefinition("Keyspace2"); - assert ks != null; - final CFMetaData oldCfm = ks.cfMetaData().get("Standard1"); - assert oldCfm != 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(oldCfm.cfName, null, ByteBufferUtil.bytes(("col" + i))), ByteBufferUtil.bytes("anyvalue"), 1L); - rm.apply(); - ColumnFamilyStore store = Table.open(oldCfm.ksName).getColumnFamilyStore(oldCfm.cfName); - assert store != null; - store.forceBlockingFlush(); - int fileCount = DefsTable.getFiles(oldCfm.ksName, oldCfm.cfName).size(); - assert fileCount > 0; - - final String cfName = "St4ndard1Replacement"; - new RenameColumnFamily(oldCfm.ksName, oldCfm.cfName, cfName).apply(); - - assert !DatabaseDescriptor.getTableDefinition(ks.name).cfMetaData().containsKey(oldCfm.cfName); - assert DatabaseDescriptor.getTableDefinition(ks.name).cfMetaData().containsKey(cfName); - - // verify that new files are there. - assert DefsTable.getFiles(oldCfm.ksName, cfName).size() == fileCount; - - // do some reads. - store = Table.open(oldCfm.ksName).getColumnFamilyStore(cfName); - assert store != null; - ColumnFamily cfam = store.getColumnFamily(QueryFilter.getSliceFilter(dk, new QueryPath(cfName), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1000)); - assert cfam.getSortedColumns().size() == 100; // should be good enough? - - // do some writes - rm = new RowMutation(ks.name, dk.key); - rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes("col5")), ByteBufferUtil.bytes("updated"), 2L); - rm.apply(); - store.forceBlockingFlush(); - - cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath(cfName), ByteBufferUtil.bytes("col5"))); - assert cfam.getColumnCount() == 1; - assert cfam.getColumn(ByteBufferUtil.bytes("col5")).value().equals( ByteBufferUtil.bytes("updated")); - } - + @Test public void addNewKS() throws ConfigurationException, IOException, ExecutionException, InterruptedException { @@ -489,87 +433,6 @@ public class DefsTest extends CleanupHel } @Test - public void renameKs() throws ConfigurationException, IOException, ExecutionException, InterruptedException - { - DecoratedKey dk = Util.dk("renameKs"); - final KSMetaData oldKs = DatabaseDescriptor.getTableDefinition("Keyspace2"); - assert oldKs != null; - final String cfName = "Standard3"; - assert oldKs.cfMetaData().containsKey(cfName); - assert oldKs.cfMetaData().get(cfName).ksName.equals(oldKs.name); - - // write some data that we hope to read back later. - RowMutation rm = new RowMutation(oldKs.name, dk.key); - for (int i = 0; i < 10; i++) - rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(("col" + i))), ByteBufferUtil.bytes("value"), 1L); - rm.apply(); - ColumnFamilyStore store = Table.open(oldKs.name).getColumnFamilyStore(cfName); - assert store != null; - store.forceBlockingFlush(); - assert DefsTable.getFiles(oldKs.name, cfName).size() > 0; - - final String newKsName = "RenamedKeyspace2"; - new RenameKeyspace(oldKs.name, newKsName).apply(); - KSMetaData newKs = DatabaseDescriptor.getTableDefinition(newKsName); - - assert DatabaseDescriptor.getTableDefinition(oldKs.name) == null; - assert newKs != null; - assert newKs.name.equals(newKsName); - assert newKs.cfMetaData().containsKey(cfName); - assert newKs.cfMetaData().get(cfName).ksName.equals(newKsName); - assert DefsTable.getFiles(newKs.name, cfName).size() > 0; - - // read on old should fail. - // reads should fail too. - boolean threw = false; - try - { - Table.open(oldKs.name); - } - catch (Throwable th) - { - threw = true; - } - assert threw; - - // write on old should fail. - rm = new RowMutation(oldKs.name, ByteBufferUtil.bytes("any key will do")); - boolean success = true; - try - { - rm.add(new QueryPath(cfName, 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/Table no longer exists."; - - // write on new should work. - rm = new RowMutation(newKsName, dk.key); - rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes("col0")), ByteBufferUtil.bytes("newvalue"), 2L); - rm.apply(); - store = Table.open(newKs.name).getColumnFamilyStore(cfName); - assert store != null; - store.forceBlockingFlush(); - - // read on new should work. - SortedSet<ByteBuffer> cols = new TreeSet<ByteBuffer>(BytesType.instance); - cols.add(ByteBufferUtil.bytes("col0")); - cols.add(ByteBufferUtil.bytes("col1")); - ColumnFamily cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath(cfName), cols)); - assert cfam.getColumnCount() == cols.size(); - // tests new write. - - ByteBuffer val = cfam.getColumn(ByteBufferUtil.bytes("col0")).value(); - assertEquals(ByteBufferUtil.string(val), "newvalue"); - // tests old write. - val = cfam.getColumn(ByteBufferUtil.bytes("col1")).value(); - assertEquals(ByteBufferUtil.string(val), "value"); - } - - @Test public void createEmptyKsAddNewCf() throws ConfigurationException, IOException, ExecutionException, InterruptedException { assert DatabaseDescriptor.getTableDefinition("EmptyKeyspace") == null;