db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bakk...@apache.org
Subject svn commit: r325896 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/reference/ engine/org/apache/derby/impl/store/raw/ engine/org/apache/derby/impl/store/raw/data/ engine/org/apache/derby/loc/ testing/org/apache/derbyTesting/functionTests/...
Date Mon, 17 Oct 2005 14:10:30 GMT
Author: bakksjo
Date: Mon Oct 17 07:09:51 2005
New Revision: 325896

URL: http://svn.apache.org/viewcvs?rev=325896&view=rev
Log:
Committed DERBY-555 for Øystein Grøvlen (oystein.grovlen@sun.com):

With this patch, when a database is booted in read-only mode, the boot message in derby.log
will contain information about that.

I have also added a test, TurnsReadOnly.java, that without the fix, get the NPE. This is not
in a disk full scenario, but it also occurs with a read-only DB directory. Since there is
currently no way to turn write access back on from a Java program, the DB directory will be
read-only after the test is run. Hence, the test framework will not be able to clean up the
test directory. Therefore, this test is not added to the derbyall test suite.

The following files are changed:

M java/engine/org/apache/derby/impl/store/raw/RawStore.java
      Do not check log location for read-only databases (avoids NPE)
M java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java
      Add information to boot message in derby.log when database is booted in read-only mode.
M java/engine/org/apache/derby/iapi/reference/MessageId.java
      Added message id for the read-only part of the boot message
M java/engine/org/apache/derby/loc/messages_en.properties
      Added text for the read-only part of the boot message
M java/testing/org/apache/derbyTesting/functionTests/tests/store/copyfiles.ant
      Added TurnsReadOnly_app.properties
A java/testing/org/apache/derbyTesting/functionTests/tests/store/TurnsReadOnly.java
      New test that boots a database with log in non-default location, shuts it down, sets
DB directory to read-only, boots again and checks that DML is not allowed.
A java/testing/org/apache/derbyTesting/functionTests/tests/store/TurnsReadOnly_app.properties
      Test properties
A java/testing/org/apache/derbyTesting/functionTests/master/TurnsReadOnly.out
      Master file for new test. 


Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/TurnsReadOnly.out
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TurnsReadOnly.java
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TurnsReadOnly_app.properties
  (with props)
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/MessageId.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java
    db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/copyfiles.ant

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/MessageId.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/MessageId.java?rev=325896&r1=325895&r2=325896&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/MessageId.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/MessageId.java Mon Oct
17 07:09:51 2005
@@ -80,6 +80,7 @@
     String STORE_BACKUP_COMPLETED           = "D012";
     String STORE_DURABILITY_TESTMODE_NO_SYNC = "D013"; // for derby.system.durability is

                                                        // set to test
+    String STORE_BOOT_READONLY_MSG          = "D014";
 
 
 	/*

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java?rev=325896&r1=325895&r2=325896&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java Mon Oct
17 07:09:51 2005
@@ -274,8 +274,10 @@
 		String logDevice = properties.getProperty(Attribute.LOG_DEVICE);
 		if (logDevice !=null)
 		{
-			if (create || !logDevice.equals(logFactory.getCanonicalLogPath()) ||
-				restoreFromBackup!=null)
+            if (!isReadOnly() // We do not care about log location if read only
+                && (create 
+                    || !logDevice.equals(logFactory.getCanonicalLogPath()) 
+                    || restoreFromBackup!=null))
 			{
 				// get the real location from the log factory
 				properties.put(Attribute.LOG_DEVICE, logFactory.getCanonicalLogPath());

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java?rev=325896&r1=325895&r2=325896&view=diff
==============================================================================
--- 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
Mon Oct 17 07:09:51 2005
@@ -326,12 +326,16 @@
 
 		logMsg(LINE);
 		long bootTime = System.currentTimeMillis();
+        String readOnlyMsg = (isReadOnly()) 
+            ? MessageService.getTextMessage(MessageId.STORE_BOOT_READONLY_MSG)
+            : "";
 
 		logMsg(CheapDateFormatter.formatDate(bootTime) +
 			   MessageService.getTextMessage(MessageId.STORE_BOOT_MSG,
-			   									jbmsVersion,
-												identifier,
-												dataDirectory));
+                                             jbmsVersion,
+                                             identifier,
+                                             dataDirectory,
+                                             readOnlyMsg));
 
 		uf = null;
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties?rev=325896&r1=325895&r2=325896&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties Mon Oct 17
07:09:51 2005
@@ -1180,7 +1180,7 @@
 
 # RawStore Data
 
-D001=:\n Booting Derby version {0}: instance {1}\non database directory {2} \n
+D001=:\n Booting Derby version {0}: instance {1}\non database directory {2} {3} \n
 D002=:\nShutting down instance {0}
 D004=Backup started for database located at {0}
 D005=moved old backup copy from {0} to {1}
@@ -1192,6 +1192,7 @@
 D011=removed old backup copy at {0}
 D012=Backup completed, log instant at {0} \n
 D013=WARNING: The database is booted with {0}={1}. In this mode, it is possible that database
may not be able to recover, committed transactions may be lost, database may be in an inconsistent
state. Please use this mode only when these consequences are acceptable  \n
+D014=in READ ONLY mode
 
 # Connectivity 
 J004=database identity

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/TurnsReadOnly.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/TurnsReadOnly.out?rev=325896&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/TurnsReadOnly.out
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/TurnsReadOnly.out
Mon Oct 17 07:09:51 2005
@@ -0,0 +1,6 @@
+Database has been booted.
+Table t1 created.
+Shutting down database ...
+Database shutdown completed
+Database has been booted.
+Database is read-only

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/TurnsReadOnly.out
------------------------------------------------------------------------------
    svn:eol-style = native

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TurnsReadOnly.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TurnsReadOnly.java?rev=325896&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TurnsReadOnly.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TurnsReadOnly.java
Mon Oct 17 07:09:51 2005
@@ -0,0 +1,109 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.store.LogChecksumSetup
+
+   Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+
+package org.apache.derbyTesting.functionTests.tests.store;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Properties;
+
+import javax.sql.DataSource;
+
+import org.apache.derby.tools.ij;
+import org.apache.derbyTesting.functionTests.util.TestUtil;
+
+/*
+ * This class is a test where you are not able to create the lock file
+ * when booting an existing database.  The database will then become
+ * read-only.  The tests first creates a database and then shutdowns,
+ * turns off write access to the database directory and then boots the
+ * database again.  A non-default log directory is used since that
+ * uncovered a bug (DERBY-555).  (logDevice is set in the
+ * _app.properties file)
+ *
+ * NB! This test is not included in derbyall since it creates a
+ * read-only directory which will be annoying when trying to clean
+ * test directories.  When Java 6 can be used, it will be possible to
+ * turn on write access at the end of the test.
+ *
+ * @author oystein.grovlen@sun.com
+ */
+
+public class TurnsReadOnly
+{
+    
+    public static void main(String[] argv) throws Throwable 
+    {
+        try {
+            ij.getPropertyArg(argv); 
+            Connection conn = ij.startJBMS();
+            conn.setAutoCommit(true);
+            System.out.println("Database has been booted.");
+
+            Statement s = conn.createStatement();
+            s.execute("CREATE TABLE t1(a INT)");
+            System.out.println("Table t1 created.");
+
+            // Shut down database
+            Properties shutdownAttrs = new Properties();
+            shutdownAttrs.setProperty("shutdownDatabase", "shutdown");
+            System.out.println("Shutting down database ...");
+            try {
+                DataSource ds = TestUtil.getDataSource(shutdownAttrs);
+                ds.getConnection();
+            } catch(SQLException se) {
+				if (se.getSQLState() != null 
+                    && se.getSQLState().equals("XJ015")) {
+					System.out.println("Database shutdown completed");
+                } else {
+                    throw se;
+                }
+            }
+
+            // Make database directory read-only.
+            String derbyHome = System.getProperty("derby.system.home");
+            File dbDir = new File(derbyHome, "wombat");
+            dbDir.setReadOnly();
+            
+            // Boot database, check that it is read-only
+            conn = ij.startJBMS();
+            conn.setAutoCommit(true);
+            System.out.println("Database has been booted.");
+            s = conn.createStatement();
+            try {
+                s.execute("INSERT INTO t1 VALUES(1)");
+            } catch(SQLException se) {
+				if (se.getSQLState() != null 
+                    && se.getSQLState().equals("25502")) {
+					System.out.println("Database is read-only");
+                } else {
+                    throw se;
+                }
+            }
+
+        } catch (SQLException sqle) {
+            org.apache.derby.tools.JDBCDisplayUtil.ShowSQLException(System.out, 
+                                                                    sqle);
+            sqle.printStackTrace(System.out);
+        }
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TurnsReadOnly.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TurnsReadOnly_app.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TurnsReadOnly_app.properties?rev=325896&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TurnsReadOnly_app.properties
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TurnsReadOnly_app.properties
Mon Oct 17 07:09:51 2005
@@ -0,0 +1 @@
+database=jdbc:derby:wombat;create=true;logDevice=extinout/wombatlog

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TurnsReadOnly_app.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/copyfiles.ant
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/copyfiles.ant?rev=325896&r1=325895&r2=325896&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/copyfiles.ant
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/copyfiles.ant
Mon Oct 17 07:09:51 2005
@@ -23,6 +23,7 @@
 TransactionTable.sql
 TransactionTable_app.properties
 TransactionTable_derby.properties
+TurnsReadOnly_app.properties
 access.sql
 access_app.properties
 access_derby.properties



Mime
View raw message