CMU 15-445 Lecture #16: Concurrency Control Theory
CMU 15-445 Database Systems
Lecture #16: Concurrency Control Theory
Motivation
- Lost Update Problem (Concurrency Control):数据竞争
- Durability Problem (Recovery):故障恢复
Transactions
-
特点:ACID
-
Atomicity: Atomicity ensures that either all actions in the transaction happen, or none happen.
-
Consistency: If each transaction is consistent and the database is consistent at the beginning of the transaction, then the database is guaranteed to be consistent when the transaction completes. Data is consistent if it satisfies all validation rules such as constraints, cascades and triggers.
-
Isolation: Isolation means that when a transaction executes, it should have the illusion that it is isolated from other transactions. Isolation ensures that concurrent execution of transactions should have the same resulting database state as a sequential execution of the transactions.
-
Durability: If a transaction commits, then its effects on the database should persist.
ACID: Atomicity
-
Approach #1: Logging:常用的方法就是记日志,典型的就是undo log,日志也能提交性能(异步刷磁盘)
-
Approach #2: Shadow Paging:备份自己改的那些页
ACID: Consistency
- 后面的事务能看见前面事务的变动
- 业务的一致性是后端程序员保证的
ACID: Isolation
- 好像就我一个人在用数据库
- 但是实际上是好多txn在一起跑
- 这边也是两大流派
- 悲观控制
- 乐观控制+回滚
- 三种冲突
- R-W
- W-R
- W-W
ACID: Durability
- 一旦commit,必须保证持久化到磁盘上面