From wikipedia  https://en.wikipedia.org/wiki/CAP_theorem

In theoretical computer science, the CAP theorem, also named Brewer's theorem after computer scientist Eric Brewer, states that it is impossible for a distributed data store to simultaneously provide more than two out of the following three guarantees:[1][2][3]

Consistency Availability Partition tolerance
Every read receives the most recent write or an error Every request receives a (non-error) response – without guarantee that it contains the most recent write The system continues to operate despite an arbitrary number of messages being dropped (or delayed) by the network between nodes

In other words, the CAP Theorem states that in the presence of a network partition, one has to choose between consistency and availability. Note that consistency as defined in the CAP Theorem is quite different from the consistency guaranteed in ACID database transactions.

维基上对CAP有简单的解释

C 一致性 读请求要么读到最新值,要么触发错误

A 可用性 每个请求都能收到一个非错误的相应,不保证读取的一定是最新值

P 分区容忍性 系统可在网络节点之间丢包或者包延迟的情况下继续运行

CAP理论说,分布式系统无法三者兼顾,须有舍得。

As a distributed system, multiple nodes are required to balance and handle growing loads, which is why P is usually required as default. Since the module has more than one nodes, scacrificing either consistency or 100% availability is unavoidable according to the theory.

作为分布式系统,为了负载均衡以及应对日益增长的访问压力,分区容忍性通常都是需要的。根据CAP理论,我们只好在一致性与100%可用之间做出一定的牺牲。

ACID is typical property of traditional relational databse.

ACID是传统关系型数据库的特点。

Atomicity Atomicity requires that each transaction be "all or nothing": if one part of the transaction fails, then the entire transaction fails, and the database state is left unchanged

原子性 一个事务中所有操作都必须全部完成,要么全部不完成。

Consistency The consistency property ensures that any transaction will bring the database from one valid state to another.

一致性 事务将把数据库从一个状态带入另一个状态。

Isolation The isolation property ensures that the concurrent execution of transactions results in a system state that would be obtained if transactions were executed sequentially, i.e., one after the other.

隔离性 各种事务并发执行会感觉到和串行无差。

Durability The durability property ensures that once a transaction has been committed, it will remain so, even in the event of power loss, crashes, or errors.

持久性 一旦事务完成,宕机,断电都不会影响

Another consistent model is called BASE ( Basically Available, Soft state, Eventual consistency)

另一个与之相对的一致性模型叫做BASE,基本可用,柔性事务,最终一致性。

Cassandra is NoSQL database.  Directed by CAP theory, it sacfrices some features of traditional database like table joins and acid transactions. But the trade off may worth it. Cassandra handles high incoming data velocity, supports very large data volumes, and no single point of failure.

Cassandra是非关系型数据库。在CAP理论的指导下,它牺牲掉了传统数据库的一些特性,比如联合查询,ACID事务。然而Cassandra可以处理较高的数据写入速率,支持大数据存储,也没有单点失败的问题,可谓有得有失。

Cassandra is well known for its impressive performance in both reading and writing data.

Data is written to Cassandra in a way that provides both full data durability and high performance. Data written to a Cassandra node is first recorded in an on-disk commit log and then written to a memory-based structure called a memtable. When a memtable’s size exceeds a configurable threshold, the data is written to an immutable file on disk called an SSTable. Buffering writes in memory in this way allows writes always to be a fully sequential operation, with many megabytes of disk I/O happening at the same time, rather than one at a time over a long period. This architecture gives Cassandra its legendary write performance.

写入Cassandra节点的数据会首先写入commit日志,之后写入内存中的memtable。当memtable大到超过阈值,数据会写入磁盘上的SSTable持久化文件。缓冲写使得写操作总是顺序操作,让许多兆的IO读写能同时发生。这种架构给予了Cassandra传奇的写入速度。

Sharding is a familiar term for dba who manages relational database cluster. Cassandra automatically distributes and maintains data across a cluster thus freeing developers and archtects.  Canssandra has an internal component called partioner. It take a row's primary key, calculates a token and then assign to a predicatable node.

对于关系型数据库的DBA,分片是一个很常听到的术语。而Cassandra能够自动的分布和维护集群的数据,这对开发者和构架师都是一个好消息。Cassandra 内部有一个叫做partioner的组件,它根据数据行的主键,计算出token,然后以可预测的方式分配给数据节点。

Cassandra introduced CQL as query language.

Cassandra使用CQL来进行数据查询

CREATE TABLE test.demo (
    id int,
    name text,
    PRIMARY KEY (id)
) 
insert into test.demo (id, name) values (1, 'hello')

select * from test.demo

Result:

How to use cassandra in Java?

Java里面怎么使用Cassandra呢? 参见下面代码片段 (注意红色部分,Cassandra支持给插入的数据加入TTL)

Statement statement = QueryBuilder.insertInto("test","demo")
.value("id", 1)
.value("name", "hello")
.using(QueryBuilder.ttl(MSG_TTL)); //We can set ttl for a row
session.execute(statement);

Here we go a little deeper into Cassandra data storage. The first element in the PRIMARY KEY is what we call a partition key. In this case, it's "id".

Partition key is responsible for data distribution in the cluster. Cassandra use consistent hashing to distribute data so that data reorganization when nodes are added or removed can be minimized.

Data center below has four nodes. Each is responsible for a hash range. Suddenly, node B run into failure,  data should be stored in B will be relocated to A instead.

这里我们稍微多谈谈Cassandra的数据存储。 主键的第一部分叫做分区键,这个例子中是id。分区键用于数据分区,具体地,Cassandra通过一致性哈希来进行分区,这还可以减少节点增减带来的数据转移。

如下图所示的数据中心,有4个节点,每个节点负责一段哈希范围。突然,节点B宕机,本应该存储在B的数据就会转移去节点A,而不是到所有的节点去。

In practice, we can add many more nodes (far larger than real nodes) to the ring. The additional virtual nodes can be mapped to the real nodes so that data can be distributed evenly among nodes.

实际使用中,我们可以增加许多的虚拟节点到哈希环上。然后把多余的虚拟节点映射到真实节点上,这样数据的分布可以更加均匀。

Brief introduction to Cassandra 【Cassandra简介】的更多相关文章

  1. Cassandra -- Cassandra 3.0版本安装

    ============================================================ 服务器信息 搭建三节点的Cassandra群集: SERVER1: 192.1 ...

  2. Cassandra安装及其简单试用

    官方主页:http://cassandra.apache.org/ 简介: The Apache Cassandra Project develops a highly scalable second ...

  3. Cassandra 备份 - 1 - 节点镜像恢复

    之前比较关注如何使用Cassandra,但是真正想大规模使用前提还是需要搞清楚备份机制,确保数据安全. 本文主要内容来自文档 "Cassandra2.2"的翻译.最后部分为真实操作 ...

  4. cassandra 3.x官方文档(2)---架构解析

    写在前面 cassandra3.x官方文档的非官方翻译.翻译内容水平全依赖本人英文水平和对cassandra的理解.所以强烈建议阅读英文版cassandra 3.x 官方文档.此文档一半是翻译,一半是 ...

  5. Cassandra使用pycassa批量导入数据

    本周接手了一个Cassandra系统的维护工作,有一项是需要将应用方的数据导入我们维护的Cassandra集群,并且为应用方提供HTTP的方式访问服务.这是我第一次接触KV系统,原来只是走马观花似的看 ...

  6. Cassandra 在 360 的实践与改进

    分享嘉宾:王锋 奇虎360 技术总监 文章整理:王彦 内容来源:Cassandra Meetup 出品平台:DataFunTalk 注:欢迎转载,转载请留言. 导读:2010年,Dropbox 在线云 ...

  7. Cassandra与Kafka的集成

    Cassandra和Kafka经常一起用于微服务架构中.本文将介绍几种Cassandra和Kafka常见的集成模式.   简介   如果您的开发团队乐于接纳微服务架构的优点,那么您就会了解到,Kafk ...

  8. cassandra指定数据库路径

    参考 https://docs.datastax.com/en/cassandra/2.1/cassandra/configuration/configCassandra_yaml_r.html 我们 ...

  9. 在.net中使用aquiles访问Cassandra(四)

    数据的持久化我们都已经完成了,和所有应有程序一样,最重要的是要向用户展示数据.下面我们就推出这部分代码,读取任意行任何列: public IList<TRowResult> Execute ...

  10. 在.net中使用aquiles访问Cassandra(三)

    之前我们实现了如何修改数据,还需要相应的删除动作.删除方式会有几种情况,以下分别一一介绍.   1.批量删除,适应于多行多列的情况. public void Remove(string columnF ...

随机推荐

  1. Python之路-计算机基础

    一·计算机的组成 一套完整的计算机系统分为:计算机硬件,操作系统,软件.   硬件系统:运算器,控制器和存储器 ,输入设备,输出设备. 1.运算器:负责算数运算和逻辑运算,与控制器一起组成CPU. 2 ...

  2. SQL SERVER:CASE判断空,错误一例

     -----错误判断------------------------------------------------------------------------------------ SELEC ...

  3. ngrok把本地主机映射到公网域名

    这两天又要搞微信项目,然后我下载了一个QQ浏览器,搜索微信调试工具,我再搜,再搜,搜不出来,问了下客服,暂时下架了,好吧! 我上网搜了一下,就找到了  ngrok 这个东西,它也可以把你本地主机映射到 ...

  4. 使用express创建新应用的骨架

    通过应用生成器工具 express 可以快速创建一个应用的骨架. 通过如下命令安装: $ npm install express-generator -g -h 选项可以列出所有可用的命令行选项: $ ...

  5. RabbitMQ-从基础到实战(6)— 与Spring集成

    0.目录 RabbitMQ-从基础到实战(1)- Hello RabbitMQ RabbitMQ-从基础到实战(2)- 防止消息丢失 RabbitMQ-从基础到实战(3)- 消息的交换(上) Rabb ...

  6. 处理json数据的空数据为任意字符

    处理json数据的空数据为任意字符 有时候从后台返回来的数据需要处理一下,根据实际开发需求,不能在页面上直接显示空字符,需要显示为"无内容"或者其他字段,而有些json数据结构比较 ...

  7. gulp基于seaJs模块化项目打包实践【原创】

    公司还一直在延续使用jq+seajs的技术栈,所以只能基于现在的技术栈进行静态文件打包,而众所周知seajs的打包比较"偏门",在查了不少的文档和技术分享后终于琢磨出了自己的打包策 ...

  8. DHTMLX 修改方法加参数

    dhtmlx下拉框选项过长,导致显示不全,所以在下拉框里加了title 具体方法如下: dhtmlXCombo.prototype.modes.checkbox.render=function(c, ...

  9. Mysql安装设置建议(参数设置)

    当我们监测MySQL性能时,人们希望我们能够检视一下MySQL配置然后给出一些提高建议.许多人在事后都非常惊讶,因为我们建议他们仅仅改动几个设置,即使是这里有好几百个配置项.这篇文章的目的在于给你一份 ...

  10. C++ STL学习之容器set和multiset (补充材料)

    一.set和multiset基础 set和multiset会根据特定的排序准则,自动将元素进行排序.不同的是后者允许元素重复而前者不允许. 需要包含头文件: #include <set> ...