Apache Cassandra là gì?
Apache Cassandra là một NoSQL cơ sở dữ liệu phân tán khá phổ biến đối với các hệ thống lớn
Các khái niệm và thành phần
Node : Một máy tính hoặc một máy ảo khởi chạy một Cassandra instance. Các node trong cluster có vai trò như nhau, không có node nào làm node chính
Rack : Nhóm một hoặc nhiều nodes
Data Center : Nhóm một hoặc nhiều Rack
Cluster : Bao gồm một hoặc nhiều Data Center trong đó gồm một hay nhiều nodes kết nối với nhau, Dữ liệu của toàn hệ thống sẽ được tự động phân chia đến các nodes trong cluster
Gossip Protocol : Giao thức truyền thông giữa các nodes
Memtable và SSTable : Không gian bộ nhớ và không gian đĩa.
Khi write dữ liệu thì đầu tiên sẽ lưu trên memtable. Sau khi dữ liệu trên memtable full thì khi đó sẽ thực hiện ghi toàn bộ dữ liệu trên memtable xuống SSTable.
Khi read dữ liệu thì đầu tiên sẽ tìm trong memtable trước. Nếu không có thì lại tìm xuống SSTable để lấy.
Khi xoá dữ liệu thì thực tế dữ liệu không được xoá, mà nó được gán một cờ gọi là tombstone. Sau một khoảng thời gian nào đó các dữ liệu này sẽ được scan và xoá.
Row : Tập hợp các columns đã được sắp xếp. Có thể coi Row là đơn vị dữ liệu cơ bản và nhỏ nhất trong Cassandra. Nó có 3 thành phần: Row Key , Column Key và Column ValueColumn Family : Là tập hợp một hoặc nhiều Rows có cấu trúc giống nhau , tương đương với khái niệm table trong RDBMS. Column Family sẽ được sắp xếp theo key
Keyspace : Một tập hợp các Column Families. Tương đương với khái niệm Schema trong RDBMS
Cài đặt
Cài đặt JDK
https://filehippo.com/download_java_development_kit_64/8-update-181
Environment Variable
JAVA_HOME = C:\Program Files\Java\jdk1.8.0_181\bin
Cài đặt Cassandra
https://cassandra.apache.org/download
https://www.apache.org/dyn/closer.lua/cassandra/3.11.9/apache-cassandra-3.11.9-bin.tar.gz
cd C:\Program Files\apache-cassandra-3.11.9\bin
Edit JAVA_HOME in cassandra.bat
Cài đặt cqlsh
Python
https://www.python.org/download/releases/2.7
Copy all to C:\Program Files\apache-cassandra-3.11.9\bin
cassandra.bat -f
cqlsh
cqlsh> create keyspace test
cqlsh:test>CREATE TABLE emp(
emp_id int PRIMARY KEY,
emp_name text,
emp_city text,
emp_sal varint,
emp_phone varint
);
cqlsh:test> select * from emp;
https://medium.com/@sushantgautam_930/simple-way-to-install-cassandra-in-windows-10-6497e93989e6
Công cụ quản lý
NodeTool
https://cassandra.apache.org/doc/latest/tools/nodetool/nodetool.html
NoSQL Manager for Cassandra
https://www.mongodbmanager.com/cassandra
TablePlus
Thư viện C#
https://www.nuget.org/packages/CassandraCSharpDriver
https://github.com/datastax/csharp-driver
ORM
https://www.nuget.org/packages/CqlPoco
https://github.com/LukeTillman/cqlpoco
Tham khảo thêm
https://nghethuatcoding.com/2019/05/26/tat-tan-tat-ve-apache-cassandra
https://medium.com/@brunocrt/the-distributed-architecture-behind-cassandra-database-fba8b5cc4785
https://jiankaiwang.gitbooks.io/itsys/content/cassandra/architecture.html
Tiếp tục cập nhật ...