cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject [4/5] git commit: Allow KS + CF names up to 48 characters
Date Tue, 17 Apr 2012 07:27:01 GMT
Allow KS + CF names up to 48 characters

patch by jbellis; reviewed by yukim for CASSANDRA-4157


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

Branch: refs/heads/cassandra-1.1
Commit: 5b57673c962a2d9451356877b9f825b4ee003509
Parents: 7dc6aca
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Tue Apr 17 09:10:23 2012 +0200
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Tue Apr 17 09:10:23 2012 +0200

----------------------------------------------------------------------
 CHANGES.txt                                        |    4 ++++
 .../org/apache/cassandra/config/CFMetaData.java    |    6 +++---
 .../org/apache/cassandra/config/KSMetaData.java    |    2 +-
 src/java/org/apache/cassandra/config/Schema.java   |    8 ++++++++
 .../statements/CreateColumnFamilyStatement.java    |    7 +++----
 .../cql3/statements/CreateKeyspaceStatement.java   |    9 +++------
 src/java/org/apache/cassandra/db/Directories.java  |    7 +++++--
 7 files changed, 27 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/5b57673c/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index be3264a..b2f33ed 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,8 @@
 1.1-dev
+ * Allow KS and CF names up to 48 characters (CASSANDRA-4157)
+
+
+1.1-rc1
  * (Hadoop) fix wide row iteration when last row read was deleted
    (CASSANDRA-4154)
  * fix read_repair_chance to really default to 0.1 in the cli (CASSANDRA-4114)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/5b57673c/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 1a21ffc..14b964f 100644
--- a/src/java/org/apache/cassandra/config/CFMetaData.java
+++ b/src/java/org/apache/cassandra/config/CFMetaData.java
@@ -864,7 +864,7 @@ public final class CFMetaData
 
     public static boolean isNameValid(String name)
     {
-        return name != null && !name.isEmpty() && name.length() <= 32
&& name.matches("\\w+");
+        return name != null && !name.isEmpty() && name.length() <= Schema.NAME_LENGTH
&& name.matches("\\w+");
     }
 
     public static boolean isIndexNameValid(String name)
@@ -875,9 +875,9 @@ public final class CFMetaData
     public CFMetaData validate() throws ConfigurationException
     {
         if (!isNameValid(ksName))
-            throw new ConfigurationException(String.format("Invalid keyspace name: shouldn't
be empty nor more than 32 character long (got \"%s\")", ksName));
+            throw new ConfigurationException(String.format("Invalid keyspace name: shouldn't
be empty nor more than %s characters long (got \"%s\")", Schema.NAME_LENGTH, ksName));
         if (!isNameValid(cfName))
-            throw new ConfigurationException(String.format("Invalid keyspace name: shouldn't
be empty nor more than 32 character long (got \"%s\")", cfName));
+            throw new ConfigurationException(String.format("Invalid keyspace name: shouldn't
be empty nor more than %s characters long (got \"%s\")", Schema.NAME_LENGTH, cfName));
 
         if (cfType == null)
             throw new ConfigurationException(String.format("Invalid column family type for
%s", cfName));

http://git-wip-us.apache.org/repos/asf/cassandra/blob/5b57673c/src/java/org/apache/cassandra/config/KSMetaData.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/config/KSMetaData.java b/src/java/org/apache/cassandra/config/KSMetaData.java
index e739a1f..1627d58 100644
--- a/src/java/org/apache/cassandra/config/KSMetaData.java
+++ b/src/java/org/apache/cassandra/config/KSMetaData.java
@@ -181,7 +181,7 @@ public final class KSMetaData
     public KSMetaData validate() throws ConfigurationException
     {
         if (!CFMetaData.isNameValid(name))
-            throw new ConfigurationException(String.format("Invalid keyspace name: shouldn't
be empty nor more than 32 character long (got \"%s\")", name));
+            throw new ConfigurationException(String.format("Invalid keyspace name: shouldn't
be empty nor more than %s characters long (got \"%s\")", Schema.NAME_LENGTH, name));
 
         // Attempt to instantiate the ARS, which will throw a ConfigException if the strategy_options
aren't fully formed
         TokenMetadata tmd = StorageService.instance.getTokenMetadata();

http://git-wip-us.apache.org/repos/asf/cassandra/blob/5b57673c/src/java/org/apache/cassandra/config/Schema.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/config/Schema.java b/src/java/org/apache/cassandra/config/Schema.java
index 6aa43e0..245fa5f 100644
--- a/src/java/org/apache/cassandra/config/Schema.java
+++ b/src/java/org/apache/cassandra/config/Schema.java
@@ -48,6 +48,14 @@ public class Schema
 
     public static final Schema instance = new Schema();
 
+    /**
+     * longest permissible KS or CF name.  Our main concern is that filename not be more
than 255 characters;
+     * the filename will contain both the KS and CF names. Since non-schema-name components
only take up
+     * ~64 characters, we could allow longer names than this, but on Windows, the entire
path should be not greater than
+     * 255 characters, so a lower limit here helps avoid problems.  See CASSANDRA-4110.
+     */
+    public static final int NAME_LENGTH = 48;
+
     private static final int MIN_CF_ID = 1000;
     private final AtomicInteger cfIdGen = new AtomicInteger(MIN_CF_ID);
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/5b57673c/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java
b/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java
index ad217f4..8287a49 100644
--- a/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java
@@ -18,7 +18,6 @@
  */
 package org.apache.cassandra.cql3.statements;
 
-import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -28,6 +27,7 @@ import org.apache.commons.lang.StringUtils;
 import com.google.common.collect.HashMultiset;
 import com.google.common.collect.Multiset;
 
+import org.apache.cassandra.config.Schema;
 import org.apache.cassandra.cql3.*;
 import org.apache.cassandra.config.CFMetaData;
 import org.apache.cassandra.config.ColumnDefinition;
@@ -39,7 +39,6 @@ import org.apache.cassandra.service.ClientState;
 import org.apache.cassandra.service.MigrationManager;
 import org.apache.cassandra.thrift.CqlResult;
 import org.apache.cassandra.thrift.InvalidRequestException;
-import org.apache.cassandra.thrift.ThriftValidation;
 import org.apache.cassandra.io.compress.CompressionParameters;
 
 /** A <code>CREATE COLUMNFAMILY</code> parsed from a CQL query statement. */
@@ -152,8 +151,8 @@ public class CreateColumnFamilyStatement extends SchemaAlteringStatement
                 // Column family name
                 if (!columnFamily().matches("\\w+"))
                     throw new InvalidRequestException(String.format("\"%s\" is not a valid
column family name (must be alphanumeric character only: [0-9A-Za-z]+)", columnFamily()));
-                if (columnFamily().length() > 32)
-                    throw new InvalidRequestException(String.format("Column family names
shouldn't be more than 32 character long (got \"%s\")", columnFamily()));
+                if (columnFamily().length() > Schema.NAME_LENGTH)
+                    throw new InvalidRequestException(String.format("Column family names
shouldn't be more than %s characters long (got \"%s\")", Schema.NAME_LENGTH, columnFamily()));
 
                 for (Multiset.Entry<ColumnIdentifier> entry : definedNames.entrySet())
                     if (entry.getCount() > 1)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/5b57673c/src/java/org/apache/cassandra/cql3/statements/CreateKeyspaceStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/CreateKeyspaceStatement.java b/src/java/org/apache/cassandra/cql3/statements/CreateKeyspaceStatement.java
index c1cbca2..0c347ce 100644
--- a/src/java/org/apache/cassandra/cql3/statements/CreateKeyspaceStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/CreateKeyspaceStatement.java
@@ -18,21 +18,18 @@
  */
 package org.apache.cassandra.cql3.statements;
 
-import java.io.IOException;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.cassandra.config.ConfigurationException;
 import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.config.KSMetaData;
+import org.apache.cassandra.config.Schema;
 import org.apache.cassandra.locator.AbstractReplicationStrategy;
 import org.apache.cassandra.service.ClientState;
 import org.apache.cassandra.service.MigrationManager;
 import org.apache.cassandra.service.StorageService;
-import org.apache.cassandra.thrift.CfDef;
 import org.apache.cassandra.thrift.InvalidRequestException;
-import org.apache.cassandra.thrift.KsDef;
 import org.apache.cassandra.thrift.SchemaDisagreementException;
 import org.apache.cassandra.thrift.ThriftValidation;
 
@@ -74,8 +71,8 @@ public class CreateKeyspaceStatement extends SchemaAlteringStatement
         // keyspace name
         if (!name.matches("\\w+"))
             throw new InvalidRequestException(String.format("\"%s\" is not a valid keyspace
name", name));
-        if (name.length() > 32)
-            throw new InvalidRequestException(String.format("Keyspace names shouldn't be
more than 32 character long (got \"%s\")", name));
+        if (name.length() > Schema.NAME_LENGTH)
+            throw new InvalidRequestException(String.format("Keyspace names shouldn't be
more than %s characters long (got \"%s\")", Schema.NAME_LENGTH, name));
 
         // required
         if (!attrs.containsKey("strategy_class"))

http://git-wip-us.apache.org/repos/asf/cassandra/blob/5b57673c/src/java/org/apache/cassandra/db/Directories.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/Directories.java b/src/java/org/apache/cassandra/db/Directories.java
index 1441fd2..30c22ad 100644
--- a/src/java/org/apache/cassandra/db/Directories.java
+++ b/src/java/org/apache/cassandra/db/Directories.java
@@ -442,8 +442,11 @@ public class Directories
                 if (System.getProperty("os.name").startsWith("Windows")
                     && longestLocation + (ksname.length() + cfname.length()) * 2
+ 63 > 255)
                 {
-                    throw new RuntimeException("Starting with 1.1, keyspace names and column
family names must be less than 32 characters long. "
-                        + ksname + "/" + cfname + " doesn't respect that restriction. Please
rename your keyspace/column families to respect that restriction before updating.");
+                    throw new RuntimeException(String.format("Starting with 1.1, keyspace
names and column family " +
+                                                             "names must be less than %s
characters long. %s/%s doesn't" +
+                                                             " respect that restriction.
Please rename your " +
+                                                             "keyspace/column families to
respect that restriction " +
+                                                             "before updating.", Schema.NAME_LENGTH,
ksname, cfname));
                 }
 
                 if (ksm.name.length() + cfname.length() + 28 > 255)


Mime
View raw message