db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r1056591 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data: BaseContainer.java RAFContainer.java RAFContainer4.java
Date Sat, 08 Jan 2011 01:54:31 GMT
Author: dag
Date: Sat Jan  8 01:54:31 2011
New Revision: 1056591

URL: http://svn.apache.org/viewvc?rev=1056591&view=rev
Log:
DERBY-4960 Race condition in FileContainer#allocCache when reopening RAFContainer after interrupt

Patch derby-4960-2. When reopening the container after an interrupt we
now call "reopenContainer" instead of
"openContainer". "reopenContainer" is a (new) variant of
"openContainer" which skips reading the header, which is ok, since it
has not changed. This sidesteps the race situation.


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseContainer.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.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/impl/store/raw/data/BaseContainer.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseContainer.java?rev=1056591&r1=1056590&r2=1056591&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseContainer.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseContainer.java
Sat Jan  8 01:54:31 2011
@@ -82,7 +82,7 @@ abstract class BaseContainer implements 
 
 
 	/**
-		Committed Drop state of the container.  If a post comit action
+		Committed Drop state of the container.  If a post commit action
 		determined that the drop container operation is committed, the whole
 		container may be removed and space reclaimed.
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java?rev=1056591&r1=1056590&r2=1056591&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java
Sat Jan  8 01:54:31 2011
@@ -94,6 +94,7 @@ class RAFContainer extends FileContainer
      * closed by the interrupt.
      */
     protected ContainerKey currentIdentity;
+    private boolean reopen;
 
     private boolean actionStub;
     private boolean actionErrorOK;
@@ -901,9 +902,21 @@ class RAFContainer extends FileContainer
     protected ContainerKey idAPriori = null;
 
     synchronized boolean openContainer(ContainerKey newIdentity)
-        throws StandardException
+            throws StandardException {
+        return openContainerMinion(newIdentity, false);
+    }
+
+    synchronized boolean reopenContainer(ContainerKey newIdentity)
+            throws StandardException {
+        return openContainerMinion(newIdentity, true);
+    }
+
+    private boolean openContainerMinion(
+        ContainerKey newIdentity,
+        boolean doReopen) throws StandardException
     {
         actionCode = OPEN_CONTAINER_ACTION;
+        reopen = doReopen;
         actionIdentity = newIdentity;
         boolean success = false;
         idAPriori = currentIdentity;
@@ -1485,8 +1498,15 @@ class RAFContainer extends FileContainer
              try {
 
                  fileData = file.getRandomAccessFile(canUpdate ? "rw" : "r");
-                 readHeader(getEmbryonicPage(fileData,
-                                             FIRST_ALLOC_PAGE_OFFSET));
+
+                 if (!reopen) {
+                     // under reopen: can give race condition or if we
+                     // synchronize access, deadlock, so skip, we know
+                     // what's there anyway.
+                     readHeader(getEmbryonicPage(fileData,
+                                                 FIRST_ALLOC_PAGE_OFFSET));
+                 }
+
 
                  if (SanityManager.DEBUG)
                  {

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=1056591&r1=1056590&r2=1056591&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
Sat Jan  8 01:54:31 2011
@@ -857,7 +857,7 @@ class RAFContainer4 extends RAFContainer
                     synchronized(this) {
                         try {
                             closeContainer();
-                            openContainer(currentIdentity);
+                            reopenContainer(currentIdentity);
                         } catch (InterruptDetectedException e) {
                             // Interrupted again?
                             debugTrace("interrupted during recovery's " +
@@ -1097,9 +1097,9 @@ class RAFContainer4 extends RAFContainer
      * @throws IOException if an I/O error occurs while reading
      * @throws StandardException If thread is interrupted.
      */
-    private final void readFull(ByteBuffer dstBuffer,
-                                FileChannel srcChannel,
-                                long position)
+    private void readFull(ByteBuffer dstBuffer,
+                          FileChannel srcChannel,
+                          long position)
             throws IOException, StandardException
     {
         while(dstBuffer.remaining() > 0) {
@@ -1134,9 +1134,9 @@ class RAFContainer4 extends RAFContainer
      * @throws IOException if an I/O error occurs while writing
      * @throws StandardException If thread is interrupted.
      */
-    private final void writeFull(ByteBuffer srcBuffer,
-                                 FileChannel dstChannel,
-                                 long position)
+    private void writeFull(ByteBuffer srcBuffer,
+                           FileChannel dstChannel,
+                           long position)
             throws IOException
     {
         while(srcBuffer.remaining() > 0) {



Mime
View raw message