Alter a keyspace
You can change a keyspace’s strategy class and replication factor. See Data replication for more information.
Change a simple replication_factor
value
To change a simple replication factor, either increase or decrease the value to change the total number of copies of keyspace data stored in a cluster.
Use the ALTER KEYSPACE
command to change the value of a keyspace using the SimpleStrategy
class:
ALTER KEYSPACE cycling
WITH REPLICATION = {
'class' : 'SimpleStrategy',
'replication_factor' : 2,
};
This change requires that a datacenter is named, not just a replication factor.
Changing the replication factor of a keyspace impacts each node that the keyspace replicates to (or no longer replicates to). It can take some time for data to redistribute to new nodes or for removed nodes to scale down. |
Change the replication strategy
and the replication_factor
values
The most common replication strategy modification is to switch the strategy class from SimpleStrategy
to NetworkTopologyStrategy (NTS)
.
When the NetworkTopologyStrategy
class is set, the replication_factor
must be modified to specify one or more datacenters.
You cannot insert data into a table in a keyspace that uses |
Altering the distribution of nodes within multiple datacenters when data is present can be accomplished by adding a datacenter. Then, add data to the new nodes in the new datacenter, and remove nodes from the old datacenter.
You must make this change on all affected nodes.
Verify the spelling of the datacenter name before using this command because datacenter names are case-sensitive.
ALTER KEYSPACE cycling
WITH REPLICATION = {
'class' : 'NetworkTopologyStrategy',
'DC1' : 3,
'DC2' : 2
};
Run full repair
If you add datacenters or reduce the replication factor, you must run a full repair on the keyspace. |
Run a full repair of the keyspace on all nodes belonging to the datacenters where the replication factor has been increased. Also, run a full repair of the keyspace in the datacenters that have been added to the replication list.
nodetool repair --full -pr <keyspace_name>
If you decrease the replication factor, run a cleanup of the keyspace on all nodes belonging to the datacenters that had their replication factor decreased. Also, run a cleanup of the keyspace on the datacenters that were removed from the replication list. This action will free up the space held by the now unused replicas of the data.
nodetool cleanup <keyspace_name>