Changing replica count

You can modify replica count when you add or remove a data center to consider the increased or decreased number of nodes.

When you add a data center, you might have to change the keyspace definition to set a replication policy for the new data center. Complete the following steps to change the replica count:
Important: The configureDatabase uses the init.py script, which in turn uses the cqlsh utility. Therefore, to run the init.py script, you must set the path for the cqlsh utility after you install Cassandra. The path to cqlsh utility is, <install_dir>/apache-cassandra/bin.
  1. Start the configureDatabase script.
    Note:

    To start the script, the current working directory of the shell does not need to be the same directory as the script.

  2. Type the following command to mark the script as executable:

    chmod u+x init.py

  3. To see the usage information, start the script with either the -h or -help option, as follows:

    bash configureDatabase.sh

    The following usage information is displayed:

    --- BEGIN USAGE ---

    bash configureDatabase.sh <consistency|replication> <settings>

    consistency <consistency setting> <mailbox.properties file>

    replication <configuration file> <init.py file> <optional host to alter replication settings on (defaults to localhost)>

    --- END USAGE ---

  4. To configure the replica count, type the following command:

    bash configureDatabase.sh replication /path/to/configuration/XML /path/to/init.py <optional hostname>

    <configuration file> is a replication XML configuration file. The XML configuration file defines the keyspaces that must be created when you initialize the database. Following is a sample XML configuration file:
    <?xml version="1.0" encoding="UTF-8" ?>
    <keyspaces>
        <keyspace>
            <name>mailbox</name>
            <datacenters>
                <datacenter>
                    <name>datacenter1</name>
                    <replication_factor>1</replication_factor>
                </datacenter>
            </datacenters>
        </keyspace>
        <keyspace>
            <name>gatekeeper</name>
            <datacenters>
                <datacenter>
                    <name>datacenter1</name>
                    <replication_factor>1</replication_factor>
                </datacenter>
            </datacenters>
        </keyspace>
    </keyspaces>
    As illustrated in the preceding example, a configuration file contains a keyspaces root element. Within this element, there exist a series of keyspace subelements. Each keyspace has a name and an associated list of datacenters. Each datacenter is a name and replication_factor pair. It is possible to have arbitrarily many datacenter elements that are associated with a datacenters parent element, but each keyspace can have exactly one datacenters element, which in turn must define at least one datacenter.