Setting Up Cassandra for Development
Let's get a local Cluster
- Cassandra Cluster Manager (CCM)
- https://github.com/pcmanus/ccm
- Works with Cassandra and DataStax Enterprise
- Quickly setup/tear down clusters for development
ccm create cassandra_dev_cluster -n 3 -v 2.1.2
ccm create dse_dev_cluster --dse
--dse-username=philip.s.doctor_gmail.com
--dse-password=ffddHgn5rS -v 4.6.5
ccm start
Cqlsh
- CQL is Cassandra Query Language, it looks a lot like SQL
- There is a shell for connecting to a node and trying out commands, let's try it.
./ccm status
Cluster: 'cassandra_dev_cluster'
--------------------------------
node1: UP
node3: UP
node2: UP
./ccm node2 cqlsh
Connected to cassandra_dev_cluster
at 127.0.0.2:9042.
Create a Keyspace
- Keyspaces manage tables
- They specify Replication Factor (RF)
- They specify Replication Strategy (where data goes)
- SimpleStrategy is a Replication Strategy that says "Store on node that partitioner says, then go around the ring clockwise for replicas"
CREATE KEYSPACE intro
WITH REPLICATION =
{ 'class' : 'SimpleStrategy',
'replication_factor' : 3 };
use intro;
Create a Table
- Tables hold your data
- Choose a Primary Key that fits your data usage patterns.
- Specify other options such as encryption and compression.
- Lots of table creation options useful for optimizations.
CREATE TABLE test_data (
data_id int PRIMARY KEY,
data_item text
);
Insert and Select Data
- When selecting, we don't have joins and we want to select using the primary key if we can.
insert into test_data (data_id, data_item)
values (1, 'foo');
select * from test_data where data_id = 1;
Replication Power
- One last demo, let's see some nodes "crash" on us and what it looks like to a client consuming Cassandra.
ccm node1 stop && ccm node2 stop
ccm status
ccm node3 cqlsh
Learn More
Datastax Academy
https://academy.datastax.com/
Datastax Documentation
http://docs.datastax.com/en/cql/3.1/cql/cql_reference/create_keyspace_r.html
http://docs.datastax.com/en/cql/3.1/cql/cql_reference/create_table_r.html
CCM
https://github.com/pcmanus/ccm
Setting up C* for Dev
By Philip Doctor
Setting up C* for Dev
A short tutorial to get your feet wet and start dev.
- 1,362