8. Cassandra Operations¶
In this section operations on Cassandra are described.Descriptions in this document are based on [[Table 1. Cassandra Connection Information Setting Example]].
[[Table 1. Cassandra Connection Information Setting Example]]
Cluster Name
IMBox Cluster
Host IP Address
localhost
Host Port Number
9160
Authentication Setting Enable
false
Keyspace
default
Topics
8.1. Keyspace Creation¶
Please start Cassandra.
Confirm that Cassandra has been started, and start cassandra-cli.
- In case of Windows, double-click <%CASSANDRA_HOME%/bin/cassandra-cli.bat>.
- In case of Linux, execute the command below to start it.
/usr/local/cassandra/bin/cassandra-cliWhen the console has shown up, please enter the command below.
connect localhost/9160;Please confirm that the connection is successful, and enter the command below.
create keyspace default;The message below is displayed, and you can confirm that the keyspace [default] has been created successfully.
... schemas agree across the cluster
8.2. Keyspace Creation Method (with Authentication Setting)¶
Procedures for creating the keyspace in Cassandra with the following conditions are introduced.
- Connection User Name : aoyagi
- Password : aoyagi_pwd
- Keyspace Name : imbox_keyspace
Password should be added to Connection Authentication Setting (passwd.properties).
admin=admin_pwd user=user_pwd aoyagi=aoyagi_pwdAdd the keyspace which aoyagi can access to Access Authority Setting (access.properties).
# The magical '<modify-keyspaces>' property lists users who can modify the # list of keyspaces: all users will be able to view the list of keyspaces. <modify-keyspaces>=admin # Access to Keyspace 'default' default.<rw>=admin default.<ro>=user # Access to all ColumnFamily default.*.<rw>=admin default.*.<ro>=user # Access to Keyspace 'imbox_keyspace' imbox_keyspace.<rw>=aoyagi imbox_keyspace.<ro>=user # Access to all ColumnFamily imbox_keyspace.*.<rw>=aoyagi imbox_keyspace.*.<ro>=userWarning
In case authentication setting is used, keyspace other than the one set in access.properties may not be created.Please start Cassandra.
Then, please specify authentication information, and start cassandra-cli.
In case of Windows, please start the Command Prompt, and execute the command below.
%CASSANDRA_HOME%/bin/cassandra-cli -u aoyagi -pw aoyagi_pwdIn case of Linux, please execute the command below to do startup.
/usr/local/cassandra/bin/cassandra-cli -u aoyagi -pw aoyagi_pwdNote
Please refer to [How Connection Authentication is Confirmed] for the method of specifying authentication information.Please confirm that the connection is successful, enter the command below, and create [imbox_keyspace].
create keyspace imbox_keyspace;The message below should be displayed, and you can confirm that the keyspace [imbox_keyspace] has been added.
... schemas agree across the clusterNote
In case you need to build the cluster and create keyspaces in multiple Cassandra’s, you can create the keyspace in Cassandra of seed node,and then execute the nodetool repair command. As a consequence, keyspaces are created in other nodes, and it would not be necessary to create the keyspace on every node.
8.3. Keyspace Deletion Method¶
Cassandra should be started.
Please confirm that Cassandra has been started, and start cassandra-cli.
Startup method of cassandra-cli is as follows.
In case of Windows, please double-click <%CASSANDRA_HOME%/bin/cassandra-cli.bat>.
In case of Linux, please run the command below and do the startup.
/usr/local/cassandra/bin/cassandra-cliWhen the console has shown up, please enter the command below.
connect localhost/9160;[Connected to: “IMBox Cluster” on localhost/9160] should be displayed on the console. Please enter the command below.
drop keyspace default;Deletion is completed, if [... schemas agree across the cluster] is displayed on the console.
8.4. Flush¶
On Cassandra, data is stored to the memory called memtable.In order to write data to SStable on the file system which is set by [data_file_directories] property of cassandra.yaml, it is necessary to execute the flush command of nodetool.In case no redundancy is provided, data loss might occur if the server should stop before memtable data is written to SStable. It is recommended that you do the flush operation periodically.
In case of Windows, please start the Command Prompt, and execute the command below.
%CASSANDRA_HOME%/bin/nodetool -h [IP address of the Node to be executed] flushIn case of Linux, please execute the command below.
# /usr/local/cassandra/bin/nodetool -h [IP address of the Node to be executed] flushAfter the execution, following log will be generated on Cassandra.
INFO 15:12:11,104 Enqueuing flush of Memtable-Versions@2895088(83/103 serialized/live bytes, 3 ops) INFO 15:12:11,105 Writing Memtable-Versions@2895088(83/103 serialized/live bytes, 3 ops) INFO 15:12:11,258 Completed flushing %CASSANDRA_HOME%\data\system\Versions\system-Versions-he-3-Data.db (247 bytes) for commitlog position ReplayPosition(segmentId=42805933509718, position=544)
8.5. Snapshot¶
In order to back up the data of Cassandra, it is necessary to make a snapshot using the snapshot command of nodetool.However, since the snapshot of Cassandra is generated by simply copying the SStable file, you must not fail to execute the flush command before executing the snapshot.Procedures for making the snapshot are as follows.
In case of Windows, please start the Command Prompt, and execute the commands below.
%CASSANDRA_HOME%/bin/nodetool -h [IP address of the Node to be executed] flush %CASSANDRA_HOME%/bin/nodetool -h [IP address of the node to be executed] snapshot -t (arbitrary snapshot name)In case of Linux, please execute the commands below.
# /usr/local/cassandra/bin/nodetool -h [IP address of the Node to be executed] flush # /usr/local/cassandra/bin/nodetool -h [IP address of the Node to be executed] snapshot -t (arbitrary snapshot name)Note
Data that was snapshot shall be copied to the directory specified by [data_file_directories] property of conf/cassandra.yaml. Please see below for details.In case [data_file_directories] of %CASSANDRA_HOME%/conf/cassandra.yaml is /var/lib/cassandra/data/
Cassandra System Information /var/lib/cassandra/data/system/(Column Family Name)/snapshot/(Snapshot Name) IMBox Data /var/lib/cassandra/data/default/(Column Family Name)/snapshot/(Snapshpot Name) Note
Snapshot Deletion
All snapshot directories should be deleted.
# /usr/local/cassandra/bin/nodetool -h [IP address of the Node to be executed] clearsnapshotPlease delete arbitrary snapshot.
# /usr/local/cassandra/bin/nodetool -h [IP address of the Node to be executed] clearsnapshot -t (arbitrary snapshot name)Warning
Even if you execute clearsnapshot command in Windows environment, deletion process will fail, because the file to be deleted is seized by the Cassandra process.If you execute the command below, SSTable will be recreated at which time the reference to the file is released.nodetool upgradesstablesBy subsequently executing clearsnapshot, snapshot can be successfully deleted.This problem would not occur in the Linux environment.
8.6. Recovery (Restore) by Snapshot Data¶
If the data has been saved by snapshot, it can be recovered (restored) to the point of snapshot.
- In case of Windows
- Cassandra should be stopped.
- Please delete the file of commitlog (example: C:/var/lib/cassandra/commit_log).
- Please delete SSTable (example: Each db file of C:/var/lib/cassandra/data/default/(Column Family Name)/ should be deleted).
- Please copy each db file of snapshot to C:/var/lib/cassandra/data/default/(Column Family Name).
- Please start Cassandra.
- In case of Linux
- Cassandra should be stopped.
- Please delete the file of commitlog (example: /var/lib/cassandra/commit_log).
- Please delete SSTable (Each db file of /var/lib/cassandra/data/default/(Column Family Name)/ should be deleted).
- Please copy each db file of snapshot to /var/lib/cassandra/data/default/(Column Family Name).
- Please start Cassandra.