Task: Create new keyspace and tables and insert rows and columns to tables.
Objective: Learn how cassandra replication factor works and how partition key and cluster determine where and how data is stored.
https://github.com/smhillin/cassandra_bootcamp/blob/master/ccm_install.md
ccm node1 cqlsh
CREATE KEYSPACE my_test WITH replication = {'class' : 'SimpleStrategy','replication_factor':2};
use my_test;
CREATE TABLE students (name text, email text, PRIMARY KEY(name));
DESCRIBE students;
INSERT INTO students (name, email) VALUES ('shaun', '[email protected]');
INSERT INTO students (name, email) VALUES ('meghan', '[email protected]');
SELECT * FROM students;
What is happening here?
exit;
ccm node1 json -k my_test -c students test; cat test;
ccm node2 json -k my_test -c students test; cat test;
ccm node3 json -k my_test -c students test; cat test;
ccm flush
ccm node1 json -k my_test -c students test; cat test;
ccm node2 json -k my_test -c students test; cat test;
ccm node3 json -k my_test -c students test; cat test;
ccm node4 json -k my_test -c students test; cat test;
CREATE KEYSPACE my_test_3 WITH replication = {'class' : 'SimpleStrategy','replication_factor':3};
use my_test_3;
CREATE TABLE amigos (name text, email text, PRIMARY KEY(name));
DESCRIBE amigos;
INSERT INTO amigos (name, email) VALUES ('shaun', '[email protected]');
INSERT INTO amigos (name, email) VALUES ('meghan', '[email protected]');
INSERT INTO amigos (name, email) VALUES ('george', 'george @gmail.com');
SELECT * FROM amigos;
ccm flush amigos
ccm node1 json -k my_test_3 -c amigos test; cat test;
ccm node2 json -k my_test_3 -c amigos test; cat test;
ccm node3 json -k my_test_3 -c amigos test; cat test;
ccm node4 json -k my_test_3 -c amigos test; cat test;
DROP TABLE amigos;
CREATE TABLE mates (first_name text , last_name text, PRIMARY KEY(first_name));
INSERT INTO mates (first_name, last_name) VALUES ('John', 'Bonham');
INSERT INTO mates (first_name, last_name) VALUES ('John', 'Lennon');
INSERT INTO mates (first_name, last_name) VALUES ('Jimmy', 'Paige');
INSERT INTO mates (first_name, last_name) VALUES ('Jimmy', 'Hendrix');
SELECT * FROM mates
DROP TABLE mates;
CREATE TABLE mates (first_name text , last_name text, PRIMARY KEY(first_name, last_name));
DESCRIBE mates;
INSERT INTO mates (first_name, last_name) VALUES ('John', 'Bonham'); ' INSERT INTO mates (first_name, last_name) VALUES ('John', 'Lennon');
INSERT INTO mates (first_name, last_name) VALUES ('Jimmy', 'Paige');
INSERT INTO mates (first_name, last_name) VALUES ('Jimmy', 'Hendrix');
SELECT * FROM mates
Jot down each row that you inserted, and make note of what node they reside on. What is happening here? Whats the replication appear to be?
exit;
ccm flush
ccm node1 json -k my_test_3 -c mates test; cat test;
ccm node2 json -k my_test_3 -c mates test; cat test;
ccm node3 json -k my_test_3 -c mates test; cat test;
ccm node4 json -k my_test_3 -c mates test; cat test;