Cassandra

Overview

一個cassandra 集群是由一些commodity server組成的ring-like的去中心化網(wǎng)絡(luò)。一個client連接cluster是通過連接這個ring中的任意一個node。然后使用CQL interface。這個client連接的node就叫做coordinator。

Cassandra是一個分布式的系統(tǒng),它依賴于data partitioning去將數(shù)據(jù)分布到cluster的node上。 為了防止single-point-of-failure, 它需要employ data replication去存儲數(shù)據(jù)副本(replicas)。 這樣才會有high availability。

我們會設(shè)置一個參數(shù),表示每一次成功的讀寫至少需要多少的replicas acknowledge。也可以說,當(dāng)一定數(shù)量的讀寫被relicas執(zhí)行之后,Coordinator 才會告訴client本次讀寫成功

一個operation在data propagated 給所有node的之前就可以標(biāo)記為成功了. 這個對performance是非常重要的。
Nodes in the Cassandra cluster rely on the Gossip Protocol to exchange information with each other.
This protocol allows nodes to obtain state information about other nodes by exchanging information a node has about itself and other nodes. A particular node does not directly exchange information with every other node in the cluster;

node通過流言協(xié)議就可以知道其它node的情況,所以不需要直接和所有其它node交換信息。

Cassandra Query Language

With the Cassandra server running, open a new terminal window and access the Cassandra Query Language shell by typing:

$ cqlsh 

A keyspace is a container for our application data. You could think of it as an analogue to schema of a RDBMS. The keyspace requires that the replication strategy and replication factor be specified — the number of nodes data must be distributed as replicas to.

CREATE KEYSPACE test01
    WITH REPLICATION = {
        'class': 'SimpleStrategy', 
        'replication_factor': 1
    };
$ DESCRIBE KEYSPACES
system_schema  system_auth  system  system_distributed  system_traces  test01

swithc key space

USE test01;
CREATE TABLE countries (
    id INT PRIMARY KEY,
    official_name TEXT,
    capital_city TEXT
);
INSERT INTO countries (id, official_name, capital_city) VALUES (1, 'Islamic Republic of Afghanistan', 'Kabul');
SELECT * FROM countries WHERE id = 1;
image.png

Reference:
https://medium.com/@areeves9/cassandras-gossip-on-os-x-single-node-installation-of-apache-cassandra-on-mac-634e6729fad6

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容