博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Distributed Systems: What is atomic counting, with respect to cassandra?
阅读量:4923 次
发布时间:2019-06-11

本文共 2345 字,大约阅读时间需要 7 分钟。

Distributed Data Systems @ LinkedIn

 

If you have used "atomic increment" in your programming life, you are probably familiar with the ability to increment a number and store it in main memory without fear that another thread will sneak in intermediate changes that would result in some increments being lost. 

If you are familiar with Java, Java has classes under the java.util.concurrent.atomic package that provide features like atomic increment or atomic compare-and-set.
For example, AtomicInteger's getAndIncrement() method returns the current value, increments it, and stores it in main memory in a thread-safe manner. 
Hence, if 10 threads were to call AtomicInteger.getAndIncrement() simultaneously (assuming the starting value of the variable were 0). the final value of the variable would always be 10.
Distributed systems take this operation to another level. Not only does an increment need to be atomically executed in one machine (with multiple CPUs and memory barriers), the increment needs to be reliably carried out on multiple machines in case one of the machines dies. Systems like Cassandra are built around the concept that data and access to the data survives random node failures.
Cassandra offered Distributed Counters as mentioned by Cameron in version 0.8. However, there are problems with it.
One problem had to do with idempotence.
Under load, an increment operation issued across the network can time out. The client machine does not know if the increment reached the destination, so it reissues the increment. The result is that the increment is carried out once or twice.
If the client were not to reissue the increment, the result is that the increment is carried out zero or once. 
Cassandra counters (when I last used them in 1.0) were not idempotent. 
To make them idempotent would require that clients issue a "request token" that the Cassandra servers kept around for "some time". If a previously (successfully) executed token were seen again during the "some time" duration, the call would not be re-executed on the server side. Clients would need to re-send increment requests on time out operations. 
Zookeeper is another distributed system that offers counters in the form of recipes. I have not used them, but have heard they are reliable

转载于:https://www.cnblogs.com/hljyunxi/archive/2012/07/04/2576164.html

你可能感兴趣的文章
weekend110(Hadoop)的 第三天笔记
查看>>
io流和序列化
查看>>
观察者模式
查看>>
【Window Power Shell】介绍与使用
查看>>
数据库 外连接于内连接
查看>>
NHibernate系列文章二十一:延迟加载
查看>>
shell 编程(1)
查看>>
asp.net 项目在 IE 11 下出现 “__doPostBack”未定义 的解决办法
查看>>
ef core 2.0 执行update-database命令时提示__EFMigrationsHistory doesn’t exist
查看>>
在项目中使用log4net记录日志
查看>>
计算几何----线段交
查看>>
重载函数的参数匹配与转换
查看>>
A. Kirill And The Game
查看>>
python里的splitlines具体解释
查看>>
WLC Crash采集什么信息?
查看>>
mysql中查询字段为null或者不为null的sql语句怎么写?
查看>>
Javascript之深入浅出prototype
查看>>
分类添加属性
查看>>
WIN7每次从关闭屏幕状态恢复都会挂断宽带连接,请问如何解决?
查看>>
kafka 集群--3个broker 3个zookeeper创建实战
查看>>