public enum IsolationLevel extends Enum<IsolationLevel>
The following isolation anomalies have been identified:
The DirtyRead isolation anomaly is that one transaction could observe uncommitted changes made by another transaction. The biggest problem with this anomaly is that eventually the updating transaction could abort and the reading transaction sees changes that never made it into the system.
Currently the Dirty Read anomaly is not possible in Multiverse since writes to main memory are deferred until commit and once the first write to main memory is executed, the following writes are guaranteed to succeed.
The Unrepeatable Read isolation anomaly is that a transaction could see changes made by other transactions. So at one moment it could see value X and a moment later it could see Y. This could lead to all kinds of erratic behavior like transaction that can get stuck in an infinitive loop.
Such a transaction is called a zombie transaction and can cause serious damage since they are consuming resources (like cpu) and are holding on to various resources (like Locks). So the unrepeatable read should be used with care.
With the inconsistent read it is possible that a value is read depending on a previous read value that has been updated by another transaction. E.g. there are 100 refs all initialized with the same value and there is an updating transaction that increments all value's by one, and there is a reading transaction that reads all refs, then it should see the same values for all values.
With the writeskew problem it is possible that 2 transactions commit....
Example 1: there are 1 person that has 2 bank accounts and the invariant is that the sum of both bank accounts is always equal or larger than zero. If user has has 50 euro on both accounts (so the sum is 100) and there are 2 transactions that both subtract 100 euro from the bank accounts, and the first sees account1=50 and account2=50, the subtraction is allowed and subtracts it 100 from the first account, and the second transaction sees exactly the same and subtracts 100 from the second account, it could be possible that the person ends up with -50 on both accounts (so a sum of -100), clearly violating the contract that the the sum should never be smaller than 0.
Example 2:
The following isolation levels are currently defined in Multiverse:
An implementation of the Txn
is free to upgrade the isolation level to a higher one if it doesn't support that specific isolation
level. This is the same as Oracle is doing with the ReadUncommitted, which automatically is upgraded to a ReadCommitted or the RepeatableRead which is
automatically upgraded to Snapshot (Oracle calls this the Serialized isolation level).
TxnFactoryBuilder.setIsolationLevel(IsolationLevel)
Enum Constant and Description |
---|
RepeatableRead
With the RepeatableRead isolation level you will always see committed data and next to that once a read
is done, this read is going to be repeatable (so you will see the same value every time).
|
Serializable
Provides truly serialized transaction at the cost of reduced performance and concurrency.
|
Snapshot
The default isolation level that allows for the writeskew problem but not for dirty or unrepeatable
or inconsistent reads.
|
Modifier and Type | Method and Description |
---|---|
boolean |
doesAllowInconsistentRead()
Checks if the inconsistent read is allowed to happen.
|
boolean |
doesAllowUnrepeatableRead()
Checks if the dirty read is allowed to happen (so reading data that has not been committed).
|
boolean |
doesAllowWriteSkew()
Checks if the writeskew problem is allowed to happen.
|
String |
toString() |
static IsolationLevel |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static IsolationLevel[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final IsolationLevel RepeatableRead
public static final IsolationLevel Snapshot
public static final IsolationLevel Serializable
public static IsolationLevel[] values()
for (IsolationLevel c : IsolationLevel.values()) System.out.println(c);
public static IsolationLevel valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic final boolean doesAllowWriteSkew()
public boolean doesAllowUnrepeatableRead()
public boolean doesAllowInconsistentRead()
public String toString()
toString
in class Enum<IsolationLevel>
Copyright © 2020. All rights reserved.