ALTER KEYSPACE
When you alter a keyspace, you can modify the following options:
-
Replication strategy class
-
Replication factor
-
Durable writes for the commit log
-
Graph engine
You cannot change the keyspace name. If you need to change the keyspace name, you must create a new keyspace with the desired name and migrate the data accordingly.
|
Changing the replication factor of a keyspace impacts the distribution of replica nodes across the cluster. It can take time for data to redistribute to new nodes or for removed nodes to scale down. |
Synopsis
ALTER KEYSPACE <keyspace_name>
WITH REPLICATION = { <replication_map> }
[ AND DURABLE_WRITES = ( true | false ) ]
[ AND graph_engine = 'Core' ];
| Syntax conventions | Description |
|---|---|
UPPERCASE |
Literal keyword. |
Lowercase |
Not literal. |
|
Variable value. Replace with a user-defined value. |
|
Optional.
Square brackets ( |
|
Group.
Parentheses ( |
|
Or.
A vertical bar ( |
|
Repeatable.
An ellipsis ( |
|
Single quotation ( |
|
Map collection.
Braces ( |
|
Set, list, map, or tuple.
Angle brackets ( |
|
End CQL statement.
A semicolon ( |
|
Separate the command line options from the command arguments with two hyphens ( |
|
Search CQL only: Single quotation marks ( |
|
Search CQL only: Identify the entity and literal value to overwrite the XML element in the schema and solrConfig files. |
Options
| Option | Description | Default | ||
|---|---|---|---|---|
|
Name of the keyspace to alter. |
|||
|
A map of settings for the replication strategy and factor. The The The For examples, see Examples. |
|||
|
Non-default configuration not recommended. If
|
|
||
|
Optional.
Use to treat a Cassandra keyspace as a graph.
Only the |
Examples
- Use the SimpleStrategy class
-
ALTER KEYSPACE cycling WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 3 }; - Use the NetworkTopologyStrategy class
-
Switching from
SimpleStrategytoNetworkTopologyStrategyis a common operation when moving from a single-datacenter setup to a multi-datacenter setup. With this strategy, you provide a list of datacenters with individual replication factors, instead of a single replication factor for the entire cluster.You cannot insert data into a table in a keyspace that uses
NetworkTopologyStrategyunless you define the datacenter names in the snitch properties file.Altering the distribution of nodes within multiple datacenters when data is present can be accomplished by adding a datacenter. Then, send new writes to the 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 and must match the names configured in the snitch properties file.
ALTER KEYSPACE cycling WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'DC1' : 3 [, 'DC2' : 5 ] }; - Mark a keyspace as a graph
-
ALTER KEYSPACE food_cql WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor': 1 } AND graph_engine = 'Core';
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 altered keyspace on all nodes in the datacenters where you increased the replication factor, including new datacenters added to the replication strategy:
nodetool repair --full -pr <keyspace_name> -
If you decreased the replication factor or removed datacenters from the replication strategy, run a cleanup of the keyspace on all nodes belonging to the relevant datacenters.
This operation releases the space previously held by the now unused replicas.
nodetool cleanup <keyspace_name>