Creating a keyspace

Add a new keyspace and set the replication factor.

A keyspace is the equivalent to a SQL database. It is the top level container for database objects. The keyspace replication strategy and factor control data availability for a set of tables in each datacenter of the cluster.
  • SimpleStrategy: Applies the same replication setting across the cluster. Use this setting only on single node test or development environments.
  • NetworkTopography: Applies the replication setting per datacenter. Use in production environments.

Procedure

  1. Verify the datacenter name using nodetool status.
    installation_location/bin/nodetool status

    The output is:

    Datacenter: datacenter1
    ================
    Status=Up/Down
    |/ State=Normal/Leaving/Joining/Moving
    --  Address         Load       Tokens       Owns    Host ID                               Rack
    UN  10.200.181.134  4.97 MiB   1            ?       c9027497-011c-4390-ae59-e4ed1ac794cc  rack1
    UN  10.200.181.135  5.16 MiB   1            ?       af2af8ec-5fa2-4a04-ac9c-c75669d8d3a0  rack1
    
  2. Verify the datacenter names, which are case sensitive and ensure that you exactly match the case in the next step.
  3. Start cqlsh and create a keyspace.
    CREATE KEYSPACE IF NOT EXISTS cycling 
    WITH REPLICATION = { 
      'class' : 'NetworkTopologyStrategy', 
      'datacenter1' : 3};
  4. Switch to the keyspace.
    USE cycling;