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 2005/10/07 01:47:36 UTC

svn commit: r306963 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java

Author: mikem
Date: Thu Oct  6 16:47:31 2005
New Revision: 306963

URL: http://svn.apache.org/viewcvs?rev=306963&view=rev
Log:
committing on behalf of: Suresh Thalamati

 was hoping this issue will go away , but it seems to have appeared again in jdk1.5. Although there is a workaround by
 setting derby.storage.fileSyncTransactionLog=true. I think for users who are just tryingout Derby , hitting this problem is very annoying.
 Resubmmitting the workaround patch(derby1.diff) for this problem againest main trunk. This patch solves the problem by
 Catching the FileNotFoundException then set log write mode to file Sync and then open the log files in plain "rw" mode. 

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java?rev=306963&r1=306962&r2=306963&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java Thu Oct  6 16:47:31 2005
@@ -92,6 +92,7 @@
 import java.io.DataOutputStream;
 import java.io.ByteArrayInputStream;
 import java.io.DataInputStream;
+import java.io.FileNotFoundException;
 
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -903,7 +904,7 @@
 							//extend the file by wring zeros to it
 							preAllocateNewLogFile(theLog);
 							theLog.close();
-							theLog=  privRandomAccessFile(logFile, "rws");
+							theLog = openLogFileInWriteMode(logFile);
 							//postion the log at the current end postion
 							theLog.seek(endPosition);
 						}
@@ -939,7 +940,7 @@
 						try
 						{
 							if(isWriteSynced)
-								theLog = privRandomAccessFile(logFile, "rws");
+								theLog = openLogFileInWriteMode(logFile);
 							else
 								theLog = privRandomAccessFile(logFile, "rw");
 						}
@@ -1914,7 +1915,7 @@
 						//extend the file by wring zeros to it
 						preAllocateNewLogFile(newLog);
 						newLog.close();
-						newLog=  privRandomAccessFile(newLogFile, "rws");
+						newLog = openLogFileInWriteMode(newLogFile);
 						newLog.seek(endPosition);
 					}
 
@@ -3029,7 +3030,7 @@
                         //extend the file by wring zeros to it
                         preAllocateNewLogFile(firstLog);
                         firstLog.close();
-                        firstLog=  privRandomAccessFile(logFile, "rws");
+                        firstLog = openLogFileInWriteMode(logFile);
                         //postion the log at the current log end postion
                         firstLog.seek(endPosition);
                     }
@@ -4643,15 +4644,32 @@
         }
     } // end of preAllocateNewLogFile
 
-	/*open the given log file name for writes; if write sync 
-	 *is enabled open in rws mode otherwise in rw mode. 
-	 */
-	public StorageRandomAccessFile openLogFileInWriteMode(StorageFile logFile) throws IOException
+
+	/**
+	 * open the given log file name for writes; if file can not be 
+	 * be opened in write sync mode then disable the write sync mode and 
+	 * open the file in "rw" mode.
+ 	 */
+	private StorageRandomAccessFile openLogFileInWriteMode(StorageFile logFile) throws IOException
 	{
-		if(isWriteSynced)
-			return privRandomAccessFile(logFile, "rws");
-		else
-			return privRandomAccessFile(logFile, "rw");
+		StorageRandomAccessFile log;
+		try{
+			log = privRandomAccessFile(logFile, "rws");
+		}catch(FileNotFoundException ex)
+		{
+			// Normally this exception should never occur. For some reason
+			// currently on Mac JVM 1.4.2 FileNotFoundException exception is
+			// thrown if a file is opened in "rws" mode and if it already
+			// exists. Please refere to Derby-1 for more/ details on this issue.
+			// Temporary workaround to avoid this problem is to make the logging 
+			// system use file sync mechanism. 
+
+			// disable the write sync and open the file in "rw" mode. 
+			isWriteSynced = false;
+			log = privRandomAccessFile(logFile, "rw");
+		}
+		
+		return log ;
 	}