The isolation level of things, say simple is very simple (novice can say is an isolation level and influence), said the male is also very difficult. (Many programmers with years of programming experience are still unclear)
Nonsense not much straight start:
The isolation level of a transaction is used to describe the read relationship of a transaction, and it is completely not related to writing. All databases do not allow modification of a row of data that is not committed by a transaction.
READ UNCOMMITTED (Read UNCOMMITTED content)
Description of the. Data that is modified within an uncommitted transaction can be queried immediately by another transaction (Dirty Read)
Experiment Design 1: Bar database Isolation level changed to Read uncommitted, two methods a loop query out the specified line, every time to sleep one second. Another method modifies the data for this row, but does not commit the transaction (sleeps 100 seconds). Call the Query method first, and then call the Modify method,
Result: The modification is immediately queried by the query method. We read the dirty data.
Read Committed (read submit content)
Description: Only read the data that has been committed for a transaction modification, but in 2 queries of the same transaction, data submitted to another transaction can be read.
Experimental Design 2: Bar database Isolation level changed to read Committed, two methods a loop to query out the specified line, every time to sleep one second. Another method modifies the data for this row and commits the transaction. Call the Query method first, and then call the Modify method,
Results: Using the experiment 1 to verify that the dirty data can not be read, with the experiment 2 to verify that 2 modifications are perceived.
Note: Experiment 2 may be affected by the cache. If SQL is not issued multiple times, then the cache is affected, and the MyBatis cache needs to be closed.
Springboot the way to close the mybits cache is as follows:
MyBatis: configuration: cache-enabled:false local-cache-scope:statement
Repeatable Read (can be reread)
Description: Repeatable Read is the default level for MySQL. The general explanation is that it avoids non-repeatable reads, but does not avoid Phantom reads, but the MySQL InnoDB and Falcon storage engine solves the problem through a multi-version concurrency control (mvcc,multiversion Concurrency control) mechanism .
This means that the MySQL level is no longer a phantom read. On the interpretation of Phantom reading: Phantom Reading (Phantom read). To put it simply, Phantom reads when a user reads a range of data rows, another transaction inserts a new row within that range, and when the user reads the data row of that range, a new phantom row is found.
Experiment 3: Modify experiment 2, query change to query a total number of lines, modify the method to change to query method;
Results: Using the Experiment 2 proved that the non-repeatable reading was not present, and the experiment 3 proved that InnoDB solved the Phantom reading.
Note: InnoDB mysql default database engine
Serializable (Serializable) an exclusive lock is added regardless of the read or write transaction. Only one transaction can be completed before a transaction can be executed.
This is the best authentication, the query transaction is not committed when the write transaction is not executed.
How to modify the transaction isolation level of MySQL and query the isolation level of MySQL in my other post:https://www.cnblogs.com/cxygg/p/9338555.html
MySQL Transaction ISOLATION level detailed