db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r793900 - in /db/derby/code/branches/10.5: ./ java/drda/org/apache/derby/impl/drda/ java/engine/org/apache/derby/iapi/jdbc/ java/engine/org/apache/derby/impl/jdbc/ java/engine/org/apache/derby/jdbc/ java/testing/org/apache/derbyTesting/func...
Date Tue, 14 Jul 2009 13:41:09 GMT
Author: mamta
Date: Tue Jul 14 13:41:08 2009
New Revision: 793900

URL: http://svn.apache.org/viewvc?rev=793900&view=rev
Log:
DERBY-4053 Migrating changes from trunk(revision 793588) into 10.5 codeline. Commit
comments for trunk checkin were as follows
************** 
DERBY-4053 The local XA connections were not getting rollback during Database close and 
this resulted into exception at connection close if the connection object had any pending

transaction. Made changes so that all the connections(except global XA connections) will 
have their transactions rolled back before those connections are closed. 
************** 



Modified:
    db/derby/code/branches/10.5/   (props changed)
    db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/Database.java
    db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/XADatabase.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/jdbc/EngineConnection.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATransactionTest.java

Propchange: db/derby/code/branches/10.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jul 14 13:41:08 2009
@@ -1 +1 @@
-/db/derby/code/trunk:769596,772090,772449,772534,774281,779681,782991,785163,785570,785662,788369,788670,788674,788968,789264,790218,792434
+/db/derby/code/trunk:769596,772090,772449,772534,774281,779681,782991,785163,785570,785662,788369,788670,788674,788968,789264,790218,792434,793588

Modified: db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/Database.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/Database.java?rev=793900&r1=793899&r2=793900&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/Database.java (original)
+++ db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/Database.java Tue Jul
14 13:41:08 2009
@@ -70,7 +70,6 @@
 	protected boolean RDBUPDRM_sent = false;	//We have sent that an update
 											// occurred in this transaction
 	protected boolean sendTRGDFTRT = false; // Send package target default value
-
     /**
      * Connection to the database in the embedded engine.
      */
@@ -80,8 +79,6 @@
 	private DRDAStatement currentStatement; // current statement we are working on
 	private Hashtable stmtTable;		// Hash table for storing statements
 
-	boolean forXA = false;
-
 	// constructor
 	/**
 	 * Database constructor
@@ -336,7 +333,12 @@
 			conn.rollback();
 	}
 	/**
-	  * Close the connection and clean up the statement table
+	  * Database close does following cleanup tasks
+	  * 1)Rollback any pending transaction on the Connection object (except 
+	  * for a global-XA Connection obejct) before closing the Connection. 
+	  * Without the rollback, the Connection close will result into an 
+	  * exception if there is a pending transaction on that Connection.
+	  * 2)Clean up the statement table 
 	  * @throws SQLException on conn.close() error to be handled in DRDAConnThread.
 	  */
 	protected void close() throws SQLException
@@ -355,7 +357,8 @@
 				defaultStatement.close();
 			if ((conn != null) && !conn.isClosed())
 			{
-				if (! forXA)
+				//rollback all the pending transactions except global XA trans
+				if (! conn.isInGlobalTransaction())
 				{
 					conn.rollback();
 				}

Modified: db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/XADatabase.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/XADatabase.java?rev=793900&r1=793899&r2=793900&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/XADatabase.java (original)
+++ db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/XADatabase.java Tue Jul
14 13:41:08 2009
@@ -57,7 +57,6 @@
 	XADatabase (String dbName)
 	{
 		super(dbName);
-		forXA = true;
 	}
 
 	/**

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java?rev=793900&r1=793899&r2=793900&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java
(original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java
Tue Jul 14 13:41:08 2009
@@ -475,6 +475,11 @@
         }
 	}
 
+    /** @see EngineConnection#isInGlobalTransaction() */
+    public boolean isInGlobalTransaction() {
+    	return control.isInGlobalTransaction();
+    }
+
 	/**
 	 *  Set the internal isolation level to use for preparing statements.
 	 *  Subsequent prepares will use this isoalation level

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java?rev=793900&r1=793899&r2=793900&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java
(original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java
Tue Jul 14 13:41:08 2009
@@ -91,6 +91,12 @@
 	*/
 	public void resetIsolationLevelFlag() throws SQLException;
 
+    /**
+     * Is this a global transaction
+     * @return true if this is a global XA transaction
+     */
+    public boolean isInGlobalTransaction();
+
 	/**
 		Close called on BrokeredConnection. If this call
 		returns true then getRealConnection().close() will be called.

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/jdbc/EngineConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/jdbc/EngineConnection.java?rev=793900&r1=793899&r2=793900&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/jdbc/EngineConnection.java
(original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/jdbc/EngineConnection.java
Tue Jul 14 13:41:08 2009
@@ -40,6 +40,12 @@
      */
     public void setDrdaID(String drdaID);
 
+    /**
+     * Is this a global transaction
+     * @return true if this is a global XA transaction
+     */
+    public boolean isInGlobalTransaction();
+    
     /** 
      * Set the transaction isolation level that will be used for the 
      * next prepare.  Used by network server to implement DB2 style 

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java?rev=793900&r1=793899&r2=793900&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
(original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
Tue Jul 14 13:41:08 2009
@@ -2733,6 +2733,11 @@
 		getLanguageConnection().setDrdaID(drdaID);
 	}
 
+    /** @see EngineConnection#isInGlobalTransaction() */
+    public boolean isInGlobalTransaction() {
+    	return false;
+    }
+
 	/**
 		Reset the connection before it is returned from a PooledConnection
 		to a new application request (wrapped by a BrokeredConnection).

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java?rev=793900&r1=793899&r2=793900&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java
(original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java
Tue Jul 14 13:41:08 2009
@@ -409,7 +409,11 @@
 	public void resetIsolationLevelFlag() throws SQLException {
 		realConnection.getLanguageConnection().resetIsolationLevelFlagUsedForSQLandJDBC();
 	}
-	
+
+    /** @see BrokeredConnectionControl#isInGlobalTransaction() */
+    public boolean isInGlobalTransaction() {
+    	return false;
+    }	
 	
 	/**
 		Notify the control class that a SQLException was thrown

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java?rev=793900&r1=793899&r2=793900&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java Tue
Jul 14 13:41:08 2009
@@ -22,6 +22,7 @@
 package org.apache.derby.jdbc;
 
 import org.apache.derby.impl.jdbc.Util;
+import org.apache.derby.iapi.jdbc.BrokeredConnectionControl;
 import org.apache.derby.iapi.jdbc.EngineConnection;
 import org.apache.derby.iapi.jdbc.ResourceAdapter;
 
@@ -53,6 +54,11 @@
                 xaRes = new EmbedXAResource (this, ra);
 	}
 
+    /** @see BrokeredConnectionControl#isInGlobalTransaction() */
+    public boolean isInGlobalTransaction() {
+    	return isGlobal();
+    }	
+
     /**
      * Check if this connection is part of a global XA transaction.
      *

Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATransactionTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATransactionTest.java?rev=793900&r1=793899&r2=793900&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATransactionTest.java
(original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XATransactionTest.java
Tue Jul 14 13:41:08 2009
@@ -51,6 +51,55 @@
   */
 public class XATransactionTest extends BaseJDBCTestCase {
 
+	/**
+	  * This test does following 
+	  * 1)Start the network server
+	  * 2)Start a local xa transaction
+	  * 3)Do not commit the local XA transaction
+	  * 4)Shutdown the network server
+	  * 5)Start the server again
+	  * 
+	  * Before the fix for DERBY-4053 went in, step 4) would not shutdown the
+	  * server properly because of the pending local XA transaction. During the
+	  * server shutdown, we try to close all the open connections but the close 
+	  * on the XA connection results into an exception because there is still a
+	  * pending transaction. That exception is not handled by the server and
+	  * because of that, all the code necessary to shutdown the server is not
+	  * executed. The next time around, step 5), when we try to bring up the
+	  * server again, it ends up hanging
+	  * 2009-07-09 21:21:28.828 GMT : Invalid reply from network server: Insufficient data.
+	  * 2009-07-09 21:21:28.843 GMT : Could not listen on port 1527 on host 127.0.0.1: java.net.BindException:
Address already in use: JVM_Bind
+	  * 
+	  * The fix for DERBY-4053 makes sure that before calling close on local XA
+	  * transaction, we first rollback any transaction active on the 
+	  * connection. 
+	 */
+	public void testPendingLocalTranAndServerShutdown() throws Exception {
+        if (usingEmbedded())
+            return;
+        //1)Server must be up already through the Derby junit framework
+        //2)Start a local xa transaction
+        XADataSource xaDataSource = J2EEDataSource.getXADataSource();
+        XAConnection xaconn = xaDataSource.getXAConnection();
+        XAResource xar = xaconn.getXAResource();
+        Connection conn = xaconn.getConnection();
+        Statement s = conn.createStatement();
+        s.executeUpdate("create table tab(i int)");
+        s.executeUpdate("insert into tab values (1),(2),(3),(4)");
+        conn.commit();
+        conn.setAutoCommit(false);
+        ResultSet rs = s.executeQuery("select * from tab");
+        rs.next();
+        //3)Do not commit this pending local XA transaction
+    	
+        //4)Shutdown the network server
+        //bring the server down while the local xa transaction is still active
+        TestConfiguration.getCurrent().stopNetworkServer();
+        
+        //5)Start the server again
+        TestConfiguration.getCurrent().startNetworkServer();
+	}
+	
     /** Tests whether it is possible to reconstruct the original Xid value
       * correctly from SYSCS_DIAG.TRANSACTION_TABLE. */
     public void testGlobalXIDinTransactionTable() throws Exception {



Mime
View raw message