cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r960925 - in /cassandra/trunk: interface/ interface/thrift/gen-java/org/apache/cassandra/thrift/ src/java/org/apache/cassandra/config/ src/java/org/apache/cassandra/db/ test/unit/org/apache/cassandra/config/ test/unit/org/apache/cassandra/db/
Date Tue, 06 Jul 2010 15:54:49 GMT
Author: jbellis
Date: Tue Jul  6 15:54:49 2010
New Revision: 960925

URL: http://svn.apache.org/viewvc?rev=960925&view=rev
Log:
switch IndexType to enum.  patch by jbellis

Added:
    cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/IndexType.java
Modified:
    cassandra/trunk/interface/cassandra.thrift
    cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/ColumnDef.java
    cassandra/trunk/src/java/org/apache/cassandra/config/ColumnDefinition.java
    cassandra/trunk/src/java/org/apache/cassandra/db/Table.java
    cassandra/trunk/test/unit/org/apache/cassandra/config/ColumnDefinitionTest.java
    cassandra/trunk/test/unit/org/apache/cassandra/db/DefsTest.java

Modified: cassandra/trunk/interface/cassandra.thrift
URL: http://svn.apache.org/viewvc/cassandra/trunk/interface/cassandra.thrift?rev=960925&r1=960924&r2=960925&view=diff
==============================================================================
--- cassandra/trunk/interface/cassandra.thrift (original)
+++ cassandra/trunk/interface/cassandra.thrift Tue Jul  6 15:54:49 2010
@@ -314,10 +314,14 @@ struct AuthenticationRequest {
     1: required map<string, string> credentials
 }
 
+enum IndexType {
+    KEYS,
+}
+
 struct ColumnDef {
     1: required binary name,
     2: required string validation_class,
-    3: optional string index_type,
+    3: optional IndexType index_type,
     4: optional string index_name
 }
 

Modified: cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/ColumnDef.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/ColumnDef.java?rev=960925&r1=960924&r2=960925&view=diff
==============================================================================
--- cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/ColumnDef.java (original)
+++ cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/ColumnDef.java Tue
Jul  6 15:54:49 2010
@@ -49,18 +49,26 @@ public class ColumnDef implements TBase<
 
   private static final TField NAME_FIELD_DESC = new TField("name", TType.STRING, (short)1);
   private static final TField VALIDATION_CLASS_FIELD_DESC = new TField("validation_class",
TType.STRING, (short)2);
-  private static final TField INDEX_TYPE_FIELD_DESC = new TField("index_type", TType.STRING,
(short)3);
+  private static final TField INDEX_TYPE_FIELD_DESC = new TField("index_type", TType.I32,
(short)3);
   private static final TField INDEX_NAME_FIELD_DESC = new TField("index_name", TType.STRING,
(short)4);
 
   public byte[] name;
   public String validation_class;
-  public String index_type;
+  /**
+   * 
+   * @see IndexType
+   */
+  public IndexType index_type;
   public String index_name;
 
   /** The set of fields this struct contains, along with convenience methods for finding
and manipulating them. */
   public enum _Fields implements TFieldIdEnum {
     NAME((short)1, "name"),
     VALIDATION_CLASS((short)2, "validation_class"),
+    /**
+     * 
+     * @see IndexType
+     */
     INDEX_TYPE((short)3, "index_type"),
     INDEX_NAME((short)4, "index_name");
 
@@ -123,7 +131,7 @@ public class ColumnDef implements TBase<
     put(_Fields.VALIDATION_CLASS, new FieldMetaData("validation_class", TFieldRequirementType.REQUIRED,

         new FieldValueMetaData(TType.STRING)));
     put(_Fields.INDEX_TYPE, new FieldMetaData("index_type", TFieldRequirementType.OPTIONAL,

-        new FieldValueMetaData(TType.STRING)));
+        new EnumMetaData(TType.ENUM, IndexType.class)));
     put(_Fields.INDEX_NAME, new FieldMetaData("index_name", TFieldRequirementType.OPTIONAL,

         new FieldValueMetaData(TType.STRING)));
   }});
@@ -220,11 +228,19 @@ public class ColumnDef implements TBase<
     }
   }
 
-  public String getIndex_type() {
+  /**
+   * 
+   * @see IndexType
+   */
+  public IndexType getIndex_type() {
     return this.index_type;
   }
 
-  public ColumnDef setIndex_type(String index_type) {
+  /**
+   * 
+   * @see IndexType
+   */
+  public ColumnDef setIndex_type(IndexType index_type) {
     this.index_type = index_type;
     return this;
   }
@@ -290,7 +306,7 @@ public class ColumnDef implements TBase<
       if (value == null) {
         unsetIndex_type();
       } else {
-        setIndex_type((String)value);
+        setIndex_type((IndexType)value);
       }
       break;
 
@@ -479,8 +495,8 @@ public class ColumnDef implements TBase<
           }
           break;
         case 3: // INDEX_TYPE
-          if (field.type == TType.STRING) {
-            this.index_type = iprot.readString();
+          if (field.type == TType.I32) {
+            this.index_type = IndexType.findByValue(iprot.readI32());
           } else { 
             TProtocolUtil.skip(iprot, field.type);
           }
@@ -520,7 +536,7 @@ public class ColumnDef implements TBase<
     if (this.index_type != null) {
       if (isSetIndex_type()) {
         oprot.writeFieldBegin(INDEX_TYPE_FIELD_DESC);
-        oprot.writeString(this.index_type);
+        oprot.writeI32(this.index_type.getValue());
         oprot.writeFieldEnd();
       }
     }

Added: cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/IndexType.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/IndexType.java?rev=960925&view=auto
==============================================================================
--- cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/IndexType.java (added)
+++ cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/IndexType.java Tue
Jul  6 15:54:49 2010
@@ -0,0 +1,62 @@
+/**
+ * Autogenerated by Thrift
+ *
+ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+ */
+package org.apache.cassandra.thrift;
+/*
+ * 
+ * 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.
+ * 
+ */
+
+
+
+import java.util.Map;
+import java.util.HashMap;
+import org.apache.thrift.TEnum;
+
+public enum IndexType implements TEnum {
+  KEYS(0);
+
+  private final int value;
+
+  private IndexType(int value) {
+    this.value = value;
+  }
+
+  /**
+   * Get the integer value of this enum value, as defined in the Thrift IDL.
+   */
+  public int getValue() {
+    return value;
+  }
+
+  /**
+   * Find a the enum type by its integer value, as defined in the Thrift IDL.
+   * @return null if the value is not found.
+   */
+  public static IndexType findByValue(int value) { 
+    switch (value) {
+      case 0:
+        return KEYS;
+      default:
+        return null;
+    }
+  }
+}

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=960925&r1=960924&r2=960925&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/config/ColumnDefinition.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/config/ColumnDefinition.java Tue Jul  6
15:54:49 2010
@@ -8,15 +8,16 @@ import org.apache.commons.lang.builder.H
 
 import org.apache.cassandra.db.marshal.AbstractType;
 import org.apache.cassandra.thrift.ColumnDef;
+import org.apache.cassandra.thrift.IndexType;
 import org.apache.cassandra.utils.FBUtilities;
 
 public class ColumnDefinition {
     public final byte[] name;
     public final AbstractType validator;
-    public final String index_type;
+    public final IndexType index_type;
     public final String index_name;
 
-    public ColumnDefinition(byte[] name, String validation_class, String index_type, String
index_name) throws ConfigurationException
+    public ColumnDefinition(byte[] name, String validation_class, IndexType index_type, String
index_name) throws ConfigurationException
     {
         this.name = name;
         this.index_type = index_type;
@@ -62,7 +63,7 @@ public class ColumnDefinition {
 
         out.writeBoolean(cd.index_type != null);
         if (cd.index_type != null)
-            out.writeUTF(cd.index_type);
+            out.writeInt(cd.index_type.ordinal());
 
         out.writeBoolean(cd.index_name != null);
         if (cd.index_name != null)
@@ -80,9 +81,9 @@ public class ColumnDefinition {
         in.readFully(name);
         String validation_class = in.readUTF();
 
-        String index_type = null;
+        IndexType index_type = null;
         if (in.readBoolean())
-            index_type = in.readUTF();
+            index_type = IndexType.values()[in.readInt()];
 
         String index_name = null;
         if (in.readBoolean())

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/Table.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/Table.java?rev=960925&r1=960924&r2=960925&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/Table.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/Table.java Tue Jul  6 15:54:49 2010
@@ -80,7 +80,7 @@ public class Table 
     /* Table name. */
     public final String name;
     /* ColumnFamilyStore per column family */
-    private final Map<Integer, ColumnFamilyStore> columnFamilyStores = new HashMap<Integer,
ColumnFamilyStore>();
+    public final Map<Integer, ColumnFamilyStore> columnFamilyStores = new HashMap<Integer,
ColumnFamilyStore>(); // TODO make private again
     // cache application CFs since Range queries ask for them a _lot_
     private SortedSet<String> applicationColumnFamilies;
     private final TimerTask flushTask;
@@ -279,7 +279,8 @@ public class Table 
     /** adds a cf to internal structures, ends up creating disk files). */
     public void initCf(Integer cfId, String cfName)
     {
-        assert !columnFamilyStores.containsKey(cfId) : cfId;
+        assert !columnFamilyStores.containsKey(cfId) : String.format("tried to init %s as
%s, but already used by %s",
+                                                                     cfName, cfId, columnFamilyStores.get(cfId));
         columnFamilyStores.put(cfId, ColumnFamilyStore.createColumnFamilyStore(name, cfName));
     }
     

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=960925&r1=960924&r2=960925&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/config/ColumnDefinitionTest.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/config/ColumnDefinitionTest.java Tue Jul
 6 15:54:49 2010
@@ -2,6 +2,8 @@ package org.apache.cassandra.config;
 
 import org.junit.Test;
 
+import org.apache.cassandra.thrift.IndexType;
+
 public class ColumnDefinitionTest
 {
     @Test
@@ -9,7 +11,7 @@ public class ColumnDefinitionTest
     {
         ColumnDefinition cd0 = new ColumnDefinition("TestColumnDefinitionName0".getBytes("UTF8"),
                                                     "BytesType",
-                                                    "random index type 0",
+                                                    IndexType.KEYS,
                                                     "random index name 0");
 
         ColumnDefinition cd1 = new ColumnDefinition("TestColumnDefinition1".getBytes("UTF8"),

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=960925&r1=960924&r2=960925&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/db/DefsTest.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/db/DefsTest.java Tue Jul  6 15:54:49 2010
@@ -76,7 +76,7 @@ public class DefsTest extends CleanupHel
             throw new AssertionError("Unexpected exception.");
         }
     }
-    
+
     @Test
     public void testMigrations() throws IOException, ConfigurationException
     {
@@ -85,7 +85,7 @@ public class DefsTest extends CleanupHel
         UUID ver0 = UUIDGen.makeType1UUIDFromHost(FBUtilities.getLocalAddress());
         DefsTable.dumpToStorage(ver0);
         assert DatabaseDescriptor.getDefsVersion().equals(prior);
-        
+
         // add a cf.
         CFMetaData newCf1 = new CFMetaData("Keyspace1", "MigrationCf_1", ColumnFamilyType.Standard,
ClockType.Timestamp, UTF8Type.instance, null, new TimestampReconciler(), "Migration CF ",
0, false, 1.0, 0, Collections.<byte[], ColumnDefinition>emptyMap());
         Migration m1 = new AddColumnFamily(newCf1);



Mime
View raw message