ACID properties

Detailed ACID properties

 

  Computer Science ACID (Atomicity Atomicity, Consistency Consistency, Isolation Isolation, Durability Durability) a list of attributes.

1, Atomicity Atomicity

  All operations require that each atom of things either completed or did not like all the same happen: If some things in the operation fails, the whole thing things fail, the result is the state of the database remains unchanged. Atoms of atomic system must ensure in each case, including power down a host, the host of an error, the host Ben collapse. To the outside world, things look a submitted (by affecting things on the database generated) are inseparable, a failure of things to the outside world as if nothing had happened.

 

2, Consistency Consistency

  Consistency ensures that anything will make the database from one state to another legitimate legal status. Defined by the various rules, including constraints (Constraints), cascade (Cascades), the trigger (Triggers), and combinations thereof to ensure that all data written to the database must be valid. Consistency does not guarantee the accuracy of things (program), in other words the consistency of things are not necessarily as a programmer would expect (this should be by the application layer of code responsible), it can only ensure database All data is not in violation of defined rules, regardless of the program there are no errors or even any error has occurred will not violate defined rules.

 

3, Isolation Isolation

  Isolation to ensure the concurrent execution of multiple things affect the state of the system and perform a number of things affect the serialization of the state of the system is the same. Isolation is a major target concurrency control. By means of concurrency control, the impact of an unfinished things to other things that are not visible.

 

4, Durability persistence

  Persistence ensures a thing Once submitted, its status remains unchanged even it occurred off the host, Ben collapse, errors. For example, in a relational database, once a set of sql statement is executed, the result is stored permanently (even just been submitted to the database system of things occurred Ben collapse). In order to withstand risks host off of things (either as a result of things) it must be recorded in permanent storage.

 

5、For Example

The following examples further illustrate the ACID properties. In the following example, a database table has two columns, A and B. Data integrity constraint required value of the column A and column B and the value 100 must be equal. The following SQL statement creates a table, this table meet the above constraints --A + B = 100.

CREATE TABLE acidtest (A INTEGER, B INTEGER, CHECK (A + B = 100));

Atom sexual counterexamples

In the database system, atomicity is one of four things ACID properties. In an atomic transaction, a series of database operations either all happen or not happen all. This series of operation can not be separated from each other to implement only part of the operation. Atomicity requires a series of operations can not be separated, as the name of the atom. Atomicity guarantees partial update of the database does not occur. Part of the problem situation update brings far better than all of the operations all failed to bring the problem worse. Atomicity means indivisible.

Consistency counterexamples

Consistency is a very generic term, it requires that the data must meet all the legal rules. In the previous example, for example, the legitimacy of the rule is to require A + B = 100, while the A and B must be an integer. For A and B, its valid range can be inferred. All legal rules must be checked to ensure the consistency of things. Suppose a thing to try without subtracting 10 from A modified B. Because after the end of each thing will be checked for consistency in the database before things begin to know A + B = 100. If things successful subtract 10 from A, atomicity will take effect. However, the validity checking will find the A + B = 90, inconsistent with the constraint rules database. The whole thing has to be canceled, the affected rows rolled back to the state before the execution of things. If there are other constraints, triggers, cascade, each individual change operation must be checked for consistency, as before, before things being submitted.

Violation of isolation

To demonstrate isolation, we assume two things at the same time to modify the same piece of data. In order to maintain isolation, one thing must wait until after the completion of another thing to execute. Consider the following two object, T1 10 to a transfer B from A. T2 B from 10 to transfer an A. There are four operations that can be analyzed: 
. 1, 10 is subtracted from the A of Tl. 
2, T1 to B, plus 10. 
3, T2 is subtracted from the 10 B, respectively. 
4, T2 to A, plus 10. 
If the sequence of operations performed in accordance with the above, the isolation can be achieved, despite the need to wait for T1 to T2 performed. If the T1 fail in the middle, the database system will eliminate the influence of the T1 database generated, T2 still seeing legitimate data.

Since the two things might staggered execution, the actual implementation of the order of these operations may be:

  • 10 A, is subtracted from T1.
  • T2 is subtracted from the 10 B, respectively.
  • A T2 increased to 10.
  • B increasing to 10 T1.

Assume again, T1 fail in the middle, and what will happen. If the fourth step T1: T1 to the B-10 failed to increase, at a time T2 has been modified over A and B; changed data can not be restored to the state before execution T1, resulting in generation of a database illegal state. This is the famous "write-write failure" failed due to two things at the same time try to modify the same data block. In a typical system, this problem can be solved. By eliminating the failure of things T1, so that the database back to the legal status of the last, and then things started again interrupted T2.

Persistent violation

Suppose an object is subtracted from the 10 A and B was added. First of all, things will subtract 10 from A, and then add 10 in B. At this time, the program execution will tell users things, things that have been successfully implemented. Then, when the data of these changes is still in the disk buffer queue waiting to be written to disk. If then host a power failure, the database all changes will be lost. Users also thought that all changes have persisted to the disk.

achieve

Processing a thing usually require a series of operations, any one operation fails will result in failure of the whole thing, therefore, a good number of things that cause the failure. For example, the system disk is full, no space, or is it something has run out of CPU time slice allocated to the operating system. There are two popular techniques you are familiar with: write-ahead logging and shadow paging. These two techniques, it must acquire locks on all the information will be updated. Get things depend lock isolation level, it is possible that all the data is only read, but also need to acquire a lock. In the write-ahead logging technique, the log records to ensure atomicity before changing the database by copying the original (unchanged) data. With logging you can restore the database to a consistent state before Ben collapse incidents. In the shadow paging technique, the updates are applied to a partial copies of the database, when the database is being filed, a new copy is activated.

lock

A lot of database lock to rely on the ability to achieve ACID. Lock means something to make a mark on the need to access their data, so that the database management system will know that these data do not allow other things, the completion of these modifications was beaten tagged data before (things success or failure) in this thing. Locks must be acquired before the data is processed, including those before the data can only be read but not modified process must acquire the lock. Non-ordinary things usually requires a lot of locks, resulting in no small performance overhead while also blocking other things. For example, user A is performing a thing, a row need to read data at this time another user B is modifying the data line. User B must wait until things user A fully completed. It can often be to ensure full isolation by two-phase locking.

Guess you like

Origin www.cnblogs.com/RHadoop-Hive/p/11129226.html