Acid is the four attributes of a transaction.Atomicity, consistency, isolation(Isolation), persistence (durability )..
1. the most confusing thing is atomicity and consistency. Let's talk about these two points first:
Atomicity: the atomicity of a transaction refers to the fact that the program contained in the transaction acts as the logical unit of work of the database, and it performs all or no modification operations on the data.
Consistency: Transaction consistency means that the database must be consistent before and after a transaction is executed. This feature is called transaction consistency. If the database status meets all integrity constraints, the database is consistent.
Some may ask, can I guarantee the atomicity? The key difference here is that the transaction operation boundary is defined. This is customized for the operations that have always been performed in transactions, and consistency is for the business logic itself. For example, if you define a transaction, the operations in the transaction are steps A, B, and C. The Atomic performance of the system guarantees that the three steps are either executed or not executed, and cannot be split. However, you may have damaged data consistency. For example, you have defined that you have allocated 200 yuan from account A to account B. If your transaction only includes fee deduction from account A, it does not include the addition of money to account B. After the system guarantees atomicity, it can ensure that either the fee deduction from account A is successful or fails, and there will be no exceptions such as the deduction of half of the fee. But there is no way to ensure that B's account has been paid. Therefore, account a deducts money and Account B adds money. This is a continuous action. To ensure business logic consistency, you must put the two steps in one transaction to ensure consistency.
In other words, Atomicity is a function provided by the system, and consistency is guaranteed based on the business logic and the boundaries of custom transactions. Both are indispensable.
2. Isolation
The isolation of transactions is the transactions opened by the database for each user when multiple users access the database concurrently. The transactions cannot be disturbed by the operation data of other transactions. multiple concurrent transactions must be isolated from each other.
3. Persistence
Durability means that once a transaction is committed, its changes to the data in the database are permanent. In the future, even if the database fails, it should not have any impact on it.
Acid in things