cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xe...@apache.org
Subject git commit: fix "Can't Modify Index Name" problem on CF update patch by Pavel Yaskevich; reviewed by Yuki Morishita for CASSANDRA-4439
Date Wed, 18 Jul 2012 22:15:49 GMT
Updated Branches:
  refs/heads/cassandra-1.1 7c982717a -> 202f3940d


fix "Can't Modify Index Name" problem on CF update
patch by Pavel Yaskevich; reviewed by Yuki Morishita for CASSANDRA-4439


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/202f3940
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/202f3940
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/202f3940

Branch: refs/heads/cassandra-1.1
Commit: 202f3940dc35411f9b2351a026e859e487b94591
Parents: 7c98271
Author: Pavel Yaskevich <xedin@apache.org>
Authored: Tue Jul 17 17:18:46 2012 +0300
Committer: Pavel Yaskevich <xedin@apache.org>
Committed: Thu Jul 19 01:15:28 2012 +0300

----------------------------------------------------------------------
 CHANGES.txt                                        |    1 +
 .../org/apache/cassandra/config/CFMetaData.java    |   22 +++++++++++++++
 test/unit/org/apache/cassandra/cli/CliTest.java    |    8 +++++
 3 files changed, 31 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/202f3940/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 67b5410..b2a9faf 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -14,6 +14,7 @@
  * change nanoTime() to currentTimeInMillis() in schema related code (CASSANDRA-4432)
  * add a token generation tool (CASSANDRA-3709)
  * Fix LCS bug with sstable containing only 1 row (CASSANDRA-4411)
+ * fix "Can't Modify Index Name" problem on CF update (CASSANDRA-4439)
 Merged from 1.0:
  * allow dropping columns shadowed by not-yet-expired supercolumn or row
    tombstones in PrecompactedRow (CASSANDRA-4396)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/202f3940/src/java/org/apache/cassandra/config/CFMetaData.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/config/CFMetaData.java b/src/java/org/apache/cassandra/config/CFMetaData.java
index c6411af..5b3f227 100644
--- a/src/java/org/apache/cassandra/config/CFMetaData.java
+++ b/src/java/org/apache/cassandra/config/CFMetaData.java
@@ -862,6 +862,28 @@ public final class CFMetaData
      */
     public void addDefaultIndexNames() throws ConfigurationException
     {
+        // if this is ColumnFamily update we need to add previously defined index names to
the existing columns first
+        Integer cfId = Schema.instance.getId(ksName, cfName);
+        if (cfId != null)
+        {
+            CFMetaData cfm = Schema.instance.getCFMetaData(cfId);
+
+            for (Map.Entry<ByteBuffer, ColumnDefinition> entry : column_metadata.entrySet())
+            {
+                ColumnDefinition newDef = entry.getValue();
+
+                if (!cfm.column_metadata.containsKey(entry.getKey()) || newDef.getIndexType()
== null)
+                    continue;
+
+                String oldIndexName = cfm.column_metadata.get(entry.getKey()).getIndexName();
+
+                if (newDef.getIndexName() != null && !oldIndexName.equals(newDef.getIndexName()))
+                    throw new ConfigurationException("Can't modify index name: was '" + oldIndexName
+ "' changed to '" + newDef.getIndexName() + "'.");
+
+                newDef.setIndexName(oldIndexName);
+            }
+        }
+
         Set<String> existingNames = existingIndexNames(null);
         for (ColumnDefinition column : column_metadata.values())
         {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/202f3940/test/unit/org/apache/cassandra/cli/CliTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cli/CliTest.java b/test/unit/org/apache/cassandra/cli/CliTest.java
index 756dc7f..c13cf01 100644
--- a/test/unit/org/apache/cassandra/cli/CliTest.java
+++ b/test/unit/org/apache/cassandra/cli/CliTest.java
@@ -39,6 +39,14 @@ public class CliTest extends SchemaLoader
     // please add new statements here so they could be auto-runned by this test.
     private String[] statements = {
         "use TestKeySpace;",
+        "create column family SecondaryIndicesWithoutIdxName" +
+                " with comparator = UTF8Type" +
+                " and default_validation_class = UTF8Type" +
+                " and column_metadata = [{column_name: profileId, validation_class: UTF8Type,
index_type: KEYS}];",
+        "update column family SecondaryIndicesWithoutIdxName" +
+                " with column_metadata = " +
+                "[{column_name: profileId, validation_class: UTF8Type, index_type: KEYS},"
+
+                 "{column_name: postedDate, validation_class: LongType}];",
         "create column family 123 with comparator=UTF8Type and column_metadata=[{ column_name:world,
validation_class:IntegerType, index_type:0, index_name:IdxName }, " +
                                                                                "{ column_name:world2,
validation_class:LongType, index_type:KEYS, index_name:LongIdxName}, " +
                                                                                "{ column_name:617070,
validation_class:UTF8Type, index_type:KEYS }, " +


Mime
View raw message