ACID is: atomicity, consistency, isolation and durability.
1. Atomicity
The atomic attribute is used to identify whether a transaction is completed completely. Any update of a transaction must be completed completely on the system. If an error occurs for some reason and the transaction cannot complete its entire task, the system will return to the state before the transaction begins.
Let's take a look at the example of bank transfers again. If an error occurs during the transfer process, the entire transaction will be rolled back. Only when all parts of the transaction are executed successfully will the transaction be written to disk and the changes are permanent.
To provide the ability to roll back or uncommitted changes, many data sources use logging mechanisms. For example, SQL Server uses a write-pre-transaction log that is written on the transaction log before applying (or submitting) the data to the actual data page. However, some other data sources are not relational database management systems (RDBMSs), and they manage uncommitted transactions in a completely different way. This technique should be used to manage transactions as long as the data source can undo all uncommitted changes when the transaction is rolled back.
2. Consistency
Transactions implement consistency in system integrity, which is achieved by ensuring that any transaction in the system is finally in a valid state. If the transaction completes successfully, all changes in the system will be applied correctly and the system is in a valid state. If an error occurs in a transaction, all changes in the system will automatically roll back and the system will return to its original state. Because the business starts
At the beginning, the system was in a consistent state, so now the system is still in a consistent state.
Let’s look back at the example of bank transfers. Before the account is converted and funds are transferred, the account is in a valid state. If the transaction completes successfully and the transaction is committed, the account is in a new and valid state. If a transaction error occurs, after termination, the account will return to its original valid state.
Remember that a transaction is not responsible for implementing data integrity, but is only responsible for ensuring that the data returns to a consistent state after the transaction is committed or terminated. The burden of understanding data integrity rules and writing code to achieve integrity is often on the shoulders of developers, who design according to business requirements.
When many users use and modify the same data simultaneously, a transaction must maintain the integrity and consistency of its data. Therefore, we further study the next characteristic in the A C I D characteristics: isolation.
3. Isolation
Transactions are executed in isolation so that they seem to be the only operations the system performs within a given time. If there are two transactions running for the same time and performing the same function, the isolation of the transaction will ensure that each transaction is considered to be the only transaction in the system in the system.
This property is sometimes called serialization, and in order to prevent confusion between transaction operations, the request must be serialized or serialized so that only one request is used for the same data at the same time.
It is important that when the transaction is executed in an isolated state, the state of the system may be inconsistent. Before ending the transaction, ensure that the system is in a consistent state. But in each individual transaction, the state of the system may change. If the transaction is not running in an isolated state, it may access data from the system, which may be in an inconsistent state. By providing things
Service isolation can prevent such incidents from happening.
In the bank's example, this means that within this system, other processes and transactions do not see any changes caused by our transactions until our transactions are completed, which is very important for termination situations. If there is another process that processes according to the account balance and it can see the changes it causes before our transaction is completed, then the decisions for this process may
Built on the wrong data because our transaction may terminate. This explains why the changes in the transaction are not visible to other parts of the system until the transaction is completed.
Isolation not only ensures that multiple transactions cannot modify the same data at the same time, but also ensures that changes caused by transaction operations cannot be visible to another transaction until the change is committed or terminated, and concurrent transactions have no effect on each other. This means that all data required to be modified or read has been locked in the transaction and cannot be released until the transaction is completed. Most databases, such as SQL Server and other RDBMS, use locking to achieve isolation, and individual data items or data sets involved in a transaction use locking to prevent concurrent access.
4. Persistence
Persistence means that once the transaction executes successfully, all changes that occur in the system will be permanent. There should be some checkpoints to prevent the loss of information when the system fails. Even if the hardware itself fails, the system's state can still be rebuilt by recording tasks completed by transactions in the log. The concept of persistence allows developers to believe that no matter what changes happen to the system later, the completed transactions are a permanent part of the system.