Transaction
Definition:
- A transaction is a unit of program execution that accesses and possibly updates various data items
- For example, transfer money from one account to another
ACID Properties:
-
Atomicity 原子性
Either all operations of the transaction are properly reflected in the database, or none are. Ensuring atomicity is the responsibility of the recovery system.
-
Durability 持久性
After a transaction completes, the changes it has made to the database persist, even if there is a system failure. Ensuring durability is the responsibility of the recovery system.
-
Isolation 隔离性
The intermediate inconsistent states from other concurrently executed transactions must be hidden. Ensuring isolation is the responsibility of the concurrency control system.
-
Consistency 一致性
If a transaction is run atomically in isolation starting from a consistent database, the database must again be consistent at the end of the transaction. Ensuring consistency is the responsibility of the application programmer.
Schedules 调度
specify the order in which instructions of concurrent transactions are executed
Serial Schedule 串行调度
The transactions execute one by one, without interleaving
Serializability 可串行化调度
A schedule is serializable if it is equivalent to a serial schedule.
即:如果一个调度能够与某个串行调度等价,它就是“可串行化”的,也叫“可串行化调度”
Order of Instructions
-
If I and J access the same data item
If I=read(Q), J=read(Q), then the order of I and J does not matter
If I=read(Q), J=write(Q), then their order matters
If I=write(Q), J=read(Q), then their order also matters
If I=write(Q), J=write(Q), then their order also matters -
We say that I and J conflict if they access the same data item and at least one of them is a write operation
Conflict Serializability 冲突可串行化
We say that a schedule S is conflict serializable (冲突可串行化) if it is conflict equivalent to a serial schedule
即:如果把一个调度S中的不冲突命令调换位置后,可得到一个串行调度,那么这个调度S是“冲突可串行化”
区别:
-
Serial schedule 串行调度
the transactions execute one by one, without interleaving
-
Serializable schedule 可串行调度
equivalent to a serial schedule
-
Conflict serializable schedule 冲突可串行调度
conflict equivalent to a serial schedule
Recoverable Schedules 可恢复调度
For each pair of transactions X and Y,
if Y reads a data item previously written by X, then Y must commit after X has committed
即:如果 Y 读了 X 修改过的数据,那么在 X 提交后,Y 才能提交
Cascadeless Schedules 无连锁回滚调度
For each pair of transactions X and Y ,
if Y reads a data item previously written by X,
then Y must read after X has committed
在 X 提交后,Y 才能读 X 修改过的数据
无连锁回滚调度一定是可恢复调度