diff --git a/src/main/java/org/elasticsearch/cassandra/cluster/InternalCassandraClusterService.java b/src/main/java/org/elasticsearch/cassandra/cluster/InternalCassandraClusterService.java index c78564464af..238d8066b32 100644 --- a/src/main/java/org/elasticsearch/cassandra/cluster/InternalCassandraClusterService.java +++ b/src/main/java/org/elasticsearch/cassandra/cluster/InternalCassandraClusterService.java @@ -713,11 +713,11 @@ public ClusterState updateNumberOfShards(ClusterState currentState) { String keyspace = indexMetaData.getSettings().get(IndexMetaData.SETTING_KEYSPACE,indexMetaData.getIndex()); if (Schema.instance != null && Schema.instance.getKeyspaceInstance(keyspace) != null) { AbstractReplicationStrategy replicationStrategy = Schema.instance.getKeyspaceInstance(keyspace).getReplicationStrategy(); + int rf = replicationStrategy.getReplicationFactor(); if (replicationStrategy instanceof IDistributedReplicationStrategy) { - indexMetaDataBuilder.numberOfReplicas( ((IDistributedReplicationStrategy)replicationStrategy).getReplicationFactor(DatabaseDescriptor.getLocalDataCenter()) - 1 ); - } else { - indexMetaDataBuilder.numberOfReplicas( replicationStrategy.getReplicationFactor() - 1 ); - } + rf = ((IDistributedReplicationStrategy)replicationStrategy).getReplicationFactor(DatabaseDescriptor.getLocalDataCenter()); + } + indexMetaDataBuilder.numberOfReplicas( Math.max(0, rf -1) ); } else { indexMetaDataBuilder.numberOfReplicas( 0 ); }