文章目录
?
- It turns out that there are deep connections between ordering, linearizability, and consensus. 阐明它们之间的关系?
- 相比于单机事务,分布式事务有何不同?如何实现?
- 了解 google spanner(事务) 和 zk(consensus) 的实现
- CAP 定理的理解
resource
http://www.bailis.org/blog/linearizability-versus-serializability
In this chapter, we will talk about some examples of algorithms and protocols for building fault-tolerant(可用性?)
distributed systems. 本章讲什么
The best way of building fault-tolerant systems is to find some general-purpose abstractions with useful guarantees, implement them once, and then let applications rely on those guarantees.
Summary
Consistent:
Linearizability: 提供 stronger consistency
, make replicated data appear as though there were only a single copy
, and to make all operations act on it atomically
- 优点: 易于理解
- 缺点: 对网络问题敏感,性能慢
Causality: which puts all operations in a single, totally ordered
timeline, causality provides us with a weaker consistency
model
- 优点: 对网络问题不敏感
- 使用场景受限
Consensus
Consensus algorithms are a huge breakthrough for distributed systems: they bring concrete
safety properties
(agreement, integrity, and validity) to systems where everything else is uncertain, and they nevertheless remainfault-tolerant
(able to make progress as long as a majority of nodes are working and reachable). They providetotal order broadcast
, and therefore they can also implement linearizable atomic operations in a fault-tolerant way.
定义: Deciding something in such a way that all nodes agree on what was decided, and such that the decision is irrevocable.
使用场景:
- Linearizable compare-and-set registers
- Atomic transaction commit
- Total order broadcast
- Locks and leases
- Membership/coordination service
- Uniqueness constraint
Zookeeper:
- providing an “outsourced” consensus
- failure detection
- membership service
Consistency Guaranteess
分布式 db 中,由于网络等因素,数据不一致一定会发生,因此 Most replicated databases provide at least eventual consistency
。
eventual consistency: 所有 replicas 的数据最终会达到一致。
- this is a very weak guarantee—it doesn’t say anything about
when
the replicas will converge - 难以使用和测试: you need to be constantly aware of its limitations and not accidentally assume too much
stronger consistency: 所有 replicas 数据总是保持一致
- 缺点: worse performance, less fault-tolerant
- 优势: easier to use correctly
distributed consistency is mostly about
coordinating
the state of replicas in the face of delays and faults.
Linearizability:
3 个特质:
- Recency gurantee
- single operations on singel object
- time dependency and always move forward in time
定义:
Linearizability(atomic consistency) is a guarantee about single operations
on single objects.
It provides a real-time
(i.e., wall-clock) guarantee on the behavior of a set of single operations (often reads and writes) on a single object。
Linearizability is a recency guarantee
(once a new value has been written or read, all subsequent reads see the value that was written, until it is overwritten again) on reads and writes of a register (an individual object). It doesn’t group operations
together into transactions.
Vs Serializability:
linearizability can be viewed as a special case of strict serializability where transactions are restricted to consist of a single operation applied to a single object.
[http://www.bailis.org/blog/linearizability-versus-serializability/]
使用场景:
- Locking and leader election: They use consensus algorithms to implement linearizable