db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject svn commit: r414853 - /db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java
Date Fri, 16 Jun 2006 15:57:49 GMT
Author: mikem
Date: Fri Jun 16 08:57:49 2006
New Revision: 414853

URL: http://svn.apache.org/viewvc?rev=414853&view=rev
Log:
DERBY-1392 - merged and resolved conflicts change by Anders Morken from trunk 
to 10.1 line.

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/branches/10.1/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java?rev=414853&r1=414852&r2=414853&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java
(original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java
Fri Jun 16 08:57:49 2006
@@ -233,25 +233,47 @@
 				// space
 				writeHeader(pageData);
 
-				if (SanityManager.DEBUG) {
-					if (FormatIdUtil.readFormatIdInteger(pageData) != AllocPage.FORMAT_NUMBER)
+				if (SanityManager.DEBUG) 
+                {
+					if (FormatIdUtil.readFormatIdInteger(pageData) != 
+                            AllocPage.FORMAT_NUMBER)
+                    {
 						SanityManager.THROWASSERT(
 							"expect " +
 							AllocPage.FORMAT_NUMBER +
 							"got " +
 							FormatIdUtil.readFormatIdInteger(pageData));
+                    }
 				}
 
 			}
 
-		///////////////////////////////////////////////////
-		//
-		// 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
-		//
-		/////////////////////////////////////////////////
+            // set dataToWrite to actual page buffer or encrypt buffer for
+            // use by normal write code, and retry catch block write code.
+            byte[] dataToWrite;
+
+            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.
+                dataToWrite = encryptPage(pageData, pageSize);
+            } 
+            else 
+            {
+                dataToWrite = pageData;
+            }
+
+            ///////////////////////////////////////////////////
+            //
+            // 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;
 
@@ -267,20 +289,6 @@
 				if (fileData.getFilePointer() != pageOffset)
 					padFile(fileData, pageOffset);
 
-				byte[] dataToWrite;
-
-				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.
-					dataToWrite = encryptPage(pageData, pageSize);
-				} else {
-					dataToWrite = pageData;
-				}
-
 				dataFactory.writeInProgress();
 				try
 				{
@@ -305,13 +313,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
 				{



Mime
View raw message