cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r960972 - in /cassandra/trunk: src/java/org/apache/cassandra/config/ test/conf/
Date Tue, 06 Jul 2010 18:21:23 GMT
Author: jbellis
Date: Tue Jul  6 18:21:22 2010
New Revision: 960972

URL: http://svn.apache.org/viewvc?rev=960972&view=rev
Log:
introduce RawColumnDefinition for yaml import and fix CFMetaData deserialize bug.  patch by
jbellis

Added:
    cassandra/trunk/src/java/org/apache/cassandra/config/RawColumnDefinition.java
Modified:
    cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java
    cassandra/trunk/src/java/org/apache/cassandra/config/ColumnFamily.java
    cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
    cassandra/trunk/test/conf/cassandra.yaml

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=960972&r1=960971&r2=960972&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java Tue Jul  6 18:21:22
2010
@@ -255,14 +255,13 @@ public final class CFMetaData
         double keyCacheSize = din.readDouble();
         double readRepairChance = din.readDouble();
         int cfId = din.readInt();
-        int columnMetadataSize = din.readInt();
+        int columnMetadataEntries = din.readInt();
         Map<byte[], ColumnDefinition> column_metadata = new TreeMap<byte[], ColumnDefinition>(FBUtilities.byteArrayComparator);
-        while (columnMetadataSize > 0)
+        for (int i = 0; i < columnMetadataEntries; i++)
         {
             int cdSize = din.readInt();
             byte[] cdBytes = new byte[cdSize];
-            if (in.read(cdBytes) != cdSize)
-                throw new IOException("short read of ColumnDefinition");
+            din.readFully(cdBytes);
             ColumnDefinition cd = ColumnDefinition.deserialize(cdBytes);
             column_metadata.put(cd.name, cd);
         }

Modified: cassandra/trunk/src/java/org/apache/cassandra/config/ColumnFamily.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/config/ColumnFamily.java?rev=960972&r1=960971&r2=960972&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/config/ColumnFamily.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/config/ColumnFamily.java Tue Jul  6 18:21:22
2010
@@ -18,5 +18,5 @@ public class ColumnFamily {
     public double keys_cached = CFMetaData.DEFAULT_KEY_CACHE_SIZE; 
     public double read_repair_chance = CFMetaData.DEFAULT_READ_REPAIR_CHANCE;
     public boolean preload_row_cache = CFMetaData.DEFAULT_PRELOAD_ROW_CACHE;
-    public Map<byte[], ColumnDefinition> column_metata = Collections.emptyMap();
+    public RawColumnDefinition[] column_metadata = new RawColumnDefinition[0];
 }

Modified: cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java?rev=960972&r1=960971&r2=960972&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java Tue Jul 
6 18:21:22 2010
@@ -115,11 +115,14 @@ public class DatabaseDescriptor
             InputStream input = new FileInputStream(new File(configFileName));
             org.yaml.snakeyaml.constructor.Constructor constructor = new org.yaml.snakeyaml.constructor.Constructor(Config.class);
             TypeDescription desc = new TypeDescription(Config.class);
+            desc.putListPropertyType("keyspaces", Keyspace.class);
             TypeDescription ksDesc = new TypeDescription(Keyspace.class);
             ksDesc.putListPropertyType("column_families", ColumnFamily.class);
-            desc.putListPropertyType("keyspaces", Keyspace.class);
+            TypeDescription cfDesc = new TypeDescription(ColumnFamily.class);
+            cfDesc.putListPropertyType("column_metadata", RawColumnDefinition.class);
             constructor.addTypeDescription(desc);
             constructor.addTypeDescription(ksDesc);
+            constructor.addTypeDescription(cfDesc);
             Yaml yaml = new Yaml(new Loader(constructor));
             conf = (Config)yaml.load(input);
             
@@ -536,7 +539,34 @@ public class DatabaseDescriptor
                 {                        
                     throw new ConfigurationException("read_repair_chance must be between
0.0 and 1.0");
                 }
-                cfDefs[j++] = new CFMetaData(keyspace.name, cf.name, cfType, cf.clock_type,
comparator, subcolumnComparator, reconciler, cf.comment, cf.rows_cached, cf.preload_row_cache,
cf.keys_cached, cf.read_repair_chance, cf.column_metata);
+                
+                Map<byte[], ColumnDefinition> metadata = new TreeMap<byte[], ColumnDefinition>(FBUtilities.byteArrayComparator);
+                for (RawColumnDefinition rcd : cf.column_metadata)
+                {
+                    try
+                    {
+                        byte[] columnName = rcd.name.getBytes("UTF-8");
+                        metadata.put(columnName, new ColumnDefinition(columnName, rcd.validator_class,
rcd.index_type, rcd.index_name));
+                    }
+                    catch (UnsupportedEncodingException e)
+                    {
+                        throw new AssertionError(e);
+                    }
+                }
+
+                cfDefs[j++] = new CFMetaData(keyspace.name, 
+                                             cf.name, 
+                                             cfType, 
+                                             cf.clock_type, 
+                                             comparator, 
+                                             subcolumnComparator, 
+                                             reconciler, 
+                                             cf.comment, 
+                                             cf.rows_cached,
+                                             cf.preload_row_cache, 
+                                             cf.keys_cached, 
+                                             cf.read_repair_chance, 
+                                             metadata);
             }
             defs.add(new KSMetaData(keyspace.name, strategyClass, keyspace.replication_factor,
cfDefs));
             

Added: cassandra/trunk/src/java/org/apache/cassandra/config/RawColumnDefinition.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/config/RawColumnDefinition.java?rev=960972&view=auto
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/config/RawColumnDefinition.java (added)
+++ cassandra/trunk/src/java/org/apache/cassandra/config/RawColumnDefinition.java Tue Jul
 6 18:21:22 2010
@@ -0,0 +1,11 @@
+package org.apache.cassandra.config;
+
+import org.apache.cassandra.thrift.IndexType;
+
+public class RawColumnDefinition
+{
+    public String name;
+    public String validator_class;
+    public IndexType index_type;
+    public String index_name;
+}

Modified: cassandra/trunk/test/conf/cassandra.yaml
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/conf/cassandra.yaml?rev=960972&r1=960971&r2=960972&view=diff
==============================================================================
--- cassandra/trunk/test/conf/cassandra.yaml (original)
+++ cassandra/trunk/test/conf/cassandra.yaml Tue Jul  6 18:21:22 2010
@@ -62,6 +62,12 @@ keyspaces:
           column_type: Super
           compare_subcolumns_with: UTF8Type
 
+        - name: Indexed1
+          column_metadata:
+            - name: birthdate
+              validator_class: LongType
+              index_type: KEYS
+
     - name: Keyspace2
       replica_placement_strategy: org.apache.cassandra.locator.RackUnawareStrategy
       replication_factor: 1



Mime
View raw message