Class TransactionCoordinator
- All Implemented Interfaces:
TransactionalSystemControl
TransactionCoordinator per group of TransactionalComponents.
TransactionalComponents can not be shared across TransactionCoordinators.
This is a general engine although tested and most used for multiple-reader
and single-writer (MR+SW). TransactionalComponentLifecycle provides the
per-thread style.
Contrast to MRSW: multiple-reader or single-writer.
Block writers
Block until no writers are active. When this returns, this guarantees that the database is not changing and the journal is flushed to disk.
See blockWriters(), enableWriters(), execAsWriter(Runnable)
Exclusive mode
Exclusive mode is when the current thread is the only active code : no readers, no writers.
See startExclusiveMode()/tryExclusiveMode() finishExclusiveMode(), execExclusive(Runnable)
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionTransactionCoordinator(Journal journal) Create a TransactionCoordinator, initially with no associatedTransactionalComponents.TransactionCoordinator(Journal journal, List<TransactionalComponent> components) Create a TransactionCoordinator, initially withTransactionalComponentsin the ComponentGroup -
Method Summary
Modifier and TypeMethodDescriptionAdd aTransactionalComponent.voidAdd a shutdown hook.Add aTransactionalComponentfor an external sub-system (e.g.jena-text).addListener(TransactionListener listener) voidattach(TransactionCoordinatorState coordinatorState) begin(org.apache.jena.query.TxnType txnType) Start a transaction.begin(org.apache.jena.query.TxnType txnType, boolean canBlock) Start a transaction.voidBlock until no writers are active.longlonglonglonglonglonglongstatic TransactionCoordinatorcreate(org.apache.jena.dboe.base.file.Location location) Create a TransactionCoordinator, initially with no associatedTransactionalComponentsdetach(Transaction txn) voidAllow writers.voidexecAsWriter(Runnable action) Execute an action in as if a Write but no write transaction started.voidexecExclusive(Runnable action) Execute an action in exclusive mode.voidReturn to normal (release waiting transactions, allow new transactions).voidEnd non-exclusive mode.voidRelease any waiting potential writers.org.apache.jena.dboe.base.file.LocationReturn a list of externalTransactionalComponent, registered viaaddExternal(org.apache.jena.dboe.transaction.txn.TransactionalComponent).voidmodifyConfig(Runnable action) Perform modification of thisTransactionCoordiatorafter it has been started.voidmodifyConfigDirect(Runnable action) Perform modification of thisTransactionCoordiator.Remove aTransactionalComponent.voidRemove a shutdown hookRemove an externalTransactionalComponentregistered viaaddExternal(org.apache.jena.dboe.transaction.txn.TransactionalComponent).removeListener(TransactionListener listener) voidvoidsetTxnIdGenerator(TxnIdGenerator generator) voidshutdown()Shutdown the coordinator; this operation does not check the state of the transaction system.voidshutdown(boolean silent) Shutdown the coordinator; this operation does not check the state of the transaction system.voidstart()voidEnter exclusive mode; block if necessary.voidEnter non-exclusive mode; block if necessary.voidBlock write activity - let active potential writers finish while blocking new potential writers.voidInternal operation only.booleanTry to block all writers, or return if can't at the moment.booleantryBlockWriters(boolean canBlock) Block until no writers are active, optionally blocking or returning if can't at the moment.booleanTry to enter exclusive mode.booleantryExclusiveMode(boolean canBlock) Try to enter exclusive mode.booleantryNonExclusiveMode(boolean canBlock) Try to enter non-exclusive mode; return true if successful.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.jena.dboe.transaction.txn.TransactionalSystemControl
execReadOnlyDatabase, tryNonExclusiveMode
-
Constructor Details
-
TransactionCoordinator
Create a TransactionCoordinator, initially with no associatedTransactionalComponents. -
TransactionCoordinator
Create a TransactionCoordinator, initially withTransactionalComponentsin the ComponentGroup
-
-
Method Details
-
create
Create a TransactionCoordinator, initially with no associatedTransactionalComponents -
takeOverFrom
Internal operation only. Call only when no write or potential writer transaction is active in either coordinator. -
add
Add aTransactionalComponent. Safe to call at any time (viamodifyConfig(java.lang.Runnable)) but it is good practice is to add all the components before any transactions start. Internally, the coordinator ensures the add will safely happen but it does not add the component to existing transactions. This must be setup before recovery is attempted. -
remove
Remove aTransactionalComponent. -
addExternal
Add aTransactionalComponentfor an external sub-system (e.g.jena-text). The component will be transfered to any TransactionCoordinator created when switching (for example, by compaction). Use withmodifyConfig(java.lang.Runnable). -
removeExternal
Remove an externalTransactionalComponentregistered viaaddExternal(org.apache.jena.dboe.transaction.txn.TransactionalComponent). -
listExternals
Return a list of externalTransactionalComponent, registered viaaddExternal(org.apache.jena.dboe.transaction.txn.TransactionalComponent). Changing this list has no effect on the TrasnactionCooridnator. -
addListener
-
removeListener
-
modifyConfig
Perform modification of thisTransactionCoordiatorafter it has been started.This operation enters exclusive mode, releases the configuration lock, then calls the
action. On exit from the action, it resets the configuration lock, and exits exclusive mode.Do not call inside a transaction, it may cause a deadlock.
Use with care!
-
modifyConfigDirect
Perform modification of thisTransactionCoordiator.The caller must use exclusive mode (e.g.
#execExclusive(Runnable)).Do not call inside a transaction, it may cause a deadlock.
Use with care!
-
add
Add a shutdown hook. Shutdown is not guaranteed to be called and hence hooks may not get called. -
remove
Remove a shutdown hook -
setQuorumGenerator
-
start
public void start() -
setTxnIdGenerator
-
getJournal
-
getLocation
public org.apache.jena.dboe.base.file.Location getLocation() -
detach
-
attach
-
shutdown
public void shutdown()Shutdown the coordinator; this operation does not check the state of the transaction system.It expects the caller to decide when to shutdown; maybe waiting for all transactions to finish or maybe forcing the system to shutdown for some reason, causing later transaction exceptions.
Use inside exclusive mode to be sure no active transaction are present.
-
shutdown
public void shutdown(boolean silent) Shutdown the coordinator; this operation does not check the state of the transaction system.It expects the caller to decide when to shutdown; maybe waiting for all transactions to finish or maybe forcing the system to shutdown for some reason, causing later transaction exceptions.
Use inside exclusive mode to be sure no active transaction are present.
-
startReadOnlyDatabase
public void startReadOnlyDatabase()Description copied from interface:TransactionalSystemControlBlock write activity - let active potential writers finish while blocking new potential writers. On exit, there are no active writers or promote transactions. (Promotes would otherwise become write mode in their lifetime.)- Specified by:
startReadOnlyDatabasein interfaceTransactionalSystemControl
-
finishReadOnlyDatabase
public void finishReadOnlyDatabase()Description copied from interface:TransactionalSystemControlRelease any waiting potential writers.- Specified by:
finishReadOnlyDatabasein interfaceTransactionalSystemControl
-
startNonExclusiveMode
public void startNonExclusiveMode()Description copied from interface:TransactionalSystemControlEnter non-exclusive mode; block if necessary.- Specified by:
startNonExclusiveModein interfaceTransactionalSystemControl
-
tryNonExclusiveMode
public boolean tryNonExclusiveMode(boolean canBlock) Description copied from interface:TransactionalSystemControlTry to enter non-exclusive mode; return true if successful.- Specified by:
tryNonExclusiveModein interfaceTransactionalSystemControl
-
finishNonExclusiveMode
public void finishNonExclusiveMode()Description copied from interface:TransactionalSystemControlEnd non-exclusive mode.- Specified by:
finishNonExclusiveModein interfaceTransactionalSystemControl
-
startExclusiveMode
public void startExclusiveMode()Enter exclusive mode; block if necessary. There are no active transactions on return; new transactions will be held up in 'begin'. Return to normal (release waiting transactions, allow new transactions) withfinishExclusiveMode().Do not call inside an existing transaction.
- Specified by:
startExclusiveModein interfaceTransactionalSystemControl
-
tryExclusiveMode
public boolean tryExclusiveMode()Try to enter exclusive mode. If return is true, then there are no active transactions on return and new transactions will be held up in 'begin'. If false, there were in-progress transactions. Return to normal (release waiting transactions, allow new transactions) withfinishExclusiveMode().Do not call inside an existing transaction.
- Specified by:
tryExclusiveModein interfaceTransactionalSystemControl
-
tryExclusiveMode
public boolean tryExclusiveMode(boolean canBlock) Try to enter exclusive mode. If return is true, then there are no active transactions on return and new transactions will be held up in 'begin'. If false, there were in-progress transactions. Return to normal (release waiting transactions, allow new transactions) withfinishExclusiveMode().Do not call inside an existing transaction.
- Specified by:
tryExclusiveModein interfaceTransactionalSystemControl- Parameters:
canBlock- Allow the operation block and wait for the exclusive mode lock.
-
finishExclusiveMode
public void finishExclusiveMode()Return to normal (release waiting transactions, allow new transactions). Must be paired with an earlierstartExclusiveMode().- Specified by:
finishExclusiveModein interfaceTransactionalSystemControl
-
execExclusive
Execute an action in exclusive mode. This method can block. Equivalent to:startExclusiveMode(); try { action.run(); } finally { finishExclusiveMode(); }- Specified by:
execExclusivein interfaceTransactionalSystemControl- Parameters:
action-
-
blockWriters
public void blockWriters()Block until no writers are active. When this returns, this guarantees that the database is not changing and the journal is flushed to disk.The application must call
enableWriters()later.This operation must not be nested (it will block).
- See Also:
-
tryBlockWriters
public boolean tryBlockWriters()Try to block all writers, or return if can't at the moment.Unlike a write transaction, there is no associated transaction.
If it returns true, the application must call
enableWriters()later.- Returns:
- true if the operation succeeded and writers are blocked
- See Also:
-
tryBlockWriters
public boolean tryBlockWriters(boolean canBlock) Block until no writers are active, optionally blocking or returning if can't at the moment.Unlike a write transaction, there is no associated transaction.
If it returns true, the application must call
enableWriters()later.- Parameters:
canBlock-- Returns:
- true if the operation succeeded and writers are blocked
-
enableWriters
public void enableWriters()Allow writers. This must be used in conjunction withblockWriters()ortryBlockWriters()- See Also:
-
execAsWriter
Execute an action in as if a Write but no write transaction started. This method can block.Equivalent to:
blockWriters(); try { action.run(); } finally { enableWriters(); }- Parameters:
action-
-
begin
Start a transaction. This may block. -
begin
Start a transaction. Returns null if this operation would block. Readers can start at any time. A single writer policy is currently imposed so a "begin(WRITE)" may block. -
countActiveReaders
public long countActiveReaders() -
countActiveWriter
public long countActiveWriter() -
countActive
public long countActive() -
countBegin
public long countBegin() -
countBeginRead
public long countBeginRead() -
countBeginWrite
public long countBeginWrite() -
countFinished
public long countFinished()
-