Changing keyspace replication strategy

A keyspace is created with a replication strategy. For development, 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, and then add data to the new nodes in the new datacenter and remove nodes from the old datacenter.

Procedure

  1. If necessary, change the snitch to a network-aware setting.

  2. Alter the keyspace properties using ALTER KEYSPACE:

    • Example 1: Switch the keyspace cycling from SimpleStrategy to NetworkTopologyStrategy for a single datacenter:

      cqlsh> ALTER KEYSPACE cycling WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'DC1' : 3};
    • Example 2: Switch the keyspace cycling from SimpleStrategy to NetworkTopologyStrategy for two datacenters:

      cqlsh> ALTER KEYSPACE cycling WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'DC1' : 3, 'DC2' : 2 };

      Simply altering the keyspace may lead to faulty data replication.

  3. Run nodetool repair using the -full option on each node affected by the change.

    nodetool repair -full keyspace

    Tarball and Installer No-Services path:

    <installation_location>/resources/cassandra/bin

    It is possible to restrict the replication of a keyspace to selected datacenters or a single datacenter. To do this, use the NetworkTopologyStrategy and set the replication factors of the excluded datacenters to 0 (zero):

    cqlsh> ALTER KEYSPACE cycling WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'DC1' : 0, 'DC2' : 3, 'DC3' : 0 };

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com