ACID特性和分布式系统CAP理论
事物的介绍和认识
事务通常指的是数据库事务,不要把它太概念化,就是一些列操作要么都执行要么都不执行,把这些操作封装在一个不可分割的单元体里这么理解就可以。
//备注最常见用来举例说明事务的例子应该就是银行账户转账的场景了吧。
在mysql中只有部分数据库引擎才支持事务,推荐尽量都使用支持事务的引擎,不然给后面开发带来很多麻烦
(切身体会,曾经在一家公司做支付系统和订单业务太痛苦了,公司每天流水有几百万搞得真是提心吊胆啊)
ACID的介绍和理解
数据库事务所应具备的四个特性:
1、Atomicity(原子性)
2、Consistency(一致性)
3、Isolation(隔离性)
4、Durability(持久性)
备注:这里的数据库事务通常指的是关系型数据库的事务。
原子性
An atomic transaction is an indivisible and irreducible series
of database operations such that either all occur, or nothing occurs.
原子性事务是一个不可分割和一系列不可约数据库操作,要么全部执行要么就都不执行。
原子性事务:首先我们应该从表面意思去理解原子,原子是世界上最小不可分割单
位体,原子性事务就是在事务的基础上加上原子的特性。
Example
Example of atomic transaction is a monetary transfer from bank account A to account B. It consists of two operations,
withdrawing the money from account A and saving it to account B. Performing these operations in an atomic transaction ensures
that the database remains in a consistent state, that is, money is not lost nor created if either of those two operations fail.
Atomicity requires that each transaction be "all or nothing": if one part of the transaction fails, then the entire transaction
fails, and the database state is left unchanged.
一致性
Consistency in database systems refers to the requirement that any given database transaction must change affected
data only in allowed ways. Any data written to the database must be valid according to all defined rules,
including constraint