Change keyspace replication strategy
A keyspace is created with a replication strategy.
For development environments, the SimpleStrategy class is acceptable.
For production, you must use NetworkTopologyStrategy.
To change the strategy, alter the distribution of nodes within multiple datacenters by adding a datacenter, add data to the new nodes in the new datacenter, then finally remove nodes from the old datacenter.
Procedure
-
If necessary, change the snitch to a network-aware setting.
-
Alter the keyspace properties using the CQL
ALTER KEYSPACEcommand.-
To change the replication strategy for the
cyclingkeyspace fromSimpleStrategytoNetworkTopologyStrategyfor a single datacenter:ALTER KEYSPACE cycling WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'DC1' : 3 }; -
To change the replication strategy for the
cyclingkeyspace fromSimpleStrategytoNetworkTopologyStrategyfor two datacenters:ALTER KEYSPACE cycling WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'DC1' : 3, 'DC2' : 3 };
-
-
Simply altering the keyspace may lead to faulty data replication. Run
nodetool repairwith the-fulloption on each node affected by the change.nodetool repair -full KEYSPACEReplace
KEYSPACEwith the name of the keyspace. -
It is possible to restrict the replication of a keyspace to selected datacenters or a single datacenter. To do this, use the
NetworkTopologyStrategyand set the replication factors of the excluded datacenters to0(zero):ALTER KEYSPACE cycling WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'DC1' : 0, 'DC2' : 3, 'DC3' : 0 };