A basic knowledge of transactions is required before proceeding with the below article.
What are isolation levels?
If you have gone through my previous article, you would know the various problems that comes with transactions, i.e., dirty read, non-repeatable read, overwriting uncommitted Data and phantom read. Isolation levels aims to solve these problems. They determine the strategy to be used while a data is accessed by multiple transactions simultaneously. For example, if a data is read by a transaction, should other transaction running in parallel be allowed to read that data. Similarly, what should happen when one transaction has modified some data but not committed as of yet and other transaction has to use that data. All these different scenarios are handled by specifying the correct isolation level.Types of Isolation Levels
There are four types of isolation levels:- Read uncommitted
- Read committed
- Repeatable read
- Serializable
Isolation Level | Description |
Read uncommitted |
|
Read committed
|
|
Repeatable read |
|
Serializable
|
|
Transaction isolation level
|
Dirty reads
|
Non Repeatable reads
|
Phantom Data
|
Read uncommitted
|
Not Solved
|
Not Solved
|
Not Solved
|
Read committed
|
Solved
|
Not Solved
|
Not Solved
|
Repeatable read
|
Solved
|
Solved
|
Not Solved
|
Serializable |
Solved
|
Solved
|
Solved
|
Things to note:
- Only one of the isolation level options can be set at a time, and it remains set for that connection until it is explicitly changed.
- In case of change of isolation level, resources that are read after the change are protected according to the rules of the new level. Resources that are read before the change continue to be protected according to the rules of the previous level.
- Transaction isolation level does not affect a transaction's ability to see its own changes; transactions can always see any changes they make.
That is it! Thanks for reading. Hope you liked the article. Please do post in the comment section for any query.
Do not forget to follow us at +Java Territory to stay updated.
0 comments:
Post a Comment