分布式架构
- 从集中式到分布式
- 集中式
- 整个系统的所有业务单元都集中部署在这个中心节点上
- 计算机有主/从之分
- 分布式
- 特点
- 分布性
- 对等性: Replica (副本)
- 并发性
- 缺乏全局时钟
- Leslie Lamport: 《Time, Clocks, and the Ordering of Events in a Distributed System》
- 故障总是会发生
- 常见问题
- 从 ACID 到 CAP/BASE
- 事务 (Transaction)
- Atomicity (原子性)
- Consistency (一致性): 数据库从一个状态迁移到另外一个状态
- Isolation (隔离性): 并发环境中, 事务与事务之间互不干扰
- 4 个事务隔离级别
- 未授权读取: (Read Uncommitted)
- 授权读取: (Read Committed)
- 只允许获取已经被提交的数据
- 无法看到中间状态
- 不可以重复读
- 可重复读取: (Repeatable Read)
- 串行化: (Serializable)
- Durability (持久性)
- CAP 和 BASE 理论
- CAP
- 一个分布式系统不可能同时满足:
- Consistency
- Availability
- Partition tolerance (分区容错性)
- 系统架构师往往需要把经历放在 C 和 A 之间寻求平衡
- BASE
- Basically Available
- Soft state
- Eventually consistent (最终一致性)
- Causal constency 因果一致性
- Read your writes 读已至所写
- Session consistency
- Monotonic read consistency (单调读一致性)
- Monotonic write consistency (单调写一致性)