Author: jbellis Date: Wed Oct 6 19:37:15 2010 New Revision: 1005215 URL: http://svn.apache.org/viewvc?rev=1005215&view=rev Log: allow keyspace creation with RF > N. patch by jbellis; reviewed by gdusbabek for CASSANDRA-1428
Modified: cassandra/trunk/CHANGES.txt cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java cassandra/trunk/test/system/test_avro_system.py cassandra/trunk/test/system/test_thrift_server.py Modified: cassandra/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/cassandra/trunk/CHANGES.txt?rev=1005215&r1=1005214&r2=1005215&view=diff ============================================================================== --- cassandra/trunk/CHANGES.txt (original) +++ cassandra/trunk/CHANGES.txt Wed Oct 6 19:37:15 2010 @@ -15,6 +15,7 @@ dev * deletion support in secondary indexes (CASSANDRA-1571) * meaningful error message for invalid replication strategy class (CASSANDRA-1566) + * allow keyspace creation with RF > N (CASSANDRA-1428) 0.7-beta2 Modified: cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java?rev=1005215&r1=1005214&r2=1005215&view=diff ============================================================================== --- cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java (original) +++ cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java Wed Oct 6 19:37:15 2010 @@ -635,11 +635,6 @@ public class CassandraServer implements if (!(DatabaseDescriptor.getAuthenticator() instanceof AllowAllAuthenticator)) throw newInvalidRequestException("Unable to create new keyspace while authentication is enabled."); - int totalNodes = Gossiper.instance.getLiveMembers().size() + Gossiper.instance.getUnreachableMembers().size(); - if (totalNodes < ksDef.replication_factor) - throw newInvalidRequestException(String.format("%s live nodes are not enough to support replication factor %s", - totalNodes, ksDef.replication_factor)); - //generate a meaningful error if the user setup keyspace and/or column definition incorrectly for (CfDef cf : ksDef.cf_defs) { @@ -744,10 +739,6 @@ public class CassandraServer implements if (ks_def.cf_defs != null && ks_def.cf_defs.size() > 0) throw newInvalidRequestException("Keyspace update must not contain any column family definitions."); - int totalNodes = Gossiper.instance.getLiveMembers().size() + Gossiper.instance.getUnreachableMembers().size(); - if (totalNodes < ks_def.replication_factor) - throw newInvalidRequestException(String.format("%s live nodes are not enough to support replication factor %s", - totalNodes, ks_def.replication_factor)); if (DatabaseDescriptor.getTableDefinition(ks_def.name.toString()) == null) throw newInvalidRequestException("Keyspace does not exist."); Modified: cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java?rev=1005215&r1=1005214&r2=1005215&view=diff ============================================================================== --- cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java (original) +++ cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java Wed Oct 6 19:37:15 2010 @@ -1903,13 +1903,6 @@ public class StorageService implements I if (DatabaseDescriptor.getDefsVersion().timestamp() > 0 || Migration.getLastMigrationId() != null) throw new ConfigurationException("Cannot load from XML on top of pre-existing schemas."); - // cycle through first to make sure we can satisfy live nodes constraint. - int totalNodes = Gossiper.instance.getLiveMembers().size() + Gossiper.instance.getUnreachableMembers().size(); - for (KSMetaData table : tables) - if (totalNodes < table.replicationFactor) - throw new ConfigurationException(String.format("%s live nodes are not enough to support replication factor %s", - totalNodes, table.replicationFactor)); - Migration migration = null; for (KSMetaData table : tables) { 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=1005215&r1=1005214&r2=1005215&view=diff ============================================================================== --- cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java (original) +++ cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java Wed Oct 6 19:37:15 2010 @@ -766,11 +766,6 @@ public class CassandraServer implements { state().hasKeyspaceListAccess(Permission.WRITE); - int totalNodes = Gossiper.instance.getLiveMembers().size() + Gossiper.instance.getUnreachableMembers().size(); - if (totalNodes < ks_def.replication_factor) - throw new InvalidRequestException(String.format("%s live nodes are not enough to support replication factor %s", - totalNodes, ks_def.replication_factor)); - // generate a meaningful error if the user setup keyspace and/or column definition incorrectly for (CfDef cf : ks_def.cf_defs) { @@ -864,10 +859,6 @@ public class CassandraServer implements if (ks_def.getCf_defs() != null && ks_def.getCf_defs().size() > 0) throw new InvalidRequestException("Keyspace update must not contain any column family definitions."); - int totalNodes = Gossiper.instance.getLiveMembers().size() + Gossiper.instance.getUnreachableMembers().size(); - if (totalNodes < ks_def.replication_factor) - throw new InvalidRequestException(String.format("%s live nodes are not enough to support replication factor %s", - totalNodes, ks_def.replication_factor)); if (DatabaseDescriptor.getTableDefinition(ks_def.name) == null) throw new InvalidRequestException("Keyspace does not exist."); @@ -875,7 +866,7 @@ public class CassandraServer implements { KSMetaData ksm = new KSMetaData( ks_def.name, - (Class<? extends AbstractReplicationStrategy>)FBUtilities.<AbstractReplicationStrategy>classForName(ks_def.strategy_class, "keyspace replication strategy"), + FBUtilities.<AbstractReplicationStrategy>classForName(ks_def.strategy_class, "keyspace replication strategy"), ks_def.strategy_options, ks_def.replication_factor); applyMigrationOnStage(new UpdateKeyspace(ksm)); Modified: cassandra/trunk/test/system/test_avro_system.py URL: http://svn.apache.org/viewvc/cassandra/trunk/test/system/test_avro_system.py?rev=1005215&r1=1005214&r2=1005215&view=diff ============================================================================== --- cassandra/trunk/test/system/test_avro_system.py (original) +++ cassandra/trunk/test/system/test_avro_system.py Wed Oct 6 19:37:15 2010 @@ -56,19 +56,12 @@ class TestSystemOperations(AvroTester): self.client.request('set_keyspace', {'keyspace' : 'CreateKeyspace'}) - # modify invalid + # modify valid modified_keyspace = {'name': 'CreateKeyspace', 'strategy_class': 'org.apache.cassandra.locator.OldNetworkTopologyStrategy', 'strategy_options': {}, - 'replication_factor': 2, + 'replication_factor': 1, 'cf_defs': []} - avro_utils.assert_raises(AvroRemoteException, - self.client.request, - 'system_update_keyspace', - {'ks_def': modified_keyspace}) - - # modify valid - modified_keyspace['replication_factor'] = 1 self.client.request('system_update_keyspace', {'ks_def': modified_keyspace}) modks = self.client.request('describe_keyspace', {'keyspace': 'CreateKeyspace'}) assert modks['replication_factor'] == modified_keyspace['replication_factor'] Modified: cassandra/trunk/test/system/test_thrift_server.py URL: http://svn.apache.org/viewvc/cassandra/trunk/test/system/test_thrift_server.py?rev=1005215&r1=1005214&r2=1005215&view=diff ============================================================================== --- cassandra/trunk/test/system/test_thrift_server.py (original) +++ cassandra/trunk/test/system/test_thrift_server.py Wed Oct 6 19:37:15 2010 @@ -1208,9 +1208,8 @@ class TestMutations(ThriftTester): client.system_drop_keyspace(keyspace) def test_system_keyspace_operations(self): - """ Test keyspace (add, drop, rename) operations """ - # create - keyspace = KsDef('CreateKeyspace', 'org.apache.cassandra.locator.SimpleStrategy', {}, 1, + # create. note large RF, this is OK + keyspace = KsDef('CreateKeyspace', 'org.apache.cassandra.locator.SimpleStrategy', {}, 10, [CfDef('CreateKeyspace', 'CreateKsCf')]) client.system_add_keyspace(keyspace) newks = client.describe_keyspace('CreateKeyspace') @@ -1218,14 +1217,8 @@ class TestMutations(ThriftTester): _set_keyspace('CreateKeyspace') - # modify invlid - modified_keyspace = KsDef('CreateKeyspace', 'org.apache.cassandra.locator.OldNetworkTopologyStrategy', {}, 2, []) - def fail_too_high_rf(): - client.system_update_keyspace(modified_keyspace) - _expect_exception(fail_too_high_rf, InvalidRequestException) - # modify valid - modified_keyspace.replication_factor = 1 + modified_keyspace = KsDef('CreateKeyspace', 'org.apache.cassandra.locator.OldNetworkTopologyStrategy', {}, 1, []) client.system_update_keyspace(modified_keyspace) modks = client.describe_keyspace('CreateKeyspace') assert modks.replication_factor == modified_keyspace.replication_factor