Interface TransactionalComponent
- All Known Implementing Classes:
TransactionalComponentBase,TransactionalComponentByLock,TransactionalComponentExternal,TransactionalComponentLifecycle,TransactionalComponentWrapper,TransInteger,TransLogger,TransMonitor
The TransactionCoordinator manages a number of components
which provide the TransactionalComponent interface.
When a new coordinator starts, typically being when the in-process system starts,
there is a recovery phase when work from a previous coordinator is recovered.
Transactions were either were properly committed by the previous coordinator,
and hence redo actions (finalization) should be done,
or they were not, in which case undo actions may be needed.
Transctions to discard are not notified, only fully committed transaction are
notified during recovery. The component may need to keepit's own record of
undo actions needed across restarts.
Lifecycle of startup:
startRecovery()recover(java.nio.ByteBuffer)for each commited/durable transaction (redo actions)finishRecovery(), discarding any other transactions (undo actions).
Lifecycle of a read transaction:
begin(org.apache.jena.dboe.transaction.txn.Transaction)complete(org.apache.jena.dboe.transaction.txn.Transaction)
A read transaction may also include
commit or abort lifecycles.
commitPrepare(org.apache.jena.dboe.transaction.txn.Transaction) and commitEnd(org.apache.jena.dboe.transaction.txn.Transaction) are not called.
Lifecycle of a write transaction:
begin(org.apache.jena.dboe.transaction.txn.Transaction)commitPrepare(org.apache.jena.dboe.transaction.txn.Transaction)commit(org.apache.jena.dboe.transaction.txn.Transaction)orabort(org.apache.jena.dboe.transaction.txn.Transaction)commitEnd(org.apache.jena.dboe.transaction.txn.Transaction)complete(org.apache.jena.dboe.transaction.txn.Transaction)including abort
or if the application aborts the transaction:
begin(org.apache.jena.dboe.transaction.txn.Transaction)abort(org.apache.jena.dboe.transaction.txn.Transaction)complete(org.apache.jena.dboe.transaction.txn.Transaction)
complete(org.apache.jena.dboe.transaction.txn.Transaction) may be called out of sequence and it forces an abort if before
commitPrepare(org.apache.jena.dboe.transaction.txn.Transaction). Once commitPrepare(org.apache.jena.dboe.transaction.txn.Transaction) has been called, the component
can not decide whether to commit finally or to cause a system abort; it must wait
for the coordinator. After commitEnd(org.apache.jena.dboe.transaction.txn.Transaction), the coordinator has definitely
commited the overall transaction and local prepared state can be released, and changes
made to the permanent state of the component.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidabort(Transaction transaction) Abort a transaction (undo the effect of a transaction)voidattach(SysTransState systemState) Set the current thread to be in the transaction.voidbegin(Transaction transaction) Start a transaction; return an identifier for this components use.voidIndicate that no recovery is being done (the journal thinks everything was completed last time)voidcommit(Transaction transaction) Commit a transaction (make durable).voidcommitEnd(Transaction transaction) Signal all commits on all components are done and replay from the journal will not happen.commitPrepare(Transaction transaction) Prepare for a commit.voidcomplete(Transaction transaction) Finalization - the coordinator will not mention the transaction again.detach()Detach this component from the transaction of the current thread and return some internal state that can be used in a future call ofattach(SysTransState)voidEnd of the recovery phaseEvery component instance must supplied a unique number.booleanpromote(Transaction transaction) Promote a component in a transaction.voidrecover(ByteBuffer ref) Notification thatrefwas really committed and is being recovered.voidshutdown()Shutdown component, aborting any in-progress transactions.void
-
Method Details
-
getComponentId
ComponentId getComponentId()Every component instance must supplied a unique number. It is used to route journal entries to subsystems, including across restarts/recovery. Uniqueness scope is within the sameTransactionCoordinator, and the same across restarts.If a component imposes the rule of one-per-
TransactionCoordinator, the same number can be used (if different from all other component type instances).If a component can have multiple instances per
TransactionCoordinator, for example indexes, each must have a unique instance id. -
startRecovery
void startRecovery() -
recover
Notification thatrefwas really committed and is being recovered.- Parameters:
ref- Same bytes as were written during prepare originally.
-
finishRecovery
void finishRecovery()End of the recovery phase -
cleanStart
void cleanStart()Indicate that no recovery is being done (the journal thinks everything was completed last time) -
begin
Start a transaction; return an identifier for this components use. -
promote
Promote a component in a transaction.May return "false" for "can't do that" if the transaction can not be promoted.
May throw
UnsupportedOperationExceptionif promotion is not supported. -
commitPrepare
Prepare for a commit. Returns some bytes that will be written to the journal. The journal remains valid untilcommitEnd(org.apache.jena.dboe.transaction.txn.Transaction)is called. -
commit
Commit a transaction (make durable). The transaction will commit and not abort. Other components may not have committed yet and recovery may occur still causing replay of the commit step. -
commitEnd
Signal all commits on all components are done and replay from the journal will not happen. The component can clear up now. -
abort
Abort a transaction (undo the effect of a transaction) -
complete
Finalization - the coordinator will not mention the transaction again. -
detach
SysTransState detach()Detach this component from the transaction of the current thread and return some internal state that can be used in a future call ofattach(SysTransState)After this call, the component is not in a transaction but the existing transaction still exists. The thread may start a new transaction; that transaction is completely independent of the detached transaction.
Returns
nullif the current thread not in a transaction. The component may return null to indicate it has no state. The return system state should be used in a call toattach(SysTransState)and the transaction ended in the usual way. -
attach
Set the current thread to be in the transaction. ThesystemStatemust be obtained from a call ofdetach(). This method can only be called once persystemState. -
shutdown
void shutdown()Shutdown component, aborting any in-progress transactions. This operation is not guaranteed to be called.
-