Author: jbellis
Date: Sat Apr 23 00:13:25 2011
New Revision: 1096094
URL: http://svn.apache.org/viewvc?rev=1096094&view=rev
Log:
validate CQL create keyspace options
patch by jbellis; reviewed by eevans for CASSANDRA-2525
Modified:
cassandra/branches/cassandra-0.8/CHANGES.txt
cassandra/branches/cassandra-0.8/doc/cql/CQL.textile
cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/cql/CreateKeyspaceStatement.java
Modified: cassandra/branches/cassandra-0.8/CHANGES.txt
URL:
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/CHANGES.txt?rev=1096094&r1=1096093&r2=1096094&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/CHANGES.txt (original)
+++ cassandra/branches/cassandra-0.8/CHANGES.txt Sat Apr 23 00:13:25 2011
@@ -1,6 +1,8 @@
0.8.0-?
* fix NPE compacting index CFs (CASSANDRA-2528)
* Remove checking all column families on startup for compaction candidates
(CASSANDRA-2444)
+ * validate CQL create keyspace options (CASSANDRA-2525)
+
0.8.0-beta1
* remove Avro RPC support (CASSANDRA-926)
Modified: cassandra/branches/cassandra-0.8/doc/cql/CQL.textile
URL:
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/doc/cql/CQL.textile?rev=1096094&r1=1096093&r2=1096094&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/doc/cql/CQL.textile (original)
+++ cassandra/branches/cassandra-0.8/doc/cql/CQL.textile Sat Apr 23 00:13:25
2011
@@ -165,15 +165,13 @@ h2. CREATE KEYSPACE
_Synopsis:_
bc.
-CREATE KEYSPACE <NAME> WITH replication_factor = <NUM> AND strategy_class =
<STRATEGY>
- [AND strategy_options.<OPTION> = <VALUE> [AND strategy_options.<OPTION> =
<VALUE>]];
+CREATE KEYSPACE <NAME> WITH AND strategy_class = <STRATEGY>
+ AND strategy_options.<OPTION> = <VALUE> [AND strategy_options.<OPTION> =
<VALUE>];
The @CREATE KEYSPACE@ statement creates a new top-level namespace (aka
"keyspace"). Valid names are any string constructed of alphanumeric characters
and underscores, but must begin with a letter. Properties such as replication
strategy and count are specified during creation using the following accepted
keyword arguments:
|_. keyword|_. required|_. description|
-|replication_factor|yes|Numeric argument that specifies the number of replicas
for this keyspace.|
-|strategy_class|yes|Class name to use for managing replica placement. Any of
the shipped strategies can be used by specifying the class name relative to
org.apache.cassandra.locator, others will need to be fully-qualified and
located on the classpath.|
-|strategy_options|no|Some strategies require additional arguments which can be
supplied by appending the option name to the @strategy_options@ keyword,
separated by a colon (@:@). For example, a strategy option of "DC1" with a
value of "1" would be specified as @strategy_options:DC1 = 1@.|
+|strategy_options|no|Most strategies require additional arguments which can be
supplied by appending the option name to the @strategy_options@ keyword,
separated by a colon (@:@). For example, a strategy option of "DC1" with a
value of "1" would be specified as @strategy_options:DC1 = 1@;
replication_factor for SimpleStrategy could be
@strategy_options:replication_factor=3@.|
h2. CREATE COLUMNFAMILY
Modified:
cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/cql/CreateKeyspaceStatement.java
URL:
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/cql/CreateKeyspaceStatement.java?rev=1096094&r1=1096093&r2=1096094&view=diff
==============================================================================
---
cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/cql/CreateKeyspaceStatement.java
(original)
+++
cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/cql/CreateKeyspaceStatement.java
Sat Apr 23 00:13:25 2011
@@ -23,6 +23,13 @@ package org.apache.cassandra.cql;
import java.util.HashMap;
import java.util.Map;
+
+import org.apache.cassandra.config.ConfigurationException;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.locator.AbstractReplicationStrategy;
+import org.apache.cassandra.locator.IEndpointSnitch;
+import org.apache.cassandra.locator.TokenMetadata;
+import org.apache.cassandra.service.StorageService;
import org.apache.cassandra.thrift.InvalidRequestException;
/** A <code>CREATE KEYSPACE</code> statement parsed from a CQL query. */
@@ -68,6 +75,20 @@ public class CreateKeyspaceStatement
for (String key : attrs.keySet())
if ((key.contains(":")) && (key.startsWith("strategy_options")))
strategyOptions.put(key.split(":")[1], attrs.get(key));
+
+ // trial run to let ARS validate class + per-class options
+ try
+ {
+ AbstractReplicationStrategy.createReplicationStrategy(name,
+
AbstractReplicationStrategy.getClass(strategyClass),
+
StorageService.instance.getTokenMetadata(),
+
DatabaseDescriptor.getEndpointSnitch(),
+
strategyOptions);
+ }
+ catch (ConfigurationException e)
+ {
+ throw new InvalidRequestException(e.getMessage());
+ }
}
public String getName()