📄 xact.java
字号:
} catch (StandardException se) { // This catches any exceptions that have System severity // or less (e.g. Statement exception). // // If we have any error during an undo we just shut the system // down, this is a bit drastic but it does ensure that the database // will not become corrupted by changes that see half committed // changes. // // Note that we do not release our locks if we come thorugh this // path, if we did then another transaction could complete before // the system shuts down and make changes based upon the changes // that we couldn't back out. if (se.getSeverity() < ExceptionSeverity.SYSTEM_SEVERITY) { throw logFactory.markCorrupt( StandardException.newException( SQLState.XACT_ABORT_EXCEPTION, se)); } throw se; } // this releases our locks. postComplete(0, ABORT); // get rid of all post commit work - we aborted, therefore no post // commit work if (postCommitWorks != null && !postCommitWorks.isEmpty()) { postCommitWorks.clear(); } // Now do post termination work - must do this after the rollback is // complete because the rollback itself may generate postTermination // work. postTermination(); myGlobalId = null; } /** * During recovery re-prepare a transaction. * <p> * 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. * <p> * This routine is only called during Recovery. * * @exception StandardException Standard exception policy. **/ public void reprepare() throws StandardException { if (state == CLOSED) { throw StandardException.newException( SQLState.XACT_PROTOCOL_VIOLATION); } // Should only be called during recovery on global transactions, // after redo and undo. if (SanityManager.DEBUG) { SanityManager.ASSERT(myGlobalId != null); SanityManager.ASSERT(state == PREPARED); } try { if (logger == null) { throw StandardException.newException( SQLState.XACT_CANNOT_ABORT_NULL_LOGGER); } // temporarily set state back to UPDATE, so that the reprepare() // call can do operations on the xact that would "normally" be // disallowed on a prepared xact - like opening a container to // lock it. state = UPDATE; // re-prepare the transaction. logger.reprepare( this, getId(), getFirstLogInstant(), getLastLogInstant()); // make sure the xact is prepare state when we are done. state = PREPARED; seenUpdates = true; } catch (StandardException se) { // This catches any exceptions that have System severity // or less (e.g. Statement exception). // // If we have any error during an reprepare we just shut the system // down, this is a bit drastic but it does ensure that the database // will not become corrupted by changes that see data that is part // of a prepared transaction. // // Note that we do not release our locks if we come thorugh this // path, if we did then another transaction could complete before // the system shuts down and make changes based upon the changes // that we couldn't back out. if (se.getSeverity() < ExceptionSeverity.SYSTEM_SEVERITY) { throw logFactory.markCorrupt( StandardException.newException( SQLState.XACT_ABORT_EXCEPTION, se)); } throw se; } // RESOLVE - something needs to change the state of the XACT so that // it is not recovery state anymore? } /** If this transaction is not idle, abort it. After this call close(). @exception StandardException Standard Cloudscape error policy Thrown if the transaction is not idle. */ public void destroy() throws StandardException { if (state != CLOSED) abort(); close(); } /** @exception StandardException Standard cloudscape exception policy @exception StandardException Thrown if the transaction is not idle, the transaction remains open. @see Transaction#close @exception StandardException Standard cloudscape policy */ public void close() throws StandardException { /* if (((LogToFile) logFactory).inRedo) { SanityManager.showTrace(new Throwable()); SanityManager.THROWASSERT("in Redo while in close"); } */ switch (state) { case CLOSED: return; case IDLE: break; default: throw StandardException.newException( SQLState.XACT_TRANSACTION_NOT_IDLE); } if (SanityManager.DEBUG) { SanityManager.ASSERT(xc.getTransaction() == this); SanityManager.ASSERT( (postCommitWorks == null || postCommitWorks.isEmpty()), "cannot close a transaction with post commit work pending"); // use this for sanity checking if (myGlobalId != null) sanityCheck_xaclosed = true; } getLockFactory().clearLimit(this, this); if (SanityManager.DEBUG) { if (SanityManager.DEBUG_ON("XATrace")) SanityManager.DEBUG("XATrace","closing " + myId + " " + myGlobalId); // Thread.dumpStack(); } // if we just finished recovery myId could be null if (myId != null) xactFactory.remove((XactId)myId); xc.popMe(); xc = null; myGlobalId = null; myId = null; logStart = null; logLast = null; /* MT - no need to synchronize it, the state is current IDLE which will * return the same result to isActive() as if it is CLOSED */ state = CLOSED; } /** 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). @exception StandardException Standard cloudscape exception policy @see Transaction#logAndDo */ public void logAndDo(Loggable operation) throws StandardException { LogInstant instant = null; if (logger == null) getLogger(); if (logger == null) { throw StandardException.newException( SQLState.XACT_CANNOT_LOG_CHANGE); } setActiveState(); if (state == ACTIVE) { instant = logger.logAndDo( this, new BeginXact(getGlobalId(), statusForBeginXactLog())); setUpdateState(); } seenUpdates = true; if (operation != null) { instant = logger.logAndDo(this, operation); if (instant != null) { setLastLogInstant(instant); if ((savePoints != null) && !savePoints.empty()) { for (int i = savePoints.size() - 1; i >= 0; i--) { // set the top savepoint to rollback to this record if // it doesn't yet have a point saved SavePoint sp = (SavePoint) savePoints.elementAt(i); if (sp.getSavePoint() == null) { sp.setSavePoint(instant); } else break; } } } } else { if (instant != null) setLastLogInstant(instant); } } public void addPostCommitWork(Serviceable work) { if (recoveryTransaction) return; if (postCommitWorks == null) postCommitWorks = new ArrayList(1); postCommitWorks.add(work); } public void addPostTerminationWork(Serviceable work) { if (recoveryTransaction) return; if (postTerminationWorks == null) postTerminationWorks = new ArrayList(2); postTerminationWorks.add(work); } /** Return a record handle that is initialized to the given page number and record id. @exception StandardException Standard cloudscape exception policy. @param segmentId segment where the RecordHandle belongs. @param containerId container where the RecordHandle belongs. @param pageNumber the page number of the RecordHandle. @param recordId the record id of the RecordHandle. @see RecordHandle */// public RecordHandle makeRecordHandle(long segmentId, long containerId, long pageNumber, int recordId)// throws StandardException // {// return(this.dataFactory.makeRecordHandle(// segmentId, containerId, pageNumber, recordId));// } /** @exception StandardException Standard cloudscape exception policy @see Transaction#openContainer */ public ContainerHandle openContainer(ContainerKey containerId, int mode) throws StandardException { return openContainer(containerId, defaultLockingPolicy(), mode); } /** @exception StandardException Standard cloudscape exception policy @see Transaction#openContainer */ public ContainerHandle openContainer(ContainerKey containerId, LockingPolicy locking, int mode) throws StandardException { setActiveState(); if (locking == null) locking = xactFactory.getLockingPolicy(LockingPolicy.MODE_NONE, TransactionController.ISOLATION_NOLOCK, false); return dataFactory.openContainer(this, containerId, locking, mode); } /** Open a container that may already have been dropped. @exception StandardException Standard cloudscape exception policy @see RawTransaction#openDroppedContainer */ public RawContainerHandle openDroppedContainer(ContainerKey containerId, LockingPolicy locking) throws StandardException { setActiveState(); if (locking == null) locking = xactFactory.getLockingPolicy(LockingPolicy.MODE_NONE, TransactionController.ISOLATION_NOLOCK, false); RawContainerHandle hdl = null; // first try to open it for update, if that fail, open it for read try { hdl = dataFactory.openDroppedContainer(this, containerId, locking, ContainerHandle.MODE_FORUPDATE); } catch (StandardException se) { // if this also fail, throw exception hdl = dataFactory.openDroppedContainer(this, containerId, locking, ContainerHandle.MODE_READONLY); } return hdl; } /** @exception StandardException Standard cloudscape exception policy @see Transaction#addContainer */ public long addContainer(long segmentId, long containerid, int mode, Properties tableProperties, int temporaryFlag) throws StandardException { setActiveState(); return dataFactory.addContainer(this, segmentId, containerid, mode, tableProperties, temporaryFlag); } /** @exception StandardException Standard cloudscape exception policy @see Transaction#addAndLoadStreamContainer */ public long addAndLoadStreamContainer(long segmentId, Properties tableProperties, RowSource rowSource) throws StandardException { setActiveState(); return dataFactory.addAndLoadStreamContainer(this, segmentId, tableProperties, rowSource); } /** @exception StandardException Standard cloudscape exception policy @see Transaction#openStreamContainer */ public StreamContainerHandle openStreamContainer( long segmentId, long containerId, boolean hold) throws StandardException { setActiveState(); return( dataFactory.openStreamContainer( this, segmentId, containerId, hold)); } /** @see Transaction#dropStreamContainer @exception StandardException Standard Cloudscape error policy */ public void dropStreamContainer(long segmentId, long containerId) throws StandardException { setActiveState(); dataFactory.dropStreamContainer(this, segmentId, containerId); } /** Recreate a container during load tran - use only by media recovery. @exception StandardException Standard cloudscape exception policy @see RawTransaction#reCreateContainerForLoadTran */ public void reCreateContainerForLoadTran (long segmentId, long containerId, ByteArray containerInfo) throws StandardException { setActiveState(); dataFactory.reCreateContainerForLoadTran( this, segmentId, containerId, containerInfo); } /** @see Transaction#dropContainer @exception StandardException Standard Cloudscape error policy */ public void dropContainer(ContainerKey containerId) throws StandardException {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -