About acid theory and cap theory

Source: Internet
Author: User

Transactions (Transaction):

a transaction (Transaction) is a unit of concurrency control and is a user-defined sequence of operations. These operations are either done or not, and are an inseparable unit of work. In a relational database, a transaction can be an SQL statement, a set of SQL statements, or an entire program. When an update is made to multiple tables, an execution fails. In order to maintain the integrity of the data, transaction rollback is required.



Four elements in a Acid:rdbms

ACID Refers to the narrowing of the four features in the database where transactions are performed correctly, including atomicity (atomicity), consistency (consistency), isolation (isolation), persistence (durability). A database that supports transactions (Transaction) must be satisfied with these four features, otherwise the correctness of the data cannot be guaranteed in the transactional process (Transaction processing)

Atomicity (atomicity):

All operations in the whole transaction, either complete or incomplete, cannot stall at some stage in the middle, and if an error occurs during the execution of the transaction, it will be rolled (Rollback) to the state before the start of the transaction, as if the transaction had never been executed.

Example:

A to B transfer 100 Yuan

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/89/C8/wKioL1gcU12h0-O6AABCK0VokpA197.png-wh_500x0-wm_3 -wmp_4-s_2618519386.png "title=" capture. PNG "alt=" Wkiol1gcu12h0-o6aabck0vokpa197.png-wh_50 "/>

Consistency (consistency):

The integrity constraints of the database are not compromised before the transaction begins and after the transaction ends.

Isolation (Isolation):

The isolated state performs transactions so that they appear to be the only operations that the system performs within a given time. If there are two transactions that run at the same time and perform the same function, the isolation of the transaction will ensure that every transaction in the system considers only that the transaction is in use by the system. This property is sometimes serialized, and in order to prevent confusion between transactional operations, the request must be serialized or sequenced so that only one request is used for the same data at a time.

Persistence (Durability):

After the transaction is complete, the transaction's operations on the database persist in the database and are not rolled back.


The (ACID) nature of a transaction is implemented by a relational database management system (RDBMS, database System). The database management system uses logs to ensure the atomicity, consistency and persistence of transactions. The log records the updates that the transaction makes to the database, and if a transaction has an error during execution, it can undo the updates that the transaction has made to the database based on the log, returning the database to the initial state before the transaction was executed.

The database management system adopts the lock mechanism to realize the isolation of the transaction. When multiple transactions update the same data in the database at the same time, only transactions that hold the lock are allowed to update the data, and other transactions must wait until the previous transaction releases the lock, and other transactions have the opportunity to update the data .


There are two main ways to achieve acid: the first is write ahead logging, which is the way of logging. The second kind is shadow paging .


cap theorem:

The cap theorem, also known as the cap principle, refers to consistency (consistency), availability (availability), Partition tolerance (partition fault tolerance) in a distributed system, The three must not be combined. The cap theorem clarifies the limitations of the system that can be implemented by a distributed system, and many distributed systems in the Internet are designed based on the primary satisfaction of usability and partition tolerance.

At the same time, the CAP principle is the cornerstone of a NoSQL database and a theoretical basis for nosql.

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/89/C8/wKioL1gcWwbRAj8_AAKVHHJHG7Y139.png-wh_500x0-wm_3 -wmp_4-s_2023941452.png "title=" capture. PNG "alt=" Wkiol1gcwwbraj8_aakvhhjhg7y139.png-wh_50 "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/89/C9/wKioL1gcWzugAD0MAAGdtqDFBiY847.png "title=" Capture 1. PNG "alt=" Wkiol1gcwzugad0maagdtqdfbiy847.png "/>

Consistency (consistency):

that is, data consistency, simply said, is the data copied to the N machine, if there is an update, n machine data is updated together.

Availability (availability):

each request can receive a response, regardless of the success or failure of the response

Partition tolerance (partition fault tolerance):

in the large-scale distributed data system, the network partition phenomenon, that is, the partition between the machine can not network communication situation is inevitable, so the system should be able to continue to work in this situation.



in a series of research results found that in larger distributed systems, because of network separation, consistency and availability can not be met at the same time, which means that these three elements can only be implemented at the same time two, it is not possible to balance the three , the requirement to relax consistency increases the availability of the system, and increasing consistency means that the system needs to sacrifice some availability.




This article is from the "berniem2m" blog, make sure to keep this source http://berniem2m.blog.51cto.com/9203249/1869571

About acid theory and cap theory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.