Check cluster status
You can obtain information about the cluster such as the state, the load rate of each node and IDs. Connect to one of the nodes of your cluster and run the following command:
$ nodetool status
This is an example of the output from running the nodetool status command:
datacenter: datacenter1
========================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 10.0.6.66 335.61 KiB 256 39.6% 73d7741f-40a8-4f8f-8f49-073ce37e2c23 rack1
UN 10.0.4.215 199.95 KiB 256 41.2% 0fa77708-f5a7-4160-93ac-09944fd4c66c rack1
UN 10.0.7.42 227.53 KiB 256 41.7% cd6c98b5-1551-4dff-8fa6-feeb11da32ed rack1
- UN= Up and Normal.
- UJ= Up and Joining.
The replication is automatic between nodes. Check the Cassandra official documentation to know more about replication.
Users can define how many replicas are needed, and Cassandra handles replica creation and management transparently. To understand how it works, consider the example below of a two-node cluster (pick a single node in the cluster on which to perform the initial configuration):
-
Node 1, creating the data:
-
Create a keyspace and verify that it has been added, then change to that keyspace:
CREATE KEYSPACE bntest WITH REPLICATION = { 'class': 'SimpleStrategy', 'replication_factor' : 2 }; DESCRIBE KEYSPACES; USE bntest;
NOTE: In this example we have used the replication_factor in order to copy the data to a minimum of 2 nodes.
-
Create a table and check that it has been created correctly:
CREATE TABLE bntest.bntable ( key text PRIMARY KEY, values set<text>); DESCRIBE TABLES;
-
Insert some sample data in the table and check it:
INSERT INTO bntest.bntable (key, values) VALUES ('foo', {'bar'}); SELECT key, values FROM bntest.bntable WHERE key = 'foo';
-
-
Node 2, checking the replication:
-
Execute the following commands to check that you obtain an identical output as in node 1:
DESCRIBE KEYSPACES; USE bntest; DESCRIBE TABLES; SELECT key, values FROM bntest.bntable WHERE key = 'foo';
-
Delete the data in node 1 and verify that it was removed:
USE bntest; DELETE FROM bntest.bntable WHERE key = 'foo'; SELECT key, values FROM bntest.bntable WHERE key = 'foo'; DROP TABLE bntest.bntable; DESCRIBE TABLES; DROP KEYSPACE bntest; DESCRIBE KEYSPACES;
-
Check that the data has been also deleted in node 2:
USE bntest; SELECT key, values FROM bntest.bntable WHERE key = 'foo'; DESCRIBE TABLES; DESCRIBE KEYSPACES;
-