Vector Clocks, 时间向量

Why Vector Clock are Easy or Hard?

Amazon's Dynamo, 4.4版本化的数据

 

常用的版本化技术

Timestamps seem to be an obvious solution for developing a chronological order. However, timestamps “rely on synchronized clocks and don’t capture causality” as Lipcon points out

Optimistic Locking implies that a unique counter or clock value is saved for each piece of data. When a client tries to update a dataset it has to provide the counter/clock-value of the revision it likes to update (cf. [K+10b]). As a downside of this procedure, the Project Voldemort development team notes that it does not work well in a distributed and dynamic scenario where servers show up and go away often and without prior notice.

悲观锁和乐观锁
http://www.cnblogs.com/guyufei/archive/2011/01/10/1931632.html
悲观锁:假定会发生并发冲突(悲观), 屏蔽一切可能违反数据完整性的操作
虽然简单安全, 但是当一个用户锁定记录的时候,会block所有其它用户

乐观锁: 假设不会发生并发冲突(乐观), 只在提交操作时检查是否违反数据完整性 
          可以随意的并发读取和修改, 只在数据提交的时候通过数据版本判断是否存在冲突

两种锁并没有好坏之说, 在于使用的场景更符合哪种假设, 如果符合悲观假设, 那么使用乐观锁可能效率更低 
当然两者都必须依赖master来保证锁机制, 本质上都是主从结构, 所以都会有单点问题 
当然好处是两者都能保证全序

Vector Clocks are an alternative approach to capture order and allow reasoning between updates in a distributed system. 
向量时钟也是一种乐观锁, 只是更通用, 因为不依赖于master, 基于因果关系的狭义相对论 
所以他只能保证偏序 
发生冲突时, 必须依靠client去做resolve以达成全序

Multiversion Storage means to store a timestamp for each table cell. 
These timestamps “don’t necessarily need to correspond to real life”, but can also be some artificial values that can be brought into a definite order. For a given row multiple versions can exist concurrently. Besides the most recent version a reader may also request the “most recent before T” version. This provides “optimistic concurrency control with compare-and-swap on timestamps” and also allows to take snapshots of datasets (cf. [Lip09, slide 20]) 
其实多版本存储和乐观锁的区别在于, 提交的时候它允许冲突, 并不会试图解决冲突. 
而是采用另外一种方法, 把所有版本都保存下来, 即保存版本之间的偏序关系 
但实际上这并不真正解决问题, 只是把冲突解决的时机延迟, 当用户使用时, 自己选择使用什么版本, 即做冲突解决

 

Vector Clocks

Vector clocks is an algorithm for generating a partial ordering of events in a distributed system and detecting causalityviolations.

其实vector clocks就是Lamport的偏序理论的一个实际应用 
具体的使用方法, 参考, 
Why Vector Clock are Easy or Hard?

A vector clock is defined as a tuple V [0], V [1], ..., V [n] of clock values from each node (cf. [Lip09, slide18]).

In a distributed scenario node i maintains such a tuple of clock values, which represent the state of itself and the other (replica) nodes’ state as it is aware about at a given time (Vi[0] for the clock value of the first node, Vi[1] for the clock value of the second node, . . . Vi[i] for itself, . . . Vi[n] for the clock value of the last node).

时钟向量, 表示的含义由下面这个图很好的表示出来.

通过一个向量, 不但记录了当前节点上该数据的version, 还记录了其他节点该数据的版本情况(不一定是最新的)

 image


本文章摘自博客园,原文发布日期: 2013-04-13

内容概要:本文档是一份基于最新Java技术趋势的实操指南,涵盖微服务架构(Spring Cloud Alibaba)、响应式编程(Spring WebFlux + Reactor)、容器化与云原生(Docker + Kubernetes)、函数式编程与Java新特性、性能优化与调优以及单元测试与集成测试六大技术领域。针对每个领域,文档不仅列出了面试中的高频考点,还提供了详细的实操场景、具体实现步骤及示例代码。例如,在微服务架构中介绍了如何利用Nacos进行服务注册与发现、配置管理,以及使用Sentinel实现熔断限流;在响应式编程部分展示了响应式控制器开发、数据库访问和流处理的方法;对于容器化,则从Dockerfile编写到Kubernetes部署配置进行了讲解。 适合人群:具有一定的Java编程基础,尤其是正在准备面试或希望深入理解并掌握当前主流Java技术栈的研发人员。 使用场景及目标:①帮助求职者熟悉并能熟练运用微服务、响应式编程等现代Java开发技术栈应对面试;②指导开发者在实际项目中快速上手相关技术,提高开发效率和技术水平;③为那些想要深入了解Java新特性和最佳实践的程序员提供有价值的参考资料。 阅读建议:由于文档内容丰富且涉及多个方面,建议读者按照自身需求选择感兴趣的主题深入学习,同时结合实际项目进行练习,确保理论与实践相结合。对于每一个技术点,不仅要关注代码实现,更要理解背后的原理和应用场景,这样才能更好地掌握这些技能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值