Author: gdusbabek
Date: Tue Apr 6 16:02:39 2010
New Revision: 931203
URL: http://svn.apache.org/viewvc?rev=931203&view=rev
Log:
thrift impl. Patch by Gary Dusbabek, reviewed by Jonthan Ellis. CASSANDRA-827
Modified:
cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java
cassandra/trunk/test/system/__init__.py
cassandra/trunk/test/system/test_thrift_server.py
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=931203&r1=931202&r2=931203&view=diff
==============================================================================
---
cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
(original)
+++
cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
Tue Apr 6 16:02:39 2010
@@ -695,11 +695,11 @@ public class DatabaseDescriptor
}
// Parse out the column comparator
- AbstractType comparator = getComparator(columnFamily,
"CompareWith");
+ AbstractType comparator =
getComparator(XMLUtils.getAttributeValue(columnFamily, "CompareWith"));
AbstractType subcolumnComparator = null;
if (columnType.equals("Super"))
{
- subcolumnComparator = getComparator(columnFamily,
"CompareSubcolumnsWith");
+ subcolumnComparator =
getComparator(XMLUtils.getAttributeValue(columnFamily,
"CompareSubcolumnsWith"));
}
else if (XMLUtils.getAttributeValue(columnFamily,
"CompareSubcolumnsWith") != null)
{
@@ -772,21 +772,11 @@ public class DatabaseDescriptor
return thriftFramed;
}
- private static AbstractType getComparator(Node columnFamily, String attr)
throws ConfigurationException
+ public static AbstractType getComparator(String compareWith) throws
ConfigurationException
// throws ConfigurationException, TransformerException,
NoSuchMethodException, InvocationTargetException, IllegalAccessException,
InstantiationException
{
Class<? extends AbstractType> typeClass;
- String compareWith = null;
- try
- {
- compareWith = XMLUtils.getAttributeValue(columnFamily, attr);
- }
- catch (TransformerException e)
- {
- ConfigurationException ex = new
ConfigurationException(e.getMessage());
- ex.initCause(e);
- throw ex;
- }
+
if (compareWith == null)
{
typeClass = BytesType.class;
@@ -800,7 +790,7 @@ public class DatabaseDescriptor
}
catch (ClassNotFoundException e)
{
- throw new ConfigurationException("Unable to load class " +
className + " for " + attr + " attribute");
+ throw new ConfigurationException("Unable to load class " +
className);
}
}
try
Modified:
cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java
URL:
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java?rev=931203&r1=931202&r2=931203&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java
(original)
+++ cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java
Tue Apr 6 16:02:39 2010
@@ -22,8 +22,21 @@ import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;
+import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException;
+import org.apache.cassandra.concurrent.StageManager;
+import org.apache.cassandra.config.ConfigurationException;
+import org.apache.cassandra.config.KSMetaData;
+import org.apache.cassandra.db.marshal.AbstractType;
+import org.apache.cassandra.db.migration.AddColumnFamily;
+import org.apache.cassandra.db.migration.AddKeyspace;
+import org.apache.cassandra.db.migration.DropColumnFamily;
+import org.apache.cassandra.db.migration.DropKeyspace;
+import org.apache.cassandra.db.migration.RenameColumnFamily;
+import org.apache.cassandra.db.migration.RenameKeyspace;
+import org.apache.cassandra.locator.AbstractReplicationStrategy;
+import org.apache.cassandra.locator.IEndPointSnitch;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.commons.lang.ArrayUtils;
@@ -678,31 +691,217 @@ public class CassandraServer implements
public void system_add_column_family(CfDef cf_def) throws
InvalidRequestException, TException
{
checkLoginAuthorized(AccessLevel.FULL);
+
+ // if there is anything going on in the migration stage, fail.
+ if
(StageManager.getStage(StageManager.MIGRATION_STAGE).getQueue().size() > 0)
+ throw new InvalidRequestException("This node appears to be
handling gossiped migrations.");
+
+ try
+ {
+ CFMetaData cfm = new CFMetaData(
+ cf_def.table,
+ cf_def.name,
+ ColumnFamily.getColumnType(cf_def.column_type),
+
DatabaseDescriptor.getComparator(cf_def.comparator_type),
+ cf_def.subcomparator_type.length() == 0 ? null :
DatabaseDescriptor.getComparator(cf_def.subcomparator_type),
+ cf_def.comment,
+ cf_def.row_cache_size,
+ cf_def.key_cache_size);
+ AddColumnFamily add = new AddColumnFamily(cfm);
+ add.apply();
+ add.announce();
+ }
+ catch (ConfigurationException e)
+ {
+ InvalidRequestException ex = new
InvalidRequestException(e.getMessage());
+ ex.initCause(e);
+ throw ex;
+ }
+ catch (IOException e)
+ {
+ InvalidRequestException ex = new
InvalidRequestException(e.getMessage());
+ ex.initCause(e);
+ throw ex;
+ }
}
public void system_drop_column_family(String keyspace, String
column_family) throws InvalidRequestException, TException
{
checkLoginAuthorized(AccessLevel.FULL);
+
+ // if there is anything going on in the migration stage, fail.
+ if
(StageManager.getStage(StageManager.MIGRATION_STAGE).getQueue().size() > 0)
+ throw new InvalidRequestException("This node appears to be
handling gossiped migrations.");
+
+ try
+ {
+ DropColumnFamily drop = new DropColumnFamily(keyspace,
column_family, true);
+ drop.apply();
+ drop.announce();
+ }
+ catch (ConfigurationException e)
+ {
+ InvalidRequestException ex = new
InvalidRequestException(e.getMessage());
+ ex.initCause(e);
+ throw ex;
+ }
+ catch (IOException e)
+ {
+ InvalidRequestException ex = new
InvalidRequestException(e.getMessage());
+ ex.initCause(e);
+ throw ex;
+ }
}
public void system_rename_column_family(String keyspace, String old_name,
String new_name) throws InvalidRequestException, TException
{
checkLoginAuthorized(AccessLevel.FULL);
+
+ // if there is anything going on in the migration stage, fail.
+ if
(StageManager.getStage(StageManager.MIGRATION_STAGE).getQueue().size() > 0)
+ throw new InvalidRequestException("This node appears to be
handling gossiped migrations.");
+
+ try
+ {
+ RenameColumnFamily rename = new RenameColumnFamily(keyspace,
old_name, new_name);
+ rename.apply();
+ rename.announce();
+ }
+ catch (ConfigurationException e)
+ {
+ InvalidRequestException ex = new
InvalidRequestException(e.getMessage());
+ ex.initCause(e);
+ throw ex;
+ }
+ catch (IOException e)
+ {
+ InvalidRequestException ex = new
InvalidRequestException(e.getMessage());
+ ex.initCause(e);
+ throw ex;
+ }
}
public void system_add_keyspace(KsDef ks_def) throws
InvalidRequestException, TException
{
checkLoginAuthorized(AccessLevel.FULL);
+
+ // if there is anything going on in the migration stage, fail.
+ if
(StageManager.getStage(StageManager.MIGRATION_STAGE).getQueue().size() > 0)
+ throw new InvalidRequestException("This node appears to be
handling gossiped migrations.");
+
+ try
+ {
+ Collection<CFMetaData> cfDefs = new
ArrayList<CFMetaData>(ks_def.cf_defs.size());
+ for (CfDef cfDef : ks_def.cf_defs)
+ {
+ CFMetaData cfm = new CFMetaData(
+ cfDef.table,
+ cfDef.name,
+ ColumnFamily.getColumnType(cfDef.column_type),
+
DatabaseDescriptor.getComparator(cfDef.comparator_type),
+ cfDef.subcomparator_type.length() == 0 ? null :
DatabaseDescriptor.getComparator(cfDef.subcomparator_type),
+ cfDef.comment,
+ cfDef.row_cache_size,
+ cfDef.key_cache_size);
+ cfDefs.add(cfm);
+ }
+
+ KSMetaData ksm = new KSMetaData(
+ ks_def.name,
+ (Class<? extends
AbstractReplicationStrategy>)Class.forName(ks_def.strategy_class),
+ ks_def.replication_factor,
+
(IEndPointSnitch)Class.forName(ks_def.snitch_class).newInstance(),
+ cfDefs.toArray(new CFMetaData[cfDefs.size()]));
+ AddKeyspace add = new AddKeyspace(ksm);
+ add.apply();
+ add.announce();
+ }
+ catch (ClassNotFoundException e)
+ {
+ InvalidRequestException ex = new
InvalidRequestException(e.getMessage());
+ ex.initCause(e);
+ throw ex;
+ }
+ catch (InstantiationException e)
+ {
+ InvalidRequestException ex = new
InvalidRequestException(e.getMessage());
+ ex.initCause(e);
+ throw ex;
+ }
+ catch (IllegalAccessException e)
+ {
+ InvalidRequestException ex = new
InvalidRequestException(e.getMessage());
+ ex.initCause(e);
+ throw ex;
+ }
+ catch (ConfigurationException e)
+ {
+ InvalidRequestException ex = new
InvalidRequestException(e.getMessage());
+ ex.initCause(e);
+ throw ex;
+ }
+ catch (IOException e)
+ {
+ InvalidRequestException ex = new
InvalidRequestException(e.getMessage());
+ ex.initCause(e);
+ throw ex;
+ }
}
public void system_drop_keyspace(String keyspace) throws
InvalidRequestException, TException
{
checkLoginAuthorized(AccessLevel.FULL);
+
+ // if there is anything going on in the migration stage, fail.
+ if
(StageManager.getStage(StageManager.MIGRATION_STAGE).getQueue().size() > 0)
+ throw new InvalidRequestException("This node appears to be
handling gossiped migrations.");
+
+ try
+ {
+ DropKeyspace drop = new DropKeyspace(keyspace, true);
+ drop.apply();
+ drop.announce();
+ }
+ catch (ConfigurationException e)
+ {
+ InvalidRequestException ex = new
InvalidRequestException(e.getMessage());
+ ex.initCause(e);
+ throw ex;
+ }
+ catch (IOException e)
+ {
+ InvalidRequestException ex = new
InvalidRequestException(e.getMessage());
+ ex.initCause(e);
+ throw ex;
+ }
}
public void system_rename_keyspace(String old_name, String new_name)
throws InvalidRequestException, TException
{
checkLoginAuthorized(AccessLevel.FULL);
+
+ // if there is anything going on in the migration stage, fail.
+ if
(StageManager.getStage(StageManager.MIGRATION_STAGE).getQueue().size() > 0)
+ throw new InvalidRequestException("This node appears to be
handling gossiped migrations.");
+
+ try
+ {
+ RenameKeyspace rename = new RenameKeyspace(old_name, new_name);
+ rename.apply();
+ rename.announce();
+ }
+ catch (ConfigurationException e)
+ {
+ InvalidRequestException ex = new
InvalidRequestException(e.getMessage());
+ ex.initCause(e);
+ throw ex;
+ }
+ catch (IOException e)
+ {
+ InvalidRequestException ex = new
InvalidRequestException(e.getMessage());
+ ex.initCause(e);
+ throw ex;
+ }
}
// main method moved to CassandraDaemon
Modified: cassandra/trunk/test/system/__init__.py
URL:
http://svn.apache.org/viewvc/cassandra/trunk/test/system/__init__.py?rev=931203&r1=931202&r2=931203&view=diff
==============================================================================
--- cassandra/trunk/test/system/__init__.py (original)
+++ cassandra/trunk/test/system/__init__.py Tue Apr 6 16:02:39 2010
@@ -67,6 +67,9 @@ class BaseTester(object):
def close_client(self):
raise NotImplementedError()
+
+ def define_schema(self):
+ raise NotImplementedError()
def setUp(self):
if self.runserver:
@@ -117,6 +120,8 @@ class BaseTester(object):
self.open_client()
except:
pass
+
+ self.define_schema()
def tearDown(self):
if self.runserver:
@@ -135,6 +140,44 @@ class ThriftTester(BaseTester):
def close_client(self):
self.client.transport.close()
+
+ def define_schema(self):
+ keyspace1 = Cassandra.KsDef('Keyspace1',
'org.apache.cassandra.locator.RackUnawareStrategy', 1,
'org.apache.cassandra.locator.EndPointSnitch',
+ [
+ Cassandra.CfDef('Keyspace1', 'Standard1'),
+ Cassandra.CfDef('Keyspace1', 'Standard2'),
+ Cassandra.CfDef('Keyspace1', 'StandardLong1',
comparator_type='LongType'),
+ Cassandra.CfDef('Keyspace1', 'StandardLong2',
comparator_type='LongType'),
+ Cassandra.CfDef('Keyspace1', 'Super1', column_type='Super',
subcomparator_type='LongType', row_cache_size=1000, key_cache_size=0),
+ Cassandra.CfDef('Keyspace1', 'Super2', column_type='Super',
subcomparator_type='LongType'),
+ Cassandra.CfDef('Keyspace1', 'Super3', column_type='Super',
subcomparator_type='LongType'),
+ Cassandra.CfDef('Keyspace1', 'Super4', column_type='Super',
subcomparator_type='UTF8Type')
+ ])
+
+ keyspace2 = Cassandra.KsDef('Keyspace2',
'org.apache.cassandra.locator.RackUnawareStrategy', 1,
'org.apache.cassandra.locator.EndPointSnitch',
+ [
+ Cassandra.CfDef('Keyspace2', 'Standard1'),
+ Cassandra.CfDef('Keyspace2', 'Standard3'),
+ Cassandra.CfDef('Keyspace2', 'Super3', column_type='Super',
subcomparator_type='BytesType'),
+ Cassandra.CfDef('Keyspace2', 'Super4', column_type='Super',
subcomparator_type='TimeUUIDType'),
+ ])
+
+ keyspace3 = Cassandra.KsDef('Keyspace3',
'org.apache.cassandra.locator.RackUnawareStrategy', 5,
'org.apache.cassandra.locator.EndPointSnitch',
+ [
+ Cassandra.CfDef('Keyspace3', 'Standard1'),
+ ])
+
+ keyspace4 = Cassandra.KsDef('Keyspace4',
'org.apache.cassandra.locator.RackUnawareStrategy', 3,
'org.apache.cassandra.locator.EndPointSnitch',
+ [
+ Cassandra.CfDef('Keyspace4', 'Standard1'),
+ Cassandra.CfDef('Keyspace4', 'Standard3'),
+ Cassandra.CfDef('Keyspace4', 'Super3', column_type='Super',
subcomparator_type='BytesType'),
+ Cassandra.CfDef('Keyspace4', 'Super4', column_type='Super',
subcomparator_type='TimeUUIDType')
+ ])
+ self.client.system_add_keyspace(keyspace1)
+ self.client.system_add_keyspace(keyspace2)
+ self.client.system_add_keyspace(keyspace3)
+ self.client.system_add_keyspace(keyspace4)
class AvroTester(BaseTester):
client = None
@@ -145,5 +188,8 @@ class AvroTester(BaseTester):
def close_client(self):
self.client.transceiver.conn.close()
+
+ def define_schema(self):
+ pass
# vim:ai sw=4 ts=4 tw=0 et
Modified: cassandra/trunk/test/system/test_thrift_server.py
URL:
http://svn.apache.org/viewvc/cassandra/trunk/test/system/test_thrift_server.py?rev=931203&r1=931202&r2=931203&view=diff
==============================================================================
--- cassandra/trunk/test/system/test_thrift_server.py (original)
+++ cassandra/trunk/test/system/test_thrift_server.py Tue Apr 6 16:02:39 2010
@@ -912,3 +912,50 @@ class TestMutations(ThriftTester):
def test_describe_ring(self):
assert list(client.describe_ring('Keyspace1'))[0].endpoints ==
['127.0.0.1']
+
+ def test_system_keyspace_operations(self):
+ """ Test keyspace (add, drop, rename) operations """
+ # create
+ keyspace = KsDef('CreateKeyspace',
'org.apache.cassandra.locator.RackUnawareStrategy', 1,
'org.apache.cassandra.locator.EndPointSnitch',
+ [
+ CfDef('CreateKeyspace', 'CreateKsCf')
+ ])
+ client.system_add_keyspace(keyspace)
+ newks = client.describe_keyspace('CreateKeyspace')
+ assert 'CreateKsCf' in newks
+
+ # rename
+ client.system_rename_keyspace('CreateKeyspace', 'RenameKeyspace')
+ renameks = client.describe_keyspace('RenameKeyspace')
+ assert 'CreateKsCf' in renameks
+ def get_first_ks():
+ client.describe_keyspace('CreateKeyspace')
+ _expect_exception(get_first_ks, NotFoundException)
+
+ # drop
+ client.system_drop_keyspace('RenameKeyspace')
+ def get_second_ks():
+ client.describe_keyspace('RenameKeyspace')
+ _expect_exception(get_second_ks, NotFoundException)
+
+ def test_system_column_family_operations(self):
+ """ Test cf (add, drop, rename) operations """
+ # create
+ newcf = CfDef('Keyspace1', 'NewColumnFamily')
+ client.system_add_column_family(newcf)
+ ks1 = client.describe_keyspace('Keyspace1')
+ assert 'NewColumnFamily' in ks1
+
+ # rename
+ client.system_rename_column_family('Keyspace1', 'NewColumnFamily',
'RenameColumnFamily')
+ ks1 = client.describe_keyspace('Keyspace1')
+ assert 'RenameColumnFamily' in ks1
+ assert 'NewColumnFamily' not in ks1
+
+ # drop
+ client.system_drop_column_family('Keyspace1', 'RenameColumnFamily')
+ ks1 = client.describe_keyspace('Keyspace1')
+ assert 'RenameColumnFamily' not in ks1
+ assert 'NewColumnFamily' not in ks1
+ assert 'Standard1' in ks1
+
\ No newline at end of file