I  believe  Andrew is right ,  fixing this problem based on jvm  vendor
names is  likely to be error prone and  endorsing particular jvm's is
not good.
After Looking  at  the code  catching FileNotFoundException  when log
file is opened  "rws" mode does not seem to need major
changes in the code.  

Problem :  unable to create db on MAC  because when log files are opened
in write sync mode on MAC JVM 1.4.2 , FileNotFoundException occurs.
Possible Fix : Catch the FileNotFoundException  then  set log write mode
to file Sync  and open the log files in plain "rw" mode.


Thanks
-suresh




Index: java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
===================================================================
--- java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java      
(revision 54756)
+++ java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java      
(working copy)
@@ -80,6 +80,7 @@
 import java.io.File; // Plain files are used for backups
 import java.io.IOException;
 import java.io.SyncFailedException;
+import java.io.FileNotFoundException;
 import java.io.ByteArrayOutputStream;
 import java.io.DataOutputStream;
 import java.io.ByteArrayInputStream;
@@ -895,7 +896,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);
                                                }
@@ -931,7 +932,7 @@
                                                try
                                                {
                                                        if(isWriteSynced)
-                                                               theLog = 
privRandomAccessFile(logFile, "rws");
+                                                               theLog = 
openLogFileInWriteMode(logFile);
                                                        else
                                                                theLog = 
privRandomAccessFile(logFile, "rw");
                                                }
@@ -1930,7 +1931,7 @@
                                                //extend the file by wring 
zeros to it
                                                preAllocateNewLogFile(newLog);
                                                newLog.close();
-                                               newLog=  
privRandomAccessFile(newLogFile, "rws");
+                                               newLog = 
openLogFileInWriteMode(newLogFile);
                                                newLog.seek(endPosition);
                                        }
 
@@ -3020,7 +3021,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 log end postion
                         theLog.seek(endPosition);
                     }
@@ -4846,15 +4847,34 @@
         }
     } // end of preAllocateNewLogFile
 
-       /*open the given log file name for writes; if write sync 
-        *is enabled open in rws mode otherwise in rw mode. 
+
+
+       /**
+        * 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.
         */
-       public StorageRandomAccessFile openLogFileInWriteMode(StorageFile 
logFile) throws IOException
+       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 ;
        }
 
 

Reply via email to