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 mi...@apache.org on 2006/06/15 20:17:44 UTC

svn commit: r414647 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java

Author: mikem
Date: Thu Jun 15 11:17:44 2006
New Revision: 414647

URL: http://svn.apache.org/viewvc?rev=414647&view=rev
Log:
DERBY-1392, committed patch submitted by Anders Morken

RAFContainer.java#writePage(...) will
attempt to retry a write if an IOException is thrown on the first attempt. 
However, the next attempt does not add container header data to the first page, nor does it encrypt the data if the database is encrypted as the wrong buffer
is used in the catch block.

I'd expect this bug to be case silent corruption of encrypted databases if the 
code path was actually exercised. The fact that this bug still lives and 
nobody has discovered it is possibly an indication of how uncommon this code 
path is. Since the comment in the code says nothing about exactly what 
platforms the workaround was intended for, I don't know if these platforms are
still supported for Derby. 


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java

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=414647&r1=414646&r2=414647&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 Thu Jun 15 11:17:44 2006
@@ -352,22 +352,40 @@
 		synchronized(this)
 		{
 
-			// committed and dropped, do nothing.
-			// This file container may only be a stub
 			if (getCommittedDropState())
+            {
+                // committed and dropped, do nothing.
+                // This file container may only be a stub
+
 				return;
+            }
 
-		///////////////////////////////////////////////////
-		//
-		// RESOLVE: right now, no logical -> physical mapping.
-		// We can calculate the offset.  In the future, we may need to
-		// look at the allocation page or the in memory translation table
-		// to figure out where the page should go
-		//
-		/////////////////////////////////////////////////
+            ///////////////////////////////////////////////////
+            //
+            // RESOLVE: right now, no logical -> physical mapping.
+            // We can calculate the offset.  In the future, we may need to
+            // look at the allocation page or the in memory translation table
+            // to figure out where the page should go
+            //
+            /////////////////////////////////////////////////
 
 			long pageOffset = pageNumber * pageSize;
 
+            byte [] encryptionBuf = null; 
+            if (dataFactory.databaseEncrypted() 
+                && pageNumber != FIRST_ALLOC_PAGE_NUMBER)
+            {
+                // We cannot encrypt the page in place because pageData is
+                // still being accessed as clear text.  The encryption
+                // buffer is shared by all who access this container and can
+                // only be used within the synchronized block.
+
+                encryptionBuf = getEncryptionBuffer();
+            }
+
+            byte[] dataToWrite = 
+                updatePageArray(pageNumber, pageData, encryptionBuf, false);
+
 			try
 			{
 				fileData.seek(pageOffset);
@@ -380,23 +398,6 @@
 				if (fileData.getFilePointer() != pageOffset)
 					padFile(fileData, pageOffset);
 
-                byte [] encryptionBuf = null; 
-                if (dataFactory.databaseEncrypted() 
-					&& pageNumber != FIRST_ALLOC_PAGE_NUMBER)
-				{
-					// We cannot encrypt the page in place because pageData is
-					// still being accessed as clear text.  The encryption
-					// buffer is shared by all who access this container and can
-					// only be used within the synchronized block.
-
-                    encryptionBuf = getEncryptionBuffer();
-                }
-
-				byte[] dataToWrite = updatePageArray(pageNumber, 
-                                                     pageData, 
-                                                     encryptionBuf, 
-                                                     false);
-
 				dataFactory.writeInProgress();
 				try
 				{
@@ -421,13 +422,17 @@
 					throw ioe;	// not writing beyond EOF, rethrow exception
 
 				if (SanityManager.DEBUG)
-					SanityManager.ASSERT(fileData.length() >= pageOffset,
-										 "failed to blank filled missing pages");
+                {
+					SanityManager.ASSERT(
+                        fileData.length() >= pageOffset,
+                        "failed to blank filled missing pages");
+                }
+
 				fileData.seek(pageOffset);
 				dataFactory.writeInProgress();
 				try
 				{
-					fileData.write(pageData, 0, pageSize);
+					fileData.write(dataToWrite, 0, pageSize);
 				}
 				finally
 				{
@@ -478,7 +483,8 @@
             // space
             writeHeader(pageData);
 
-            if (SanityManager.DEBUG) {
+            if (SanityManager.DEBUG) 
+            {
                 if (FormatIdUtil.readFormatIdInteger(pageData) != AllocPage.FORMAT_NUMBER)
                     SanityManager.THROWASSERT(
                             "expect " +
@@ -489,16 +495,20 @@
 
             return pageData;
 
-        } else 
+        } 
+        else 
         {
             if (dataFactory.databaseEncrypted() || encryptWithNewEngine) 
-           {
+            {
                 return encryptPage(pageData, 
                                    pageSize, 
                                    encryptionBuf, 
                                    encryptWithNewEngine);
-            } else
+            } 
+            else
+            {
                 return pageData;
+            }
         }
     }