Read and Write path in Cassandra
Last Updated :
24 Jul, 2020
Prerequisites –
Write Path Execution in Cassandra :
- In Cassandra, while writing data, writes are written to any node in the cluster (coordinator).
- when any user will insert data, it means they write the data first to commit log then to memtable.
- When any user will write the data, every write will include a timestamp.
- Once memtable starts getting full then it is flushed to disk periodically (SSTable).
- After that a new memtable is created in memory.
- In the case of write path execution, deletes are special write cases which are called a tombstone.
Inserting Data :
In case of inserting data in Cassandra, we will create a keyspace and then create a table and then insert data into the table.
Example –
// Creating a keyspace
create keyspace UniersityData
replication = {'class': 'SimpleStrategy', 'replication_factor' : '3' };
// Creating a table and declaring the columns
create table CSE_Student(
student_id int,
name text,
email text,
primary key(student_id)
);
// Using the newly created keyspace
use UniersityData;
// Inserting values in the table for all the columns
Insert into CSE_student(student_id, name, email)
values(012345, 'Ashish', 'ashish@gmail.com');
Insert into CSE_student(student_id, name, email)
values(012346, 'Abi', 'abi@gmail.com');
Insert into CSE_student(student_id, name, email)
values(012347, 'Rana', 'rana@gmail.com');
Insert into CSE_student(student_id, name, email)
values(012348, 'Aayush', 'aayush@gmail.com');
Insert into CSE_student(student_id, name, email)
values(012349, 'harsh', 'haarsh@gmail.com');
Read Path Execution :
- In Cassandra while reading data, any server may be queried which acts as the coordinator.
- when we want to access read data then we contact nodes with requested key.
- In a data center, on each node, data is pulled from SStable and is merged.
- In Cassandra, while considering read consistency, we can check –
Consistency < ALL performs read repair in the background (read_repair_chance).
Reading Data :
Write a cqlsh query to read data from CSE_student and give output for the same.
select *
from CSE_student;
Output :
index |
student_id |
name |
email |
0 |
12345 |
Ashish |
ashish@gmail.com |
1 |
12346 |
Abi |
abi@gmail.com |
2 |
12347 |
Rana |
rana@gmail.com |
3 |
12348 |
Aayush |
aayush@gmail.com |
4 |
12349 |
harsh |
haarsh@gmail.com |
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...