Cassandra的consistency level

在将cassandra的节点配置为互备以后,某天其中一个节点突然down机了,这个时候发现通过cassandra的thrift api往另外的节点写数据也没法成功了。研究了下thrift的api以后,推测估计是跟client的consistency level有关系。

 

consistency level即一致性级别,用来根据配置的副本因子(ReplicationFactor )来控制cassandra的读写行为,在读或写操作下,不同的一致性级别有不同的含义。所以读写的一致性级别定义是不完全一样的。

 

Write

 

Level

Behavior

ANY

Ensure that the write has been written to at least 1 node, including HintedHandoff recipients.

ONE

Ensure that the write has been written to at least 1 replica's commit log and memory table before responding to the client.

QUORUM

Ensure that the write has been written to N / 2 + 1 replicas before responding to the client.

LOCAL_QUORUM

Ensure that the write has been written to <ReplicationFactor> / 2 + 1 nodes, within the local datacenter (requires NetworkTopologyStrategy )

EACH_QUORUM

Ensure that the write has been written to <ReplicationFactor> / 2 + 1 nodes in each datacenter (requires NetworkTopologyStrategy )

ALL

Ensure that the write is written to all N replicas before responding to the client. Any unresponsive replicas will fail the operation.

 

 

Read

 

Level

Behavior

ANY

Not supported. You probably want ONE instead.

ONE

Will return the record returned by the first replica to respond. A consistency check is always done in a background thread to fix any consistency issues when ConsistencyLevel.ONE is used. This means subsequent calls will have correct data even if the initial read gets an older value. (This is called ReadRepair )

QUORUM

Will query all replicas and return the record with the most recent timestamp once it has at least a majority of replicas (N / 2 + 1 ) reported. Again, the remaining replicas will be checked in the background.

LOCAL_QUORUM

Returns the record with the most recent timestamp once a majority of replicas within the local datacenter have replied.

EACH_QUORUM

Returns the record with the most recent timestamp once a majority of replicas within each datacenter have replied.

ALL

Will query all replicas and return the record with the most recent timestamp once all replicas have replied. Any unresponsive replicas will fail the operation.

 

 

在这些级别中,为了保证读写的一致性,我们基本都采用Quorum这级,但是在我们这个场景中,如果在一个节点down的情况下,还有保证另一个节点写入的话,只能使用写入ONE这个级别了。读取的时候还是Quorum,如果也用ONE的话,会存在不一致的情况,不过在这种情况下,会有一个后台线程来做同步

 

参考

http://wiki.apache.org/cassandra/API

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值