Cassandra write consistency (Consistency) Comments

Consistency

This command displays the current level of consistency, or set a new level of consistency.
Consistency can be understood Consistency Level read and write operations
to write operations consistency level specifies the number of write operations before notifying the client request is successful, you must ensure that you have successfully completed replica of the write operation.

QUORUM level

QUORUM level to ensure that data written to the specified quorum number of nodes. Rounding a quorum value calculated by the following equation is obtained:
(sum_of_replication_factors / 2) +. 1
sum_of_replication_factors sum of all replication_factor disposed in each data center.

Level: ANY

写操作:
描述: 任意一个节点写操作已经成功。如果所有的replica节点都挂了,写操作还是可以在记录一个hinted handoff事件之后,返回成功。如果所有的replica节点都挂了,写入的数据,在挂掉的replica节点恢复之前,读不到。
用法: 最小的延时等待,并且确保写请求不会失败。相对于其他级别提供最低的一致性和最高的可用性。

Level: ALL

读:
描述:向所有replica节点查询数据,返回所有的replica返回的数据中,timestamp最新的数据。如果某个replica节点没有响应,读操作会失败。
用法:相对于其他级别,提供最高的一致性和最低的可用性。
写:
描述:写操作必须将指定行的数据写到所有replica节点的commit log和memtable。
用法:相对于其他级别提供最高的一致性和最低的可用性。

Level: EACH_QUORUM

读:
描述:向每个数据中心内quorum数量的replica节点查询数据,返回时间戳最新的数据。
用法:同LOCAL_QUORUM
写:
描述:写操作必须将指定行的数据写到每个数据中心的quorum数量的replica节点的commit log和memtable。
用法:用于多数据中心集群严格的保证相同级别的一致性。例如,如果你希望,当一个数据中心挂掉了,或者不能满足quorum数量的replica节点写操作成功时,写请求返回失败。

Level: LOCAL_ONE

读:
描述:返回本地数据中心内离coordinator节点最近的replica节点的数据。
用法:同写操作Consistency level中该级别的用法。
写:
描述:任何一个本地数据中心内的replica节点写操作成功。
用法:对于多数据中心的情况,往往期望至少一个replica节点写成功,但是,又不希望有任何跨数据中心的通信。LOCAL_ONE正好能满足这样的需求。

Level: LOCAL_QUORUM

读:
描述:向每个数据中心内quorum数量的replica节点查询数据,返回时间戳最新的数据。避免跨数据中心的通信。
用法:使用SimpleStrategy时会失败。
写:
描述:本地数据中心内quorum数量的replica节点写操作成功。避免跨数据中心的通信。
用法:不能和SimpleStrategy一起使用。用于保证本地数据中心的数据一致性。

Level: LOCAL_SERIAL

读:
描述:同SERIAL,但是只限制为本地数据中心。
用法:同SERIAL。
写:
描述:本地数据中心内quorum数量的replica节点有条件地(conditionally)写成功。
用法:用于轻量级事务(lightweight transaction)下实现linearizable consistency,避免发生无条件的(unconditional)更新。。

Level: ONE

读:
描述:返回由snitch决定的最近的replica返回的结果。默认情况下,后台会触发read repair确保其他replica的数据一致。
用法:提供最高级别的可用性,但是返回的结果不一定最新。
写:
描述:任意一个replica节点写操作已经成功。    满足大多数用户的需求。
用法:一般离coordinator节点具体最近的replica节点优先执行。  

Level: QUORUM

读:
描述:读取所有数据中心中quorum数量的节点的结果,返回合并后timestamp最新的结果。 
用法:保证很强的一致性,虽然有可能读取失败。

Level: SERIAL

读:
描述:允许读取当前的(包括uncommitted的)数据,如果读的过程中发现uncommitted的事务,则commit它。  
用法:轻量级事务。

Level: TWO

读:  
描述:返回两个最近的replica的最新数据。 
用法:和ONE类似。

Level: THREE

读:
描述:返回三个最近的replica的最新数据。 
用法:和TWO类似。

Reference Address:

https://docs.datastax.com/en/archived/cassandra/2.0/cassandra/dml/dml_config_consistency_c.html

note:

Even if you specify the consistency level ON or LOCAL_QUORUM, write or will be sent to all replica nodes, including the replica node in other data centers. Consistency level just before the decision, notify the client request succeeds, the need to ensure that the number of successful operations replica node write.

Guess you like

Origin blog.51cto.com/michaelkang/2415292