db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r1049150 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/util/InterruptStatus.java impl/store/raw/data/RAFContainer4.java
Date Tue, 14 Dec 2010 16:39:23 GMT
Author: dag
Date: Tue Dec 14 16:39:23 2010
New Revision: 1049150

URL: http://svn.apache.org/viewvc?rev=1049150&view=rev
Log:
DERBY-4920 suites.All stuck in RAFContainer4.awaitRestoreChannel()

Patch derby-4920-a. 

Patch details:

* InterruptStatus.java

Make sure we always catch ShutdownException when we access the context
looking for lcc.

* RAFContainer4.java

Improved some comments, added a final, added a max count for a retry
loop that missed it: will throw FILE_IO_INTERRUPTED if it exceeds
MAX_INTERRUPT_RETRIES (as elsewhere when we give up).


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/util/InterruptStatus.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer4.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=1049150&r1=1049149&r2=1049150&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 Tue Dec
14 16:39:23 2010
@@ -68,10 +68,19 @@ public class InterruptStatus {
      * also. Use lcc if available, else thread local variable.
      */
     public static void setInterrupted() {
-        LanguageConnectionContext lcc =
-            (LanguageConnectionContext)ContextService.getContextOrNull(
+        LanguageConnectionContext lcc = null;
+        try {
+            lcc = (LanguageConnectionContext)ContextService.getContextOrNull(
                 LanguageConnectionContext.CONTEXT_ID);
 
+        } catch (ShutdownException e) {
+            // Ignore. Can happen when: a) background thread (RawStoreDaemon)
+            // is performing checkpointing and b) a user thread starts shutdown
+            // and interrupts the background thread. During recovery of the
+            // container we get here. DERBY-4920.
+        }
+
+
         Thread.interrupted();
 
         StandardException e =
@@ -204,13 +213,18 @@ public class InterruptStatus {
     public static void restoreIntrFlagIfSeen(LanguageConnectionContext lcc) {
 
         if (SanityManager.DEBUG) {
-            LanguageConnectionContext ctxLcc =
-                (LanguageConnectionContext)ContextService.
-                getContextOrNull(LanguageConnectionContext.CONTEXT_ID);
-
-            SanityManager.ASSERT(
-                lcc == ctxLcc,
-                "lcc=" + lcc + " getContextOrNull=" + ctxLcc);
+            LanguageConnectionContext ctxLcc = null;
+            try {
+                ctxLcc = (LanguageConnectionContext)ContextService.
+                    getContextOrNull(LanguageConnectionContext.CONTEXT_ID);
+
+                SanityManager.ASSERT(
+                    lcc == ctxLcc,
+                    "lcc=" + lcc + " getContextOrNull=" + ctxLcc);
+
+            } catch (ShutdownException e) {
+                // ignore
+            }
         }
 
         if (lcc.getInterruptedException() != null) {

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer4.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer4.java?rev=1049150&r1=1049149&r2=1049150&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer4.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer4.java
Tue Dec 14 16:39:23 2010
@@ -104,9 +104,9 @@ class RAFContainer4 extends RAFContainer
     private volatile boolean restoreChannelInProgress = false;
 
 
-    // In case the recovering thread can't successfully recover the container,
-    // it will throw, so other waiting threads need to give up as well.  This
-    // can happen at shutdown time when interrupts are used to stop threads.
+    // In case the recovering thread can't successfully recover the container
+    // for some reason, it will throw, so other waiting threads need to give up
+    // as well.
     private boolean giveUpIO = false;
     private final Object giveUpIOm = new Object(); // its monitor
 
@@ -530,6 +530,8 @@ class RAFContainer4 extends RAFContainer
         }
 
         boolean success = false;
+        int retries = MAX_INTERRUPT_RETRIES;
+
         while (!success) {
             try {
                 if (pageNumber == FIRST_ALLOC_PAGE_NUMBER) {
@@ -591,6 +593,10 @@ class RAFContainer4 extends RAFContainer
                 // had seen ClosedChannelException.
 
                 awaitRestoreChannel(e, stealthMode);
+                if (retries-- == 0) {
+                    throw StandardException.newException(
+                        SQLState.FILE_IO_INTERRUPTED);
+                }
             }
         }
 
@@ -702,7 +708,7 @@ class RAFContainer4 extends RAFContainer
                 }
 
                 // Since the channel is presumably ok (lest giveUpIO is set,
-                // see below), we put ourselveds back in the IO set of threads:
+                // see below), we put ourselves back in the IO set of threads:
 
                 threadsInPageIO++;
                 break;



Mime
View raw message