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 dj...@apache.org on 2006/12/07 19:59:29 UTC

svn commit: r483606 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/io/ engine/org/apache/derby/impl/services/monitor/ engine/org/apache/derby/impl/store/raw/data/ testing/org/apache/derbyTesting/functionTests/tests/lang/

Author: djd
Date: Thu Dec  7 10:59:27 2006
New Revision: 483606

URL: http://svn.apache.org/viewvc?view=rev&rev=483606
Log:
DERBY-2083 Ensure the store closes the StorageFactory it is using at database shutdown time.
Add shutdown code for the JarStorageFactory to close the jar file it has opened.
Ensure the monitor does not use a stream opened from a StorageFactory after it has called shutdown().

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/io/JarStorageFactory.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DatabaseClassLoadingTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/io/JarStorageFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/io/JarStorageFactory.java?view=diff&rev=483606&r1=483605&r2=483606
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/io/JarStorageFactory.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/io/JarStorageFactory.java Thu Dec  7 10:59:27 2006
@@ -21,21 +21,12 @@
 
 package org.apache.derby.impl.io;
 
-import org.apache.derby.iapi.services.sanity.SanityManager;
-
-import org.apache.derby.io.StorageFactory;
-import org.apache.derby.io.StorageFile;
-
 import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.io.OutputStream;
 import java.io.IOException;
-
-import java.util.Properties;
-import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 
+import org.apache.derby.io.StorageFile;
+
 /**
  * This class provides a Jar file based implementation of the StorageFactory interface. It is used by the
  * database engine to access persistent data and transaction logs under the jar subsubprotocol.
@@ -122,6 +113,20 @@
         separatedDataDirectory = dataDirectory + '/'; // Zip files use '/' as a separator
         createTempDir();
     } // end of doInit
+    
+    /**
+     * Close the opened jar/zip file on shutdown.
+     * (Fix for DERBY-2083).
+     */
+    public void shutdown() {
+        if (zipData != null) {
+            try {
+                zipData.close();
+            } catch (IOException e) {
+            }
+            zipData = null;
+        }
+    }
 
     private File getJarFile( String name)
     {

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java?view=diff&rev=483606&r1=483605&r2=483606
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java Thu Dec  7 10:59:27 2006
@@ -250,14 +250,14 @@
 		//recreate the service root  if requested by the user.
 		final String recreateFrom = recreateServiceRoot(serviceName, defaultProperties);
 
-        InputStream is = null;
+        final Properties serviceProperties = new Properties(defaultProperties);
 		try
         {
-            is = (InputStream) AccessController.doPrivileged(
+            AccessController.doPrivileged(
                 new PrivilegedExceptionAction()
                 {
                     public Object run()
-                        throws FileNotFoundException, IOException, StandardException,
+                        throws IOException, StandardException,
                         InstantiationException, IllegalAccessException
                     {
                         if( recreateFrom != null) // restore from a file
@@ -269,17 +269,24 @@
                         {
                             StorageFactory storageFactory = privGetStorageFactoryInstance( true, serviceName, null, null);
                             StorageFile file = storageFactory.newStorageFile( PersistentService.PROPERTIES_NAME);
-                            InputStream is1 = file.getInputStream();
-                            storageFactory.shutdown();
-                            return is1;
+                            try {
+                                InputStream is = file.getInputStream();
+                                try {
+                                    // Need to load the properties before closing the
+                                    // StorageFactory.
+                                    serviceProperties.load(new BufferedInputStream(is));
+                                } finally {
+                                    is.close();
+                                }
+                            } finally {
+                               storageFactory.shutdown();
+                            }
+                            return null;
                         }
                     }
                 }
                 );
 
-			Properties serviceProperties = new Properties(defaultProperties);
-			serviceProperties.load(new BufferedInputStream(is));
-
 			return serviceProperties;
 		}
         catch (PrivilegedActionException pae)
@@ -288,20 +295,7 @@
                 return null;
             throw Monitor.exceptionStartingModule( pae.getException());
         }
-        catch (FileNotFoundException fnfe) {return null ;}
 		catch (SecurityException se) { throw Monitor.exceptionStartingModule(/*serviceName, */ se);	}
-        catch (IOException ioe) { throw Monitor.exceptionStartingModule(/*serviceName, */ ioe); }
-        finally
-        {
-			if (is != null)
-            {
-				try
-                {
-					is.close();
-				}
-                catch (IOException ioe2) {}
-			}
-		}
 	} // end of getServiceProperties
 
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java?view=diff&rev=483606&r1=483605&r2=483606
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java Thu Dec  7 10:59:27 2006
@@ -126,7 +126,6 @@
     implements DataFactory, CacheableFactory, ModuleControl, ModuleSupportable, PrivilegedExceptionAction
 {
 
-    private String subSubProtocol;
     StorageFactory storageFactory;
 
     /* writableStorageFactory == (WritableStorageFactory) storageFactory if 
@@ -496,6 +495,7 @@
 
 		if (isReadOnly())		// do enough to close all files, then return 
         {
+            storageFactory.shutdown();
 			return;
         }
 
@@ -506,6 +506,8 @@
 			removeStubs();
 
 		releaseJBMSLockOnDB();
+        
+        writableStorageFactory.shutdown();
 	} // end of stop
 
 	/*

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DatabaseClassLoadingTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DatabaseClassLoadingTest.java?view=diff&rev=483606&r1=483605&r2=483606
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DatabaseClassLoadingTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DatabaseClassLoadingTest.java Thu Dec  7 10:59:27 2006
@@ -99,13 +99,12 @@
            suite.addTest(SecurityManagerSetup.noSecurityManager(
                    new DatabaseClassLoadingTest("testRemoveJar"))); 
 
-/*  SKIP due to DERBY-2083         
+       
            suite.addTest(SecurityManagerSetup.noSecurityManager(
                    new DatabaseClassLoadingTest("testDatabaseInJar"))); 
 
            suite.addTest(SecurityManagerSetup.noSecurityManager(
                    new DatabaseClassLoadingTest("testDatabaseInClasspath"))); 
-*/
 
            test = new SupportFilesSetup(suite,
                    new String[] {
@@ -616,7 +615,10 @@
         
         setContextClassLoader(jarURL);
         try {
-            readOnlyTest(ds);
+            // Disabled due to DERBY-2162, running this opens
+            // the database thus accessing resources and means the
+            // jar file cannot be cleaned up.
+            // readOnlyTest(ds);
         } finally {
             setContextClassLoader(null);
         } 
@@ -660,7 +662,7 @@
             assertStatementError("25502", s,
                     "CALL EMC.ADDCONTACT(3, 'really@is_read_only.gov')");
 
-            // Disabled due to DERBY-522
+            // Disabled due to DERBY-552
             // getResourceTests(conn);
             
             // Disabled due to DERBY-553