"Data-intensive applications design" of the transaction

It is estimated that after zui article, after the article should not be made in Denver

the reason:

Prohibited content, check xxxxxxxxxxxx

Abandoned pit Nuggets

x

x

x

DDIA book Zhennai God also book, read very, very cool.

Book database is now read a few of

"Redis Design and Implementation" "NoSQL essence" "DDIA" "MySQL innodb storage engine technology insider"

Are several books, at Amway

ACID

Atomicity (Atomicity)

Generally, not broken down into atoms refers to a small portion of things. The word means different branches of the calculation of similar but subtly different things. For example, in a multi-threaded programming, if one thread executes an atomic operation, which means that another thread can not see half of the result of the operation. Only after the system is in a state before the operation or operations, rather than the state interposed therebetween.

Consistency (consistency)

ACID consistency concept is that a specific set of presentation data must always be set up. That is invariant (invariants). For example, in the accounting system, you must be on all accounts overall lending balance. If a transaction begins with a valid database does not meet these variables, and any write operation during a transaction are to maintain this effectiveness, it can be determined, no variables are always satisfied.

However, this concept of consistency depends on the application responsible for the concept of invariants, the application correctly defined its affairs, and maintain consistency. This is not something the database can guarantee: If you do not write dirty data in violation of the variables, the database can not stop you. (Certain types of invariant can be checked by the database, for example, foreign key constraint or constraints yi-only, but in general, is an application to define what kind of data is valid, what is simply stored in a database invalid .-- .

Isolation (Isolation)

Most of the database will be accessed by multiple clients simultaneously. If they each read and write different parts of the database, this is no problem, but if they access the same database records, you may experience concurrency issues (race conditions (race conditions)).

Persistent (Durability)

The purpose database systems is to provide a safe place to store data without worrying about loss. Persistence is a promise that once the transaction is completed successfully, even in the event of hardware failure or database crash, any written data will not be lost.

problem

Dirty read compromise isolation

Rollback ensure consistency is not destroyed

Weak isolation level

Reading - Submit level

  • Prevents dirty reads
  • Prevent dirty write

Dirty read

User 2 User 1 only after the transaction has been submitted to see the new value of x.

Dirty write

If a transaction updates multiple objects, dirty write will lead to bad results. For example, consider Figure 7-5, Figure 7-5 with a two-3x 12x hand car sale 2 pin 3 x 4 network station 5, for example, Alice and Bob, two people trying to buy the same car. Buying a car requires two database writes: Product List on the website need to be updated to reflect the buyer's purchase, sell 23 534 tickets sold 434 hair needs to be sent to the buyer.

A large segment, then deleted, the investigation dichotomy out what sensitive words, but I really do not see .........

Realize read - Submit level

Database by using row lock (row-level lock) to prevent dirty write: When the transaction you want to modify a particular object (line or document), it must first obtain a lock on the object. Then you must hold the lock until the transaction is committed or aborted. Only one transaction may hold any lock for a given object; if another transaction to be written to the same object, you must wait until after the transaction commits or aborts yi, in order to acquire the lock and continue. This lock mode is Read Committed (or stronger isolation level) database automatically.

How to prevent dirty reads? One option is to use the same lock, and ask any transaction wants to read an object to simply acquire the lock, and then immediately release the lock again after reading. This will ensure that will not be read, not the object in the dirty state, has a value of uncommitted (because the lock can be written to the transaction holding the object at that time).

But requires a read lock approach in practice, the effect is not good. Because of a long-running write transaction will force many read-only transaction until the transaction is complete write slow. This loss of response time read-only transactions, and is not conducive to operability: because waiting for the lock, a part of the application may be slow due to the knock-on effect, leading to problems with other parts.

For this reason, most of the database using a delayed way to prevent dirty reads: for each object is written, the database will remember the old values ​​have been submitted, and the new value set by the write lock held by the current transaction. When the transaction is in progress, any other object to be read transaction will get the old value. Only when the new values ​​submitted, the transaction will switch to read the new value. In fact, jiu is a snapshot!

Snapshot isolation level

Non-repeatable read / read inclination

It refers to a transaction, reading the same data multiple times. When this transaction is not over, another transaction also access the same data. So, between the two read data yi-th transaction, due to the modification of the second transaction, then the first two yi transaction may read data is not the same. Jiu such a transaction occurred in both of the read data is not the same, so called non-repeatable read. For example, an editor who read the same document twice, but between the two readings, the authors rewrite the document. When the second editorial staff read the document, the document has changed. Read the original can not be repeated

MVCC (multi-version concurrency control)

Read-only transactions to resolve the problem of non-repeatable read, to achieve a repeatable read isolation level

To prevent lost updates

For rewritable problem affairs

Atomic write

Explicit locking operation

Automatic detection of lost update

Atomic operation and the lock is forced by reading - modification - writing sequence occur in sequence, to a method of preventing the loss of updates. Another method is to allow them to execute in parallel, if the transaction manager detects lost update, the transaction is aborted and force them to retry its read - modify - write sequence.

One advantage of this method is that the database may be combined with a high xiao snapshot isolation to perform this check. In fact, PostgreSQL repeatable read, Oracle's serialization and SQL Server snapshot isolation level will automatically detect missing updates, and aborted transactions trouble.

Write tilt and phantom read

Magic Reading

Gives the comparison image phantom read mysql scenario: users: id primary key. 1, Tl: SELECT * from Users WHERE ID =. 1; 2, T2: INSERT INTO users( id, name) values (. 1, 'Big CAT');. 3, Tl : iNSERT INTO users( id, name) values (1, 'Big CAT'); Tl: primary transaction, detecting whether there is a table id of a record, there is no insert, which is what we expect normal business logic. T2: interfere with the transaction, the transaction object that disrupt the normal execution of T1. In the RR isolation level, will normally executed 1,2, 3 primary key violation will be given, for T1 service is failed, where T1 is the phantom read JIU occurs, because the data and the read status T1 can not support his next business, met with the same gui.

Source: know almost www.zhihu.com/question/47...

Write tilt

Leading to write slanted phantom read all these cases follow a similar pattern:

A SELECT query to find the qualifying rows, and check compliance with some requirements. (Example: there are at least two doctors on duty; scheduled for the same time period of the conference room does not exist; position on the board is not occupied by other pieces; user name has not been registered; there are sufficient account balance)

According to the results of a query yi, decide whether to continue the application code. (May continue to operate, it may abort and error)

If the application decides to proceed, jiu a write (insert, update, or delete), and commit the transaction.

This effect changes the preconditions written in step 2. In other words, if the commit write, a SELECT query is repeatedly executed step 1, may give different results. Because the change is written set of rows meet the search criteria (now less of a doctor on duty, then meeting room has now been booked, this position on the board has been occupied, the user name has been registered, the account balance is not enough ).

These steps may occur in different order. For example, can be written first, and then SELECT query, after zui decided to give up or submit the query results.

Find sensitive word deleted

xzxxxxx

Reproduced in: https: //juejin.im/post/5cefb288e51d45508c2fb7e4

Guess you like

Origin blog.csdn.net/weixin_34402090/article/details/91471606