Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 54772 invoked from network); 21 Jan 2010 08:44:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 21 Jan 2010 08:44:09 -0000 Received: (qmail 98213 invoked by uid 500); 21 Jan 2010 08:44:08 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 98162 invoked by uid 500); 21 Jan 2010 08:44:08 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 98153 invoked by uid 99); 21 Jan 2010 08:44:08 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Jan 2010 08:44:08 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Jan 2010 08:44:06 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 8270223888E2; Thu, 21 Jan 2010 08:43:44 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r901597 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/xact: TransactionTable.java XactXAResourceManager.java Date: Thu, 21 Jan 2010 08:43:30 -0000 To: derby-commits@db.apache.org From: kahatlen@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100121084344.8270223888E2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kahatlen Date: Thu Jan 21 08:43:14 2010 New Revision: 901597 URL: http://svn.apache.org/viewvc?rev=901597&view=rev Log: DERBY-3092 (partial) Don't expose TransactionTable's Hashtable Added a visitEntries() method that could be used instead of getTableForXA() to inspect the contents of the transaction table. Now, the Hashtable is only visible to the TransactionTable class, which will make it easier to replace it with another Map implementation later. Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/xact/TransactionTable.java db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/xact/XactXAResourceManager.java Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/xact/TransactionTable.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/xact/TransactionTable.java?rev=901597&r1=901596&r2=901597&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/xact/TransactionTable.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/xact/TransactionTable.java Thu Jan 21 08:43:14 2010 @@ -117,7 +117,38 @@ return (TransactionTableEntry)trans.get(id); } + /** + * Interface for visiting entries in the transaction table. + * @see #visitEntries(EntryVisitor) + */ + static interface EntryVisitor { + /** + * Visit an entry. {@link #visitEntries(EntryVisitor)} will call this + * method once for each entry in the transaction table. + * + * @param entry the {@code TransactionTableEntry} being visited + */ + void visit(TransactionTableEntry entry); + } + /** + *

+ * Visit all the entries in the transaction table. + *

+ * + *

+ * MT - MT safe + *

+ * + * @param visitor the visitor to apply on each transaction table entry + */ + void visitEntries(EntryVisitor visitor) { + synchronized (trans) { + for (Iterator it = trans.values().iterator(); it.hasNext(); ) { + visitor.visit((TransactionTableEntry) it.next()); + } + } + } void add(Xact xact, boolean exclude) @@ -276,27 +307,6 @@ ************************************************************************** */ - /** - * Return the hash table to the XA layer. - *

- * The XA code will do linear read-only operations on the hash table, - * write operations are only done in this module. It is a little ugly - * to export the hash table, but I wanted to move the XA specific code - * into the XA module, so that we could configure out the XA code if - * necessary. - *

- * - * Must be MT -safe, depends on sync hash table, and must get - * synchronized(hash_table) for linear searches. - * - * @return The ContextManager of the transaction being searched for. - * - **/ - public Map getTableForXA() - { - return(trans); - } - /** Change transaction to prepared. Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/xact/XactXAResourceManager.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/xact/XactXAResourceManager.java?rev=901597&r1=901596&r2=901597&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/xact/XactXAResourceManager.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/xact/XactXAResourceManager.java Thu Jan 21 08:43:14 2010 @@ -37,8 +37,7 @@ import org.apache.derby.iapi.store.raw.RawStoreFactory; import org.apache.derby.iapi.store.raw.Transaction; -import java.util.Iterator; -import java.util.Map; +import java.util.ArrayList; import javax.transaction.xa.Xid; import javax.transaction.xa.XAResource; @@ -244,48 +243,33 @@ if ((flags & XAResource.TMSTARTRSCAN) != 0) { - Map trans_hashtable = transaction_table.getTableForXA(); - XAXactId[] xid_list = new XAXactId[trans_hashtable.size()]; - int num_prepared = 0; - - // Need to hold sync while linear searching the hash table. - synchronized (trans_hashtable) - { - int i = 0; - - for (Iterator it = trans_hashtable.values().iterator(); - it.hasNext(); i++) - { - Xact xact = - ((TransactionTableEntry) it.next()).getXact(); + final ArrayList xid_list = new ArrayList(); + // Create a visitor that adds each of the prepared transactions + // to xid_list. + final TransactionTable.EntryVisitor visitor = + new TransactionTable.EntryVisitor() { + public void visit(TransactionTableEntry entry) { + Xact xact = entry.getXact(); if (xact.isPrepared()) { GlobalTransactionId xa_id = xact.getGlobalId(); - xid_list[i] = + xid_list.add( new XAXactId( xa_id.getFormat_Id(), xa_id.getGlobalTransactionId(), - xa_id.getBranchQualifier()); - num_prepared++; + xa_id.getBranchQualifier())); } } - } + }; - // now need to squish the nulls out of the array to return. - ret_xid_list = new XAXactId[num_prepared]; - int ret_index = 0; - for (int i = xid_list.length; i-- > 0; ) - { - if (xid_list[i] != null) - ret_xid_list[ret_index++] = xid_list[i]; - } - - if (SanityManager.DEBUG) - { - SanityManager.ASSERT(ret_index == num_prepared); - } + // Collect the prepared transactions. + transaction_table.visitEntries(visitor); + + // Convert the list to an array suitable for being returned. + ret_xid_list = new XAXactId[xid_list.size()]; + ret_xid_list = (XAXactId[]) xid_list.toArray(ret_xid_list); } else {