- DBMS 和 KV 数据库比较:In a key-value store, all the relationships and operations are managed by the programmer (p29左右)
关系relation, 元组tuple
怎么定位一个tuple?Table name + primary key
- procedural 过程式、declarative 声明式
-
Duplication and normalizing 重复和规范化(p65)
-
representing one-to-many 表示一对多关系(p66)
- 解决方案1:添加新表和外键
- 解决方案2:document model 文档模型 (一对多关系)
- schema flexibility:任意修改schema
- 关系数据库中的schema更改很慢
关系模型和文档模型对比
-
OldSQL = Relational Model + SQL + ACID
-
OLTP transaction
- 生命周期短
- 需要的数据量小
-
[√] Read/Write single Record
-
[×] No Distributed Transaction & Join
- Unavailable when: Changing schema - Server failover
- Data Scaling & Re-sharding
- 简化数据模型 => 降低复杂度
- 弱化transaction,异步复制 => 牺牲一致性,换取scalability和availability
定义:A class of modern RDBMS, which provides:
- NoSQL’s Scalability
- SQL’s ACID Transaction & Relational Model
怎么扩展scale?
- Shared-nothing Partitioning
-
real-time analytics on fresh data
-
OLAP (ML)
-
Atomicity: TX is either performed entirety or not performed at all. (rollback回滚)
-
Cosistency: Transaction must change the data from a consistent state to another
-
Isolation: Two concurrently executed transactions are isolated from each other
-
Durability: Once a transaction is committed, its changes must durably stored to a persistent storage
如何保证?(p28)
- I:一致性控制方法
-
是理想化的:并发事务T1,T2,...,TN好像是按顺序执行的一样
-
如何检查是不是serializability?replay the concurrent execution to a serial of reads/writes(例子p35-42)
-
全局锁global lock:一次只能一个TX, 不并发(性能差)
-
简单细粒度锁simple fine-grained lock:每个record有一个锁(锁容易放太早,不正确)
-
Two-phase locking 2PL:TX commit之后再放所有的锁 -> 保证Serializability
- Executing TXs optimistically w/o acquiring the lock
- Checks the results of TX before it commits
- If violate serializability, then aborts & retries
- phase1: Operates in private workspace; rare inter-thread synchronization (optimistic)
- phase2, 3: Needs synchronization, but usually very short at low contention
- False Aborts 错误的abort
- livelock:high contention情况下,一直abort,没有progress
Hardware support for transactional memory总结
- Easy programming model for the programmer
- Good performance if using properly
- However, the programmer should handle its pitfalls
a TX system to use RTM for acceleration, but avoids its pitfalls for TXs
回顾:优化TX的方向?Improve the TX algorithms properties
- E.g., better deadlock detection algorithms in 2PL
- E.g., reduce aborts in OCC