cassandra 读写数据一致性(consistency level),
cassandra 提供了高性能的数据写入、读取功能,整个集群形成去中心化的环形结构,没有单点故障,没有主从节点之分,内部节点通过gossip协议进行通讯, 不需要依赖外部(hbase通过zookeeper)
用户可以制定数据读写一致性(指定数据一次成功写入或读取的副本数目,判断一次读写是否成功),这种策略保证了数据读写一致性,同时满足了不同用户的不同需求。
1 读写一致性配置: http://docs.datastax.com/en/cassandra/latest/cassandra/dml/dmlConfigConsistency.html、
最常用的几种
QUORUM |
A write must be written to the commit log and memtable on a quorum of replica nodes across all datacenters. | Used in either single or multiple datacenter clusters to maintain strong consistency across the cluster. Use if you can tolerate some level of failure. |
LOCAL_QUORUM |
Strong consistency. A write must be written to the commit log and memtable on a quorum of replica nodes in the same datacenter as the coordinator. Avoids latency of inter-datacenter communication. | Used in multiple datacenter clusters with a rack-aware replica placement strategy, such as NetworkTopologyStrategy, and a properly configured snitch. Use to maintain consistency locally (within the single datacenter). Can be used withSimpleStrategy. |
ONE |
A write must be written to the commit log and memtable of at least one replica node. | Satisfies the needs of most users because consistency requirements are not stringent. |
output.consistency.level |
LOCAL_QUORUM | Consistency level for writing |
https://github.com/datastax/spark-cassandra-connector/blob/master/doc/reference.md#write-tuning-parameters
3. java 写入cassandra 配置 写入数据一致性
QueryOptions queryOptions = new QueryOptions();
queryOptions.setConsistencyLevel( ConsistencyLevel.ONE ); //The default consistency level for queries: ConsistencyLevel.ONE.
cluster = Cluster.builder()
.addContactPoints( contactPointArray )
//.withLoadBalancingPolicy(new RoundRobinPolicy())
.withPoolingOptions(poolingOptions)
.withQueryOptions( queryOptions )
.build();
https://github.com/datastax/java-driver/tree/3.x/manual
http://docs.datastax.com/en/drivers/java/3.2/com/datastax/driver/core/QueryOptions.html