Cassandra DBA – Tricks and tips

Change replication factor for an existing keyspace

ALTER KEYSPACE acme WITH REPLICATION =  { 'class' : 'SimpleStrategy', 'replication_factor' : 2 };

Drop a keyspace

DROP KEYSPACE acme;

Drop a column

ALTER TABLE person DROP mail;

Add a column

ALTER TABLE person ADD email text;

Counting keys (rows) in column. Here is a quick way to get an “estimated” count

nodetool cfstats acme.person

Command to check cluster / node status

nodetool status

Force restart of datastax agent

service datastax-agent force-reload

How to insert current date-time into a table using CQL?

This can be done using the now and dateof functions.

The now function takes no arguments and generates a new unique timeuuid (at the time where the statement using it is executed).

The dateof function takes a timeuuid argument and extracts the embedded timestamp.

INSERT INTO account (name, created) VALUES ('acme', dateof(now()));
Advertisements

Java and Cassandra setup on an AWS Linux server

Java 7 Setup

# First verify the version of Java being used is not Oracle JDK.
java -version

# Get the latest JDK 7 from Oracle http://www.oracle.com/technetwork/java/javase/downloads/
wget http://download.oracle.com/otn-pub/java/jdk/XXXXXX/jdk-7u71-linux-x64.rpm
# Install Java
sudo rpm -i jdk-7u71-linux-x64.rpm
# Check if the default java version is set to Oracle jdk
java -version

# If not then lets create one more alternative for Java for Oracle JDK
sudo /usr/sbin/alternatives --install /usr/bin/java java /usr/java/jdk1.7.0_71/bin/java 20000
# Set the Oracle JDK as the default java
sudo /usr/sbin/alternatives --config java

# Verify if change in SDK was done.
java -version

Cassandra Setup

Download Cassandra from http://cassandra.apache.org/download/

  • Unzip/Untar the file apache-cassandra-2.1.0-bin.tar.gz
    • Copy the Cassandra folder apache-cassandra-2.1.0 to /usr/share
  • Edit the file /usr/share/apache-cassandra-2.1.0/conf/cassandra.yaml if necessary
  • Make sure /var/lib/cassandra has sufficient space

Start cassandra using the command:

/usr/share/apache-cassandra-2.1.o/bin/cassandra