jackyfkc.github.io

教土豆学计算机

Transaction 事务

A transaction is a transformation of state which has the properties of atomicity (all or nothing), durability (effects survive failures) and consistency (a correct transformation).

The transaction concept is key to the structuring of data management applications.

ACID 酸 :-)

Atomic 原子性

A transaction’s changes to the state are atomic: either all happen or none happen

Consistency 一致性

A transaction is a correct transformation of the state. The actions taken as a group do not violate any of the integrity constraints associated with the state.

Isolation level 隔离级别

Repeatable Read 可重复读

The default isolation level, in this level, InnoDB use next-key locking strategy to prevents phantom reads: rather than locking only the rows you’ve touched in a query, InnoDB locks gaps in the index structure as well, preventing phantom rows from being inserted.

InnoDB 的默认隔离级别; 在这个级别上, InnoDB 使用 next-key 锁策略避免了幻读: 不仅仅对查询的 rows 上锁, 同时也锁住了索引结构上间隙 gap, 用以阻止幻影行的写入. 注意这与 SQL ANSI 标准不同, 后者在这个级别会出现幻读.

Read Committed 读提交

Read Uncommitted 读未提交

适合的场景极少, 极少使用

Serializable 序列化

Durability 持久化

Once a transaction completes successfully(commits), its changes to the state survive failure

For durability and consistency in a replication setup that uses InnoDB with transactions:

Further Readings