cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xe...@apache.org
Subject svn commit: r1161230 - in /cassandra/trunk: ./ src/java/org/apache/cassandra/config/ src/java/org/apache/cassandra/cql/ src/java/org/apache/cassandra/db/ src/java/org/apache/cassandra/db/migration/ src/java/org/apache/cassandra/thrift/ test/unit/org/ap...
Date Wed, 24 Aug 2011 18:52:23 GMT
Author: xedin
Date: Wed Aug 24 18:52:23 2011
New Revision: 1161230

URL: http://svn.apache.org/viewvc?rev=1161230&view=rev
Log:
Clean up KSMetadata, CFMetadata from unnecessary Thrift<->Avro conversion methods
patch by Jonathan Ellis and Pavel Yaskevich; reviewed by Pavel Yaskevich for CASSANDRA-3032

Added:
    cassandra/trunk/test/unit/org/apache/cassandra/config/CFMetaDataTest.java
Modified:
    cassandra/trunk/CHANGES.txt
    cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java
    cassandra/trunk/src/java/org/apache/cassandra/config/ColumnDefinition.java
    cassandra/trunk/src/java/org/apache/cassandra/config/KSMetaData.java
    cassandra/trunk/src/java/org/apache/cassandra/cql/AlterTableStatement.java
    cassandra/trunk/src/java/org/apache/cassandra/cql/DropIndexStatement.java
    cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java
    cassandra/trunk/src/java/org/apache/cassandra/db/DefsTable.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/Migration.java
    cassandra/trunk/src/java/org/apache/cassandra/db/migration/UpdateColumnFamily.java
    cassandra/trunk/src/java/org/apache/cassandra/db/migration/UpdateKeyspace.java
    cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java
    cassandra/trunk/test/unit/org/apache/cassandra/SchemaLoader.java
    cassandra/trunk/test/unit/org/apache/cassandra/config/ColumnDefinitionTest.java
    cassandra/trunk/test/unit/org/apache/cassandra/config/DatabaseDescriptorTest.java
    cassandra/trunk/test/unit/org/apache/cassandra/db/DefsTest.java
    cassandra/trunk/test/unit/org/apache/cassandra/thrift/ThriftValidationTest.java

Modified: cassandra/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/trunk/CHANGES.txt?rev=1161230&r1=1161229&r2=1161230&view=diff
==============================================================================
--- cassandra/trunk/CHANGES.txt (original)
+++ cassandra/trunk/CHANGES.txt Wed Aug 24 18:52:23 2011
@@ -39,7 +39,8 @@
    for query-by-name requests (CASSANDRA-2498)
  * Add query-by-column mode to stress.java (CASSANDRA-3064)
  * Add "install" command to cassandra.bat (CASSANDRA-292)
-
+ * clean up KSMetadata, CFMetadata from unnecessary
+   Thrift<->Avro conversion methods (CASSANDRA-3032)
 
 0.8.5
  * fix NPE when encryption_options is unspecified (CASSANDRA-3007)

Modified: cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java?rev=1161230&r1=1161229&r2=1161230&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java Wed Aug 24 18:52:23 2011
@@ -18,6 +18,8 @@
 
 package org.apache.cassandra.config;
 
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
 import java.nio.ByteBuffer;
 import java.util.*;
 
@@ -27,29 +29,18 @@ import org.apache.commons.lang.builder.T
 
 import org.apache.avro.util.Utf8;
 import org.apache.cassandra.cache.IRowCacheProvider;
+import org.apache.cassandra.db.*;
+import org.apache.cassandra.db.compaction.AbstractCompactionStrategy;
 import org.apache.cassandra.db.marshal.*;
-import org.apache.cassandra.db.migration.avro.ColumnDef;
-import org.apache.cassandra.db.Column;
-import org.apache.cassandra.db.ColumnFamilyType;
-import org.apache.cassandra.db.HintedHandOffManager;
-import org.apache.cassandra.db.SuperColumn;
-import org.apache.cassandra.db.SystemTable;
-import org.apache.cassandra.db.Table;
-import org.apache.cassandra.db.ColumnFamilyStore;
-import org.apache.cassandra.db.marshal.AbstractType;
-import org.apache.cassandra.db.marshal.BytesType;
-import org.apache.cassandra.db.marshal.TimeUUIDType;
-import org.apache.cassandra.db.marshal.UTF8Type;
 import org.apache.cassandra.db.migration.Migration;
-import org.apache.cassandra.db.compaction.AbstractCompactionStrategy;
+import org.apache.cassandra.db.migration.avro.ColumnDef;
 import org.apache.cassandra.io.IColumnSerializer;
-import org.apache.cassandra.io.SerDeUtils;
 import org.apache.cassandra.thrift.InvalidRequestException;
 import org.apache.cassandra.utils.ByteBufferUtil;
 import org.apache.cassandra.utils.FBUtilities;
 
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public final class CFMetaData
 {
@@ -59,6 +50,8 @@ public final class CFMetaData
     // for how to do so safely.
     //
 
+    private static Logger logger = LoggerFactory.getLogger(CFMetaData.class);
+
     public final static double DEFAULT_ROW_CACHE_SIZE = 0.0;
     public final static double DEFAULT_KEY_CACHE_SIZE = 200000;
     public final static double DEFAULT_READ_REPAIR_CHANCE = 1.0;
@@ -306,7 +299,8 @@ public final class CFMetaData
         return cfName + "." + (info.getIndexName() == null ? ByteBufferUtil.bytesToHex(info.name) : info.getIndexName());
     }
 
-    public org.apache.cassandra.db.migration.avro.CfDef deflate()
+    // converts CFM to avro CfDef
+    public org.apache.cassandra.db.migration.avro.CfDef toAvro()
     {
         org.apache.cassandra.db.migration.avro.CfDef cf = new org.apache.cassandra.db.migration.avro.CfDef();
         cf.id = cfId;
@@ -315,15 +309,19 @@ public final class CFMetaData
         cf.column_type = new Utf8(cfType.name());
         cf.comparator_type = new Utf8(comparator.toString());
         if (subcolumnComparator != null)
+        {
+            assert cfType == ColumnFamilyType.Super
+                   : String.format("%s CF %s should not have subcomparator %s defined", cfType, cfName, subcolumnComparator);
             cf.subcomparator_type = new Utf8(subcolumnComparator.toString());
-        cf.comment = new Utf8(comment);
+        }
+        cf.comment = new Utf8(enforceCommentNotNull(comment));
         cf.row_cache_size = rowCacheSize;
         cf.key_cache_size = keyCacheSize;
         cf.read_repair_chance = readRepairChance;
         cf.replicate_on_write = replicateOnWrite;
         cf.gc_grace_seconds = gcGraceSeconds;
-        cf.default_validation_class = new Utf8(defaultValidator.toString());
-        cf.key_validation_class = new Utf8(keyValidator.toString());
+        cf.default_validation_class = defaultValidator == null ? null : new Utf8(defaultValidator.toString());
+        cf.key_validation_class = new Utf8(keyValidator.getClass().getName());
         cf.min_compaction_threshold = minCompactionThreshold;
         cf.max_compaction_threshold = maxCompactionThreshold;
         cf.row_cache_save_period_in_seconds = rowCacheSavePeriodInSeconds;
@@ -334,10 +332,9 @@ public final class CFMetaData
         cf.merge_shards_chance = mergeShardsChance;
         cf.key_alias = keyAlias;
         cf.compression = compression;
-        cf.column_metadata = SerDeUtils.createArray(column_metadata.size(),
-                                                    org.apache.cassandra.db.migration.avro.ColumnDef.SCHEMA$);
+        cf.column_metadata = new ArrayList<ColumnDef>(column_metadata.size());
         for (ColumnDefinition cd : column_metadata.values())
-            cf.column_metadata.add(cd.deflate());
+            cf.column_metadata.add(cd.toAvro());
         cf.row_cache_provider = new Utf8(rowCacheProvider.getClass().getName());
         cf.compaction_strategy = new Utf8(compactionStrategyClass.getName());
         if (compactionStrategyOptions != null)
@@ -349,7 +346,7 @@ public final class CFMetaData
         return cf;
     }
 
-    public static CFMetaData inflate(org.apache.cassandra.db.migration.avro.CfDef cf)
+    public static CFMetaData fromAvro(org.apache.cassandra.db.migration.avro.CfDef cf)
     {
         AbstractType comparator;
         AbstractType subcolumnComparator = null;
@@ -371,7 +368,7 @@ public final class CFMetaData
         Map<ByteBuffer, ColumnDefinition> column_metadata = new TreeMap<ByteBuffer, ColumnDefinition>(BytesType.instance);
         for (ColumnDef aColumn_metadata : cf.column_metadata)
         {
-            ColumnDefinition cd = ColumnDefinition.inflate(aColumn_metadata);
+            ColumnDefinition cd = ColumnDefinition.fromAvro(aColumn_metadata);
             if (cd.getIndexType() != null && cd.getIndexName() == null)
                 cd.setIndexName(getDefaultIndexName(cf.name.toString(), comparator, cd.name));
             column_metadata.put(cd.name, cd);
@@ -663,7 +660,7 @@ public final class CFMetaData
         if (null == cf_def.compaction_strategy)
             cf_def.compaction_strategy = DEFAULT_COMPACTION_STRATEGY_CLASS;
         if (null == cf_def.compaction_strategy_options)
-            cf_def.compaction_strategy_options = Collections.<String, String>emptyMap();
+            cf_def.compaction_strategy_options = Collections.emptyMap();
         if (!cf_def.isSetCompression())
             cf_def.setCompression(CFMetaData.DEFAULT_COMPRESSION);
     }
@@ -682,7 +679,8 @@ public final class CFMetaData
                                             cf_def.name,
                                             cfType,
                                             TypeParser.parse(cf_def.comparator_type),
-                                            cf_def.subcomparator_type == null ? null : TypeParser.parse(cf_def.subcomparator_type));
+                                            cf_def.subcomparator_type == null ? null : TypeParser.parse(cf_def.subcomparator_type),
+                                            cf_def.isSetId() ? cf_def.id : Schema.instance.nextCFId());
 
         if (cf_def.isSetGc_grace_seconds()) { newCFMD.gcGraceSeconds(cf_def.gc_grace_seconds); }
         if (cf_def.isSetMin_compaction_threshold()) { newCFMD.minCompactionThreshold(cf_def.min_compaction_threshold); }
@@ -717,13 +715,14 @@ public final class CFMetaData
                       .replicateOnWrite(cf_def.replicate_on_write)
                       .defaultValidator(TypeParser.parse(cf_def.default_validation_class))
                       .keyValidator(TypeParser.parse(cf_def.key_validation_class))
-                      .columnMetadata(ColumnDefinition.fromColumnDef(cf_def.column_metadata))
+                      .columnMetadata(ColumnDefinition.fromThrift(cf_def.column_metadata))
                       .compression(cf_def.compression);
     }
 
-    // merges some final fields from this CFM with modifiable fields from CfDef into a new CFMetaData.
+    /** updates CFMetaData in-place to match cf_def */
     public void apply(org.apache.cassandra.db.migration.avro.CfDef cf_def) throws ConfigurationException
     {
+        logger.debug("applying {} to {}", cf_def, this);
         // validate
         if (!cf_def.keyspace.toString().equals(ksName))
             throw new ConfigurationException(String.format("Keyspace mismatch (found %s; expected %s)",
@@ -788,7 +787,9 @@ public final class CFMetaData
         
         // remove the ones leaving.
         for (ByteBuffer indexName : toRemove)
+        {
             column_metadata.remove(indexName);
+        }
         // update the ones staying
         for (org.apache.cassandra.db.migration.avro.ColumnDef def : cf_def.column_metadata)
         {
@@ -828,6 +829,8 @@ public final class CFMetaData
             for (Map.Entry<CharSequence, CharSequence> e : cf_def.compaction_strategy_options.entrySet())
                 compactionStrategyOptions.put(e.getKey().toString(), e.getValue().toString());
         }
+
+        logger.debug("application result is {}", this);
     }
     
     public AbstractCompactionStrategy createCompactionStrategyInstance(ColumnFamilyStore cfs)
@@ -861,37 +864,38 @@ public final class CFMetaData
     }
 
     // converts CFM to thrift CfDef
-    public static org.apache.cassandra.thrift.CfDef convertToThrift(CFMetaData cfm)
+    public org.apache.cassandra.thrift.CfDef toThrift()
     {
-        org.apache.cassandra.thrift.CfDef def = new org.apache.cassandra.thrift.CfDef(cfm.ksName, cfm.cfName);
-        def.setId(cfm.cfId);
-        def.setColumn_type(cfm.cfType.name());
-        def.setComparator_type(cfm.comparator.toString());
-        if (cfm.subcolumnComparator != null)
-        {
-            def.setSubcomparator_type(cfm.subcolumnComparator.toString());
-            def.setColumn_type("Super");
-        }
-        def.setComment(enforceCommentNotNull(cfm.comment));
-        def.setRow_cache_size(cfm.rowCacheSize);
-        def.setKey_cache_size(cfm.keyCacheSize);
-        def.setRead_repair_chance(cfm.readRepairChance);
-        def.setReplicate_on_write(cfm.replicateOnWrite);
-        def.setGc_grace_seconds(cfm.gcGraceSeconds);
-        def.setDefault_validation_class(cfm.defaultValidator.toString());
-        def.setKey_validation_class(cfm.keyValidator.toString());
-        def.setMin_compaction_threshold(cfm.minCompactionThreshold);
-        def.setMax_compaction_threshold(cfm.maxCompactionThreshold);
-        def.setRow_cache_save_period_in_seconds(cfm.rowCacheSavePeriodInSeconds);
-        def.setKey_cache_save_period_in_seconds(cfm.keyCacheSavePeriodInSeconds);
-        def.setRow_cache_keys_to_save(cfm.rowCacheKeysToSave);
-        def.setMemtable_throughput_in_mb(cfm.memtableThroughputInMb);
-        def.setMemtable_operations_in_millions(cfm.memtableOperationsInMillions);
-        def.setMerge_shards_chance(cfm.mergeShardsChance);
-        def.setKey_alias(cfm.getKeyName());
-        def.setCompression(cfm.compression);
-        List<org.apache.cassandra.thrift.ColumnDef> column_meta = new ArrayList< org.apache.cassandra.thrift.ColumnDef>(cfm.column_metadata.size());
-        for (ColumnDefinition cd : cfm.column_metadata.values())
+        org.apache.cassandra.thrift.CfDef def = new org.apache.cassandra.thrift.CfDef(ksName, cfName);
+        def.setId(cfId);
+        def.setColumn_type(cfType.name());
+        def.setComparator_type(comparator.toString());
+        if (subcolumnComparator != null)
+        {
+            assert cfType == ColumnFamilyType.Super
+                   : String.format("%s CF %s should not have subcomparator %s defined", cfType, cfName, subcolumnComparator);
+            def.setSubcomparator_type(subcolumnComparator.toString());
+        }
+        def.setComment(enforceCommentNotNull(comment));
+        def.setRow_cache_size(rowCacheSize);
+        def.setKey_cache_size(keyCacheSize);
+        def.setRead_repair_chance(readRepairChance);
+        def.setReplicate_on_write(replicateOnWrite);
+        def.setGc_grace_seconds(gcGraceSeconds);
+        def.setDefault_validation_class(defaultValidator.toString());
+        def.setKey_validation_class(keyValidator.toString());
+        def.setMin_compaction_threshold(minCompactionThreshold);
+        def.setMax_compaction_threshold(maxCompactionThreshold);
+        def.setRow_cache_save_period_in_seconds(rowCacheSavePeriodInSeconds);
+        def.setKey_cache_save_period_in_seconds(keyCacheSavePeriodInSeconds);
+        def.setRow_cache_keys_to_save(rowCacheKeysToSave);
+        def.setMemtable_throughput_in_mb(memtableThroughputInMb);
+        def.setMemtable_operations_in_millions(memtableOperationsInMillions);
+        def.setMerge_shards_chance(mergeShardsChance);
+        def.setKey_alias(getKeyName());
+        def.setCompression(compression);
+        List<org.apache.cassandra.thrift.ColumnDef> column_meta = new ArrayList<org.apache.cassandra.thrift.ColumnDef>(column_metadata.size());
+        for (ColumnDefinition cd : column_metadata.values())
         {
             org.apache.cassandra.thrift.ColumnDef tcd = new org.apache.cassandra.thrift.ColumnDef();
             tcd.setIndex_name(cd.getIndexName());
@@ -901,115 +905,10 @@ public final class CFMetaData
             column_meta.add(tcd);
         }
         def.setColumn_metadata(column_meta);
-        def.setCompaction_strategy(cfm.compactionStrategyClass.getName());
-        Map<String, String> compactionOptions = new HashMap<String, String>();
-        def.setCompaction_strategy_options(cfm.compactionStrategyOptions);
+        def.setCompaction_strategy(compactionStrategyClass.getName());
+        def.setCompaction_strategy_options(new HashMap<String, String>(compactionStrategyOptions));
         return def;
     }
-    
-    // converts CFM to avro CfDef
-    public static org.apache.cassandra.db.migration.avro.CfDef convertToAvro(CFMetaData cfm)
-    {
-        org.apache.cassandra.db.migration.avro.CfDef def = new org.apache.cassandra.db.migration.avro.CfDef();
-        def.name = cfm.cfName;
-        def.keyspace = cfm.ksName;
-        def.id = cfm.cfId;
-        def.column_type = cfm.cfType.name();
-        def.comparator_type = cfm.comparator.toString();
-        if (cfm.subcolumnComparator != null)
-        {
-            def.subcomparator_type = cfm.subcolumnComparator.toString();
-            def.column_type = "Super";
-        }
-        def.comment = enforceCommentNotNull(cfm.comment);
-        def.row_cache_size = cfm.rowCacheSize;
-        def.key_cache_size = cfm.keyCacheSize;
-        def.read_repair_chance = cfm.readRepairChance;
-        def.replicate_on_write = cfm.replicateOnWrite;
-        def.gc_grace_seconds = cfm.gcGraceSeconds;
-        def.default_validation_class = cfm.defaultValidator == null ? null : cfm.defaultValidator.toString();
-        def.min_compaction_threshold = cfm.minCompactionThreshold;
-        def.max_compaction_threshold = cfm.maxCompactionThreshold;
-        def.row_cache_save_period_in_seconds = cfm.rowCacheSavePeriodInSeconds;
-        def.key_cache_save_period_in_seconds = cfm.keyCacheSavePeriodInSeconds;
-        def.row_cache_keys_to_save = cfm.rowCacheKeysToSave;
-        def.memtable_throughput_in_mb = cfm.memtableThroughputInMb;
-        def.memtable_operations_in_millions = cfm.memtableOperationsInMillions;
-        def.merge_shards_chance = cfm.mergeShardsChance;
-        def.key_validation_class = cfm.keyValidator.getClass().getName();
-        def.key_alias = cfm.keyAlias;
-        def.compression = cfm.compression;
-        List<org.apache.cassandra.db.migration.avro.ColumnDef> column_meta = new ArrayList<org.apache.cassandra.db.migration.avro.ColumnDef>(cfm.column_metadata.size());
-        for (ColumnDefinition cd : cfm.column_metadata.values())
-        {
-            org.apache.cassandra.db.migration.avro.ColumnDef tcd = new org.apache.cassandra.db.migration.avro.ColumnDef();
-            tcd.index_name = cd.getIndexName();
-            tcd.index_type = cd.getIndexType() == null ? null : org.apache.cassandra.db.migration.avro.IndexType.valueOf(cd.getIndexType().name());
-            tcd.name = ByteBufferUtil.clone(cd.name);
-            tcd.validation_class = cd.getValidator().toString();
-            column_meta.add(tcd);
-        }
-        def.column_metadata = column_meta; 
-        def.row_cache_provider = new Utf8(cfm.rowCacheProvider.getClass().getName());
-        def.compaction_strategy = new Utf8(cfm.compactionStrategyClass.getName());
-        def.compaction_strategy_options = new HashMap<CharSequence, CharSequence>();
-        for (Map.Entry<String, String> e : cfm.compactionStrategyOptions.entrySet())
-            def.compaction_strategy_options.put(new Utf8(e.getKey()), new Utf8(e.getValue()));
-        return def;
-    }
-    
-    public static org.apache.cassandra.db.migration.avro.CfDef convertToAvro(org.apache.cassandra.thrift.CfDef def)
-    {
-        org.apache.cassandra.db.migration.avro.CfDef newDef = new org.apache.cassandra.db.migration.avro.CfDef();
-        newDef.keyspace = def.getKeyspace();
-        newDef.name = def.getName();
-        newDef.column_type = def.getColumn_type();
-        newDef.comment = def.getComment();
-        newDef.comparator_type = def.getComparator_type();
-        newDef.default_validation_class = def.getDefault_validation_class();
-        newDef.key_validation_class = def.getKey_validation_class();
-        newDef.gc_grace_seconds = def.getGc_grace_seconds();
-        newDef.id = def.getId();
-        newDef.key_cache_save_period_in_seconds = def.getKey_cache_save_period_in_seconds();
-        newDef.key_cache_size = def.getKey_cache_size();
-        newDef.max_compaction_threshold = def.getMax_compaction_threshold();
-        newDef.memtable_operations_in_millions = def.getMemtable_operations_in_millions();
-        newDef.memtable_throughput_in_mb = def.getMemtable_throughput_in_mb();
-        newDef.min_compaction_threshold = def.getMin_compaction_threshold();
-        newDef.read_repair_chance = def.getRead_repair_chance();
-        newDef.replicate_on_write = def.isReplicate_on_write();
-        newDef.row_cache_save_period_in_seconds = def.getRow_cache_save_period_in_seconds();
-        newDef.row_cache_keys_to_save = def.getRow_cache_keys_to_save();
-        newDef.row_cache_size = def.getRow_cache_size();
-        newDef.subcomparator_type = def.getSubcomparator_type();
-        newDef.merge_shards_chance = def.getMerge_shards_chance();
-        newDef.key_alias = def.key_alias;
-        newDef.compression = def.compression;
-        List<org.apache.cassandra.db.migration.avro.ColumnDef> columnMeta = new ArrayList<org.apache.cassandra.db.migration.avro.ColumnDef>();
-        if (def.isSetColumn_metadata())
-        {
-            for (org.apache.cassandra.thrift.ColumnDef cdef : def.getColumn_metadata())
-            {
-                org.apache.cassandra.db.migration.avro.ColumnDef tdef = new org.apache.cassandra.db.migration.avro.ColumnDef();
-                tdef.name = ByteBufferUtil.clone(cdef.bufferForName());
-                tdef.validation_class = cdef.getValidation_class();
-                tdef.index_name = cdef.getIndex_name();
-                tdef.index_type = cdef.getIndex_type() == null ? null : org.apache.cassandra.db.migration.avro.IndexType.valueOf(cdef.getIndex_type().name());
-                columnMeta.add(tdef);
-            }
-        }
-        newDef.column_metadata = columnMeta;
-        if (def.isSetCompaction_strategy())
-            newDef.compaction_strategy = new Utf8(def.getCompaction_strategy());
-
-        if (def.isSetCompaction_strategy_options() && null != def.getCompaction_strategy_options())
-        {
-            newDef.compaction_strategy_options = new HashMap<CharSequence, CharSequence>();
-            for (Map.Entry<String, String> e : def.getCompaction_strategy_options().entrySet())
-                newDef.compaction_strategy_options.put(new Utf8(e.getKey()), new Utf8(e.getValue()));
-        }
-        return newDef;
-    }
 
     public static void validateMinMaxCompactionThresholds(org.apache.cassandra.db.migration.avro.CfDef cf_def) throws ConfigurationException
     {

Modified: cassandra/trunk/src/java/org/apache/cassandra/config/ColumnDefinition.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/config/ColumnDefinition.java?rev=1161230&r1=1161229&r2=1161230&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/config/ColumnDefinition.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/config/ColumnDefinition.java Wed Aug 24 18:52:23 2011
@@ -33,8 +33,6 @@ import org.apache.cassandra.utils.ByteBu
 
 public class ColumnDefinition
 {
-    public final static String D_COLDEF_INDEXTYPE = "KEYS";
-    public final static String D_COLDEF_INDEXNAME = null;
     public final ByteBuffer name;
     private AbstractType validator;
     private IndexType index_type;
@@ -76,26 +74,26 @@ public class ColumnDefinition
         return result;
     }
 
-    public org.apache.cassandra.db.migration.avro.ColumnDef deflate()
+    public org.apache.cassandra.db.migration.avro.ColumnDef toAvro()
     {
         org.apache.cassandra.db.migration.avro.ColumnDef cd = new org.apache.cassandra.db.migration.avro.ColumnDef();
-        cd.name = name;
+        cd.name = ByteBufferUtil.clone(name);
         cd.validation_class = new Utf8(validator.toString());
-        cd.index_type = index_type == null ? null :
-            Enum.valueOf(org.apache.cassandra.db.migration.avro.IndexType.class, index_type.name());
+        cd.index_type = index_type == null
+                      ? null
+                      : org.apache.cassandra.db.migration.avro.IndexType.valueOf(index_type.name());
         cd.index_name = index_name == null ? null : new Utf8(index_name);
         return cd;
     }
 
-    public static ColumnDefinition inflate(org.apache.cassandra.db.migration.avro.ColumnDef cd)
+    public static ColumnDefinition fromAvro(org.apache.cassandra.db.migration.avro.ColumnDef cd)
     {
-        IndexType index_type = cd.index_type == null ? null :
-            Enum.valueOf(IndexType.class, cd.index_type.name());
+        IndexType index_type = cd.index_type == null ? null : Enum.valueOf(IndexType.class, cd.index_type.name());
         String index_name = cd.index_name == null ? null : cd.index_name.toString();
         try
         {
             AbstractType validatorType = TypeParser.parse(cd.validation_class);
-            return new ColumnDefinition(cd.name, validatorType, index_type, index_name);
+            return new ColumnDefinition(ByteBufferUtil.clone(cd.name), validatorType, index_type, index_name);
         }
         catch (ConfigurationException e)
         {
@@ -103,39 +101,25 @@ public class ColumnDefinition
         }
     }
 
-    public static ColumnDefinition fromColumnDef(ColumnDef thriftColumnDef) throws ConfigurationException
+    public static ColumnDefinition fromThrift(ColumnDef thriftColumnDef) throws ConfigurationException
     {
-        AbstractType validatorType = TypeParser.parse(thriftColumnDef.validation_class);
-        return new ColumnDefinition(ByteBufferUtil.clone(thriftColumnDef.name), validatorType, thriftColumnDef.index_type, thriftColumnDef.index_name);
-    }
-    
-    public static ColumnDefinition fromColumnDef(org.apache.cassandra.db.migration.avro.ColumnDef avroColumnDef) throws ConfigurationException
-    {
-        validateIndexType(avroColumnDef);
-        AbstractType validatorType = TypeParser.parse(avroColumnDef.validation_class);
-        return new ColumnDefinition(avroColumnDef.name,
-                validatorType,
-                IndexType.valueOf(avroColumnDef.index_type == null ? D_COLDEF_INDEXTYPE : avroColumnDef.index_type.name()),
-                avroColumnDef.index_name == null ? D_COLDEF_INDEXNAME : avroColumnDef.index_name.toString());
+        return new ColumnDefinition(ByteBufferUtil.clone(thriftColumnDef.name),
+                                    TypeParser.parse(thriftColumnDef.validation_class),
+                                    thriftColumnDef.index_type,
+                                    thriftColumnDef.index_name);
     }
 
-    public static Map<ByteBuffer, ColumnDefinition> fromColumnDef(List<ColumnDef> thriftDefs) throws ConfigurationException
+    public static Map<ByteBuffer, ColumnDefinition> fromThrift(List<ColumnDef> thriftDefs) throws ConfigurationException
     {
         if (thriftDefs == null)
             return new HashMap<ByteBuffer,ColumnDefinition>();
 
         Map<ByteBuffer, ColumnDefinition> cds = new TreeMap<ByteBuffer, ColumnDefinition>();
         for (ColumnDef thriftColumnDef : thriftDefs)
-            cds.put(ByteBufferUtil.clone(thriftColumnDef.name), fromColumnDef(thriftColumnDef));
+            cds.put(ByteBufferUtil.clone(thriftColumnDef.name), fromThrift(thriftColumnDef));
 
         return cds;
     }
-    
-    public static void validateIndexType(org.apache.cassandra.db.migration.avro.ColumnDef avroColumnDef) throws ConfigurationException
-    {
-        if ((avroColumnDef.index_name != null) && (avroColumnDef.index_type == null))
-            throw new ConfigurationException("index_name cannot be set if index_type is not also set");
-    }
 
     @Override
     public String toString()
@@ -158,7 +142,6 @@ public class ColumnDefinition
         index_name = s;
     }
 
-
     public IndexType getIndexType()
     {
         return index_type;

Modified: cassandra/trunk/src/java/org/apache/cassandra/config/KSMetaData.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/config/KSMetaData.java?rev=1161230&r1=1161229&r2=1161230&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/config/KSMetaData.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/config/KSMetaData.java Wed Aug 24 18:52:23 2011
@@ -96,7 +96,6 @@ public final class KSMetaData
         return other.name.equals(name)
                 && ObjectUtils.equals(other.strategyClass, strategyClass)
                 && ObjectUtils.equals(other.strategyOptions, strategyOptions)
-                && other.cfMetaData.size() == cfMetaData.size()
                 && other.cfMetaData.equals(cfMetaData)
                 && other.durable_writes == durable_writes;
     }
@@ -106,7 +105,7 @@ public final class KSMetaData
         return cfMetaData;
     }
         
-    public org.apache.cassandra.db.migration.avro.KsDef deflate()
+    public org.apache.cassandra.db.migration.avro.KsDef toAvro()
     {
         org.apache.cassandra.db.migration.avro.KsDef ks = new org.apache.cassandra.db.migration.avro.KsDef();
         ks.name = new Utf8(name);
@@ -121,7 +120,7 @@ public final class KSMetaData
         }
         ks.cf_defs = SerDeUtils.createArray(cfMetaData.size(), org.apache.cassandra.db.migration.avro.CfDef.SCHEMA$);
         for (CFMetaData cfm : cfMetaData.values())
-            ks.cf_defs.add(cfm.deflate());
+            ks.cf_defs.add(cfm.toAvro());
         
         ks.durable_writes = durable_writes;
         
@@ -142,7 +141,7 @@ public final class KSMetaData
         return sb.toString();
     }
 
-    public static KSMetaData inflate(org.apache.cassandra.db.migration.avro.KsDef ks)
+    public static KSMetaData fromAvro(org.apache.cassandra.db.migration.avro.KsDef ks)
     {
         Class<? extends AbstractReplicationStrategy> repStratClass;
         try
@@ -178,7 +177,7 @@ public final class KSMetaData
         CFMetaData[] cfMetaData = new CFMetaData[cfsz];
         Iterator<org.apache.cassandra.db.migration.avro.CfDef> cfiter = ks.cf_defs.iterator();
         for (int i = 0; i < cfsz; i++)
-            cfMetaData[i] = CFMetaData.inflate(cfiter.next());
+            cfMetaData[i] = CFMetaData.fromAvro(cfiter.next());
 
         return new KSMetaData(ks.name.toString(), repStratClass, strategyOptions, ks.durable_writes, cfMetaData);
     }
@@ -205,16 +204,16 @@ public final class KSMetaData
                               cfDefs);
     }
 
-    public static KsDef toThrift(KSMetaData ksm)
+    public KsDef toThrift()
     {
         List<CfDef> cfDefs = new ArrayList<CfDef>();
-        for (CFMetaData cfm : ksm.cfMetaData().values())
-            cfDefs.add(CFMetaData.convertToThrift(cfm));
-        KsDef ksdef = new KsDef(ksm.name, ksm.strategyClass.getName(), cfDefs);
-        ksdef.setStrategy_options(ksm.strategyOptions);
-        if (ksm.strategyOptions != null && ksm.strategyOptions.containsKey("replication_factor"))
-            ksdef.setReplication_factor(Integer.parseInt(ksm.strategyOptions.get("replication_factor")));
-        ksdef.setDurable_writes(ksm.durable_writes);
+        for (CFMetaData cfm : cfMetaData().values())
+            cfDefs.add(cfm.toThrift());
+        KsDef ksdef = new KsDef(name, strategyClass.getName(), cfDefs);
+        ksdef.setStrategy_options(strategyOptions);
+        if (strategyOptions != null && strategyOptions.containsKey("replication_factor"))
+            ksdef.setReplication_factor(Integer.parseInt(strategyOptions.get("replication_factor")));
+        ksdef.setDurable_writes(durable_writes);
 
         return ksdef;
     }

Modified: cassandra/trunk/src/java/org/apache/cassandra/cql/AlterTableStatement.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/AlterTableStatement.java?rev=1161230&r1=1161229&r2=1161230&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/AlterTableStatement.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/AlterTableStatement.java Wed Aug 24 18:52:23 2011
@@ -55,7 +55,7 @@ public class AlterTableStatement
     {
         CFMetaData meta = Schema.instance.getCFMetaData(keyspace, columnFamily);
 
-        CfDef cfDef = CFMetaData.convertToAvro(meta);
+        CfDef cfDef = meta.toAvro();
 
         ByteBuffer columnName = meta.comparator.fromString(this.columnName);
 
@@ -70,7 +70,7 @@ public class AlterTableStatement
                 cfDef.column_metadata.add(new ColumnDefinition(columnName,
                                                                TypeParser.parse(validator),
                                                                null,
-                                                               null).deflate());
+                                                               null).toAvro());
                 break;
 
             case ALTER:
@@ -83,7 +83,7 @@ public class AlterTableStatement
 
                 column.setValidator(TypeParser.parse(validator));
 
-                cfDef.column_metadata.add(column.deflate());
+                cfDef.column_metadata.add(column.toAvro());
                 break;
 
             case DROP:

Modified: cassandra/trunk/src/java/org/apache/cassandra/cql/DropIndexStatement.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/DropIndexStatement.java?rev=1161230&r1=1161229&r2=1161230&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/DropIndexStatement.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/DropIndexStatement.java Wed Aug 24 18:52:23 2011
@@ -21,8 +21,8 @@
 package org.apache.cassandra.cql;
 
 import java.io.IOException;
-import java.util.Map;
 
+import org.apache.avro.util.Utf8;
 import org.apache.cassandra.config.*;
 import org.apache.cassandra.db.migration.avro.CfDef;
 import org.apache.cassandra.db.migration.avro.ColumnDef;
@@ -31,11 +31,11 @@ import org.apache.cassandra.thrift.Inval
 
 public class DropIndexStatement
 {
-    public final String index;
+    public final CharSequence index;
 
     public DropIndexStatement(String indexName)
     {
-        index = indexName;
+        index = new Utf8(indexName);
     }
 
     public UpdateColumnFamily generateMutation(String keyspace)
@@ -45,12 +45,9 @@ public class DropIndexStatement
 
         KSMetaData ksm = Schema.instance.getTableDefinition(keyspace);
 
-        for (Map.Entry<String, CFMetaData> cf : ksm.cfMetaData().entrySet())
+        for (CFMetaData cfm : ksm.cfMetaData().values())
         {
-            CFMetaData cfm = cf.getValue();
-
-            cfDef = getUpdatedCFDef(CFMetaData.convertToAvro(cfm));
-
+            cfDef = getUpdatedCFDef(cfm.toAvro());
             if (cfDef != null)
                 break;
         }
@@ -63,20 +60,16 @@ public class DropIndexStatement
 
     private CfDef getUpdatedCFDef(CfDef cfDef) throws InvalidRequestException
     {
-
-        boolean foundColumn = false;
-
         for (ColumnDef column : cfDef.column_metadata)
         {
             if (column.index_type != null && column.index_name != null && column.index_name.equals(index))
             {
-                foundColumn = true;
-
                 column.index_name = null;
                 column.index_type = null;
+                return cfDef;
             }
         }
 
-        return (foundColumn) ? cfDef : null;
+        return null;
     }
 }

Modified: cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java?rev=1161230&r1=1161229&r2=1161230&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java Wed Aug 24 18:52:23 2011
@@ -30,19 +30,16 @@ import java.util.concurrent.ExecutionExc
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeoutException;
 
-import com.google.common.base.Predicates;
-import com.google.common.collect.Maps;
-import org.apache.cassandra.db.CounterColumn;
-import org.apache.cassandra.db.context.CounterContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.antlr.runtime.*;
 import org.apache.cassandra.auth.Permission;
 import org.apache.cassandra.concurrent.Stage;
 import org.apache.cassandra.concurrent.StageManager;
-import org.apache.cassandra.config.*;
+import org.apache.cassandra.config.CFMetaData;
+import org.apache.cassandra.config.ConfigurationException;
+import org.apache.cassandra.config.KSMetaData;
+import org.apache.cassandra.config.Schema;
+import org.apache.cassandra.db.CounterColumn;
 import org.apache.cassandra.db.*;
+import org.apache.cassandra.db.context.CounterContext;
 import org.apache.cassandra.db.filter.QueryPath;
 import org.apache.cassandra.db.marshal.AbstractType;
 import org.apache.cassandra.db.marshal.MarshalException;
@@ -52,11 +49,18 @@ import org.apache.cassandra.dht.Token;
 import org.apache.cassandra.service.ClientState;
 import org.apache.cassandra.service.StorageProxy;
 import org.apache.cassandra.service.StorageService;
-import org.apache.cassandra.thrift.Column;
 import org.apache.cassandra.thrift.*;
+import org.apache.cassandra.thrift.Column;
 import org.apache.cassandra.utils.ByteBufferUtil;
 import org.apache.cassandra.utils.FBUtilities;
 
+import com.google.common.base.Predicates;
+import com.google.common.collect.Maps;
+import org.antlr.runtime.*;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import static org.apache.cassandra.thrift.ThriftValidation.validateColumnFamily;
 
 public class QueryProcessor
@@ -725,7 +729,7 @@ public class QueryProcessor
                 ByteBuffer columnName = createIdx.getColumnName().getByteBuffer();
                 // mutating oldCfm directly would be bad, but mutating a Thrift copy is fine.  This also
                 // sets us up to use validateCfDef to check for index name collisions.
-                CfDef cf_def = CFMetaData.convertToThrift(oldCfm);
+                CfDef cf_def = oldCfm.toThrift();
                 for (ColumnDef cd : cf_def.column_metadata)
                 {
                     if (cd.name.equals(columnName))
@@ -746,7 +750,16 @@ public class QueryProcessor
                 ThriftValidation.validateCfDef(cf_def, oldCfm);
                 try
                 {
-                    applyMigrationOnStage(new UpdateColumnFamily(CFMetaData.convertToAvro(cf_def)));
+                    org.apache.cassandra.db.migration.avro.CfDef result1;
+                    try
+                    {
+                        result1 = CFMetaData.fromThrift(cf_def).toAvro();
+                    }
+                    catch (Exception e)
+                    {
+                        throw new RuntimeException(e);
+                    }
+                    applyMigrationOnStage(new UpdateColumnFamily(result1));
                 }
                 catch (ConfigurationException e)
                 {

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/DefsTable.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/DefsTable.java?rev=1161230&r1=1161229&r2=1161230&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/DefsTable.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/DefsTable.java Wed Aug 24 18:52:23 2011
@@ -55,7 +55,7 @@ public class DefsTable
         for (String ksname : ksnames)
         {
             KSMetaData ksm = org.apache.cassandra.config.Schema.instance.getTableDefinition(ksname);
-            rm.add(new QueryPath(Migration.SCHEMA_CF, null, ByteBufferUtil.bytes(ksm.name)), SerDeUtils.serialize(ksm.deflate()), now);
+            rm.add(new QueryPath(Migration.SCHEMA_CF, null, ByteBufferUtil.bytes(ksm.name)), SerDeUtils.serialize(ksm.toAvro()), now);
         }
         // add the schema
         rm.add(new QueryPath(Migration.SCHEMA_CF,
@@ -96,7 +96,7 @@ public class DefsTable
             if (column.name().equals(DEFINITION_SCHEMA_COLUMN_NAME))
                 continue;
             org.apache.cassandra.db.migration.avro.KsDef ks = SerDeUtils.deserialize(schema, column.value(), new org.apache.cassandra.db.migration.avro.KsDef());
-            keyspaces.add(KSMetaData.inflate(ks));
+            keyspaces.add(KSMetaData.fromAvro(ks));
         }
         return keyspaces;
     }

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=1161230&r1=1161229&r2=1161230&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 Wed Aug 24 18:52:23 2011
@@ -96,14 +96,14 @@ public class AddColumnFamily extends Mig
     public void subdeflate(org.apache.cassandra.db.migration.avro.Migration mi)
     {
         org.apache.cassandra.db.migration.avro.AddColumnFamily acf = new org.apache.cassandra.db.migration.avro.AddColumnFamily();
-        acf.cf = cfm.deflate();
+        acf.cf = cfm.toAvro();
         mi.migration = acf;
     }
 
     public void subinflate(org.apache.cassandra.db.migration.avro.Migration mi)
     {
         org.apache.cassandra.db.migration.avro.AddColumnFamily acf = (org.apache.cassandra.db.migration.avro.AddColumnFamily)mi.migration;
-        cfm = CFMetaData.inflate(acf.cf);
+        cfm = CFMetaData.fromAvro(acf.cf);
     }
 
     @Override

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=1161230&r1=1161229&r2=1161230&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 Wed Aug 24 18:52:23 2011
@@ -76,14 +76,14 @@ public class AddKeyspace extends Migrati
     public void subdeflate(org.apache.cassandra.db.migration.avro.Migration mi)
     {
         org.apache.cassandra.db.migration.avro.AddKeyspace aks = new org.apache.cassandra.db.migration.avro.AddKeyspace();
-        aks.ks = ksm.deflate();
+        aks.ks = ksm.toAvro();
         mi.migration = aks;
     }
 
     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);
+        ksm = KSMetaData.fromAvro(aks.ks);
     }
 
     @Override

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=1161230&r1=1161229&r2=1161230&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 Wed Aug 24 18:52:23 2011
@@ -220,7 +220,7 @@ public abstract class Migration
         long now = System.currentTimeMillis();
         // add a column for each keyspace
         for (KSMetaData ksm : ksms)
-            rm.add(new QueryPath(SCHEMA_CF, null, ByteBufferUtil.bytes(ksm.name)), SerDeUtils.serialize(ksm.deflate()), now);
+            rm.add(new QueryPath(SCHEMA_CF, null, ByteBufferUtil.bytes(ksm.name)), SerDeUtils.serialize(ksm.toAvro()), now);
         // add the schema
         rm.add(new QueryPath(SCHEMA_CF,
                              null,

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/migration/UpdateColumnFamily.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/migration/UpdateColumnFamily.java?rev=1161230&r1=1161229&r2=1161230&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/migration/UpdateColumnFamily.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/migration/UpdateColumnFamily.java Wed Aug 24 18:52:23 2011
@@ -56,11 +56,11 @@ public class UpdateColumnFamily extends 
         CFMetaData oldCfm = schema.getCFMetaData(cf_def.keyspace.toString(), cf_def.name.toString());
         
         // create a copy of the old CF meta data. Apply new settings on top of it.
-        this.metadata = CFMetaData.inflate(oldCfm.deflate());
+        this.metadata = CFMetaData.fromAvro(oldCfm.toAvro());
         this.metadata.apply(cf_def);
         
         // create a copy of the old KS meta data. Use it to create a RowMutation that gets applied to schema and migrations.
-        KSMetaData newKsMeta = KSMetaData.inflate(ksm.deflate());
+        KSMetaData newKsMeta = KSMetaData.fromAvro(ksm.toAvro());
         newKsMeta.cfMetaData().get(cf_def.name.toString()).apply(cf_def);
         rm = makeDefinitionMutation(newKsMeta, null, newVersion);
     }
@@ -71,8 +71,8 @@ public class UpdateColumnFamily extends 
         // apply the meta update.
         try 
         {
-            schema.getCFMetaData(metadata.cfId).apply(CFMetaData.convertToAvro(metadata));
-        } 
+            schema.getCFMetaData(metadata.cfId).apply(metadata.toAvro());
+        }
         catch (ConfigurationException ex) 
         {
             throw new IOException(ex);
@@ -90,14 +90,14 @@ public class UpdateColumnFamily extends 
     public void subdeflate(org.apache.cassandra.db.migration.avro.Migration mi)
     {
         org.apache.cassandra.db.migration.avro.UpdateColumnFamily update = new org.apache.cassandra.db.migration.avro.UpdateColumnFamily();
-        update.metadata = metadata.deflate();
+        update.metadata = metadata.toAvro();
         mi.migration = update;
     }
 
     public void subinflate(org.apache.cassandra.db.migration.avro.Migration mi)
     {
         org.apache.cassandra.db.migration.avro.UpdateColumnFamily update = (org.apache.cassandra.db.migration.avro.UpdateColumnFamily)mi.migration;
-        metadata = CFMetaData.inflate(update.metadata);
+        metadata = CFMetaData.fromAvro(update.metadata);
     }
 
     @Override

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/migration/UpdateKeyspace.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/migration/UpdateKeyspace.java?rev=1161230&r1=1161229&r2=1161230&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/migration/UpdateKeyspace.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/migration/UpdateKeyspace.java Wed Aug 24 18:52:23 2011
@@ -74,16 +74,16 @@ public class UpdateKeyspace extends Migr
     public void subdeflate(org.apache.cassandra.db.migration.avro.Migration mi)
     {
         org.apache.cassandra.db.migration.avro.UpdateKeyspace uks = new org.apache.cassandra.db.migration.avro.UpdateKeyspace();
-        uks.newKs = newKsm.deflate();
-        uks.oldKs = oldKsm.deflate();
+        uks.newKs = newKsm.toAvro();
+        uks.oldKs = oldKsm.toAvro();
         mi.migration = uks;
     }
 
     public void subinflate(org.apache.cassandra.db.migration.avro.Migration mi)
     {
         org.apache.cassandra.db.migration.avro.UpdateKeyspace uks = (org.apache.cassandra.db.migration.avro.UpdateKeyspace)mi.migration;
-        newKsm = KSMetaData.inflate(uks.newKs);
-        oldKsm = KSMetaData.inflate(uks.oldKs);
+        newKsm = KSMetaData.fromAvro(uks.newKs);
+        oldKsm = KSMetaData.fromAvro(uks.oldKs);
     }
 
     @Override

Modified: cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java?rev=1161230&r1=1161229&r2=1161230&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java Wed Aug 24 18:52:23 2011
@@ -653,7 +653,7 @@ public class CassandraServer implements 
         if (ksm == null)
             throw new NotFoundException();
 
-        return KSMetaData.toThrift(ksm);
+        return ksm.toThrift();
     }
 
     public List<KeySlice> get_range_slices(ColumnParent column_parent, SlicePredicate predicate, KeyRange range, ConsistencyLevel consistency_level)
@@ -1043,7 +1043,16 @@ public class CassandraServer implements 
         {
             // ideally, apply() would happen on the stage with the
             CFMetaData.applyImplicitDefaults(cf_def);
-            UpdateColumnFamily update = new UpdateColumnFamily(CFMetaData.convertToAvro(cf_def));
+            org.apache.cassandra.db.migration.avro.CfDef result;
+            try
+            {
+                result = CFMetaData.fromThrift(cf_def).toAvro();
+            }
+            catch (Exception e)
+            {
+                throw new RuntimeException(e);
+            }
+            UpdateColumnFamily update = new UpdateColumnFamily(result);
             applyMigrationOnStage(update);
             return Schema.instance.getVersion().toString();
         }

Modified: cassandra/trunk/test/unit/org/apache/cassandra/SchemaLoader.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/SchemaLoader.java?rev=1161230&r1=1161229&r2=1161230&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/SchemaLoader.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/SchemaLoader.java Wed Aug 24 18:52:23 2011
@@ -282,6 +282,6 @@ public class SchemaLoader
     }
     private static CFMetaData jdbcCFMD(String ksName, String cfName, AbstractType comp)
     {
-        return new CFMetaData(ksName, cfName, ColumnFamilyType.Standard, comp, comp).defaultValidator(comp);
+        return new CFMetaData(ksName, cfName, ColumnFamilyType.Standard, comp, null).defaultValidator(comp);
     }
 }

Added: cassandra/trunk/test/unit/org/apache/cassandra/config/CFMetaDataTest.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/config/CFMetaDataTest.java?rev=1161230&view=auto
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/config/CFMetaDataTest.java (added)
+++ cassandra/trunk/test/unit/org/apache/cassandra/config/CFMetaDataTest.java Wed Aug 24 18:52:23 2011
@@ -0,0 +1,91 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cassandra.config;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.avro.util.Utf8;
+import org.apache.cassandra.db.marshal.AsciiType;
+import org.apache.cassandra.db.marshal.UTF8Type;
+import org.apache.cassandra.thrift.CfDef;
+import org.apache.cassandra.thrift.ColumnDef;
+import org.apache.cassandra.thrift.IndexType;
+import org.apache.cassandra.utils.ByteBufferUtil;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class CFMetaDataTest
+{
+    private static String KEYSPACE = "Keyspace1";
+    private static String COLUMN_FAMILY = "Standard1";
+
+    private static List<ColumnDef> columnDefs = new ArrayList<ColumnDef>();
+
+    static
+    {
+        columnDefs.add(new ColumnDef(ByteBufferUtil.bytes("col1"), AsciiType.class.getCanonicalName())
+                                    .setIndex_name("col1Index")
+                                    .setIndex_type(IndexType.KEYS));
+
+        columnDefs.add(new ColumnDef(ByteBufferUtil.bytes("col2"), UTF8Type.class.getCanonicalName())
+                                    .setIndex_name("col2Index")
+                                    .setIndex_type(IndexType.KEYS));
+    }
+
+    @Test
+    public void testThriftToAvroConversion() throws Exception
+    {
+        CfDef cfDef = new CfDef().setDefault_validation_class(AsciiType.class.getCanonicalName())
+                                 .setComment("Test comment")
+                                 .setColumn_metadata(columnDefs)
+                                 .setKeyspace(KEYSPACE)
+                                 .setName(COLUMN_FAMILY);
+
+        // convert Thrift to CFMetaData
+        CFMetaData cfMetaData = CFMetaData.fromThrift(cfDef);
+
+        // make a correct Avro object
+        org.apache.cassandra.db.migration.avro.CfDef avroCfDef = new org.apache.cassandra.db.migration.avro.CfDef();
+        avroCfDef.keyspace = new Utf8(KEYSPACE);
+        avroCfDef.name = new Utf8(COLUMN_FAMILY);
+        avroCfDef.default_validation_class = new Utf8(cfDef.default_validation_class);
+        avroCfDef.comment = new Utf8(cfDef.comment);
+        avroCfDef.column_metadata = new ArrayList<org.apache.cassandra.db.migration.avro.ColumnDef>();
+        for (ColumnDef columnDef : columnDefs)
+        {
+            org.apache.cassandra.db.migration.avro.ColumnDef c = new org.apache.cassandra.db.migration.avro.ColumnDef();
+            c.name = ByteBufferUtil.clone(columnDef.name);
+            c.validation_class = new Utf8(columnDef.getValidation_class());
+            c.index_name = new Utf8(columnDef.getIndex_name());
+            c.index_type = org.apache.cassandra.db.migration.avro.IndexType.KEYS;
+            avroCfDef.column_metadata.add(c);
+        }
+
+        org.apache.cassandra.db.migration.avro.CfDef converted = cfMetaData.toAvro();
+
+        assertEquals(avroCfDef.keyspace, converted.keyspace);
+        assertEquals(avroCfDef.name, converted.name);
+        assertEquals(avroCfDef.default_validation_class, converted.default_validation_class);
+        assertEquals(avroCfDef.comment, converted.comment);
+        assertEquals(avroCfDef.column_metadata, converted.column_metadata);
+    }
+}

Modified: cassandra/trunk/test/unit/org/apache/cassandra/config/ColumnDefinitionTest.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/config/ColumnDefinitionTest.java?rev=1161230&r1=1161229&r2=1161230&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/config/ColumnDefinitionTest.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/config/ColumnDefinitionTest.java Wed Aug 24 18:52:23 2011
@@ -49,7 +49,7 @@ public class ColumnDefinitionTest
 
     protected void testSerializeDeserialize(ColumnDefinition cd) throws Exception
     {
-        ColumnDefinition newCd = ColumnDefinition.inflate(cd.deflate());
+        ColumnDefinition newCd = ColumnDefinition.fromAvro(cd.toAvro());
         assert cd != newCd;
         assert cd.hashCode() == newCd.hashCode();
         assert cd.equals(newCd);

Modified: cassandra/trunk/test/unit/org/apache/cassandra/config/DatabaseDescriptorTest.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/config/DatabaseDescriptorTest.java?rev=1161230&r1=1161229&r2=1161230&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/config/DatabaseDescriptorTest.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/config/DatabaseDescriptorTest.java Wed Aug 24 18:52:23 2011
@@ -51,7 +51,7 @@ public class DatabaseDescriptorTest
         {
             for (CFMetaData cfm : Schema.instance.getTableMetaData(table).values())
             {
-                CFMetaData cfmDupe = CFMetaData.inflate(serDe(cfm.deflate(), new org.apache.cassandra.db.migration.avro.CfDef()));
+                CFMetaData cfmDupe = CFMetaData.fromAvro(serDe(cfm.toAvro(), new org.apache.cassandra.db.migration.avro.CfDef()));
                 assert cfmDupe != null;
                 assert cfmDupe.equals(cfm);
             }
@@ -65,7 +65,7 @@ public class DatabaseDescriptorTest
         {
             // Not testing round-trip on the KsDef via serDe() because maps
             //  cannot be compared in avro.
-            KSMetaData ksmDupe = KSMetaData.inflate(ksm.deflate());
+            KSMetaData ksmDupe = KSMetaData.fromAvro(ksm.toAvro());
             assert ksmDupe != null;
             assert ksmDupe.equals(ksm);
         }

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=1161230&r1=1161229&r2=1161230&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/db/DefsTest.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/db/DefsTest.java Wed Aug 24 18:52:23 2011
@@ -119,7 +119,7 @@ public class DefsTest extends CleanupHel
 
         // we'll be adding this one later. make sure it's not already there.
         assert cfm.getColumn_metadata().get(ByteBuffer.wrap(new byte[] { 5 })) == null;
-        org.apache.cassandra.db.migration.avro.CfDef cfDef = CFMetaData.convertToAvro(cfm);
+        org.apache.cassandra.db.migration.avro.CfDef cfDef = cfm.toAvro();
         
         // add one.
         org.apache.cassandra.db.migration.avro.ColumnDef addIndexDef = new org.apache.cassandra.db.migration.avro.ColumnDef();
@@ -131,10 +131,10 @@ public class DefsTest extends CleanupHel
         
         // remove one.
         org.apache.cassandra.db.migration.avro.ColumnDef removeIndexDef = new org.apache.cassandra.db.migration.avro.ColumnDef();
-        removeIndexDef.index_name = "0";
+        removeIndexDef.index_name = new Utf8("0");
         removeIndexDef.index_type = org.apache.cassandra.db.migration.avro.IndexType.KEYS;
         removeIndexDef.name = ByteBuffer.wrap(new byte[] { 0 });
-        removeIndexDef.validation_class = BytesType.class.getName();
+        removeIndexDef.validation_class = new Utf8(BytesType.class.getName());
         assert cfDef.column_metadata.remove(removeIndexDef);
         
         cfm.apply(cfDef);
@@ -170,7 +170,7 @@ public class DefsTest extends CleanupHel
         for (KSMetaData loaded : defs)
         {
             KSMetaData defined = Schema.instance.getTableDefinition(loaded.name);
-            assert defined.equals(loaded);
+            assert defined.equals(loaded) : String.format("%s != %s", loaded, defined);
         }
     }
     
@@ -659,7 +659,7 @@ public class DefsTest extends CleanupHel
         assert Schema.instance.getCFMetaData(cf.ksName, cf.cfName) != null;
         
         // updating certain fields should fail.
-        org.apache.cassandra.db.migration.avro.CfDef cf_def = CFMetaData.convertToAvro(cf);
+        org.apache.cassandra.db.migration.avro.CfDef cf_def = cf.toAvro();
         cf_def.row_cache_size = 43.3;
         cf_def.column_metadata = new ArrayList<org.apache.cassandra.db.migration.avro.ColumnDef>();
         cf_def.default_validation_class ="BytesType";
@@ -803,7 +803,7 @@ public class DefsTest extends CleanupHel
         ColumnDefinition cdOld = meta.getColumn_metadata().values().iterator().next();
         ColumnDefinition cdNew = new ColumnDefinition(cdOld.name, cdOld.getValidator(), null, null);
         meta.columnMetadata(Collections.singletonMap(cdOld.name, cdNew));
-        UpdateColumnFamily update = new UpdateColumnFamily(CFMetaData.convertToAvro(meta));
+        UpdateColumnFamily update = new UpdateColumnFamily(meta.toAvro());
         update.apply();
 
         // check

Modified: cassandra/trunk/test/unit/org/apache/cassandra/thrift/ThriftValidationTest.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/thrift/ThriftValidationTest.java?rev=1161230&r1=1161229&r2=1161230&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/thrift/ThriftValidationTest.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/thrift/ThriftValidationTest.java Wed Aug 24 18:52:23 2011
@@ -50,7 +50,7 @@ public class ThriftValidationTest extend
     @Test
     public void testColumnValueSizeForIndexedColumn() throws ConfigurationException, InvalidRequestException
     {
-        CfDef cfDef = CFMetaData.convertToThrift(Schema.instance.getCFMetaData("Keyspace1", "Standard1"));
+        CfDef cfDef = Schema.instance.getCFMetaData("Keyspace1", "Standard1").toThrift();
         ByteBuffer columnName = AsciiType.instance.fromString("indexed");
 
         // add an indexed column definition
@@ -100,7 +100,7 @@ public class ThriftValidationTest extend
     public void testColumnNameEqualToKeyAlias()
     {
         CFMetaData metaData = Schema.instance.getCFMetaData("Keyspace1", "Standard1");
-        CfDef newMetadata = CFMetaData.convertToThrift(metaData);
+        CfDef newMetadata = metaData.toThrift();
 
         boolean gotException = false;
 



Mime
View raw message