Top Description Fields Constructors Methods
org.h2.mvstore.tx

public final Class Transaction

extends Object
Class Inheritance
Imports
java.util.BitSet, .HashMap, .HashSet, .Iterator, .Map, java.util.concurrent.atomic.AtomicLong, org.h2.engine.IsolationLevel, org.h2.mvstore.DataUtils, .MVMap, .MVStore, .RootReference, org.h2.mvstore.type.DataType, org.h2.value.VersionedValue

A transaction.

Field Summary

Modifier and TypeField and Description
private Object
blockingKey

Key in blockingMap on which this transaction is blocked.

private String
blockingMapName

Map on which this transaction is blocked.

private volatile Transaction
blockingTransaction

Blocking transaction, if any

pack-priv final IsolationLevel
isolationLevel

The current isolation level.

pack-priv final TransactionStore.RollbackListener
listener

Listener for this transaction's rollback changes.

pack-priv static final int
LOG_ID_BITS

How many bits of the "operation id" we store in the transaction belong to the log id (the rest belong to the transaction id).

private static final int
private static final long
private static final long
private String
name

Transaction name.

private volatile boolean
notificationRequested

Whether other transaction(s) are waiting for this to close.

private final int
ownerId

Identification of the owner of this transaction, usually the owner is a database session.

pack-priv final long
sequenceNum

This is really a transaction identity, because it's not re-used.

private static final int
public static final int
STATUS_CLOSED

The status of a closed transaction (committed or rolled back).

public static final int
STATUS_COMMITTED

The status of a transaction that has been logically committed or rather marked as committed, because it might be still listed among prepared, if it was prepared for commit.

private static final int
private static final String[]
public static final int
STATUS_OPEN

The status of an open transaction.

public static final int
STATUS_PREPARED

The status of a prepared transaction.

private static final int
STATUS_ROLLED_BACK

The status of a transaction that has been rolled back completely, but undo operations are not finished yet.

private static final int
STATUS_ROLLING_BACK

The status of a transaction that currently in a process of rolling back to a savepoint.

private final AtomicLong
pack-priv final TransactionStore
store

The transaction store.

pack-priv int
timeoutMillis

How long to wait for blocking transaction to commit or rollback.

pack-priv final int
transactionId

The transaction id. More appropriate name for this field would be "slotId"

private final Map<Integer, TransactionMap<?, ?>>
transactionMaps

Map of transactional maps for this transaction

private MVStore.TxCounter
txCounter

Reference to a counter for an earliest store version used by this transaction.

private RootReference<Long, Record<?, ?>>[]
undoLogRootReferences

RootReferences for undo log snapshots

pack-priv boolean
wasStored

Indicates whether this transaction was stored in preparedTransactions map

Constructor Summary

AccessConstructor and Description
pack-priv
Transaction(TransactionStore store, int transactionId, long sequenceNum, int status, String name, long logId, int timeoutMillis, int ownerId, IsolationLevel isolationLevel, TransactionStore.RollbackListener listener)

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if isolation level is READ_COMMITTED or READ_UNCOMMITTED
allowNonRepeatableRead
()

Whether this transaction has isolation level READ_COMMITTED or below.

private void
checkNotClosed()

Check whether this transaction is open or prepared.

private void
checkOpen(int status)

Check whether this transaction is open.

pack-priv void
closeIt()

Transition this transaction into a closed state.

public void
commit()

Commit the transaction.

private static long
composeState(int status, long logId, boolean hasRollback)

public int
public Iterator<TransactionStore.Change>

Returns:

the changes
getChanges
(long
the savepoint id, 0 meaning the beginning of the transaction
savepointId
)

Get the list of changes, starting with the latest change, up to the given savepoint (in reverse order than they occurred).

public int
public IsolationLevel

Returns:

the isolation level of this transaction
getIsolationLevel
()

Returns the isolation level of this transaction.

private long
private static long
getLogId(long state)

public String
public long
public int
private static int
getStatus(long state)

private static String
getStatusName(int status)

pack-priv RootReference<Long, Record<?, ?>>[]
public boolean

Returns:

true if there are changes to commit, false otherwise
hasChanges
()

Determine if any database changes were made as part of this transaction.

private static boolean
hasChanges(long state)

private static boolean
hasRollback(long state)

public boolean

Returns:

whether statement dependencies are currently set
hasStatementDependencies
()

Returns whether statement dependencies are currently set.

private static boolean
isActive(int status)

private boolean
pack-priv boolean
pack-priv long

Returns:

key for the newly added undo log entry
log
(Record<?, ?>
to append
logRecord
)

Add a log entry.

pack-priv void
logUndo()

Remove the last log entry.

public void
markStatementEnd()

Mark an exit from SQL statement execution within this transaction.

public void
markStatementStart(HashSet<MVMap<Object, VersionedValue<Object>>>
set of maps used by transaction or statement is about to be executed
maps
)

Mark an entry into a new SQL statement execution within this transaction.

private void
private void
public <
the key type
K
,
the value type
V
>
TransactionMap<K, V>

Returns:

the transaction map
openMap
(String
the name of the map
name
)

Open a data map.

public <
the key type
K
,
the value type
V
>
TransactionMap<K, V>

Returns:

the transaction map
openMap
(String
the name of the map
name
,
DataType<K>
the key data type
keyType
,
DataType<V>
the value data type
valueType
)

Open the map to store the data.

public <
the key type
K
,
the value type
V
>
TransactionMap<K, V>

Returns:

the transactional map
openMapX
(MVMap<K, VersionedValue<V>>
the base map
map
)

Open the transactional version of the given map.

public void
prepare()

Prepare the transaction.

private void
public <
the key type
K
,
the value type
V
>
void
removeMap(TransactionMap<K, V>
the map
map
)

Remove the map.

public void
rollback()

Roll the transaction back.

public void
rollbackToSavepoint(long
the savepoint id
savepointId
)

Roll back to the given savepoint.

public void
public long

Returns:

the savepoint id
setSavepoint
()

Create a new savepoint.

private long

Returns:

transaction state as it was before status change
setStatus
(int
to be set
status
)

Changes transaction status to a specified value

public void
setTimeoutMillis(int
the new lock timeout in milliseconds
timeoutMillis
)

Sets the new lock timeout.

private String
private static String
stateToString(long state)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

private void
tryThrowDeadLockException(boolean throwIt)

public boolean

Returns:

true if other transaction was closed and this one can proceed, false if timed out
waitFor
(Transaction
transaction to wait for
toWaitFor
,
String
name of the map containing blocking entry
mapName
,
Object
of the blocking entry
key
,
int
timeout in milliseconds, -1 for default
timeoutMillis
)

Make this transaction to wait for the specified transaction to be closed, because both of them try to modify the same map entry.

private synchronized boolean
waitForThisToEnd(int millis, Transaction waiter)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

blockingKeyback to summary
private Object blockingKey

Key in blockingMap on which this transaction is blocked.

blockingMapNameback to summary
private String blockingMapName

Map on which this transaction is blocked.

blockingTransactionback to summary
private volatile Transaction blockingTransaction

Blocking transaction, if any

isolationLevelback to summary
pack-priv final IsolationLevel isolationLevel

The current isolation level.

listenerback to summary
pack-priv final TransactionStore.RollbackListener listener

Listener for this transaction's rollback changes.

LOG_ID_BITSback to summary
pack-priv static final int LOG_ID_BITS

How many bits of the "operation id" we store in the transaction belong to the log id (the rest belong to the transaction id).

LOG_ID_BITS1back to summary
private static final int LOG_ID_BITS1
LOG_ID_LIMITback to summary
private static final long LOG_ID_LIMIT
LOG_ID_MASKback to summary
private static final long LOG_ID_MASK
nameback to summary
private String name

Transaction name.

notificationRequestedback to summary
private volatile boolean notificationRequested

Whether other transaction(s) are waiting for this to close.

ownerIdback to summary
private final int ownerId

Identification of the owner of this transaction, usually the owner is a database session.

sequenceNumback to summary
pack-priv final long sequenceNum

This is really a transaction identity, because it's not re-used.

STATUS_BITSback to summary
private static final int STATUS_BITS
STATUS_CLOSEDback to summary
public static final int STATUS_CLOSED

The status of a closed transaction (committed or rolled back).

STATUS_COMMITTEDback to summary
public static final int STATUS_COMMITTED

The status of a transaction that has been logically committed or rather marked as committed, because it might be still listed among prepared, if it was prepared for commit. Undo log entries might still exists for it and not all of it's changes within map's are re-written as committed yet. Nevertheless, those changes should be already viewed by other transactions as committed. This transaction's id can not be re-used until all of the above is completed and transaction is closed. A transactions can be observed in this state when the store was closed while the transaction was not closed yet. When opening a store, such transactions will automatically be processed and closed as committed.

STATUS_MASKback to summary
private static final int STATUS_MASK
STATUS_NAMESback to summary
private static final String[] STATUS_NAMES
STATUS_OPENback to summary
public static final int STATUS_OPEN

The status of an open transaction.

STATUS_PREPAREDback to summary
public static final int STATUS_PREPARED

The status of a prepared transaction.

STATUS_ROLLED_BACKback to summary
private static final int STATUS_ROLLED_BACK

The status of a transaction that has been rolled back completely, but undo operations are not finished yet.

STATUS_ROLLING_BACKback to summary
private static final int STATUS_ROLLING_BACK

The status of a transaction that currently in a process of rolling back to a savepoint.

statusAndLogIdback to summary
private final AtomicLong statusAndLogId
storeback to summary
pack-priv final TransactionStore store

The transaction store.

timeoutMillisback to summary
pack-priv int timeoutMillis

How long to wait for blocking transaction to commit or rollback.

transactionIdback to summary
pack-priv final int transactionId

The transaction id. More appropriate name for this field would be "slotId"

transactionMapsback to summary
private final Map<Integer, TransactionMap<?, ?>> transactionMaps

Map of transactional maps for this transaction

txCounterback to summary
private MVStore.TxCounter txCounter

Reference to a counter for an earliest store version used by this transaction. Referenced version and all newer ones can not be discarded at least until this transaction ends.

undoLogRootReferencesback to summary
private RootReference<Long, Record<?, ?>>[] undoLogRootReferences

RootReferences for undo log snapshots

wasStoredback to summary
pack-priv boolean wasStored

Indicates whether this transaction was stored in preparedTransactions map

Constructor Detail

Transactionback to summary
pack-priv Transaction(TransactionStore store, int transactionId, long sequenceNum, int status, String name, long logId, int timeoutMillis, int ownerId, IsolationLevel isolationLevel, TransactionStore.RollbackListener listener)

Method Detail

allowNonRepeatableReadback to summary
public boolean allowNonRepeatableRead()

Whether this transaction has isolation level READ_COMMITTED or below.

Returns:boolean

true if isolation level is READ_COMMITTED or READ_UNCOMMITTED

checkNotClosedback to summary
private void checkNotClosed()

Check whether this transaction is open or prepared.

checkOpenback to summary
private void checkOpen(int status)

Check whether this transaction is open.

closeItback to summary
pack-priv void closeIt()

Transition this transaction into a closed state.

commitback to summary
public void commit()

Commit the transaction. Afterwards, this transaction is closed.

composeStateback to summary
private static long composeState(int status, long logId, boolean hasRollback)
getBlockerIdback to summary
public int getBlockerId()
getChangesback to summary
public Iterator<TransactionStore.Change> getChanges(long savepointId)

Get the list of changes, starting with the latest change, up to the given savepoint (in reverse order than they occurred). The value of the change is the value before the change was applied.

Parameters
savepointId:long

the savepoint id, 0 meaning the beginning of the transaction

Returns:Iterator<TransactionStore.Change>

the changes

getIdback to summary
public int getId()
getIsolationLevelback to summary
public IsolationLevel getIsolationLevel()

Returns the isolation level of this transaction.

Returns:IsolationLevel

the isolation level of this transaction

getLogIdback to summary
private long getLogId()
getLogIdback to summary
private static long getLogId(long state)
getNameback to summary
public String getName()
getSequenceNumback to summary
public long getSequenceNum()
getStatusback to summary
public int getStatus()
getStatusback to summary
private static int getStatus(long state)
getStatusNameback to summary
private static String getStatusName(int status)
getUndoLogRootReferencesback to summary
pack-priv RootReference<Long, Record<?, ?>>[] getUndoLogRootReferences()
hasChangesback to summary
public boolean hasChanges()

Determine if any database changes were made as part of this transaction.

Returns:boolean

true if there are changes to commit, false otherwise

hasChangesback to summary
private static boolean hasChanges(long state)
hasRollbackback to summary
private static boolean hasRollback(long state)
hasStatementDependenciesback to summary
public boolean hasStatementDependencies()

Returns whether statement dependencies are currently set.

Returns:boolean

whether statement dependencies are currently set

isActiveback to summary
private static boolean isActive(int status)
isDeadlockedback to summary
private boolean isDeadlocked(Transaction toWaitFor)
isReadCommittedback to summary
pack-priv boolean isReadCommitted()
logback to summary
pack-priv long log(Record<?, ?> logRecord)

Add a log entry.

Parameters
logRecord:Record<?, ?>

to append

Returns:long

key for the newly added undo log entry

logUndoback to summary
pack-priv void logUndo()

Remove the last log entry.

markStatementEndback to summary
public void markStatementEnd()

Mark an exit from SQL statement execution within this transaction.

markStatementStartback to summary
public void markStatementStart(HashSet<MVMap<Object, VersionedValue<Object>>> maps)

Mark an entry into a new SQL statement execution within this transaction.

Parameters
maps:HashSet<MVMap<Object, VersionedValue<Object>>>

set of maps used by transaction or statement is about to be executed

Annotations
@SuppressWarnings:unchecked, rawtypes
markTransactionEndback to summary
private void markTransactionEnd()
notifyAllWaitingTransactionsback to summary
private void notifyAllWaitingTransactions()
openMapback to summary
public <K, V> TransactionMap<K, V> openMap(String name)

Open a data map.

Parameters
<K>
the key type
<V>
the value type
name:String

the name of the map

Returns:TransactionMap<K, V>

the transaction map

openMapback to summary
public <K, V> TransactionMap<K, V> openMap(String name, DataType<K> keyType, DataType<V> valueType)

Open the map to store the data.

Parameters
<K>
the key type
<V>
the value type
name:String

the name of the map

keyType:DataType<K>

the key data type

valueType:DataType<V>

the value data type

Returns:TransactionMap<K, V>

the transaction map

openMapXback to summary
public <K, V> TransactionMap<K, V> openMapX(MVMap<K, VersionedValue<V>> map)

Open the transactional version of the given map.

Parameters
<K>
the key type
<V>
the value type
map:MVMap<K, VersionedValue<V>>

the base map

Returns:TransactionMap<K, V>

the transactional map

Annotations
@SuppressWarnings:unchecked
prepareback to summary
public void prepare()

Prepare the transaction. Afterwards, the transaction can only be committed or completely rolled back.

releaseSnapshotback to summary
private void releaseSnapshot()
removeMapback to summary
public <K, V> void removeMap(TransactionMap<K, V> map)

Remove the map.

Parameters
<K>
the key type
<V>
the value type
map:TransactionMap<K, V>

the map

rollbackback to summary
public void rollback()

Roll the transaction back. Afterwards, this transaction is closed.

rollbackToSavepointback to summary
public void rollbackToSavepoint(long savepointId)

Roll back to the given savepoint. This is only allowed if the transaction is open.

Parameters
savepointId:long

the savepoint id

setNameback to summary
public void setName(String name)
setSavepointback to summary
public long setSavepoint()

Create a new savepoint.

Returns:long

the savepoint id

setStatusback to summary
private long setStatus(int status)

Changes transaction status to a specified value

Parameters
status:int

to be set

Returns:long

transaction state as it was before status change

setTimeoutMillisback to summary
public void setTimeoutMillis(int timeoutMillis)

Sets the new lock timeout.

Parameters
timeoutMillis:int

the new lock timeout in milliseconds

stateToStringback to summary
private String stateToString()
stateToStringback to summary
private static String stateToString(long state)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
tryThrowDeadLockExceptionback to summary
private void tryThrowDeadLockException(boolean throwIt)
waitForback to summary
public boolean waitFor(Transaction toWaitFor, String mapName, Object key, int timeoutMillis)

Make this transaction to wait for the specified transaction to be closed, because both of them try to modify the same map entry.

Parameters
toWaitFor:Transaction

transaction to wait for

mapName:String

name of the map containing blocking entry

key:Object

of the blocking entry

timeoutMillis:int

timeout in milliseconds, -1 for default

Returns:boolean

true if other transaction was closed and this one can proceed, false if timed out

waitForThisToEndback to summary
private synchronized boolean waitForThisToEnd(int millis, Transaction waiter)