db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r1086443 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/util/ engine/org/apache/derby/impl/sql/conn/ testing/org/apache/derbyTesting/functionTests/tests/store/
Date Mon, 28 Mar 2011 23:30:18 GMT
Author: dag
Date: Mon Mar 28 23:30:17 2011
New Revision: 1086443

URL: http://svn.apache.org/viewvc?rev=1086443&view=rev
Log:
DERBY-5152 Shutting down db, information that the thread received an interrupt will not be
restored to thread's interrupt flag

Patch derby-5152-b. When a thread receives an interrupt Derby detects
this, it will reset the thread's flag and save the fact in its lcc
(LanguageConnectionContext), if available. If not (e.g. during boot)
it will save the information in a thread local variable. For
performance reasons, we use the lcc when available. However, when
shutting down the database, the lcc goes away, and when the JDBC call
returns to the application, the thread's interrupt flag will not be
reinstated as per our specification. This is because the lcc dies
before we do the restoring (under shutdown). So, the information that
the thread was interrupted is lost with the lcc going away.

This patch copies the information from lcc over to the thread local
variable when lcc is popped and adds a new test case to
InterruptResilienceTest.



Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/util/InterruptStatus.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/InterruptResilienceTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/util/InterruptStatus.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/util/InterruptStatus.java?rev=1086443&r1=1086442&r2=1086443&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/util/InterruptStatus.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/util/InterruptStatus.java Mon Mar
28 23:30:17 2011
@@ -94,6 +94,19 @@ public class InterruptStatus {
         }
     }
 
+    /**
+     * Use when lcc is dying to save info in thread local instead. Useful under
+     * shutdown.
+     */
+    public static void saveInfoFromLcc(LanguageConnectionContext lcc) {
+        
+        StandardException e = lcc.getInterruptedException();
+
+        if (e != null) {
+            exception.set(e);
+        }
+    }
+
 
     /**
      * Checks if the thread has been interrupted in NIO, presumably because we

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java?rev=1086443&r1=1086442&r2=1086443&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java
Mon Mar 28 23:30:17 2011
@@ -75,6 +75,7 @@ import org.apache.derby.iapi.sql.Paramet
 import org.apache.derby.iapi.store.access.TransactionController;
 import org.apache.derby.iapi.store.access.XATransactionController;
 import org.apache.derby.iapi.util.IdUtil;
+import org.apache.derby.iapi.util.InterruptStatus;
 
 import org.apache.derby.catalog.UUID;
 import org.apache.derby.iapi.sql.execute.RunTimeStatistics;
@@ -3136,6 +3137,8 @@ public class GenericLanguageConnectionCo
             }
                        
             popMe();
+
+            InterruptStatus.saveInfoFromLcc(this);
         }
 
         /*

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/InterruptResilienceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/InterruptResilienceTest.java?rev=1086443&r1=1086442&r2=1086443&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/InterruptResilienceTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/InterruptResilienceTest.java
Mon Mar 28 23:30:17 2011
@@ -19,6 +19,7 @@
 */
 package org.apache.derbyTesting.functionTests.tests.store;
 
+import java.io.File;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
 import org.apache.derbyTesting.junit.TestConfiguration;
@@ -41,8 +42,12 @@ import java.lang.Math;
 import java.util.Properties;
 
 /**
- * Test started as a test reproduce and verify fix for DERBY-151.  Later
- * evolved into test for DERBY-4741.
+ * This test started out as a test reproduce and verify fix for DERBY-151.
+ * Later evolved into test for DERBY-4741.
+ * <p/>
+ * The use of stored procedures was done to make the tests meaningful in client
+ * server mode as well, but be removed/simplified as long as we only make
+ * claims about the resilience of embedded Derby.
  */
 
 public class InterruptResilienceTest extends BaseJDBCTestCase
@@ -459,7 +464,7 @@ public class InterruptResilienceTest ext
                         }
 
 
-                        if (Thread.interrupted()) {
+                        if (interrupted()) {
                             interruptsSeen++;
                         }
 
@@ -632,4 +637,37 @@ public class InterruptResilienceTest ext
         rollback();
 
     }
+
+
+    public void testInterruptShutdown() throws SQLException {
+        if (!usingEmbedded()) {
+            // Only meaningful for embedded.
+            return;
+        }
+
+        setAutoCommit(false);
+
+        try {
+            Statement s = createStatement();
+            s.executeUpdate("create table foo (i int)");
+            PreparedStatement ps =
+                prepareStatement("insert into foo values ?");
+
+            for (int i = 0; i < 1000; i++) {
+                ps.setInt(1,i);
+                ps.executeUpdate();
+            }
+
+            Thread.currentThread().interrupt();
+
+            TestConfiguration.getCurrent().shutdownDatabase();
+
+            // Assert and clear thread's flag:
+            // DERBY-5152: Fails before fix due to lcc going away.
+            assertTrue(Thread.interrupted());
+
+        } finally {
+            Thread.interrupted(); // clear flag
+        }
+    }
 }



Mime
View raw message