Package org.h2.mvstore.tx
Class TransactionStore
- java.lang.Object
-
- org.h2.mvstore.tx.TransactionStore
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class TransactionStore extends java.lang.Object implements java.lang.AutoCloseableA store that supports concurrent MVCC read-committed transactions.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTransactionStore.ChangeA change in a map.static interfaceTransactionStore.RollbackListenerThis listener can be registered with the transaction to be notified of every compensating change during transaction rollback.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringUNDO_LOG_NAME_PREFIXThe prefix for undo log entries.
-
Constructor Summary
Constructors Constructor Description TransactionStore(MVStore store)Create a new transaction store.TransactionStore(MVStore store, DataType<?> dataType)TransactionStore(MVStore store, MetaType<?> metaDataType, DataType<?> dataType, int timeoutMillis)Create a new transaction store.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Transactionbegin()Begin a new transaction.Transactionbegin(TransactionStore.RollbackListener listener, int timeoutMillis, int ownerId, IsolationLevel isolationLevel)Begin a new transaction.voidclose()Close the transaction store.voidcloseImmediately()voidendLeftoverTransactions()Commit all transactions that are in the committed state, and rollback all open transactions.java.util.List<Transaction>getOpenTransactions()Get the list of unclosed transactions that have pending writes.booleanhasMap(java.lang.String name)Check whether a given map exists.voidinit()Initialize the store without any RollbackListener.voidinit(TransactionStore.RollbackListener listener)Initialize the store.booleanisTransactionClosed(int transactionId)Checks if transaction is completely closed - status set to CLOSED, corresponding bit in open and committing bit sets cleared, transaction slot emptied.<K,V>
MVMap<K,V>openMap(java.lang.String name, DataType<K> keyType, DataType<V> valueType)Open the map with the given name.voidsetMaxTransactionId(int max)Set the maximum transaction id, after which ids are re-used.
-
-
-
Field Detail
-
UNDO_LOG_NAME_PREFIX
public static final java.lang.String UNDO_LOG_NAME_PREFIX
The prefix for undo log entries.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TransactionStore
public TransactionStore(MVStore store)
Create a new transaction store.- Parameters:
store- the store
-
TransactionStore
public TransactionStore(MVStore store, MetaType<?> metaDataType, DataType<?> dataType, int timeoutMillis)
Create a new transaction store.- Parameters:
store- the storemetaDataType- the data type for type registry map valuesdataType- default data type for map keys and valuestimeoutMillis- lock acquisition timeout in milliseconds, 0 means no wait
-
-
Method Detail
-
init
public void init()
Initialize the store without any RollbackListener.- See Also:
init(RollbackListener)
-
init
public void init(TransactionStore.RollbackListener listener)
Initialize the store. This is needed before a transaction can be opened. If the transaction store is corrupt, this method can throw an exception, in which case the store can only be used for reading.- Parameters:
listener- to notify about transaction rollback
-
isTransactionClosed
public boolean isTransactionClosed(int transactionId)
Checks if transaction is completely closed - status set to CLOSED, corresponding bit in open and committing bit sets cleared, transaction slot emptied. That also means that all uncommitted entries from this transaction, has been re-written as committed.- Parameters:
transactionId- to check- Returns:
- true if transaction is completely closed, false otherwise
-
endLeftoverTransactions
public void endLeftoverTransactions()
Commit all transactions that are in the committed state, and rollback all open transactions.
-
setMaxTransactionId
public void setMaxTransactionId(int max)
Set the maximum transaction id, after which ids are re-used. If the old transaction is still in use when re-using an old id, the new transaction fails.- Parameters:
max- the maximum id
-
hasMap
public boolean hasMap(java.lang.String name)
Check whether a given map exists.- Parameters:
name- the map name- Returns:
- true if it exists
-
getOpenTransactions
public java.util.List<Transaction> getOpenTransactions()
Get the list of unclosed transactions that have pending writes.- Returns:
- the list of transactions (sorted by id)
-
close
public void close()
Close the transaction store.- Specified by:
closein interfacejava.lang.AutoCloseable
-
closeImmediately
public void closeImmediately()
-
begin
public Transaction begin()
Begin a new transaction.- Returns:
- the transaction
-
begin
public Transaction begin(TransactionStore.RollbackListener listener, int timeoutMillis, int ownerId, IsolationLevel isolationLevel)
Begin a new transaction.- Parameters:
listener- to be notified in case of a rollbacktimeoutMillis- to wait for a blocking transactionownerId- of the owner (Session?) to be reported by getBlockerIdisolationLevel- of new transaction- Returns:
- the transaction
-
-