You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by da...@apache.org on 2011/04/18 16:09:45 UTC

svn commit: r1094585 - in /db/derby/code/branches/10.8: ./ java/engine/org/apache/derby/impl/store/raw/data/RAFContainer4.java

Author: dag
Date: Mon Apr 18 14:09:45 2011
New Revision: 1094585

URL: http://svn.apache.org/viewvc?rev=1094585&view=rev
Log:
DERBY-5185 store/rollForwardRecovery.sql stuck in RAFContainer4.recoverContainerAfterInterrupt() during shutdown

Backported from trunk: patch derby-5185-2b as

svn merge -c 1094572 https://svn.apache.org/repos/asf/db/derby/code/trunk

Patch derby-5185-2b which fixes state a state maintenance bugs (in
threadDoingRestore/restoreChannelInProgress) maintenance when throwing
FILE_IO_INTERRUPTED. The first fixes the immediate problem.

It also adds a maximum number of retries for the readPage code and
fixes some cases whereby the state variable "threadsInPageIO" could
risk not being properly update when exceptions would get thrown. The
latter may be the underlying reason for what we see here.


Modified:
    db/derby/code/branches/10.8/   (props changed)
    db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer4.java

Propchange: db/derby/code/branches/10.8/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Apr 18 14:09:45 2011
@@ -1,2 +1,2 @@
 /db/derby/code/branches/10.7:1061570,1061578,1082235
-/db/derby/code/trunk:1063809,1088633,1091000,1091221,1091285,1092067,1092795,1094315
+/db/derby/code/trunk:1063809,1088633,1091000,1091221,1091285,1092067,1092795,1094315,1094572

Modified: db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer4.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer4.java?rev=1094585&r1=1094584&r2=1094585&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer4.java (original)
+++ db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer4.java Mon Apr 18 14:09:45 2011
@@ -87,7 +87,8 @@ class RAFContainer4 extends RAFContainer
 
     // volatile on threadsInPageIO, is just to ensure that we get a correct
     // value for debugging: we can't always use channelCleanupMonitor
-    // then. Not safe on 1.4, but who cares..
+    // then. Otherwise protected by channelCleanupMonitor. Debugging value not
+    // safe on 1.4, but who cares..
     private volatile int threadsInPageIO = 0;
 
     // volatile on restoreChannelInProgress: corner case where we can't use
@@ -330,6 +331,9 @@ class RAFContainer4 extends RAFContainer
 
 
         boolean success = false;
+        int retries = MAX_INTERRUPT_RETRIES;
+
+      try {
         while (!success) {
             try {
                 if (pageNumber == FIRST_ALLOC_PAGE_NUMBER) {
@@ -393,9 +397,14 @@ class RAFContainer4 extends RAFContainer
                 // Recovery is in progress, wait for another interrupted thread
                 // to clean up.
                 awaitRestoreChannel(e, stealthMode);
+
+                if (retries-- == 0) {
+                    throw StandardException.newException(
+                        SQLState.FILE_IO_INTERRUPTED);
+                }
             }
         }
-
+      } finally {
         if (stealthMode) {
             // don't touch threadsInPageIO
         } else {
@@ -403,6 +412,7 @@ class RAFContainer4 extends RAFContainer
                 threadsInPageIO--;
             }
         }
+      }
     }
 
     private void readPage0(long pageNumber, byte[] pageData, long offset)
@@ -533,6 +543,7 @@ class RAFContainer4 extends RAFContainer
         boolean success = false;
         int retries = MAX_INTERRUPT_RETRIES;
 
+      try {
         while (!success) {
             try {
                 if (pageNumber == FIRST_ALLOC_PAGE_NUMBER) {
@@ -600,7 +611,7 @@ class RAFContainer4 extends RAFContainer
                 }
             }
         }
-
+      } finally {
         if (stealthMode) {
             // don't touch threadsInPageIO
         } else {
@@ -608,6 +619,7 @@ class RAFContainer4 extends RAFContainer
                 threadsInPageIO--;
             }
         }
+      }
     }
 
     /**
@@ -831,11 +843,16 @@ class RAFContainer4 extends RAFContainer
                     // for us to clean up (see ClosedChannelException case)
                     break;
                 }
-            }
 
-            if (retries-- == 0) {
-                throw StandardException.newException(
+                if (retries-- == 0) {
+                    // Clean up state and throw
+                    threadDoingRestore = null;
+                    restoreChannelInProgress = false;
+                    channelCleanupMonitor.notifyAll();
+
+                    throw StandardException.newException(
                         SQLState.FILE_IO_INTERRUPTED);
+                }
             }
 
             try {