cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdusba...@apache.org
Subject svn commit: r981649 - in /cassandra/trunk: src/java/org/apache/cassandra/db/ src/java/org/apache/cassandra/db/migration/ src/java/org/apache/cassandra/service/ test/unit/org/apache/cassandra/db/
Date Mon, 02 Aug 2010 18:19:29 GMT
Author: gdusbabek
Date: Mon Aug  2 18:19:28 2010
New Revision: 981649

URL: http://svn.apache.org/viewvc?rev=981649&view=rev
Log:
use avro for migration serialization. patch by stuhood, reviewed by gdusbabek. CASSANDRA-1308

Modified:
    cassandra/trunk/src/java/org/apache/cassandra/db/DefinitionsUpdateResponseVerbHandler.java
    cassandra/trunk/src/java/org/apache/cassandra/db/migration/AddColumnFamily.java
    cassandra/trunk/src/java/org/apache/cassandra/db/migration/AddKeyspace.java
    cassandra/trunk/src/java/org/apache/cassandra/db/migration/DropColumnFamily.java
    cassandra/trunk/src/java/org/apache/cassandra/db/migration/DropKeyspace.java
    cassandra/trunk/src/java/org/apache/cassandra/db/migration/Migration.java
    cassandra/trunk/src/java/org/apache/cassandra/db/migration/RenameColumnFamily.java
    cassandra/trunk/src/java/org/apache/cassandra/db/migration/RenameKeyspace.java
    cassandra/trunk/src/java/org/apache/cassandra/service/MigrationManager.java
    cassandra/trunk/test/unit/org/apache/cassandra/db/DefsTest.java

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/DefinitionsUpdateResponseVerbHandler.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/DefinitionsUpdateResponseVerbHandler.java?rev=981649&r1=981648&r2=981649&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/DefinitionsUpdateResponseVerbHandler.java
(original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/DefinitionsUpdateResponseVerbHandler.java
Mon Aug  2 18:19:28 2010
@@ -52,7 +52,7 @@ public class DefinitionsUpdateResponseVe
                 final UUID version = UUIDGen.makeType1UUID(col.name());
                 if (version.timestamp() > DatabaseDescriptor.getDefsVersion().timestamp())
                 {
-                    final Migration m = Migration.deserialize(new ByteArrayInputStream(col.value()));
+                    final Migration m = Migration.deserialize(col.value());
                     assert m.getVersion().equals(version);
                     StageManager.getStage(StageManager.MIGRATION_STAGE).submit(new WrappedRunnable()
                     {

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/migration/AddColumnFamily.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/migration/AddColumnFamily.java?rev=981649&r1=981648&r2=981649&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/migration/AddColumnFamily.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/migration/AddColumnFamily.java Mon Aug
 2 18:19:28 2010
@@ -6,16 +6,12 @@ import org.apache.cassandra.config.CFMet
 import org.apache.cassandra.config.ConfigurationException;
 import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.config.KSMetaData;
-import org.apache.cassandra.db.RowMutation;
 import org.apache.cassandra.db.Table;
 import org.apache.cassandra.db.commitlog.CommitLog;
-import org.apache.cassandra.io.ICompactSerializer;
 import org.apache.cassandra.io.SerDeUtils;
 import org.apache.cassandra.utils.FBUtilities;
 import org.apache.cassandra.utils.UUIDGen;
 
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
@@ -41,17 +37,10 @@ import java.util.List;
 
 public class AddColumnFamily extends Migration
 {
-    private static final Serializer serializer = new Serializer();
     private CFMetaData cfm;
     
-    private AddColumnFamily(DataInputStream din) throws IOException
-    {
-        super(UUIDGen.makeType1UUID(din), UUIDGen.makeType1UUID(din));
-        rm = RowMutation.serializer().deserialize(din);
-
-        // deserialize cf
-        cfm = CFMetaData.inflate(SerDeUtils.<org.apache.cassandra.config.avro.CfDef>deserializeWithSchema(FBUtilities.readShortByteArray(din)));
-    }
+    /** Required no-arg constructor */
+    protected AddColumnFamily() { /* pass */ }
     
     public AddColumnFamily(CFMetaData cfm) throws ConfigurationException, IOException
     {
@@ -100,27 +89,16 @@ public class AddColumnFamily extends Mig
             CommitLog.instance().forceNewSegment();
     }
 
-    @Override
-    public ICompactSerializer getSerializer()
+    public void subdeflate(org.apache.cassandra.db.migration.avro.Migration mi)
     {
-        return serializer;
+        org.apache.cassandra.db.migration.avro.AddColumnFamily acf = new org.apache.cassandra.db.migration.avro.AddColumnFamily();
+        acf.cf = cfm.deflate();
+        mi.migration = acf;
     }
 
-    private static final class Serializer implements ICompactSerializer<AddColumnFamily>
+    public void subinflate(org.apache.cassandra.db.migration.avro.Migration mi)
     {
-        public void serialize(AddColumnFamily addColumnFamily, DataOutputStream dos) throws
IOException
-        {
-            dos.write(UUIDGen.decompose(addColumnFamily.newVersion));
-            dos.write(UUIDGen.decompose(addColumnFamily.lastVersion));
-            RowMutation.serializer().serialize(addColumnFamily.rm, dos);
-            // serialize the added cf
-            // TODO: sloppy, but migrations should be converted to Avro soon anyway
-            FBUtilities.writeShortByteArray(SerDeUtils.serializeWithSchema(addColumnFamily.cfm.deflate()),
dos);
-        }
-
-        public AddColumnFamily deserialize(DataInputStream dis) throws IOException
-        {
-            return new AddColumnFamily(dis);
-        }
+        org.apache.cassandra.db.migration.avro.AddColumnFamily acf = (org.apache.cassandra.db.migration.avro.AddColumnFamily)mi.migration;
+        cfm = CFMetaData.inflate(acf.cf);
     }
 }

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/migration/AddKeyspace.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/migration/AddKeyspace.java?rev=981649&r1=981648&r2=981649&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/migration/AddKeyspace.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/migration/AddKeyspace.java Mon Aug  2
18:19:28 2010
@@ -24,32 +24,20 @@ import org.apache.cassandra.config.CFMet
 import org.apache.cassandra.config.ConfigurationException;
 import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.config.KSMetaData;
-import org.apache.cassandra.db.RowMutation;
 import org.apache.cassandra.db.Table;
 import org.apache.cassandra.db.commitlog.CommitLog;
-import org.apache.cassandra.io.ICompactSerializer;
 import org.apache.cassandra.io.SerDeUtils;
 import org.apache.cassandra.utils.FBUtilities;
 import org.apache.cassandra.utils.UUIDGen;
 
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
 import java.io.IOException;
 
 public class AddKeyspace extends Migration
 {
-    private static final Serializer serializer = new Serializer();
-    
     private KSMetaData ksm;
     
-    private AddKeyspace(DataInputStream din) throws IOException
-    {
-        super(UUIDGen.makeType1UUID(din), UUIDGen.makeType1UUID(din));
-        rm = RowMutation.serializer().deserialize(din);
-
-        // deserialize ks
-        ksm = KSMetaData.inflate(SerDeUtils.<org.apache.cassandra.config.avro.KsDef>deserializeWithSchema(FBUtilities.readShortByteArray(din)));
-    }
+    /** Required no-arg constructor */
+    protected AddKeyspace() { /* pass */ }
     
     public AddKeyspace(KSMetaData ksm) throws ConfigurationException, IOException
     {
@@ -63,12 +51,6 @@ public class AddKeyspace extends Migrati
     }
 
     @Override
-    public ICompactSerializer getSerializer()
-    {
-        return serializer;
-    }
-
-    @Override
     public void applyModels() throws IOException
     {
         for (CFMetaData cfm : ksm.cfMetaData().values())
@@ -94,21 +76,16 @@ public class AddKeyspace extends Migrati
         }
     }
     
-    private static final class Serializer implements ICompactSerializer<AddKeyspace>
+    public void subdeflate(org.apache.cassandra.db.migration.avro.Migration mi)
     {
-        public void serialize(AddKeyspace addKeyspace, DataOutputStream dos) throws IOException
-        {
-            dos.write(UUIDGen.decompose(addKeyspace.newVersion));
-            dos.write(UUIDGen.decompose(addKeyspace.lastVersion));
-            RowMutation.serializer().serialize(addKeyspace.rm, dos);
-            // serialize the added ks
-            // TODO: sloppy, but migrations should be converted to Avro soon anyway
-            FBUtilities.writeShortByteArray(SerDeUtils.serializeWithSchema(addKeyspace.ksm.deflate()),
dos);
-        }
+        org.apache.cassandra.db.migration.avro.AddKeyspace aks = new org.apache.cassandra.db.migration.avro.AddKeyspace();
+        aks.ks = ksm.deflate();
+        mi.migration = aks;
+    }
 
-        public AddKeyspace deserialize(DataInputStream dis) throws IOException
-        {
-            return new AddKeyspace(dis);
-        }
+    public void subinflate(org.apache.cassandra.db.migration.avro.Migration mi)
+    {
+        org.apache.cassandra.db.migration.avro.AddKeyspace aks = (org.apache.cassandra.db.migration.avro.AddKeyspace)mi.migration;
+        ksm = KSMetaData.inflate(aks.ks);
     }
 }

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/migration/DropColumnFamily.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/migration/DropColumnFamily.java?rev=981649&r1=981648&r2=981649&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/migration/DropColumnFamily.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/migration/DropColumnFamily.java Mon Aug
 2 18:19:28 2010
@@ -5,21 +5,15 @@ import org.apache.cassandra.config.Confi
 import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.config.KSMetaData;
 import org.apache.cassandra.db.ColumnFamilyStore;
-import org.apache.cassandra.db.RowMutation;
 import org.apache.cassandra.db.SystemTable;
 import org.apache.cassandra.db.Table;
 import org.apache.cassandra.db.commitlog.CommitLog;
-import org.apache.cassandra.io.ICompactSerializer;
 import org.apache.cassandra.utils.FBUtilities;
 import org.apache.cassandra.utils.UUIDGen;
 
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.concurrent.ExecutionException;
 
 /**
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -42,20 +36,12 @@ import java.util.concurrent.ExecutionExc
 
 public class DropColumnFamily extends Migration
 {
-    private static final Serializer serializer = new Serializer();
-    
     private String tableName;
     private String cfName;
     private boolean blockOnFileDeletion;
     
-    private DropColumnFamily(DataInputStream din) throws IOException
-    {
-        super(UUIDGen.makeType1UUID(din), UUIDGen.makeType1UUID(din));
-        rm = RowMutation.serializer().deserialize(din);
-        tableName = din.readUTF();
-        cfName = din.readUTF();
-        blockOnFileDeletion = din.readBoolean();
-    }
+    /** Required no-arg constructor */
+    protected DropColumnFamily() { /* pass */ }
     
     public DropColumnFamily(String tableName, String cfName, boolean blockOnFileDeletion)
throws ConfigurationException, IOException
     {
@@ -94,12 +80,6 @@ public class DropColumnFamily extends Mi
     }
 
     @Override
-    public ICompactSerializer getSerializer()
-    {
-        return serializer;
-    }
-
-    @Override
     public void applyModels() throws IOException
     {
         // reinitialize the table.
@@ -123,21 +103,20 @@ public class DropColumnFamily extends Mi
         }
     }
     
-    private static final class Serializer implements ICompactSerializer<DropColumnFamily>
+    public void subdeflate(org.apache.cassandra.db.migration.avro.Migration mi)
     {
-        public void serialize(DropColumnFamily dropColumnFamily, DataOutputStream dos) throws
IOException
-        {
-            dos.write(UUIDGen.decompose(dropColumnFamily.newVersion));
-            dos.write(UUIDGen.decompose(dropColumnFamily.lastVersion));
-            RowMutation.serializer().serialize(dropColumnFamily.rm, dos);
-            dos.writeUTF(dropColumnFamily.tableName);
-            dos.writeUTF(dropColumnFamily.cfName);
-            dos.writeBoolean(dropColumnFamily.blockOnFileDeletion);       
-        }
+        org.apache.cassandra.db.migration.avro.DropColumnFamily dcf = new org.apache.cassandra.db.migration.avro.DropColumnFamily();
+        dcf.ksname = new org.apache.avro.util.Utf8(tableName);
+        dcf.cfname = new org.apache.avro.util.Utf8(cfName);
+        dcf.block_on_deletion = blockOnFileDeletion;
+        mi.migration = dcf;
+    }
 
-        public DropColumnFamily deserialize(DataInputStream dis) throws IOException
-        {
-            return new DropColumnFamily(dis);
-        }
+    public void subinflate(org.apache.cassandra.db.migration.avro.Migration mi)
+    {
+        org.apache.cassandra.db.migration.avro.DropColumnFamily dcf = (org.apache.cassandra.db.migration.avro.DropColumnFamily)mi.migration;
+        tableName = dcf.ksname.toString();
+        cfName = dcf.cfname.toString();
+        blockOnFileDeletion = dcf.block_on_deletion;
     }
 }

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/migration/DropKeyspace.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/migration/DropKeyspace.java?rev=981649&r1=981648&r2=981649&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/migration/DropKeyspace.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/migration/DropKeyspace.java Mon Aug 
2 18:19:28 2010
@@ -23,32 +23,21 @@ import org.apache.cassandra.config.Confi
 import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.config.KSMetaData;
 import org.apache.cassandra.db.HintedHandOffManager;
-import org.apache.cassandra.db.RowMutation;
 import org.apache.cassandra.db.SystemTable;
 import org.apache.cassandra.db.Table;
 import org.apache.cassandra.db.commitlog.CommitLog;
-import org.apache.cassandra.io.ICompactSerializer;
 import org.apache.cassandra.utils.FBUtilities;
 import org.apache.cassandra.utils.UUIDGen;
 
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
 import java.io.IOException;
 
 public class DropKeyspace extends Migration
 {
-    private static final Serializer serializer = new Serializer();
-    
     private String name;
     private boolean blockOnFileDeletion;
     
-    private DropKeyspace(DataInputStream din) throws IOException
-    {
-        super(UUIDGen.makeType1UUID(din), UUIDGen.makeType1UUID(din));
-        rm = RowMutation.serializer().deserialize(din);
-        name = din.readUTF();
-    }
+    /** Required no-arg constructor */
+    protected DropKeyspace() { /* pass */ }
     
     public DropKeyspace(String name, boolean blockOnFileDeletion) throws ConfigurationException,
IOException
     {
@@ -62,12 +51,6 @@ public class DropKeyspace extends Migrat
     }
 
     @Override
-    public ICompactSerializer getSerializer()
-    {
-        return serializer;
-    }
-
-    @Override
     public void beforeApplyModels()
     {
         if (!clientMode)
@@ -107,20 +90,18 @@ public class DropKeyspace extends Migrat
         }
     }
     
-    private static final class Serializer implements ICompactSerializer<DropKeyspace>
+    public void subdeflate(org.apache.cassandra.db.migration.avro.Migration mi)
     {
-        public void serialize(DropKeyspace dropKeyspace, DataOutputStream dos) throws IOException
-        {
-            dos.write(UUIDGen.decompose(dropKeyspace.newVersion));
-            dos.write(UUIDGen.decompose(dropKeyspace.lastVersion));
-            RowMutation.serializer().serialize(dropKeyspace.rm, dos);
-            
-            dos.writeUTF(dropKeyspace.name);
-        }
+        org.apache.cassandra.db.migration.avro.DropKeyspace dks = new org.apache.cassandra.db.migration.avro.DropKeyspace();
+        dks.ksname = new org.apache.avro.util.Utf8(name);
+        dks.block_on_deletion = blockOnFileDeletion;
+        mi.migration = dks;
+    }
 
-        public DropKeyspace deserialize(DataInputStream dis) throws IOException
-        {
-            return new DropKeyspace(dis);
-        }
+    public void subinflate(org.apache.cassandra.db.migration.avro.Migration mi)
+    {
+        org.apache.cassandra.db.migration.avro.DropKeyspace dks = (org.apache.cassandra.db.migration.avro.DropKeyspace)mi.migration;
+        name = dks.ksname.toString();
+        blockOnFileDeletion = dks.block_on_deletion;
     }
 }

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/migration/Migration.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/migration/Migration.java?rev=981649&r1=981648&r2=981649&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/migration/Migration.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/migration/Migration.java Mon Aug  2 18:19:28
2010
@@ -19,7 +19,8 @@
 package org.apache.cassandra.db.migration;
 
 import java.io.*;
-import java.lang.reflect.Field;
+import java.lang.reflect.Constructor;
+import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
@@ -38,7 +39,6 @@ import org.apache.cassandra.db.filter.Qu
 import org.apache.cassandra.db.filter.QueryPath;
 import org.apache.cassandra.gms.ApplicationState;
 import org.apache.cassandra.gms.Gossiper;
-import org.apache.cassandra.io.ICompactSerializer;
 import org.apache.cassandra.io.SerDeUtils;
 import org.apache.cassandra.io.util.DataOutputBuffer;
 import org.apache.cassandra.service.MigrationManager;
@@ -61,9 +61,8 @@ import static com.google.common.base.Cha
  * Since steps 1, 2 and 3 are not committed atomically, care should be taken to ensure that
a node/cluster is reasonably
  * quiescent with regard to the keyspace or columnfamily whose schema is being modified.
  * 
- * Each class that extends Migration is required to implement a constructor that takes a
DataInputStream as its only
- * argument.  Also, each implementation must take care to ensure that its serialization can
be deserialized.  For 
- * example, it is required that the class name be serialized first always.
+ * Each class that extends Migration is required to implement a no arg constructor, which
will be used to inflate the
+ * object from it's serialized form.
  */
 public abstract class Migration
 {
@@ -75,12 +74,15 @@ public abstract class Migration
     public static final byte[] LAST_MIGRATION_KEY = "Last Migration".getBytes(UTF_8);
     
     protected RowMutation rm;
-    protected final UUID newVersion;
+    protected UUID newVersion;
     protected UUID lastVersion;
     
     // this doesn't follow the serialized migration around.
-    protected final transient boolean clientMode;
+    protected transient boolean clientMode;
     
+    /** Subclasses must have a matching constructor */
+    protected Migration() { /* pass */ }
+
     Migration(UUID newVersion, UUID lastVersion)
     {
         this.newVersion = newVersion;
@@ -108,7 +110,7 @@ public abstract class Migration
         if (!clientMode)
         {
             long now = System.currentTimeMillis();
-            byte[] buf = getBytes();
+            byte[] buf = serialize();
             RowMutation migration = new RowMutation(Table.SYSTEM_TABLE, MIGRATIONS_KEY);
             migration.add(new QueryPath(MIGRATIONS_CF, null, UUIDGen.decompose(newVersion)),
buf, new TimestampClock(now));
             migration.apply();
@@ -181,18 +183,11 @@ public abstract class Migration
     /** keep in mind that applyLive might happen on another machine */
     abstract void applyModels() throws IOException;
     
-    /** serialize migration */
-    public abstract ICompactSerializer getSerializer();
+    /** Deflate this Migration into an Avro object. */
+    public abstract void subdeflate(org.apache.cassandra.db.migration.avro.Migration mi);
     
-    private byte[] getBytes() throws IOException
-    {
-        ByteArrayOutputStream bout = new ByteArrayOutputStream();
-        DataOutputStream dout = new DataOutputStream(bout);
-        dout.writeUTF(getClass().getName());
-        getSerializer().serialize(this, dout);
-        dout.close();
-        return bout.toByteArray();
-    }
+    /** Inflate this Migration from an Avro object: called after the required no-arg constructor.
*/
+    public abstract void subinflate(org.apache.cassandra.db.migration.avro.Migration mi);
     
     public UUID getVersion()
     {
@@ -253,23 +248,67 @@ public abstract class Migration
         } 
     }
     
-    /** deserialize any Migration. */
-    public static Migration deserialize(InputStream in) throws IOException
+    public byte[] serialize() throws IOException
+    {
+        // super deflate
+        org.apache.cassandra.db.migration.avro.Migration mi = new org.apache.cassandra.db.migration.avro.Migration();
+        mi.old_version = new org.apache.cassandra.utils.avro.UUID();
+        mi.old_version.bytes(UUIDGen.decompose(lastVersion));
+        mi.new_version = new org.apache.cassandra.utils.avro.UUID();
+        mi.new_version.bytes(UUIDGen.decompose(newVersion));
+        mi.classname = new org.apache.avro.util.Utf8(this.getClass().getName());
+        // TODO: Avro RowMutation serialization?
+        DataOutputBuffer dob = new DataOutputBuffer();
+        try
+        {
+            RowMutation.serializer().serialize(rm, dob);
+        }
+        catch (IOException e)
+        {
+            throw new RuntimeException(e);
+        }
+        mi.row_mutation = ByteBuffer.wrap(dob.asByteArray());
+
+        // sub deflate
+        this.subdeflate(mi);
+
+        // serialize
+        return SerDeUtils.serializeWithSchema(mi);
+    }
+
+    public static Migration deserialize(byte[] bytes) throws IOException
     {
-        DataInputStream din = new DataInputStream(in);
-        String className = din.readUTF();
+        // deserialize
+        org.apache.cassandra.db.migration.avro.Migration mi = SerDeUtils.deserializeWithSchema(bytes);
+
+        // create an instance of the migration subclass
+        Migration migration;
         try
         {
-            Class migrationClass = Class.forName(className);
-            Field serializerField = migrationClass.getDeclaredField("serializer");
-            serializerField.setAccessible(true);
-            ICompactSerializer serializer = (ICompactSerializer)serializerField.get(migrationClass);
-            return (Migration)serializer.deserialize(din);
+            Class migrationClass = Class.forName(mi.classname.toString());
+            Constructor migrationConstructor = migrationClass.getDeclaredConstructor();
+            migrationConstructor.setAccessible(true);
+            migration = (Migration)migrationConstructor.newInstance();
         }
         catch (Exception e)
         {
-            throw new IOException(e);
+            throw new RuntimeException("Invalid migration class: " + mi.classname.toString(),
e);
+        }
+        
+        // super inflate
+        migration.lastVersion = UUIDGen.makeType1UUID(mi.old_version.bytes());
+        migration.newVersion = UUIDGen.makeType1UUID(mi.new_version.bytes());
+        try
+        {
+            migration.rm = RowMutation.serializer().deserialize(SerDeUtils.createDataInputStream(mi.row_mutation));
+        }
+        catch (IOException e)
+        {
+            throw new RuntimeException(e);
         }
+        // sub inflate
+        migration.subinflate(mi);
+        return migration;
     }
     
     /** load serialized migrations. */

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/migration/RenameColumnFamily.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/migration/RenameColumnFamily.java?rev=981649&r1=981648&r2=981649&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/migration/RenameColumnFamily.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/migration/RenameColumnFamily.java Mon
Aug  2 18:19:28 2010
@@ -5,17 +5,12 @@ import org.apache.cassandra.config.Confi
 import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.config.KSMetaData;
 import org.apache.cassandra.db.DefsTable;
-import org.apache.cassandra.db.RowMutation;
 import org.apache.cassandra.db.Table;
 import org.apache.cassandra.db.commitlog.CommitLog;
-import org.apache.cassandra.io.ICompactSerializer;
 import org.apache.cassandra.io.util.FileUtils;
 import org.apache.cassandra.utils.FBUtilities;
 import org.apache.cassandra.utils.UUIDGen;
 
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
@@ -42,22 +37,13 @@ import java.util.List;
 
 public class RenameColumnFamily extends Migration
 {
-    private static final Serializer serializer = new Serializer();
-    
     private String tableName;
     private String oldName;
     private String newName;
     private Integer cfId;
     
-    RenameColumnFamily(DataInputStream din) throws IOException
-    {
-        super(UUIDGen.makeType1UUID(din), UUIDGen.makeType1UUID(din));
-        rm = RowMutation.serializer().deserialize(din);
-        tableName = din.readUTF();
-        oldName = din.readUTF();
-        newName = din.readUTF();
-        cfId = din.readInt();
-    }
+    /** Required no-arg constructor */
+    protected RenameColumnFamily() { /* pass */ }
     
     // this this constructor sets the cfid, it can only be called form a node that is starting
the migration. It cannot
     // be called during deserialization of this migration.
@@ -95,12 +81,6 @@ public class RenameColumnFamily extends 
     }
 
     @Override
-    public ICompactSerializer getSerializer()
-    {
-        return serializer;
-    }
-
-    @Override
     public void applyModels() throws IOException
     {
         // leave it up to operators to ensure there are no writes going on durng the file
rename. Just know that
@@ -153,23 +133,22 @@ public class RenameColumnFamily extends 
             throw new IOException("One or more IOExceptions encountered while renaming files.
Most recent problem is included.", mostRecentProblem);
     }
     
-    private static final class Serializer implements ICompactSerializer<RenameColumnFamily>
+    public void subdeflate(org.apache.cassandra.db.migration.avro.Migration mi)
     {
-        public void serialize(RenameColumnFamily renameColumnFamily, DataOutputStream dos)
throws IOException
-        {
-            dos.write(UUIDGen.decompose(renameColumnFamily.newVersion));
-            dos.write(UUIDGen.decompose(renameColumnFamily.lastVersion));
-            RowMutation.serializer().serialize(renameColumnFamily.rm, dos);
-            
-            dos.writeUTF(renameColumnFamily.tableName);
-            dos.writeUTF(renameColumnFamily.oldName);
-            dos.writeUTF(renameColumnFamily.newName);
-            dos.writeInt(renameColumnFamily.cfId);
-        }
-
-        public RenameColumnFamily deserialize(DataInputStream dis) throws IOException
-        {
-            return new RenameColumnFamily(dis);
-        }
+        org.apache.cassandra.db.migration.avro.RenameColumnFamily rcf = new org.apache.cassandra.db.migration.avro.RenameColumnFamily();
+        rcf.ksname = new org.apache.avro.util.Utf8(tableName);
+        rcf.cfid = cfId;
+        rcf.old_cfname = new org.apache.avro.util.Utf8(oldName);
+        rcf.new_cfname = new org.apache.avro.util.Utf8(newName);
+        mi.migration = rcf;
+    }
+
+    public void subinflate(org.apache.cassandra.db.migration.avro.Migration mi)
+    {
+        org.apache.cassandra.db.migration.avro.RenameColumnFamily rcf = (org.apache.cassandra.db.migration.avro.RenameColumnFamily)mi.migration;
+        tableName = rcf.ksname.toString();
+        cfId = rcf.cfid;
+        oldName = rcf.old_cfname.toString();
+        newName = rcf.new_cfname.toString();
     }
 }

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/migration/RenameKeyspace.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/migration/RenameKeyspace.java?rev=981649&r1=981648&r2=981649&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/migration/RenameKeyspace.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/migration/RenameKeyspace.java Mon Aug
 2 18:19:28 2010
@@ -24,17 +24,12 @@ import org.apache.cassandra.config.Datab
 import org.apache.cassandra.config.KSMetaData;
 import org.apache.cassandra.db.DefsTable;
 import org.apache.cassandra.db.HintedHandOffManager;
-import org.apache.cassandra.db.RowMutation;
 import org.apache.cassandra.db.Table;
 import org.apache.cassandra.db.commitlog.CommitLog;
-import org.apache.cassandra.io.ICompactSerializer;
 import org.apache.cassandra.io.util.FileUtils;
 import org.apache.cassandra.utils.FBUtilities;
 import org.apache.cassandra.utils.UUIDGen;
 
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
@@ -43,18 +38,11 @@ import java.util.Set;
 
 public class RenameKeyspace extends Migration
 {
-    private static final Serializer serializer = new Serializer();
-    
     private String oldName;
     private String newName;
     
-    RenameKeyspace(DataInputStream din) throws IOException
-    {
-        super(UUIDGen.makeType1UUID(din), UUIDGen.makeType1UUID(din));
-        rm = RowMutation.serializer().deserialize(din);
-        oldName = din.readUTF();
-        newName = din.readUTF();
-    }
+    /** Required no-arg constructor */
+    protected RenameKeyspace() { /* pass */ }
     
     public RenameKeyspace(String oldName, String newName) throws ConfigurationException,
IOException
     {
@@ -89,12 +77,6 @@ public class RenameKeyspace extends Migr
     }
 
     @Override
-    public ICompactSerializer getSerializer()
-    {
-        return serializer;
-    }
-
-    @Override
     public void applyModels() throws IOException
     {
         if (!clientMode)
@@ -157,21 +139,18 @@ public class RenameKeyspace extends Migr
             throw new IOException("One or more IOExceptions encountered while renaming files.
Most recent problem is included.", mostRecentProblem);
     }
     
-    private static final class Serializer implements ICompactSerializer<RenameKeyspace>
+    public void subdeflate(org.apache.cassandra.db.migration.avro.Migration mi)
     {
-        public void serialize(RenameKeyspace renameKeyspace, DataOutputStream dout) throws
IOException
-        {
-            dout.write(UUIDGen.decompose(renameKeyspace.newVersion));
-            dout.write(UUIDGen.decompose(renameKeyspace.lastVersion));
-            RowMutation.serializer().serialize(renameKeyspace.rm, dout);
-            
-            dout.writeUTF(renameKeyspace.oldName);
-            dout.writeUTF(renameKeyspace.newName);
-        }
+        org.apache.cassandra.db.migration.avro.RenameKeyspace rks = new org.apache.cassandra.db.migration.avro.RenameKeyspace();
+        rks.old_ksname = new org.apache.avro.util.Utf8(oldName);
+        rks.new_ksname = new org.apache.avro.util.Utf8(newName);
+        mi.migration = rks;
+    }
 
-        public RenameKeyspace deserialize(DataInputStream dis) throws IOException
-        {
-            return new RenameKeyspace(dis);
-        }
+    public void subinflate(org.apache.cassandra.db.migration.avro.Migration mi)
+    {
+        org.apache.cassandra.db.migration.avro.RenameKeyspace rks = (org.apache.cassandra.db.migration.avro.RenameKeyspace)mi.migration;
+        oldName = rks.old_ksname.toString();
+        newName = rks.new_ksname.toString();
     }
 }

Modified: cassandra/trunk/src/java/org/apache/cassandra/service/MigrationManager.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/service/MigrationManager.java?rev=981649&r1=981648&r2=981649&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/service/MigrationManager.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/service/MigrationManager.java Mon Aug  2
18:19:28 2010
@@ -117,7 +117,7 @@ public class MigrationManager implements
         Collection<IColumn> migrations = Migration.getLocalMigrations(from, to);
         for (IColumn col : migrations)
         {
-            final Migration migration = Migration.deserialize(new ByteArrayInputStream(col.value()));
+            final Migration migration = Migration.deserialize(col.value());
             Future update = StageManager.getStage(StageManager.MIGRATION_STAGE).submit(new
Runnable() 
             {
                 public void run()

Modified: cassandra/trunk/test/unit/org/apache/cassandra/db/DefsTest.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/db/DefsTest.java?rev=981649&r1=981648&r2=981649&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/db/DefsTest.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/db/DefsTest.java Mon Aug  2 18:19:28 2010
@@ -115,7 +115,7 @@ public class DefsTest extends CleanupHel
         for (IColumn col : serializedMigrations)
         {
             UUID version = UUIDGen.makeType1UUID(col.name());
-            reconstituded[i] = Migration.deserialize(new ByteArrayInputStream(col.value()));
+            reconstituded[i] = Migration.deserialize(col.value());
             assert version.equals(reconstituded[i].getVersion());
             i++;
         }
@@ -125,18 +125,9 @@ public class DefsTest extends CleanupHel
         assert m3.getClass().equals(reconstituded[2].getClass());
         
         // verify that the row mutations are the same. rather than exposing the private fields,
serialize and verify.
-        assert Arrays.equals(getBytes(m1), getBytes(reconstituded[0]));
-        assert Arrays.equals(getBytes(m2), getBytes(reconstituded[1]));
-        assert Arrays.equals(getBytes(m3), getBytes(reconstituded[2]));
-    }
-    
-    private static byte[] getBytes(Migration m) throws IOException
-    {
-        ByteArrayOutputStream bout = new ByteArrayOutputStream();
-        DataOutputStream dout = new DataOutputStream(bout);
-        m.getSerializer().serialize(m, dout);
-        dout.close();
-        return bout.toByteArray();
+        assert Arrays.equals(m1.serialize(), reconstituded[0].serialize());
+        assert Arrays.equals(m2.serialize(), reconstituded[1].serialize());
+        assert Arrays.equals(m3.serialize(), reconstituded[2].serialize());
     }
 
     @Test



Mime
View raw message