db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r713515 - in /db/derby/code/branches/10.4/java: engine/org/apache/derby/impl/store/raw/ testing/org/apache/derbyTesting/functionTests/tests/store/ testing/org/apache/derbyTesting/functionTests/util/ testing/org/apache/derbyTesting/junit/
Date Wed, 12 Nov 2008 21:23:13 GMT
Author: kmarsden
Date: Wed Nov 12 13:23:13 2008
New Revision: 713515

URL: http://svn.apache.org/viewvc?rev=713515&view=rev
Log:
DERBY-3035 Cannot restore backups without BACKUP.HISTORY file


Added:
    db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/store/OfflineBackupTest.java
      - copied unchanged from r712693, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OfflineBackupTest.java
Modified:
    db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/store/raw/RawStore.java
    db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java
    db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java
    db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java

Modified: db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/store/raw/RawStore.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/store/raw/RawStore.java?rev=713515&r1=713514&r2=713515&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/store/raw/RawStore.java
(original)
+++ db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/store/raw/RawStore.java
Wed Nov 12 13:23:13 2008
@@ -1135,7 +1135,10 @@
 		// if this is a roll-forward recovery, backup history file 
 		// will already there in the database and will be the latest 
 		// copy; if it exists, do not copy from backup.
-		if (!privExists(dbHistoryFile))
+		// Backup history may not exist at all if we did an offline
+		// backup with os copy commands. In that case, don't try to 
+		// copy the history file. (DERBY-3035)
+		if (privExists(backupHistoryFile) && !privExists(dbHistoryFile))
 			if (!privCopyFile(backupHistoryFile, dbHistoryFile))
 				throw StandardException. 
 					newException(SQLState.RAWSTORE_ERROR_COPYING_FILE,

Modified: db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java?rev=713515&r1=713514&r2=713515&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java
(original)
+++ db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java
Wed Nov 12 13:23:13 2008
@@ -56,6 +56,7 @@
         suite.addTest(Derby3625Test.suite());
         suite.addTest(PositionedStoreStreamTest.suite());
         suite.addTest(BackupRestoreTest.suite());
+        suite.addTest(OfflineBackupTest.suite());
         // Encryption only supported for Derby in J2SE/J2EE environments.
         // J2ME (JSR169) does not support encryption.
         if (JDBC.vmSupportsJDBC3()) {

Modified: db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java?rev=713515&r1=713514&r2=713515&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java
(original)
+++ db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java
Wed Nov 12 13:23:13 2008
@@ -25,6 +25,9 @@
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.security.AccessController;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
@@ -158,4 +161,97 @@
             throw (FileNotFoundException)pae.getCause();
         }
     }
+
+    /**
+     * In a priv block, do a recursive copy from source to target.  
+     * If target exists it will be overwritten. Parent directory for 
+     * target will be created if it does not exist. 
+     * If source does not exist this will be a noop.
+     * 
+     * @param source  Source file or directory to copy
+     * @param target  Target file or directory to copy
+     * @throws IOException
+     * @throws SecurityException
+     */    
+    public static void copy(final File source, final File target) throws IOException {
+        try {
+            AccessController.doPrivileged(new PrivilegedExceptionAction() {
+                public Object run() throws IOException {
+                    recursiveCopy(source,target);
+                    return null;
+                }
+                });
+        } catch (PrivilegedActionException pae) {
+            throw (IOException) pae.getException();
+        
+        }
+        
+    }
+    /**
+     * Do a recursive copy from source to target.  If target exists it will 
+     * be overwritten. Parent directory for target will be created if it does
+     * not exist. If source does not exist this will be a noop.
+     * 
+     * @param source  Source file or directory to copy
+     * @param target  Target file or directory to copy
+     * @throws IOException
+     * @throws FileNotFoundException
+     */
+    private static void  recursiveCopy(File source, File target) throws IOException, FileNotFoundException{
+    
+        if (source.isFile()) {
+            copySingleFile(source,target);
+            return;
+        }
+            
+        String[] list = source.list();
+
+        // Some JVMs return null for File.list() when the
+        // directory is empty.
+        if (list != null) {
+            for (int i = 0; i < list.length; i++) {
+                File entry = new File(source, list[i]);
+                File targetEntry = new File(target, list[i]);
+                if (entry.isDirectory()) {
+                    copy(entry,targetEntry);
+                } else {
+                    copySingleFile(entry, targetEntry);
+                }
+            }
+
+        }
+    }
+
+    /**
+     * Copy a single file from source to target.  If target exists it will be 
+     * overwritten.  If source does not exist, this will be a noop.
+     * 
+     * @param source  Source file to copy
+     * @param target  Destination file for copy
+     * @throws IOException
+     * @throws FileNotFoundException
+     */
+    private static void copySingleFile (File source, File target) throws IOException, FileNotFoundException
{
+
+        File targetParent = target.getParentFile();
+        if (targetParent != null && ! targetParent.exists())
+            target.getParentFile().mkdirs();
+        
+                
+        InputStream in = new FileInputStream(source);
+        OutputStream out = new FileOutputStream(target);
+        byte[] buf = new byte[32 * 1024];
+        
+        for (;;) {
+            int read = in.read(buf);
+            if (read == -1)
+                break;
+            out.write(buf, 0, read);
+        }
+        in.close();
+        out.close();
+    }
+    
+
+
 }

Modified: db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java?rev=713515&r1=713514&r2=713515&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
(original)
+++ db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
Wed Nov 12 13:23:13 2008
@@ -1287,6 +1287,46 @@
      fail("types:" + expectedType + " and " + type + " are not equivalent");
      
     }
+  
+
+    /**
+     * Check consistency of all tables
+     * 
+     * @param conn
+     * @throws SQLException
+     */
+    protected void  checkAllConsistency(
+            Connection  conn)
+    throws SQLException
+    {
+        Statement s = createStatement();
+
+        ResultSet rs = 
+            s.executeQuery(
+                    "select schemaname, tablename, SYSCS_UTIL.SYSCS_CHECK_TABLE(schemaname,
tablename) " + 
+            "from sys.systables a,  sys.sysschemas b where a.schemaid = b.schemaid");
+
+        int table_count = 0;
+
+        while (rs.next())
+        {
+            table_count++;
+
+            if (rs.getInt(3) != 1)
+            {
+                assertEquals("Bad return from consistency check of " +
+                        rs.getString(1) + "." + rs.getString(2),1,rs.getInt(3));
+
+            }
+        }
+        assertTrue("Something wrong with consistency check query, found only " +
+                table_count + " tables.",table_count >= 5);
+
+        rs.close();
+        s.close();
+
+        conn.commit();
+    }
     
 } // End class BaseJDBCTestCase
 



Mime
View raw message