All Implemented Interfaces:
Limit, LockOwner, Transaction
Direct Known Subclasses:
InternalXact

public class Xact extends RawTransaction implements Limit, LockOwner
A transaction has five states
  1. CLOSED - cannot be used
  2. IDLE - no reads have been performed by the transaction.
  3. ACTIVE - at least one read has been attempted by the transaction
  4. UPDATE - at least one update has been attempted by the transaction
  5. 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 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_SYNC
      private 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

      protected XactContext xc
    • xactFactory

      protected final XactFactory xactFactory
    • dataFactory

      protected final DataFactory dataFactory
    • logFactory

      protected final LogFactory logFactory
    • dataValueFactory

      protected final DataValueFactory dataValueFactory
    • compatibilitySpace

      private final CompatibilitySpace compatibilitySpace
    • defaultLocking

      private LockingPolicy defaultLocking
    • myGlobalId

      private GlobalTransactionId myGlobalId
    • myId

      private volatile TransactionId myId
    • parentTransactionId

      private volatile TransactionId parentTransactionId
    • logger

      protected Logger logger
    • state

      protected volatile int state
    • inComplete

      private Integer inComplete
    • seenUpdates

      private boolean seenUpdates
    • inPostCommitProcessing

      private boolean inPostCommitProcessing
    • logStart

      private LogInstant logStart
    • logLast

      private LogInstant logLast
    • savePoints

      private Stack<SavePoint> savePoints
    • postCommitWorks

      protected List<Serviceable> postCommitWorks
    • postAbortWorks

      protected List<Serviceable> postAbortWorks
    • postTerminationWorks

      protected List<Serviceable> postTerminationWorks
    • recoveryTransaction

      private boolean recoveryTransaction
    • logBuffer

    • postCompleteMode

      private boolean postCompleteMode
    • sanityCheck_xaclosed

      private boolean sanityCheck_xaclosed
    • transName

      private String transName
    • readOnly

      private boolean readOnly
    • flush_log_on_xact_end

      private boolean flush_log_on_xact_end
    • backupBlocked

      private boolean backupBlocked
    • dontWaitForLocks

      private boolean dontWaitForLocks
      Tells if lock requests should time out immediately if they cannot be granted without waiting.
  • Constructor Details

  • Method Details

    • getLockFactory

      public final LockFactory getLockFactory()
      Description copied from class: RawTransaction
      Get the lock factory to be used during this transaction.
      Specified by:
      getLockFactory in class RawTransaction
    • getDataFactory

      public final DataFactory getDataFactory()
      Description copied from class: RawTransaction
      Get the data factory to be used during this transaction.
      Specified by:
      getDataFactory in class RawTransaction
    • getLogFactory

      public final LogFactory 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 class RawTransaction
    • anyoneBlocked

      public boolean anyoneBlocked()
      Return true if any transaction is currently blocked, even if not by this transaction.
      Specified by:
      anyoneBlocked in interface Transaction
    • getLogBuffer

      public DynamicByteArrayOutputStream getLogBuffer()
      Description copied from class: RawTransaction
      Get the log buffer to be used during this transaction.
      Specified by:
      getLogBuffer in class RawTransaction
    • 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 class RawTransaction
      Parameters:
      compensation - the Compensation Operation
      undoInstant - the LogInstant of the Loggable Operation this compensation operation is going to roll back
      in - 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 class RawTransaction
    • removeUpdateTransaction

      public void removeUpdateTransaction()
      Remove this from the xactFactory list of update transaction.
      Specified by:
      removeUpdateTransaction in class RawTransaction
    • prepareTransaction

      public void prepareTransaction()
      Remove this from the xactFactory list of update transaction.
      Specified by:
      prepareTransaction in class RawTransaction
    • setFirstLogInstant

      public void setFirstLogInstant(LogInstant instant)
      Set the log instant for the first log record written by this transaction.
      Specified by:
      setFirstLogInstant in class RawTransaction
    • getFirstLogInstant

      public LogInstant getFirstLogInstant()
      Get the log instant for the first log record written by this transaction.
      Specified by:
      getFirstLogInstant in class RawTransaction
    • setLastLogInstant

      public void setLastLogInstant(LogInstant instant)
      Set the log instant for the last log record written by this transaction.
      Specified by:
      setLastLogInstant in class RawTransaction
    • getLastLogInstant

      public LogInstant getLastLogInstant()
      Get the log instant for the last log record written by this transaction.
      Specified by:
      getLastLogInstant in class RawTransaction
    • setTransactionId

      void setTransactionId(GlobalTransactionId extid, TransactionId localid)
      Set my transaction identifier.
    • setTransactionId

      public void setTransactionId(Loggable beginXact, TransactionId localId)
      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 class RawTransaction
    • setup

      public void setup(PersistentSet set) throws StandardException
      The default value for LOCKS_ESCALATION_THRESHOLD
      Specified by:
      setup in interface Transaction
      Throws:
      StandardException - Standard Derby exception policy
    • getGlobalId

      public final GlobalTransactionId getGlobalId()
      get the Global (external to raw store) transaction id that is unique across all raw stores
      Specified by:
      getGlobalId in interface Transaction
      Specified by:
      getGlobalId in class RawTransaction
    • getContextManager

      public final ContextManager getContextManager()
      Description copied from interface: Transaction
      Return the context manager this transaction is associated with.
      Specified by:
      getContextManager in interface Transaction
    • getCompatibilitySpace

      public final CompatibilitySpace 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 interface Transaction
      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.
      Specified by:
      noWait in interface LockOwner
      Returns:
      whether waiting for locks should time out immediately
    • 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 interface Transaction
      Parameters:
      noWait - if true never wait for a lock in this transaction, but time out immediately
      See Also:
    • getId

      public final TransactionId getId()
      get the short (internal to raw store) transaction id that is unique only for this raw store
      Specified by:
      getId in class RawTransaction
    • getIdNoCheck

      protected final TransactionId getIdNoCheck()
      Get the transaction id without sanity check, this should only be called by a cloned TransactionTableEntry
    • getContextId

      public final String getContextId()
      Get my transaction context Id
    • getDefaultLockingPolicy

      public LockingPolicy getDefaultLockingPolicy()
      Get the current default locking policy for all operations within this transaction. The transaction is initially started with a default locking policy equivalent to
                               newLockingPolicy(
                    LockingPolicy.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, true);
                      
      This default can be changed by subsequent calls to setDefaultLockingPolicy(LockingPolicy policy).
      Specified by:
      getDefaultLockingPolicy in interface Transaction
      Returns:
      The current default locking policy in this transaction.
      See Also:
    • newLockingPolicy

      public final LockingPolicy newLockingPolicy(int mode, int isolation, boolean stricterOk)
      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 interface Transaction
      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

      public final void setDefaultLockingPolicy(LockingPolicy policy)
      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 to
                               newLockingPolicy(
                    LockingPolicy.MODE_RECORD, LockingPolicy.ISOLATION_SERIALIZABLE, true);
                      
      Specified by:
      setDefaultLockingPolicy in interface Transaction
      Parameters:
      policy - The lock policy to use, if null then then a no locking policy will be installed as the default.
      See Also:
    • commit

      public LogInstant commit() throws StandardException
      Description copied from interface: Transaction
      Commit this transaction. All savepoints within this transaction are released.
      Specified by:
      commit in interface Transaction
      Returns:
      the commit instant of this transaction, or null if it didn't make any changes
      Throws:
      StandardException - Standard Derby exception policy
    • commitNoSync

      public LogInstant commitNoSync(int commitflag) throws StandardException
      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 interface Transaction
      Throws:
      StandardException - Standard Derby exception policy
    • prepareCommit

      private LogInstant prepareCommit(int commitflag) throws StandardException
      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

      private void completeCommit(int commitflag) throws StandardException
      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

      private LogInstant commit(int commitflag) throws StandardException
      Throws:
      StandardException - Standard Derby exception policy
      See Also:
    • abort

      public void abort() throws StandardException
      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 interface Transaction
      Throws:
      StandardException - Standard Derby exception policy
      See Also:
    • reprepare

      public void reprepare() throws StandardException
      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 class RawTransaction
      Throws:
      StandardException - Standard exception policy.
    • destroy

      public void destroy() throws StandardException
      If this transaction is not idle, abort it. After this call close().
      Specified by:
      destroy in interface Transaction
      Throws:
      StandardException - Standard Derby error policy Thrown if the transaction is not idle.
      See Also:
    • close

      public void close() throws StandardException
      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 interface Transaction
      Throws:
      StandardException - Thrown if the transaction is not idle, the transaction remains open.
      See Also:
    • logAndDo

      public void logAndDo(Loggable operation) throws StandardException
      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 interface Transaction
      Parameters:
      operation - the operation that is to be applied
      Throws:
      StandardException - Standard Derby exception policy
      See Also:
    • addPostCommitWork

      public void addPostCommitWork(Serviceable work)
      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 interface Transaction
      Parameters:
      work - the post commit work that is added
    • addPostAbortWork

      public void addPostAbortWork(Serviceable work)
      Add to the list of post abort work that may be processed after this transaction aborts.
      Specified by:
      addPostAbortWork in interface Transaction
      Parameters:
      work - the post commit work that is added
    • addPostTerminationWork

      public void addPostTerminationWork(Serviceable work)
      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 interface Transaction
      Parameters:
      work - the post termination work that is added
    • openContainer

      public ContainerHandle openContainer(ContainerKey containerId, int mode) throws StandardException
      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 interface Transaction
      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 interface Transaction
      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 class RawTransaction
      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 interface Transaction
      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 interface Transaction
      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 interface Transaction
      Returns:
      a valid StreamContainerHandle or null if the container does not exist.
      Throws:
      StandardException - Standard Derby exception policy
      See Also:
    • dropStreamContainer

      public void dropStreamContainer(long segmentId, long containerId) throws StandardException
      Description copied from interface: Transaction
      Drop a stream container.

      Synchronisation

      This call will remove the container.

      Specified by:
      dropStreamContainer in interface Transaction
      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 class RawTransaction
      Throws:
      StandardException - Standard Derby exception policy
      See Also:
    • dropContainer

      public void dropContainer(ContainerKey containerId) throws StandardException
      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 interface Transaction
      Throws:
      StandardException - Standard Derby error policy
      See Also:
    • setSavePoint

      public int setSavePoint(String name, Object kindOfSavepoint) throws StandardException
      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 interface Transaction
      Parameters:
      name - The user provided name of the savepoint
      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:
    • throwExceptionIfSQLSavepointNotAllowed

      private void throwExceptionIfSQLSavepointNotAllowed(Object kindOfSavepoint) throws StandardException
      Throws:
      StandardException - Standard Derby exception policy
      See Also:
    • releaseSavePoint

      public int releaseSavePoint(String name, Object kindOfSavepoint) throws StandardException
      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 interface Transaction
      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

      public int rollbackToSavePoint(String name, Object kindOfSavepoint) throws StandardException
      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 interface Transaction
      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

      protected void assumeIdentity(TransactionTableEntry ent)
      Transform this identity to the one stored in transaction table entry. Used by recovery only!
    • assumeGlobalXactIdentity

      protected void assumeGlobalXactIdentity(TransactionTableEntry ent)
      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

      private final void setUpdateState() throws StandardException
      Move the transaction into the update state.
      Throws:
      StandardException - problem setting a transaction id
    • setIdleState

      protected void setIdleState()
    • setActiveState

      protected final void setActiveState() throws StandardException
      Throws:
      StandardException
    • setPrepareState

      protected final void setPrepareState() throws StandardException
      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

      public final LockingPolicy defaultLockingPolicy()
    • releaseAllLocks

      private final void releaseAllLocks()
    • resetDefaultLocking

      void resetDefaultLocking()
    • preComplete

      protected void preComplete(Integer commitOrAbort) throws StandardException
      Throws:
      StandardException
    • postComplete

      protected void postComplete(int commitflag, Integer commitOrAbort) throws StandardException
      Throws:
      StandardException
    • doComplete

      protected void doComplete(Integer commitOrAbort) throws StandardException
      Throws:
      StandardException
    • checkObserverException

      private void checkObserverException() throws StandardException
      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 class RawTransaction
    • recoveryTransaction

      public void recoveryTransaction()
      Description copied from class: RawTransaction
      Make this transaction aware that it is being used by recovery
      Specified by:
      recoveryTransaction in class RawTransaction
    • transferPostCommitorAbortWork

      private void transferPostCommitorAbortWork(List<Serviceable> work_list) throws StandardException
      Throws:
      StandardException
    • postTermination

      private final void postTermination() throws StandardException
      Throws:
      StandardException
    • getSavePointPosition

      private int getSavePointPosition(String name, Object kindOfSavepoint, boolean forRollbackOrRelease)
      Does a save point exist in the stack with the given name. Returns the position of the savepoint in the array
    • popSavePoints

      protected boolean popSavePoints(int position, boolean release) throws StandardException
      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

      public RawTransaction startNestedTopTransaction() throws StandardException
      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 class RawTransaction
      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 interface Transaction
      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 interface Transaction
      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 class RawTransaction
    • getFileHandler

      public FileResource getFileHandler()
      Description copied from interface: Transaction
      Get an object to handle non-transactional files.
      Specified by:
      getFileHandler in interface Transaction
    • 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 class RawTransaction
    • statusForEndXactLog

      protected int statusForEndXactLog()
      put this into the endXact log record to help recovery, nothing to add
      Specified by:
      statusForEndXactLog in class RawTransaction
    • 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

      public boolean blockBackup(boolean wait) throws StandardException
      Make the transaction block the online backup.
      Specified by:
      blockBackup in class RawTransaction
      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 class RawTransaction
      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 interface Limit
      Parameters:
      compatibilitySpace - lock space the limit was set for
      group - lock group the limit was set for
      limit - the limit's setting
      lockList - the list of Lockable's in the group
      lockCount - 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 interface Transaction
      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

      public void xa_commit(boolean onePhase) throws StandardException
      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 interface Transaction
      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

      public int xa_prepare() throws StandardException
      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 interface Transaction
      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

      public void xa_rollback() throws StandardException
      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 interface Transaction
      Throws:
      StandardException - Standard exception policy.
    • toString

      public String 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().

      Overrides:
      toString in class Object
      Returns:
      The xid as a string.
    • toInternalDetailString

      public String toInternalDetailString()
    • getActiveStateTxIdString

      public String 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 interface Transaction
      Returns:
      The a string which identifies the transaction.
    • getDataValueFactory

      public DataValueFactory getDataValueFactory() throws StandardException
      Get DataValueFactory.

      Return a DataValueFactory that can be used to allocate objects. Used to make calls to: DataValueFactory.getInstanceUsingFormatIdAndCollationType()

      Specified by:
      getDataValueFactory in interface Transaction
      Returns:
      a booted data value factory.
      Throws:
      StandardException - Standard exception policy.
    • getState

      String getState()
    • getTransName

      public String getTransName()
    • setTransName

      public void setTransName(String name)
    • inRollForwardRecovery

      public boolean inRollForwardRecovery()
      Is the transaction in rollforward recovery
      Specified by:
      inRollForwardRecovery in class RawTransaction
    • checkpointInRollForwardRecovery

      public void checkpointInRollForwardRecovery(LogInstant cinstant, long redoLWM, long undoLWM) throws StandardException
      Perform a checkpoint during rollforward recovery.
      Specified by:
      checkpointInRollForwardRecovery in class RawTransaction
      Parameters:
      cinstant - The LogInstant of the checkpoint
      redoLWM - Redo Low Water Mark in the check point record
      undoLWM - 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 interface LockOwner
    • nestsUnder

      public boolean nestsUnder(LockOwner other)
      Description copied from interface: LockOwner

      Return true if this owner nests under another owner.

      Specified by:
      nestsUnder in interface LockOwner