db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r1043802 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer4.java
Date Thu, 09 Dec 2010 00:35:00 GMT
Author: dag
Date: Thu Dec  9 00:34:59 2010
New Revision: 1043802

URL: http://svn.apache.org/viewvc?rev=1043802&view=rev
Log:
DERBY-4741 Make Derby work reliably in the presence of thread interrupts

Patch derby-4741-kristians-01, incorporating Kristian's comments. Should not change behavior.

Modified:
    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/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=1043802&r1=1043801&r2=1043802&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
Thu Dec  9 00:34:59 2010
@@ -79,7 +79,7 @@ class RAFContainer4 extends RAFContainer
      */
     private FileChannel ourChannel = null;
 
-    private Object channelCleanupMonitor = new Object();
+    private final Object channelCleanupMonitor = new Object();
 
     // channelCleanupMonitor protects next three state variables:
 
@@ -603,6 +603,32 @@ class RAFContainer4 extends RAFContainer
         }
     }
 
+    /**
+     * Use when seeing an exception during IO and when another thread is
+     * presumably doing the recovery.
+     * <p/>
+     * If {@code stealthMode == false}, wait for another thread to recover the
+     * container after an interrupt. If {@code stealthMode == true}, throw
+     * internal exception {@code InterruptDetectedException} to do retry from
+     * higher in the stack.
+     * <p/>
+     * If {@code stealthMode == false}, maximum wait time for the container to
+     * become available again is determined by the product {@code
+     * FileContainer#MAX_INTERRUPT_RETRIES * FileContainer#INTERRUPT_RETRY_SLEEP}.
+     * There is a chance this thread will not see any recovery occuring (yet),
+     * in which case it waits for a bit and just returns, so the caller must
+     * retry IO until success.
+     * <p/>
+     * If for some reason the recovering thread has given up on resurrecting
+     * the container, cf {@code #giveUpIO}, the method throws {@code
+     * FILE_IO_INTERRUPTED}.
+     * 
+     * @param e the exception we saw during IO
+     * @param stealthMode true if the thread doing IO in stealth mode
+
+     * @throws StandardException {@code InterruptDetectedException} and normal
+     *                            error policy
+     */
     private void awaitRestoreChannel (Exception e,
                                       boolean stealthMode)
             throws StandardException {
@@ -662,7 +688,7 @@ class RAFContainer4 extends RAFContainer
                     }
 
                     if (timesWaited > MAX_INTERRUPT_RETRIES) {
-                        // Max 60s, then give up, probably way too long anyway,
+                        // Max, give up, probably way too long anyway,
                         // but doesn't hurt?
                         throw StandardException.newException(
                             SQLState.FILE_IO_INTERRUPTED, e);
@@ -713,9 +739,14 @@ class RAFContainer4 extends RAFContainer
 
 
     /**
+     * Use this when the thread has received a AsynchronousCloseException
+     * exception during IO and its interruped flag is also set. This makes this
+     * thread a likely candicate to do container recovery (aka resurrection),
+     * unless another thread started it already, cf. return value.
+     *
      * @param whence caller site (debug info)
      * @param stealthMode don't update threadsInPageIO if true
-     * @return true if we did it, false if we saw someone else do it and
+     * @return true if we did recovery, false if we saw someone else do it and
      * abstained
      */
     private boolean recoverContainerAfterInterrupt(
@@ -881,9 +912,9 @@ class RAFContainer4 extends RAFContainer
         if (SanityManager.DEBUG) {
             if (pageNumber == FIRST_ALLOC_PAGE_NUMBER) {
                 // page 0
-                SanityManager.ASSERT(Thread.currentThread().holdsLock(this));
+                SanityManager.ASSERT(Thread.holdsLock(this));
             } else {
-                SanityManager.ASSERT(!Thread.currentThread().holdsLock(this));
+                SanityManager.ASSERT(!Thread.holdsLock(this));
             }
         }
 
@@ -1065,9 +1096,6 @@ class RAFContainer4 extends RAFContainer
                                 long position)
             throws IOException, StandardException
     {
-        boolean beforeOpen = srcChannel.isOpen();
-        boolean beforeInterrupted = Thread.currentThread().isInterrupted();
-
         while(dstBuffer.remaining() > 0) {
             if (srcChannel.read(dstBuffer,
                                     position + dstBuffer.position()) == -1) {
@@ -1105,9 +1133,6 @@ class RAFContainer4 extends RAFContainer
                                  long position)
             throws IOException
     {
-        boolean beforeOpen = dstChannel.isOpen();
-        boolean beforeInterrupted = Thread.currentThread().isInterrupted();
-
         while(srcBuffer.remaining() > 0) {
             dstChannel.write(srcBuffer, position + srcBuffer.position());
 



Mime
View raw message