⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transactiontable.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			if (SanityManager.DEBUG)				SanityManager.ASSERT(                    ent.getXid() != null,                    "read in transaction table entry with null id");			trans.put(ent.getXid(), ent);			if (ent.isUpdate() &&                 XactId.compare(ent.getXid(), largestUpdateXactId) > 0)            {				largestUpdateXactId = ent.getXid();            }		}	}	/**		Return the largest update transactionId I have seen so far.		<P>MT - unsafe, caller is recovery, which is single threaded.	*/	public TransactionId largestUpdateXactId()	{		return largestUpdateXactId;	}	/**		Is there an active internal transaction in the transaction table.		<P>MT - unsafe, caller is recovery, which is single threaded.	*/	public boolean hasRollbackFirstTransaction()	{		for (Enumeration e = trans.elements();			 e.hasMoreElements() ; )		{			TransactionTableEntry ent = (TransactionTableEntry)e.nextElement();			if (ent != null && ent.isRecovery() && 				(ent.getTransactionStatus() &                      Xact.RECOVERY_ROLLBACK_FIRST) != 0)            {				return true;            }		}		return false;	}	/**		Is there a prepared transaction in the transaction table.		<P>MT - unsafe, caller is recovery, which is single threaded.	*/	public boolean hasPreparedRecoveredXact()	{		for (Enumeration e = trans.elements(); e.hasMoreElements(); )		{			TransactionTableEntry ent = (TransactionTableEntry) e.nextElement();			if (ent != null && ent.isRecovery() && 				(ent.getTransactionStatus() & Xact.END_PREPARED) != 0)            {				return true;            }		}		return false;	}	/**		Get the most recently added transaction that says it needs to be		rolled back first (an InternalXact) from the transaction table and make		the passed in transaction assume its identity. 		<B> Should only be used in recovery undo !! </B>		RESOLVE: (sku)I don't think even these internal transactions need to be		rolled back in the reverse order, because they are physical in nature.		But it won't hurt.		<P>MT - unsafe, caller is recovery, which is single threaded.	*/	public boolean getMostRecentRollbackFirstTransaction(RawTransaction tran)	{		if (trans.isEmpty())		{			// set tranaction to idle			return findAndAssumeTransaction((TransactionId)null, tran);		}		TransactionId id = null;		for (Enumeration e = trans.elements();			 e.hasMoreElements() ; )		{			TransactionTableEntry ent = (TransactionTableEntry)e.nextElement();			if (ent != null && ent.isUpdate() && ent.isRecovery() &&				(ent.getTransactionStatus() & Xact.RECOVERY_ROLLBACK_FIRST) != 0)			{				// try to locate the most recent one				if (id == null || XactId.compare(id, ent.getXid()) < 0)					id = ent.getXid();			}		}		if (id == null)			// set transaction to idle		{			return findAndAssumeTransaction(id, tran);		}		else		{			// there is a rollback first transaction			boolean found =                 findAndAssumeTransaction(id, tran);			if (SanityManager.DEBUG)            {                if (!found)                {                    SanityManager.THROWASSERT(                        "cannot find transaction " + id + " in table");                }            }			return true;		}	}	/**		Get the most recently non-prepared added transaction from the         transaction table and make the passed in transaction assume its         identity.  Prepared transactions will not be undone.		RESOLVE: (sku) I don't think normal user transactions needs to be		rolled back in order, but it won't hurt.		<B> Should only be used in recovery undo !! </B>		<P>MT - unsafe, caller is recovery, which is single threaded.	*/	public boolean getMostRecentTransactionForRollback(RawTransaction tran)	{        TransactionId id = null;        if (!trans.isEmpty())		{			for (Enumeration e = trans.elements();				 e.hasMoreElements() ; )			{				TransactionTableEntry ent =					 (TransactionTableEntry)e.nextElement();				if (ent != null         &&                     ent.isUpdate()      &&                     ent.isRecovery()    &&                     !ent.isPrepared())				{					// try to locate the most recent one					if (id == null || XactId.compare(id, ent.getXid()) < 0)						id = ent.getXid();				}				if (SanityManager.DEBUG)				{					if (ent != null         &&                         ent.isUpdate()      &&                         ent.isRecovery()    &&						(ent.getTransactionStatus() &                          Xact.RECOVERY_ROLLBACK_FIRST) != 0)                    {						SanityManager.THROWASSERT(                            "still rollback first xacts in the tran table!");                    }				}			}			if (SanityManager.DEBUG)            {                // if all transactions are prepared then it is possible that                // no transaction will be found, in that case id will be null.                if (id != null)                {                    SanityManager.ASSERT(findTransactionEntry(id) != null);                }                else                {                    // all transactions in the table must be prepared.                    for (Enumeration e = trans.elements(); e.hasMoreElements();)                    {                        TransactionTableEntry ent =                            (TransactionTableEntry)e.nextElement();                        SanityManager.ASSERT(ent.isPrepared());                    }                }            }		}        return(findAndAssumeTransaction(id, tran));	}		/**		Get the most recently added transaction that says it is prepared during        recovery the transaction table and make the passed in transaction         assume its identity. This routine turns off the isRecovery() state		<B> Should only be used in recovery handle prepare after undo !! </B>		<P>MT - unsafe, caller is recovery, which is single threaded.	*/    /**     * Get the most recent recovered prepared transaction.     * <p>     * Get the most recently added transaction that says it is prepared during      * recovery the transaction table and make the passed in transaction      * assume its identity.      * <p>     * This routine, unlike the redo and rollback getMostRecent*() routines     * expects a brand new transaction to be passed in.  If a candidate      * transaction is found, then upon return the transaction table will      * be altered such that the old entry no longer exists, and a new entry     * will exist pointing to the transaction passed in.  The new entry will     * look the same as if the prepared transaction had been created during     * runtime rather than recovery.     *     * <B> Should only be used in recovery handle prepare after undo !! </B>     *     * <P>MT - unsafe, caller is recovery, which is single threaded.     *	 * @return true if a candidate transaction has been found.  false if no     *         prepared/recovery transactions found in the table.     *     * @param tran   Newly allocated transaction to add to link to a entry.     *     **/	public boolean getMostRecentPreparedRecoveredXact(    RawTransaction tran)	{        TransactionTableEntry   found_ent   = null;        if (!trans.isEmpty())		{            TransactionId           id          = null;            GlobalTransactionId     gid         = null;            TransactionTableEntry   ent;			for (Enumeration e = trans.elements(); e.hasMoreElements(); )			{				ent = (TransactionTableEntry)e.nextElement();				if (ent != null         &&                     ent.isRecovery()    &&                     ent.isPrepared())				{					// try to locate the most recent one					if (id == null || XactId.compare(id, ent.getXid()) < 0)                    {                        found_ent = ent;						id        = ent.getXid();						gid       = ent.getGid();                    }				}			}            if (SanityManager.DEBUG)            {                if (found_ent == null)                {                    // if no entry's were found then the transaction table                    // should have the passed in idle tran, and the rest should                    // be non-recover, prepared global transactions.                    for (Enumeration e = trans.elements(); e.hasMoreElements();)                    {                        ent = (TransactionTableEntry)e.nextElement();                        if (XactId.compare(ent.getXid(), tran.getId()) != 0)                        {                            SanityManager.ASSERT(                                !ent.isRecovery() && ent.isPrepared());                            SanityManager.ASSERT(ent.getGid() != null);                        }                    }                }            }            if (found_ent != null)            {                // At this point there are 2 tt entries of interest:                //     new_ent - the read only transaction entry that was                 //               created when we allocated a new transaction.                //               We will just throw this one away after                 //               assuming the identity of the global xact.                //     found_ent                //             - the entry of the transaction that we are going                //               to take over.                TransactionTableEntry new_ent =                    (TransactionTableEntry) trans.remove(tran.getId());                // At this point only the found_ent should be in the table.                if (SanityManager.DEBUG)                {	                SanityManager.ASSERT(findTransactionEntry(id) == found_ent);                }                ((Xact) tran).assumeGlobalXactIdentity(found_ent);                // transform this recovery entry, into a runtime entry.                found_ent.unsetRecoveryStatus();            }		}        return(found_ent != null);	}	/**		Get the least recently added (oldest) transaction		@return the RawTransaction's first log instant		<P>MT - safe, caller can be recovery or checkpoint	*/	public LogInstant getFirstLogInstant()	{		// assume for now that it is acceptable to return null if a transaction		// starts right in the middle of this call.		if (trans.isEmpty())        {			return null;        }		else		{			LogInstant logInstant = null;                        // bug 5632: need to sychronize so that another thread does not             // come in and disrupt the for loop, we got an exception on next,            // likely because hash table changed by another thread after            // hasMoreElements() called, but before nextElement().            synchronized (trans)            {                for (Enumeration e = trans.elements(); e.hasMoreElements(); )                {                    TransactionTableEntry ent =                        (TransactionTableEntry)e.nextElement();                    if (ent != null && ent.isUpdate())                    {                        if (logInstant == null ||                             ent.getFirstLog().lessThan(logInstant))                        {                            logInstant = ent.getFirstLog();                        }                    }                }            }			return logInstant;		}	}	/**		Find a transaction using the transaction id, and make the passed in		transaction assume the identity and properties of that transaction.		<P>MT - unsafe, caller is recovery, which is single threaded.		@param id transaction Id		@param tran the transaction that was made to assume the transactionID		and all other relavent information stored in the transaction table		@return true if transaction can be found, false otherwise	*/	boolean findAndAssumeTransaction(    TransactionId       id,     RawTransaction      tran)	{		// the only caller for this method right now is recovery.          // No need to put in any concurrency control		TransactionTableEntry ent = null;		if (id != null && !trans.isEmpty())		{			ent = findTransactionEntry(id);			if (SanityManager.DEBUG)			{				if (ent != null)					SanityManager.ASSERT(ent.isRecovery(),					"assuming the id of a non-recovery transaction");			}		}		// if no transaction entry found, set transaction to idle        ((Xact)tran).assumeIdentity(ent);		return(ent != null);	}	/**********************************************************	 * Transaction table vti and diagnostics	 * MT - unsafe, caller is getting a snap shot which may be inconsistent 	 *********************************************************/	/**		Get a printable version of the transaction table	 */	public TransactionInfo[] getTransactionInfo()	{		if (trans.isEmpty())			return null;		// while taking a snap shot, no adding or removing of transaction		TransactionInfo[] tinfo;		if (SanityManager.DEBUG)			SanityManager.DEBUG("TranTrace", toString());		synchronized(this)		{			int ntran = trans.size();			tinfo = new TransactionTableEntry[ntran];			LogInstant logInstant = null;			int i = 0;			for (Enumeration e = trans.elements();				 e.hasMoreElements(); )			{				TransactionTableEntry ent =					(TransactionTableEntry)e.nextElement();				if (ent != null)					tinfo[i++] = (TransactionTableEntry)ent.clone();				if (SanityManager.DEBUG)					SanityManager.ASSERT(ent != null, "transaction table has null entry");			}		}		return tinfo;	}	public String toString()	{		if (SanityManager.DEBUG)		{			StringBuffer str = new StringBuffer(1000).				append("\n**************************\n").				append(super.toString()).				append("\nTransaction Table: size = ").append(trans.size()).				append(" largestUpdateXactId = ").append(largestUpdateXactId).				append("\n");			boolean hasReadOnlyTransaction = false;			for (Enumeration e = trans.elements();				 e.hasMoreElements(); )			{				TransactionTableEntry ent =					(TransactionTableEntry)e.nextElement(); 				if (ent != null && ent.isUpdate())					str.append(ent.toString());				if (ent != null && !ent.isUpdate())					hasReadOnlyTransaction = true;			}			if (hasReadOnlyTransaction)			{				str.append("\n READ ONLY TRANSACTIONS \n");				for (Enumeration e = trans.elements();					 e.hasMoreElements(); )				{					TransactionTableEntry ent =						(TransactionTableEntry)e.nextElement(); 					if (ent != null && !ent.isUpdate())						str.append(ent.toString());				}			}			str.append("---------------------------");			return str.toString();		}		else			return null;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -