Return-Path: X-Original-To: apmail-db-derby-commits-archive@www.apache.org Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A2CB3D2A6 for ; Sat, 8 Dec 2012 00:37:08 +0000 (UTC) Received: (qmail 43140 invoked by uid 500); 8 Dec 2012 00:37:08 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 43077 invoked by uid 500); 8 Dec 2012 00:37:08 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 43065 invoked by uid 99); 8 Dec 2012 00:37:08 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 08 Dec 2012 00:37:08 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 08 Dec 2012 00:37:06 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 969682388A64; Sat, 8 Dec 2012 00:36:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1418568 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/store/access/ engine/org/apache/derby/iapi/store/raw/log/ engine/org/apache/derby/impl/sql/catalog/ engine/org/apache/derby/impl/store/access/ engine/org/apache/derby/imp... Date: Sat, 08 Dec 2012 00:36:45 -0000 To: derby-commits@db.apache.org From: mamta@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121208003646.969682388A64@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mamta Date: Sat Dec 8 00:36:44 2012 New Revision: 1418568 URL: http://svn.apache.org/viewvc?rev=1418568&view=rev Log: DERBY-5996(Create readme files (cautioning users against modifying database files) at database hard upgrade time) During hard upgrade to 10.10, Derby will create 3 readme files, one in database directory, one in "seg0" directory and one in log directory. These readme files warn users against touching any of files associated with derby database Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/AccessFactory.java db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/log/LogFactory.java db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DD_Version.java db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/RAMAccessManager.java db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/ReadOnly.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_10.java Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/AccessFactory.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/AccessFactory.java?rev=1418568&r1=1418567&r2=1418568&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/AccessFactory.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/AccessFactory.java Sat Dec 8 00:36:44 2012 @@ -112,6 +112,16 @@ public interface AccessFactory */ public boolean isReadOnly(); + /** + * DERBY-5996(Create readme files (cautioning users against modifying + * database files) at database hard upgrade time) + * This gets called during hard upgrade. It will create 3 readme files + * one in database directory, one in "seg0" directory and one in log + * directory. These readme files warn users against touching any of + * files associated with derby database + */ + public void createReadMeFiles() + throws StandardException; /************************************************************************** Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/log/LogFactory.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/log/LogFactory.java?rev=1418568&r1=1418567&r2=1418568&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/log/LogFactory.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/raw/log/LogFactory.java Sat Dec 8 00:36:44 2012 @@ -60,6 +60,13 @@ public interface LogFactory extends Corr public Logger getLogger(); + /** + * Create readme file in log directory warning users against touching + * any files in the directory + * @throws StandardException + */ + public void createDataWarningFile() throws StandardException; + /** Make log factory aware of which raw store factory it belongs to */ Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DD_Version.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DD_Version.java?rev=1418568&r1=1418567&r2=1418568&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DD_Version.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DD_Version.java Sat Dec 8 00:36:44 2012 @@ -223,6 +223,13 @@ public class DD_Version implements Forma // real upgrade changes. Get user name of current user. String userName = IdUtil.getUserNameFromURLProps(startParams); doFullUpgrade(tc, dictionaryVersion.majorVersionNumber,IdUtil.getUserAuthorizationId(userName)); + //DERBY-5996(Create readme files (cautioning users against + // modifying database files) at database hard upgrade time) + //Following will create 3 readme files. + // one in database directory, one in "seg0" directory and one in + // log directory. These readme files warn users against touching + // any of files associated with derby database + bootingDictionary.af.createReadMeFiles(); } if (!minorOnly && !isReadOnly) { Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/RAMAccessManager.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/RAMAccessManager.java?rev=1418568&r1=1418567&r2=1418568&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/RAMAccessManager.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/RAMAccessManager.java Sat Dec 8 00:36:44 2012 @@ -32,6 +32,7 @@ import org.apache.derby.iapi.services.da import org.apache.derby.iapi.services.locks.LockFactory; import org.apache.derby.iapi.services.monitor.ModuleControl; import org.apache.derby.iapi.services.monitor.Monitor; +import org.apache.derby.iapi.services.monitor.PersistentService; import org.apache.derby.iapi.services.property.PropertySetCallback; import org.apache.derby.iapi.services.sanity.SanityManager; @@ -55,6 +56,8 @@ import org.apache.derby.iapi.store.raw.C import org.apache.derby.iapi.store.raw.LockingPolicy; import org.apache.derby.iapi.store.raw.RawStoreFactory; import org.apache.derby.iapi.store.raw.Transaction; +import org.apache.derby.iapi.store.raw.log.LogFactory; +import org.apache.derby.iapi.store.raw.data.DataFactory; import org.apache.derby.catalog.UUID; @@ -888,6 +891,30 @@ public abstract class RAMAccessManager return rawstore.isReadOnly(); } + /** + * DERBY-5996(Create readme files (cautioning users against modifying + * database files) at database hard upgrade time) + * This gets called during hard upgrade. It will create 3 readme files + * one in database directory, one in "seg0" directory and one in log + * directory. These readme files warn users against touching any of + * files associated with derby database + */ + public void createReadMeFiles() + throws StandardException + { + //creating readme in "seg0" directory + rawstore.createDataWarningFile(); + + //creating readme in log directory + LogFactory logFactory =(LogFactory) Monitor.findServiceModule(this, rawstore.getLogFactoryModule()); + logFactory.createDataWarningFile(); + + //creating readme in root database directory + DataFactory dataFactory =(DataFactory) Monitor.findServiceModule(this, rawstore.getDataFactoryModule()); + PersistentService ps = Monitor.getMonitor().getServiceType(rawstore); + ps.createDataWarningFile(dataFactory.getStorageFactory()); + } + private void addPropertySetNotification(PropertySetCallback who, TransactionController tc) { pf.addPropertySetNotification(who); Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java?rev=1418568&r1=1418567&r2=1418568&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 Sat Dec 8 00:36:44 2012 @@ -2733,34 +2733,42 @@ public final class LogToFile implements throw StandardException.newException( SQLState.LOG_SEGMENT_NOT_EXIST, logDir.getPath()); } - - //Put a readme file in the log directory, alerting users to not - // touch or remove any of the files there - StorageFile fileReadMe = logStorageFactory.newStorageFile( - LogFactory.LOG_DIRECTORY_NAME, - PersistentService.DB_README_FILE_NAME); - if (!privExists(fileReadMe)) { - OutputStreamWriter osw = null; - try { - osw = privGetOutputStreamWriter(fileReadMe); - osw.write(MessageService.getTextMessage( - MessageId.README_AT_LOG_LEVEL)); - } - catch (IOException ioe) - { - } - finally + createDataWarningFile(); + } + } + + /** + * Create readme file in log directory warning users against touching + * any files in the directory + * @throws StandardException + */ + public void createDataWarningFile() throws StandardException { + //Put a readme file in the log directory, alerting users to not + // touch or remove any of the files there + StorageFile fileReadMe = logStorageFactory.newStorageFile( + LogFactory.LOG_DIRECTORY_NAME, + PersistentService.DB_README_FILE_NAME); + if (!privExists(fileReadMe)) { + OutputStreamWriter osw = null; + try { + osw = privGetOutputStreamWriter(fileReadMe); + osw.write(MessageService.getTextMessage( + MessageId.README_AT_LOG_LEVEL)); + } + catch (IOException ioe) + { + } + finally + { + if (osw != null) { - if (osw != null) + try { - try - { - osw.close(); - } - catch (IOException ioe) - { - // Ignore exception on close - } + osw.close(); + } + catch (IOException ioe) + { + // Ignore exception on close } } } Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/ReadOnly.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/ReadOnly.java?rev=1418568&r1=1418567&r2=1418568&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/ReadOnly.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/ReadOnly.java Sat Dec 8 00:36:44 2012 @@ -76,6 +76,10 @@ public class ReadOnly implements LogFact return null; } + /** Not applicable in readonly databases */ + public void createDataWarningFile() throws StandardException { + } + /** Not applicable in readonly databases */ public void setRawStoreFactory(RawStoreFactory rsf) { } Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_10.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_10.java?rev=1418568&r1=1418567&r2=1418568&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_10.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_10.java Sat Dec 8 00:36:44 2012 @@ -21,6 +21,7 @@ limitations under the License. package org.apache.derbyTesting.functionTests.tests.upgradeTests; import java.io.File; +import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; @@ -39,6 +40,7 @@ import junit.framework.Test; import junit.framework.TestSuite; import org.apache.derbyTesting.functionTests.tests.upgradeTests.helpers.DisposableIndexStatistics; +import org.apache.derbyTesting.functionTests.util.PrivilegedFileOpsForTests; import org.apache.derbyTesting.junit.IndexStatsUtil; import org.apache.derbyTesting.junit.JDBC; import org.apache.derbyTesting.junit.JDBCDataSource; @@ -60,6 +62,11 @@ public class Changes10_10 extends Upgrad private static final String SYNTAX_ERROR = "42X01"; private static final String HARD_UPGRADE_REQUIRED = "XCL47"; private static final String NEEDS_JAVA_STYLE = "42ZCA"; + /** + The readme file cautioning users against touching the files in + the database directory + */ + private static final String DB_README_FILE_NAME = "README_DO_NOT_TOUCH_FILES.txt"; /////////////////////////////////////////////////////////////////////////////////// // @@ -248,4 +255,57 @@ public class Changes10_10 extends Upgrad st.close(); } + /** + * DERBY-5996(Create readme files (cautioning users against modifying + * database files) at database hard upgrade time) + * Simple test to make sure readme files are getting created + */ + public void testReadMeFiles() throws SQLException, IOException + { + Statement s = createStatement(); + s.close(); + TestConfiguration currentConfig = TestConfiguration.getCurrent(); + String dbPath = currentConfig.getDatabasePath(currentConfig.getDefaultDatabaseName()); + switch (getPhase()) + { + case PH_CREATE: + case PH_SOFT_UPGRADE: + case PH_POST_SOFT_UPGRADE: + // DERBY-5995 Pre 10.10 databases would not have readme files + lookForReadmeFile(dbPath, false); + lookForReadmeFile(dbPath+File.separator+"seg0", false); + lookForReadmeFile(dbPath+File.separator+"log", false); + break; + case PH_HARD_UPGRADE: + case PH_POST_HARD_UPGRADE: + // DERBY-5995 Hard upgrade to 10.10 will create readme files + lookForReadmeFile(dbPath, true); + lookForReadmeFile(dbPath+File.separator+"seg0", true); + lookForReadmeFile(dbPath+File.separator+"log", true); + break; + } + } + + /** + * For pre-10.10 database, fileShouldExist will be false. For hard upgraded + * databases to 10.10, fileShouldExist will be true + * @param path - this can be root database directory, log or seg0 directory + * @param fileShouldExist + * @throws IOException + */ + private void lookForReadmeFile(String path, boolean fileShouldExist) throws IOException { + File readmeFile = new File(path, + DB_README_FILE_NAME); + if (fileShouldExist) + { + assertTrue(readmeFile + "doesn't exist", + PrivilegedFileOpsForTests.exists(readmeFile)); + } else + { + assertFalse(readmeFile + "exists", + PrivilegedFileOpsForTests.exists(readmeFile)); + + } + } + }