Class Xact
- All Implemented Interfaces:
Limit
,LockOwner
,Transaction
- Direct Known Subclasses:
InternalXact
- CLOSED - cannot be used
- IDLE - no reads have been performed by the transaction.
- ACTIVE - at least one read has been attempted by the transaction
- UPDATE - at least one update has been attempted by the transaction
- PREPARED - the transaction is ready to commit (FUTURE).
Transaction identifiers are re-used for transactions that do not enter the UPDATE state during their lifetime.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final int
private boolean
protected static final int
private static final int
private static final int
private static final int
private static - make sure these bits don't overwrite bits in Transaction.commit commitflagprivate final CompatibilitySpace
protected final DataFactory
protected final DataValueFactory
private LockingPolicy
private boolean
Tells if lock requests should time out immediately if they cannot be granted without waiting.static final int
static final int
static final int
private boolean
protected static final int
private Integer
private boolean
static final int
private boolean
(package private) DynamicByteArrayOutputStream
protected final LogFactory
protected Logger
private LogInstant
private LogInstant
private GlobalTransactionId
private TransactionId
private boolean
static final int
private TransactionId
protected List
<Serviceable> protected List
<Serviceable> private boolean
protected List
<Serviceable> protected static final int
private boolean
static final int
private boolean
private boolean
private int
private boolean
protected int
private String
protected static final int
protected final XactFactory
protected XactContext
Fields inherited from class org.apache.derby.iapi.store.raw.xact.RawTransaction
ABORT, COMMIT, LOCK_ESCALATE, observerException, SAVEPOINT_ROLLBACK
Fields inherited from interface org.apache.derby.iapi.store.raw.Transaction
KEEP_LOCKS, RELEASE_LOCKS, XA_OK, XA_RDONLY
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Xact
(XactFactory xactFactory, Xact parentTransaction, LogFactory logFactory, DataFactory dataFactory, DataValueFactory dataValueFactory, boolean readOnly, CompatibilitySpace compatibilitySpace, boolean flush_log_on_xact_end) -
Method Summary
Modifier and TypeMethodDescriptionvoid
abort()
Abort all changes made by this transaction since the last commit, abort or the point the transaction was started, whichever is the most recent.long
addAndLoadStreamContainer
(long segmentId, Properties tableProperties, RowSource rowSource) Add a new stream container to the segment and load the stream container.long
addContainer
(long segmentId, long containerid, int mode, Properties tableProperties, int temporaryFlag) Add a new container to the segment.void
addPostAbortWork
(Serviceable work) Add to the list of post abort work that may be processed after this transaction aborts.void
addPostCommitWork
(Serviceable work) Add to the list of post commit work that may be processed after this transaction commits.void
Add to the list of post termination work that may be processed after this transaction commits or aborts.void
addUpdateTransaction
(int transactionStatus) Add this to the xactFactory list of update transaction.boolean
Return true if any transaction is currently blocked, even if not by this transaction.protected void
Assume complete identity of the given Transaction Table Entry.protected void
Transform this identity to the one stored in transaction table entry.boolean
blockBackup
(boolean wait) Make the transaction block the online backup.private void
void
checkpointInRollForwardRecovery
(LogInstant cinstant, long redoLWM, long undoLWM) Perform a checkpoint during rollforward recovery.void
close()
Close this transaction, the transaction must be idle.commit()
Commit this transaction.private LogInstant
commit
(int commitflag) commitNoSync
(int commitflag) "Commit" this transaction without sync'ing the log.private void
completeCommit
(int commitflag) Do work to complete a commit which is not just a prepare.void
createXATransactionFromLocalTransaction
(int format_id, byte[] global_id, byte[] branch_id) Convert a local transaction to a global transaction.final LockingPolicy
void
destroy()
If this transaction is not idle, abort it.protected void
doComplete
(Integer commitOrAbort) protected boolean
If this is a user transaction (not an internal or nested top transaction), and this is not already taking care of post commit work, and not an XA transaction, then take care of hi prioirty work right now using this thread and this context manager.void
dropContainer
(ContainerKey containerId) Drop a container.void
dropStreamContainer
(long segmentId, long containerId) Drop a stream container.Get string id of the transaction that would be when the Transaction is IN active state.final CompatibilitySpace
Get the compatibility space of the transaction.final String
Get my transaction context Idfinal ContextManager
Return the context manager this transaction is associated with.final DataFactory
Get the data factory to be used during this transaction.Get DataValueFactory.Get the current default locking policy for all operations within this transaction.Get an object to handle non-transactional files.Get the log instant for the first log record written by this transaction.final GlobalTransactionId
get the Global (external to raw store) transaction id that is unique across all raw storesfinal TransactionId
getId()
get the short (internal to raw store) transaction id that is unique only for this raw storeprotected final TransactionId
Get the transaction id without sanity check, this should only be called by a cloned TransactionTableEntryGet the log instant for the last log record written by this transaction.final LockFactory
Get the lock factory to be used during this transaction.Get the log buffer to be used during this transaction.final LogFactory
JIRA-606.private void
Get the Logger object used to write log records to the transaction log.private int
getSavePointPosition
(String name, Object kindOfSavepoint, boolean forRollbackOrRelease) Does a save point exist in the stack with the given name.(package private) String
getState()
boolean
Can this transaction handles post termination workboolean
inAbort()
Is the transaction in the middle of an abort.boolean
Is the transaction in rollforward recoveryfinal boolean
isActive()
see if this transaction has ever done anything.boolean
Check if the transaction is blocking the backup ?boolean
isIdle()
See if this transaction is in the idle state, called by other thread to test the state of this transaction.boolean
Return true if this is a nested owner, e.g., a nested user transaction.final boolean
see if this transaction is in PREPARED state.boolean
see if this transaction is in a pristine state.private boolean
see if this transaction is a user transaction.void
Log the operation and do it.void
logAndUndo
(Compensation compensation, LogInstant undoInstant, LimitObjectInput in) Log and apply a compensation operation.boolean
nestsUnder
(LockOwner other) Return true if this owner nests under another owner.final LockingPolicy
newLockingPolicy
(int mode, int isolation, boolean stricterOk) Obtain a locking policy for use in openContainer().boolean
noWait()
Tells whether lock requests should time out immediately if they can't be granted without waiting.openContainer
(ContainerKey containerId, int mode) Open a container, with the transaction's default locking policy.openContainer
(ContainerKey containerId, LockingPolicy locking, int mode) Open a container, with the defined locking policy, otherwise as openContainer(int containerId, boolean forUpdate).openDroppedContainer
(ContainerKey containerId, LockingPolicy locking) Open a container that may already have been dropped.openStreamContainer
(long segmentId, long containerId, boolean hold) Open a stream container.protected boolean
popSavePoints
(int position, boolean release) Pop all savepoints upto the one with the given name and rollback all changes made since this savepoint was pushed.protected void
postComplete
(int commitflag, Integer commitOrAbort) private final void
protected void
preComplete
(Integer commitOrAbort) private LogInstant
prepareCommit
(int commitflag) Do work of commit that is common to xa_prepare and commit.void
Remove this from the xactFactory list of update transaction.void
reached
(CompatibilitySpace compatibilitySpace, Object group, int limit, Enumeration lockList, int lockCount) Called by the lock factory when a limit has been reached.void
Make this transaction aware that it is being used by recoveryvoid
reCreateContainerForRedoRecovery
(long segmentId, long containerId, ByteArray containerInfo) Recreate a container during redo recovery.private final void
int
releaseSavePoint
(String name, Object kindOfSavepoint) Release the save point of the given name.void
Remove this from the xactFactory list of update transaction.void
During recovery re-prepare a transaction.(package private) void
int
rollbackToSavePoint
(String name, Object kindOfSavepoint) Rollback all changes made since the named savepoint was set.protected final void
final void
setDefaultLockingPolicy
(LockingPolicy policy) Set the default locking policy for all operations within this transaction.void
setFirstLogInstant
(LogInstant instant) Set the log instant for the first log record written by this transaction.protected void
void
setLastLogInstant
(LogInstant instant) Set the log instant for the last log record written by this transaction.void
setNoLockWait
(boolean noWait) Tell this transaction whether it should time out immediately if a lock cannot be granted without waiting.(package private) void
Set the transaction to issue pre complete work at postComplete time, instead of preComplete time.protected final void
Move the state of the transaction from UPDATE to PREPARE.int
setSavePoint
(String name, Object kindOfSavepoint) Set a save point in the current transaction.(package private) void
setTransactionId
(GlobalTransactionId extid, TransactionId localid) Set my transaction identifier.void
setTransactionId
(Loggable beginXact, TransactionId localId) Set the transactionId (Global and internal) of this transaction using a log record that contains the Global idvoid
setTransName
(String name) void
setup
(PersistentSet set) The default value for LOCKS_ESCALATION_THRESHOLDprivate final void
Move the transaction into the update state.Start a nested top transaction.protected int
put this into the beginXact log record to help recovery if we needs to rolled back first, put that inprotected int
put this into the endXact log record to help recovery, nothing to addprivate void
throwExceptionIfSQLSavepointNotAllowed
(Object kindOfSavepoint) toString()
Return the xid as a string.private void
transferPostCommitorAbortWork
(List<Serviceable> work_list) private void
Unblock the backup, if it was blocked by some operation in this transaction.void
xa_commit
(boolean onePhase) This method is called to commit the current XA global transaction.int
This method is called to ask the resource manager to prepare for a transaction commit of the transaction specified in xid.void
rollback the current global transaction.Methods inherited from class org.apache.derby.iapi.store.raw.xact.RawTransaction
checkLogicalOperationOk, notifyObservers, recoveryRollbackFirst, setObserverException
Methods inherited from class org.apache.derby.iapi.services.monitor.DerbyObservable
addObserver, countObservers, deleteObserver, notifyObservers, setChanged
-
Field Details
-
CLOSED
protected static final int CLOSED- See Also:
-
IDLE
protected static final int IDLE- See Also:
-
ACTIVE
protected static final int ACTIVE- See Also:
-
UPDATE
protected static final int UPDATE- See Also:
-
PREPARED
protected static final int PREPARED- See Also:
-
END_ABORTED
public static final int END_ABORTED- See Also:
-
END_PREPARED
public static final int END_PREPARED- See Also:
-
END_COMMITTED
public static final int END_COMMITTED- See Also:
-
RECOVERY_ROLLBACK_FIRST
public static final int RECOVERY_ROLLBACK_FIRST- See Also:
-
INTERNAL_TRANSACTION
public static final int INTERNAL_TRANSACTION- See Also:
-
NESTED_TOP_TRANSACTION
public static final int NESTED_TOP_TRANSACTION- See Also:
-
COMMIT_SYNC
private static final int COMMIT_SYNCprivate static - make sure these bits don't overwrite bits in Transaction.commit commitflag- See Also:
-
COMMIT_NO_SYNC
private static final int COMMIT_NO_SYNC- See Also:
-
COMMIT_PREPARE
private static final int COMMIT_PREPARE- See Also:
-
savedEndStatus
private int savedEndStatus -
needSync
private boolean needSync -
justCreated
private boolean justCreated -
xc
-
xactFactory
-
dataFactory
-
logFactory
-
dataValueFactory
-
compatibilitySpace
-
defaultLocking
-
myGlobalId
-
myId
-
parentTransactionId
-
logger
-
state
protected volatile int state -
inComplete
-
seenUpdates
private boolean seenUpdates -
inPostCommitProcessing
private boolean inPostCommitProcessing -
logStart
-
logLast
-
savePoints
-
postCommitWorks
-
postAbortWorks
-
postTerminationWorks
-
recoveryTransaction
private boolean recoveryTransaction -
logBuffer
DynamicByteArrayOutputStream logBuffer -
postCompleteMode
private boolean postCompleteMode -
sanityCheck_xaclosed
private boolean sanityCheck_xaclosed -
transName
-
readOnly
private boolean readOnly -
flush_log_on_xact_end
private boolean flush_log_on_xact_end -
backupBlocked
private boolean backupBlocked -
dontWaitForLocks
private boolean dontWaitForLocksTells if lock requests should time out immediately if they cannot be granted without waiting.
-
-
Constructor Details
-
Xact
protected Xact(XactFactory xactFactory, Xact parentTransaction, LogFactory logFactory, DataFactory dataFactory, DataValueFactory dataValueFactory, boolean readOnly, CompatibilitySpace compatibilitySpace, boolean flush_log_on_xact_end)
-
-
Method Details
-
getLockFactory
Description copied from class:RawTransaction
Get the lock factory to be used during this transaction.- Specified by:
getLockFactory
in classRawTransaction
-
getDataFactory
Description copied from class:RawTransaction
Get the data factory to be used during this transaction.- Specified by:
getDataFactory
in classRawTransaction
-
getLogFactory
JIRA-606. As a part of this fix, it was required that LogFactory.checkVersion method to be exposed for any possible Version checks in the Transaction processing module.- Specified by:
getLogFactory
in classRawTransaction
-
anyoneBlocked
public boolean anyoneBlocked()Return true if any transaction is currently blocked, even if not by this transaction.- Specified by:
anyoneBlocked
in interfaceTransaction
-
getLogBuffer
Description copied from class:RawTransaction
Get the log buffer to be used during this transaction.- Specified by:
getLogBuffer
in classRawTransaction
-
logAndUndo
public void logAndUndo(Compensation compensation, LogInstant undoInstant, LimitObjectInput in) throws StandardException Log and apply a compensation operation. Only need to write out the compensation op itself, the optional data has already been written by the rollforward operation this is attempting to undo.- Specified by:
logAndUndo
in classRawTransaction
- Parameters:
compensation
- the Compensation OperationundoInstant
- the LogInstant of the Loggable Operation this compensation operation is going to roll backin
- optional data for the rollback operation- Throws:
StandardException
- Standard Derby exception policy- See Also:
-
addUpdateTransaction
public void addUpdateTransaction(int transactionStatus) Add this to the xactFactory list of update transaction.- Specified by:
addUpdateTransaction
in classRawTransaction
-
removeUpdateTransaction
public void removeUpdateTransaction()Remove this from the xactFactory list of update transaction.- Specified by:
removeUpdateTransaction
in classRawTransaction
-
prepareTransaction
public void prepareTransaction()Remove this from the xactFactory list of update transaction.- Specified by:
prepareTransaction
in classRawTransaction
-
setFirstLogInstant
Set the log instant for the first log record written by this transaction.- Specified by:
setFirstLogInstant
in classRawTransaction
-
getFirstLogInstant
Get the log instant for the first log record written by this transaction.- Specified by:
getFirstLogInstant
in classRawTransaction
-
setLastLogInstant
Set the log instant for the last log record written by this transaction.- Specified by:
setLastLogInstant
in classRawTransaction
-
getLastLogInstant
Get the log instant for the last log record written by this transaction.- Specified by:
getLastLogInstant
in classRawTransaction
-
setTransactionId
Set my transaction identifier. -
setTransactionId
Description copied from class:RawTransaction
Set the transactionId (Global and internal) of this transaction using a log record that contains the Global id- Specified by:
setTransactionId
in classRawTransaction
-
setup
The default value for LOCKS_ESCALATION_THRESHOLD- Specified by:
setup
in interfaceTransaction
- Throws:
StandardException
- Standard Derby exception policy
-
getGlobalId
get the Global (external to raw store) transaction id that is unique across all raw stores- Specified by:
getGlobalId
in interfaceTransaction
- Specified by:
getGlobalId
in classRawTransaction
-
getContextManager
Description copied from interface:Transaction
Return the context manager this transaction is associated with.- Specified by:
getContextManager
in interfaceTransaction
-
getCompatibilitySpace
Get the compatibility space of the transaction.Returns an object that can be used with the lock manager to provide the compatibility space of a transaction. 2 transactions with the same compatibility space will not conflict in locks. The usual case is that each transaction has it's own unique compatibility space.
- Specified by:
getCompatibilitySpace
in interfaceTransaction
- Returns:
- The compatibility space of the transaction.
-
noWait
public boolean noWait()Tells whether lock requests should time out immediately if they can't be granted without waiting. Only works if this object is the owner of the compatibility space used in the request. -
setNoLockWait
public void setNoLockWait(boolean noWait) Tell this transaction whether it should time out immediately if a lock cannot be granted without waiting. This could be used in a nested transaction to prevent long waits if there is a lock conflict between the nested transaction and its parent. If it is used this way, the calling code should catch timeout exceptions from the nested transaction and retry the operation (without disabling waiting) in the parent transaction.This only works if this transaction is the owner of the compatibility space used in the request. If this transaction has inherited the compatibility space from its parent, the call to this method has no effect (except in debug builds, where an error will be raised).
- Specified by:
setNoLockWait
in interfaceTransaction
- Parameters:
noWait
- iftrue
never wait for a lock in this transaction, but time out immediately- See Also:
-
getId
get the short (internal to raw store) transaction id that is unique only for this raw store- Specified by:
getId
in classRawTransaction
-
getIdNoCheck
Get the transaction id without sanity check, this should only be called by a cloned TransactionTableEntry -
getContextId
Get my transaction context Id -
getDefaultLockingPolicy
Get the current default locking policy for all operations within this transaction. The transaction is initially started with a default locking policy equivalent tonewLockingPolicy( LockingPolicy.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, true);
This default can be changed by subsequent calls to setDefaultLockingPolicy(LockingPolicy policy).- Specified by:
getDefaultLockingPolicy
in interfaceTransaction
- Returns:
- The current default locking policy in this transaction.
- See Also:
-
newLockingPolicy
Description copied from interface:Transaction
Obtain a locking policy for use in openContainer(). The mode and isolation must be constants from LockingPolicy. If higherOK is true then the object returned may implement a stricter form of locking than the one requested.
A null LockingPolicy reference is identical to a LockingPolicy obtained by using MODE_NONE which is guaranteed to exist.- Specified by:
newLockingPolicy
in interfaceTransaction
- Parameters:
mode
- A constant of the form LockingPolicy.MODE_*isolation
- A constant of the form LockingPolicy.ISOLATION_*stricterOk
- True if a stricter level of locking is acceptable, false if an exact match is required.- Returns:
- A object that can be used in an openContainer call, null if a matching policy cannot be found.
- See Also:
-
setDefaultLockingPolicy
Description copied from interface:Transaction
Set the default locking policy for all operations within this transaction. The transaction is intially started with a default locking policy equivalent tonewLockingPolicy( LockingPolicy.MODE_RECORD, LockingPolicy.ISOLATION_SERIALIZABLE, true);
- Specified by:
setDefaultLockingPolicy
in interfaceTransaction
- Parameters:
policy
- The lock policy to use, if null then then a no locking policy will be installed as the default.- See Also:
-
commit
Description copied from interface:Transaction
Commit this transaction. All savepoints within this transaction are released.- Specified by:
commit
in interfaceTransaction
- Returns:
- the commit instant of this transaction, or null if it didn't make any changes
- Throws:
StandardException
- Standard Derby exception policy
-
commitNoSync
Description copied from interface:Transaction
"Commit" this transaction without sync'ing the log. Everything else is identical to commit(), use this at your own risk.
bits in the commitflag can turn on to fine tuned the "commit": KEEP_LOCKS - no locks will be released by the commit and no post commit processing will be initiated. If, for some reasons, the locks cannot be kept even if this flag is set, then the commit will sync the log, i.e., it will revert to the normal commit.- Specified by:
commitNoSync
in interfaceTransaction
- Throws:
StandardException
- Standard Derby exception policy
-
prepareCommit
Do work of commit that is common to xa_prepare and commit.Do all the work necessary as part of a commit up to and including writing the commit log record. This routine is used by both prepare and commit. The work post commit is done by completeCommit().
- Parameters:
commitflag
- various flavors of commit.- Throws:
StandardException
- Standard exception policy.- See Also:
-
completeCommit
Do work to complete a commit which is not just a prepare.Releases locks, does post commit work, and moves the state of the transaction to IDLE.
- Parameters:
commitflag
- various flavors of commit.- Throws:
StandardException
- Standard exception policy.
-
commit
- Throws:
StandardException
- Standard Derby exception policy- See Also:
-
abort
Description copied from interface:Transaction
Abort all changes made by this transaction since the last commit, abort or the point the transaction was started, whichever is the most recent. All savepoints within this transaction are released.- Specified by:
abort
in interfaceTransaction
- Throws:
StandardException
- Standard Derby exception policy- See Also:
-
reprepare
During recovery re-prepare a transaction.After redo() and undo(), this routine is called on all outstanding in-doubt (prepared) transactions. This routine re-acquires all logical write locks for operations in the xact, and then modifies the transaction table entry to make the transaction look as if it had just been prepared following startup after recovery.
This routine is only called during Recovery.
- Specified by:
reprepare
in classRawTransaction
- Throws:
StandardException
- Standard exception policy.
-
destroy
If this transaction is not idle, abort it. After this call close().- Specified by:
destroy
in interfaceTransaction
- Throws:
StandardException
- Standard Derby error policy Thrown if the transaction is not idle.- See Also:
-
close
Description copied from interface:Transaction
Close this transaction, the transaction must be idle. This close will pop the transaction context off the stack that was pushed when the transaction was started.- Specified by:
close
in interfaceTransaction
- Throws:
StandardException
- Thrown if the transaction is not idle, the transaction remains open.- See Also:
-
logAndDo
Log the operation and do it. If this transaction has not generated any log records prior to this, then log a beginXact log record. If the passed in operation is null, then do nothing (after logging the beginXact if needed).- Specified by:
logAndDo
in interfaceTransaction
- Parameters:
operation
- the operation that is to be applied- Throws:
StandardException
- Standard Derby exception policy- See Also:
-
addPostCommitWork
Description copied from interface:Transaction
Add to the list of post commit work that may be processed after this transaction commits. If this transaction aborts, then the post commit work list will be thrown away. No post commit work will be taken out on a rollback to save point.- Specified by:
addPostCommitWork
in interfaceTransaction
- Parameters:
work
- the post commit work that is added
-
addPostAbortWork
Add to the list of post abort work that may be processed after this transaction aborts.- Specified by:
addPostAbortWork
in interfaceTransaction
- Parameters:
work
- the post commit work that is added
-
addPostTerminationWork
Description copied from interface:Transaction
Add to the list of post termination work that may be processed after this transaction commits or aborts.- Specified by:
addPostTerminationWork
in interfaceTransaction
- Parameters:
work
- the post termination work that is added
-
openContainer
Description copied from interface:Transaction
Open a container, with the transaction's default locking policy.Note that if NOWAIT has been specified lock will be requested with no wait time, and if lock is not granted a SQLState.LOCK_TIMEOUT exception will be thrown.
The release() method of ContainerHandle will be called when this transaction is aborted or commited, it may be called explicitly to release the ContainerHandle before the end of the transaction.
- Specified by:
openContainer
in interfaceTransaction
- Returns:
- a valid ContainerHandle or null if the container does not exist.
- Throws:
StandardException
- Standard Derby exception policy- See Also:
-
openContainer
public ContainerHandle openContainer(ContainerKey containerId, LockingPolicy locking, int mode) throws StandardException Description copied from interface:Transaction
Open a container, with the defined locking policy, otherwise as openContainer(int containerId, boolean forUpdate).Calls locking.lockContainer(this, returnValue, forUpdate) to lock the container. Note that if NOWAIT has been specified lock will be requested with no wait time, and if lock is not granted a SQLState.LOCK_TIMEOUT exception will be thrown.
- Specified by:
openContainer
in interfaceTransaction
- Parameters:
locking
- The lock policy to use, if null then then a no locking policy will be used.- Returns:
- a valid ContainerHandle or null if the container does not exist.
- Throws:
StandardException
- Standard Derby exception policy- See Also:
-
openDroppedContainer
public RawContainerHandle openDroppedContainer(ContainerKey containerId, LockingPolicy locking) throws StandardException Open a container that may already have been dropped.- Specified by:
openDroppedContainer
in classRawTransaction
- Throws:
StandardException
- Standard Derby exception policy- See Also:
-
addContainer
public long addContainer(long segmentId, long containerid, int mode, Properties tableProperties, int temporaryFlag) throws StandardException Description copied from interface:Transaction
Add a new container to the segment. The new container initially has one page, page Container.FIRST_PAGE_NUMBER.
If pageSize is equal to ContainerHandle.DEFAULT_PAGESIZE or invalid then a default page size will be picked.
SpareSpace indicates that percent (0% - 100%) of page space that will be attempted to be reserved for updates. E.g. with a value of 20 a page that would normally hold 40 rows will be limited to 32 rows, actual calculation for the threshold where no more inserts are all accepted is up to the implementation. Whatever the value of spaceSpace an empty page will always accept at least one insert. If spare space is equal to ContainerHandle.DEFAULT_PAGESIZE or invalid then a default value will be used.Synchronisation
The new container is exclusivly locked by this transaction until it commits.
- Specified by:
addContainer
in interfaceTransaction
- Parameters:
segmentId
- segment to create the container in.containerid
- If not equal to 0 then this container id will be used to create the container, else if set to 0 then the raw store will assign a number.mode
- mode description in @see ContainerHandle. This mode is only effective for the duration of the addContainer call and not stored persistently for the lifetime of the container.tableProperties
- Implementation-specific properties of the conglomerate.- Returns:
- a container identifer that can be used in openContainer() This id is only valid within this RawStoreFactory. Returns a negative number if a container could not be allocated.
- Throws:
StandardException
- Standard Derby exception policy- See Also:
-
addAndLoadStreamContainer
public long addAndLoadStreamContainer(long segmentId, Properties tableProperties, RowSource rowSource) throws StandardException Description copied from interface:Transaction
Add a new stream container to the segment and load the stream container. This stream container doesn't not have locks, and do not log. It does not have the concept of a page. It is used by the external sort only.Synchronisation
This call will mark the container as dropped and then obtain an CX lock on the container. Once a container has been marked as dropped it cannot be retrieved by any openContainer() call.
Once the exclusive lock has been obtained the container is removed and all its pages deallocated. The container will be fully removed at the commit time of the transaction.
- Specified by:
addAndLoadStreamContainer
in interfaceTransaction
- Throws:
StandardException
- Standard Derby exception policy- See Also:
-
openStreamContainer
public StreamContainerHandle openStreamContainer(long segmentId, long containerId, boolean hold) throws StandardException Description copied from interface:Transaction
Open a stream container.- Specified by:
openStreamContainer
in interfaceTransaction
- Returns:
- a valid StreamContainerHandle or null if the container does not exist.
- Throws:
StandardException
- Standard Derby exception policy- See Also:
-
dropStreamContainer
Description copied from interface:Transaction
Drop a stream container.Synchronisation
This call will remove the container.
- Specified by:
dropStreamContainer
in interfaceTransaction
- Throws:
StandardException
- Standard Derby error policy- See Also:
-
reCreateContainerForRedoRecovery
public void reCreateContainerForRedoRecovery(long segmentId, long containerId, ByteArray containerInfo) throws StandardException Recreate a container during redo recovery. Used only during redo recovery while processing log records which are trying to create a container, and no valid container is found in the database.- Specified by:
reCreateContainerForRedoRecovery
in classRawTransaction
- Throws:
StandardException
- Standard Derby exception policy- See Also:
-
dropContainer
Description copied from interface:Transaction
Drop a container.Synchronisation
This call will mark the container as dropped and then obtain an CX lock on the container. Once a container has been marked as dropped it cannot be retrieved by any openContainer() call.
Once the exclusive lock has been obtained the container is removed and all its pages deallocated. The container will be fully removed at the commit time of the transaction.
- Specified by:
dropContainer
in interfaceTransaction
- Throws:
StandardException
- Standard Derby error policy- See Also:
-
setSavePoint
Description copied from interface:Transaction
Set a save point in the current transaction. A save point defines a point in time in the transaction that changes can be rolled back to. Savepoints can be nested and they behave like a stack. Setting save points "one" and "two" and the rolling back "one" will rollback all the changes made since "one" (including those made since "two") and release savepoint "two".- Specified by:
setSavePoint
in interfaceTransaction
- Parameters:
name
- The user provided name of the savepointkindOfSavepoint
- A NULL value means it is an internal savepoint (ie not a user defined savepoint) Non NULL value means it is a user defined savepoint which can be a SQL savepoint or a JDBC savepoint A String value for kindOfSavepoint would mean it is SQL savepoint A JDBC Savepoint object value for kindOfSavepoint would mean it is JDBC savepoint- Returns:
- returns total number of savepoints in the stack.
- Throws:
StandardException
- Standard Derby exception policy- See Also:
-
throwExceptionIfSQLSavepointNotAllowed
private void throwExceptionIfSQLSavepointNotAllowed(Object kindOfSavepoint) throws StandardException - Throws:
StandardException
- Standard Derby exception policy- See Also:
-
releaseSavePoint
Description copied from interface:Transaction
Release the save point of the given name. Relasing a savepoint removes all knowledge from this transaction of the named savepoint and any savepoints set since the named savepoint was set.- Specified by:
releaseSavePoint
in interfaceTransaction
- Parameters:
name
- The user provided name of the savepoint, set by the user in the setSavePoint() call.kindOfSavepoint
- A NULL value means it is an internal savepoint (ie not a user defined savepoint) Non NULL value means it is a user defined savepoint which can be a SQL savepoint or a JDBC savepoint A String value for kindOfSavepoint would mean it is SQL savepoint A JDBC Savepoint object value for kindOfSavepoint would mean it is JDBC savepoint- Returns:
- returns total number of savepoints in the stack.
- Throws:
StandardException
- Standard Derby exception policy- See Also:
-
rollbackToSavePoint
Description copied from interface:Transaction
Rollback all changes made since the named savepoint was set. The named savepoint is not released, it remains valid within this transaction, and thus can be named it future rollbackToSavePoint() calls. Any savepoints set since this named savepoint are released (and their changes rolled back).- Specified by:
rollbackToSavePoint
in interfaceTransaction
- Parameters:
name
- The user provided name of the savepoint, set by the user in the setSavePoint() call.kindOfSavepoint
- A NULL value means it is an internal savepoint (ie not a user defined savepoint) Non NULL value means it is a user defined savepoint which can be a SQL savepoint or a JDBC savepoint A String value for kindOfSavepoint would mean it is SQL savepoint A JDBC Savepoint object value for kindOfSavepoint would mean it is JDBC savepoint- Returns:
- returns total number of savepoints in the stack.
- Throws:
StandardException
- Standard Derby exception policy- See Also:
-
getLogger
private void getLogger()Get the Logger object used to write log records to the transaction log. -
assumeIdentity
Transform this identity to the one stored in transaction table entry. Used by recovery only! -
assumeGlobalXactIdentity
Assume complete identity of the given Transaction Table Entry.Used by the final phase of the recovery to create new real transactions to take on the identity of in-doubt prepared transactions found during redo. Need to assume the globalId.
- Parameters:
ent
- The original entry we are assuming the identity of.
-
setUpdateState
Move the transaction into the update state.- Throws:
StandardException
- problem setting a transaction id
-
setIdleState
protected void setIdleState() -
setActiveState
- Throws:
StandardException
-
setPrepareState
Move the state of the transaction from UPDATE to PREPARE.The state transition should only be from UPDATE to PREPARE. Read-only transactions (IDLE and ACTIVE) will never be prepared, they will be commited when the prepare is requested. Only Update transactions will be allowed to go to prepared state.
- Throws:
StandardException
- Standard exception policy.
-
defaultLockingPolicy
-
releaseAllLocks
private final void releaseAllLocks() -
resetDefaultLocking
void resetDefaultLocking() -
preComplete
- Throws:
StandardException
-
postComplete
- Throws:
StandardException
-
doComplete
- Throws:
StandardException
-
checkObserverException
- Throws:
StandardException
-
doPostCommitWorkInTran
protected boolean doPostCommitWorkInTran()If this is a user transaction (not an internal or nested top transaction), and this is not already taking care of post commit work, and not an XA transaction, then take care of hi prioirty work right now using this thread and this context manager. Otherwise, leave it to the post commit daemon. -
handlesPostTerminationWork
public boolean handlesPostTerminationWork()Description copied from class:RawTransaction
Can this transaction handles post termination work- Specified by:
handlesPostTerminationWork
in classRawTransaction
-
recoveryTransaction
public void recoveryTransaction()Description copied from class:RawTransaction
Make this transaction aware that it is being used by recovery- Specified by:
recoveryTransaction
in classRawTransaction
-
transferPostCommitorAbortWork
- Throws:
StandardException
-
postTermination
- Throws:
StandardException
-
getSavePointPosition
Does a save point exist in the stack with the given name. Returns the position of the savepoint in the array -
popSavePoints
Pop all savepoints upto the one with the given name and rollback all changes made since this savepoint was pushed. If release is true then this savepoint is popped as well, otherwise it is left in the stack (at the top).- Returns:
- true if any work is rolled back, false if no work is rolled back
- Throws:
StandardException
- Thrown if a error of severity less than TransactionException#SEVERITY is encountered during the rollback of this savepoint.
-
startNestedTopTransaction
Description copied from class:RawTransaction
Start a nested top transaction. A nested top transaction behaves exactly like a user transaction. Nested top transaction allow system type work to proceed in a separate transaction to the current user transaction and be committed independently of the user transaction (usually before the user transaction). Only one nested top transaction can be active in a context at any one time. After a commit the transaction may be re-used. A nested top transaction conflicts on the logical locks of its "parent" transaction.- Specified by:
startNestedTopTransaction
in classRawTransaction
- Throws:
StandardException
- Derby Standard error policy
-
isUserTransaction
private boolean isUserTransaction()see if this transaction is a user transaction.- Returns:
- true if this transaction is a user transaction
-
isActive
public final boolean isActive()see if this transaction has ever done anything. MT - single thread through synchronizing this. This method may be called by other thread to test the state of this transaction. That's why we need to synchronize with all methods which enters or exits the Idle state. Local method which read the state need not be synchronized because the other thread may look at the state but it may not change it.- Returns:
- true if this transaction is not in idle or closed state
-
isPrepared
public final boolean isPrepared()see if this transaction is in PREPARED state. MT - single thread through synchronizing this. This method may be called by other thread to test the state of this transaction.- Returns:
- true if this transaction is in PREPARED state.
-
isIdle
public boolean isIdle()See if this transaction is in the idle state, called by other thread to test the state of this transaction. That's why we need to synchronzied with all methods whcih enters or exits the idle state- Specified by:
isIdle
in interfaceTransaction
- Returns:
- true if it is idle, otherwise false
-
isPristine
public boolean isPristine()see if this transaction is in a pristine state.
MT - called only by the same thread that owns the xact, no need to synchronize.- Specified by:
isPristine
in interfaceTransaction
- Returns:
- true if it hasn't done any updates, otherwise false
-
inAbort
public boolean inAbort()Description copied from class:RawTransaction
Is the transaction in the middle of an abort.- Specified by:
inAbort
in classRawTransaction
-
getFileHandler
Description copied from interface:Transaction
Get an object to handle non-transactional files.- Specified by:
getFileHandler
in interfaceTransaction
-
statusForBeginXactLog
protected int statusForBeginXactLog()put this into the beginXact log record to help recovery if we needs to rolled back first, put that in- Specified by:
statusForBeginXactLog
in classRawTransaction
-
statusForEndXactLog
protected int statusForEndXactLog()put this into the endXact log record to help recovery, nothing to add- Specified by:
statusForEndXactLog
in classRawTransaction
-
setPostComplete
void setPostComplete()Set the transaction to issue pre complete work at postComplete time, instead of preComplete time. This means that latches and containers will be held open until after a commit or an abort. -
blockBackup
Make the transaction block the online backup.- Specified by:
blockBackup
in classRawTransaction
- Parameters:
wait
- if true, waits until the transaction can block the backup.- Returns:
- true if the transaction blocked the backup. false otherwise.
- Throws:
StandardException
- if interrupted while waiting for the backup in progress to complete.
-
unblockBackup
private void unblockBackup()Unblock the backup, if it was blocked by some operation in this transaction. Unblocking is done at commit/abort of this transaction. -
isBlockingBackup
public boolean isBlockingBackup()Check if the transaction is blocking the backup ?- Specified by:
isBlockingBackup
in classRawTransaction
- Returns:
- true if this transaction is blocking the backup, otherwise false
-
reached
public void reached(CompatibilitySpace compatibilitySpace, Object group, int limit, Enumeration lockList, int lockCount) throws StandardException Description copied from interface:Limit
Called by the lock factory when a limit has been reached.- Specified by:
reached
in interfaceLimit
- Parameters:
compatibilitySpace
- lock space the limit was set forgroup
- lock group the limit was set forlimit
- the limit's settinglockList
- the list of Lockable's in the grouplockCount
- the number of locks in the group- Throws:
StandardException
- Standard Derby error policy.
-
createXATransactionFromLocalTransaction
public void createXATransactionFromLocalTransaction(int format_id, byte[] global_id, byte[] branch_id) throws StandardException Convert a local transaction to a global transaction.Must only be called a previous local transaction was created and exists in the context. Can only be called if the current transaction is in the idle state, and no current global id.
Simply call setTransactionId() which takes care of error checking.
- Specified by:
createXATransactionFromLocalTransaction
in interfaceTransaction
- Parameters:
format_id
- the format id part of the Xid - ie. Xid.getFormatId().global_id
- the global transaction identifier part of XID - ie. Xid.getGlobalTransactionId().branch_id
- The branch qualifier of the Xid - ie. Xid.getBranchQaulifier()- Throws:
StandardException
- Standard exception policy.
-
xa_commit
This method is called to commit the current XA global transaction.RESOLVE - how do we map to the "right" XAExceptions.
- Specified by:
xa_commit
in interfaceTransaction
- Parameters:
onePhase
- If true, the resource manager should use a one-phase commit protocol to commit the work done on behalf of current xid.- Throws:
StandardException
- Standard exception policy.
-
xa_prepare
This method is called to ask the resource manager to prepare for a transaction commit of the transaction specified in xid.- Specified by:
xa_prepare
in interfaceTransaction
- Returns:
- A value indicating the resource manager's vote on the the outcome of the transaction. The possible values are: XA_RDONLY or XA_OK. If the resource manager wants to roll back the transaction, it should do so by throwing an appropriate XAException in the prepare method.
- Throws:
StandardException
- Standard exception policy.
-
xa_rollback
rollback the current global transaction.The given transaction is roll'ed back and it's history is not maintained in the transaction table or long term log.
- Specified by:
xa_rollback
in interfaceTransaction
- Throws:
StandardException
- Standard exception policy.
-
toString
Return the xid as a string.The virtual lock table depends on this routine returning just the local transaction id as a string, even if it is a global transaction. Joins between the lock table and the transaction table will not work if this routine returns anything other than myId.toString().
-
toInternalDetailString
-
getActiveStateTxIdString
Get string id of the transaction that would be when the Transaction is IN active state. This transaction "name" will be the same id which is returned in the TransactionInfo information if Tx is already in Active State. If the Transaction is in IDLE state, Transaction ID is incremented when getActiveStateTxIdString() on raw transaction is called, instead of the Tx ID being incremented when Transaction gets into active state. The reason for incrementing the Tx ID earlier than when Tx is actually goes into active state is some debug statement cases like log statement text. SQL statements are written to log before they are actually executed; In such cases we would like to display the actual TX ID on which locks are acquired when the statement is executed.- Specified by:
getActiveStateTxIdString
in interfaceTransaction
- Returns:
- The a string which identifies the transaction.
-
getDataValueFactory
Get DataValueFactory.Return a DataValueFactory that can be used to allocate objects. Used to make calls to: DataValueFactory.getInstanceUsingFormatIdAndCollationType()
- Specified by:
getDataValueFactory
in interfaceTransaction
- Returns:
- a booted data value factory.
- Throws:
StandardException
- Standard exception policy.
-
getState
String getState() -
getTransName
-
setTransName
-
inRollForwardRecovery
public boolean inRollForwardRecovery()Is the transaction in rollforward recovery- Specified by:
inRollForwardRecovery
in classRawTransaction
-
checkpointInRollForwardRecovery
public void checkpointInRollForwardRecovery(LogInstant cinstant, long redoLWM, long undoLWM) throws StandardException Perform a checkpoint during rollforward recovery.- Specified by:
checkpointInRollForwardRecovery
in classRawTransaction
- Parameters:
cinstant
- The LogInstant of the checkpointredoLWM
- Redo Low Water Mark in the check point recordundoLWM
- Undo Low Water Mark in the checkpoint- Throws:
StandardException
-
isNestedOwner
public boolean isNestedOwner()Description copied from interface:LockOwner
Return true if this is a nested owner, e.g., a nested user transaction.
- Specified by:
isNestedOwner
in interfaceLockOwner
-
nestsUnder
Description copied from interface:LockOwner
Return true if this owner nests under another owner.
- Specified by:
nestsUnder
in interfaceLockOwner
-