public interface TransactionalComponent
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)
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) or abort(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
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.
Transaction,
TransactionCoordinator| Modifier and Type | Method and Description |
|---|---|
void |
abort(Transaction transaction)
Abort a transaction (undo the effect of a transaction)
|
void |
attach(SysTransState systemState)
Set the current thread to be in the transaction.
|
void |
begin(Transaction transaction)
Start a transaction; return an identifier for this components use.
|
void |
cleanStart()
Indicate that no recovery is being done (the journal thinks everything was completed last time)
|
void |
commit(Transaction transaction)
Commit a transaction (make durable).
|
void |
commitEnd(Transaction transaction)
Signal all commits on all components are done and replay from the journal will not happen.
|
ByteBuffer |
commitPrepare(Transaction transaction)
Prepare for a commit.
|
void |
complete(Transaction transaction)
Finalization - the coordinator will not mention the transaction again.
|
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 of
attach(SysTransState) |
void |
finishRecovery()
End of the recovery phase
|
ComponentId |
getComponentId()
Every component instance must supplied a unique number.
|
boolean |
promote(Transaction transaction)
Promote a component in a transaction.
|
void |
recover(ByteBuffer ref)
Notification that
ref was really committed and is being recovered. |
void |
shutdown()
Shutdown component, aborting any in-progress transactions.
|
void |
startRecovery() |
ComponentId getComponentId()
TransactionCoordinator,
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.
void startRecovery()
void recover(ByteBuffer ref)
ref was really committed and is being recovered.ref - Same bytes as were written during prepare originally.void finishRecovery()
void cleanStart()
void begin(Transaction transaction)
boolean promote(Transaction transaction)
May return "false" for "can't do that" if the transaction can not be promoted.
May throw UnsupportedOperationException if promotion is not supported.
ByteBuffer commitPrepare(Transaction transaction)
commitEnd(org.apache.jena.dboe.transaction.txn.Transaction) is called.void commit(Transaction transaction)
void commitEnd(Transaction transaction)
void abort(Transaction transaction)
void complete(Transaction transaction)
SysTransState detach()
attach(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 null if 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 to attach(SysTransState)
and the transaction ended in the usual way.
void attach(SysTransState systemState)
systemState
must be obtained from a call of detach().
This method can only be called once per systemState.void shutdown()
Licensed under the Apache License, Version 2.0