Remember once Mysql transaction isolation level pit

When writing code debugging recently I encountered a problem.

Encounter problems

Specific operation is as follows:
1. Call Procedure A, method A and adding the annotation @Transactional transaction.
2. Within a method A, query and update the value of a field F.
3. Other logic processing.
4. query and printing log, records the value of the key field comprising a field F.
5. A method ends.
Because just took this piece of code, but this method has written very long, so a lot of logic look no law, only slowly debugging.
I hit a breakpoint in step 4, view the log when debugging, I feel the data in question, copy the sql database to run again inside the manual,
found in the method and in the database, perform the same Sql, the result was not the same.
Mongolia began a little circle, that is the IDE bug, the problem may be cached like.
Then commissioning a few times, observed when stepping through the fields to manually check out the value in the database, the method is always the beginning value has not changed .
Suddenly I understand, the original transaction isolation level is caused.

Transaction isolation level

These knowledge, in fact, before the interview are back in verse. A long time now, all of a sudden forget the light.
Q: What are the isolation level of the database?
Uncommitted Read (read-uncommitted) READ COMMITTED (read-committed) Repeatable Read (repeatable-read) serialization (serializable).
Q: What is the default mysql database isolation level is?
Repeatable Read (repeatable-read)

Consistent non-locking read

Mysql using INNODB storage engine. SELECT operations, the use of non-locking read consistency.
In the READ COMMITTED transaction isolation level, snapshot data for non-uniformity always read the latest reading a snapshot of the data is locked in rows.
In REPEATABLE READ transaction isolation level, snapshot data for non-consistency always reads read data line version of the transaction began.
The problem I encountered, that after the transaction A is turned on, change the data, not yet committed, then transaction B went to search.
Because the default REPEATABLE READ transaction isolation level, data read that line version of the transaction began.

Reference: "Mysql Inside"

Guess you like

Origin www.cnblogs.com/expiator/p/11610642.html