db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject svn commit: r420892 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw: RawStore.java log/LogToFile.java
Date Tue, 11 Jul 2006 15:16:43 GMT
Author: mikem
Date: Tue Jul 11 08:16:42 2006
New Revision: 420892

URL: http://svn.apache.org/viewvc?rev=420892&view=rev
Log:
Improved the comments in some of the routines while debugging a DERBY-1248.
Separating the formatting/comment changes from the real fix.


Modified:
    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/log/LogToFile.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java?rev=420892&r1=420891&r2=420892&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 Tue Jul
11 08:16:42 2006
@@ -677,7 +677,7 @@
 	 * Backup the database.
 	 * Online backup copies all the database files (log, seg0  ...Etc) to the
 	 * specified backup location without blocking any user operation for the 
-	 * duration of the backup. Stable copy is made of each page using using 
+	 * duration of the backup. Stable copy is made of each page using 
      * page level latches and in some cases with the help of monitors.  
      * Transaction log is also backed up, this is used to bring the database to 
      * the consistent state on restore.
@@ -685,12 +685,13 @@
      * <P> MT- only one thread  is allowed to perform backup at any given time. 
      *  Synchronized on this. Parallel backups are not supported. 
 	 */
-	public synchronized void backup(Transaction t, 
-                                    File backupDir) 
+	public synchronized void backup(Transaction t, File backupDir) 
         throws StandardException
 	{
         if (!privExists(backupDir))
 		{
+            // if backup dir does not exist, go ahead and create it.
+
             if (!privMkdirs(backupDir))
             {
                 throw StandardException.newException(
@@ -700,6 +701,8 @@
 		}
 		else
 		{
+            // entity with backup name exists, make sure it is a directory.
+
             if (!privIsDirectory(backupDir))
             {
 				throw StandardException.newException(
@@ -710,10 +713,12 @@
             // check if a user has given the backup as a database directory by
             // mistake, backup path can not be a derby database directory. 
             // If a directory contains PersistentService.PROPERTIES_NAME, it 
-            // is assumed as derby database directory because derby databases
-            // always has this file. 
+            // is assumed to be a derby database directory because derby 
+            // databases always have this file. 
  
-            if (privExists(new File(backupDir, PersistentService.PROPERTIES_NAME))) { 
+            if (privExists(
+                    new File(backupDir, PersistentService.PROPERTIES_NAME))) 
+            { 
                 throw StandardException.newException(
                     SQLState.RAWSTORE_CANNOT_BACKUP_INTO_DATABASE_DIRECTORY,
                     (File) backupDir); 
@@ -732,22 +737,27 @@
         
 		try
 		{
-			// first figure out our name
-			StorageFile dbase = storageFactory.newStorageFile( null); // The database directory
-            String canonicalDbName = storageFactory.getCanonicalName();
-            int lastSep = canonicalDbName.lastIndexOf( storageFactory.getSeparator());
-			String dbname = canonicalDbName.substring( lastSep + 1);
+			// get name of the current db, ie. database directory of current db.
+			StorageFile dbase           = storageFactory.newStorageFile(null); 
+            String      canonicalDbName = storageFactory.getCanonicalName();
+            int         lastSep         = 
+                canonicalDbName.lastIndexOf(storageFactory.getSeparator());
+			String      dbname          = 
+                canonicalDbName.substring(lastSep + 1);
 
 			// append to end of history file
-			historyFile = privFileWriter( storageFactory.newStorageFile( BACKUP_HISTORY), true);
+			historyFile = 
+                privFileWriter(
+                    storageFactory.newStorageFile(BACKUP_HISTORY), true);
             
 			backupcopy = new File(backupDir, dbname);
 
-			logHistory(historyFile,
-                        MessageService.getTextMessage(
-                            MessageId.STORE_BACKUP_STARTED, 
-                            canonicalDbName, 
-                            getFilePath(backupcopy)));
+			logHistory(
+                historyFile,
+                MessageService.getTextMessage(
+                    MessageId.STORE_BACKUP_STARTED, 
+                    canonicalDbName, 
+                    getFilePath(backupcopy)));
 
             
             // check if a backup copy of this database already exists,
@@ -792,6 +802,7 @@
 
             dbHistoryFile = storageFactory.newStorageFile(BACKUP_HISTORY);
             backupHistoryFile = new File(backupcopy, BACKUP_HISTORY); 
+
             // copy the history file into the backup. 
             if(!privCopyFile(dbHistoryFile, backupHistoryFile))
                 throw StandardException. 
@@ -803,14 +814,16 @@
             // the backup. 
             StorageFile jarDir = 
                 storageFactory.newStorageFile(FileResource.JAR_DIRECTORY_NAME);
-            if (privExists(jarDir)) {
 
+            if (privExists(jarDir)) 
+            {
                 // find the list of schema directories under the jar dir and
-                // then copy only the plain files under those directories. One could
-                // just use the recursive copy of directory to copy all the files
-                // under the jar dir, but the problem with that is if a user 
-                // gives jar directory as the backup path by mistake, copy will 
-                // fail while copying the backup dir onto itself in recursion
+                // then copy only the plain files under those directories. One 
+                // could just use the recursive copy of directory to copy all 
+                // the files under the jar dir, but the problem with that is if
+                // a user gives jar directory as the backup path by mistake, 
+                // copy will fail while copying the backup dir onto itself in 
+                // recursion
 
                 String [] jarSchemaList = privList(jarDir);
                 File backupJarDir = new File(backupcopy, 
@@ -827,9 +840,12 @@
                 {
                     StorageFile jarSchemaDir = 
                         storageFactory.newStorageFile(jarDir, jarSchemaList[i]);
-                    File backupJarSchemaDir = new File(backupJarDir, jarSchemaList[i]);
+                    File backupJarSchemaDir = 
+                        new File(backupJarDir, jarSchemaList[i]);
+
                     if (!privCopyDirectory(jarSchemaDir, backupJarSchemaDir, 
-                                           (byte[])null, null, false)) {
+                                           (byte[])null, null, false)) 
+                    {
                         throw StandardException.
                             newException(SQLState.RAWSTORE_ERROR_COPYING_FILE,
                                          jarSchemaDir, backupJarSchemaDir);  
@@ -844,55 +860,69 @@
 
             StorageFile logdir = logFactory.getLogDirectory();
             
-            try {
-                
+            try 
+            {
                 String name = Monitor.getMonitor().getServiceName(this);
-                PersistentService ps = Monitor.getMonitor().getServiceType(this);
+                PersistentService ps = 
+                    Monitor.getMonitor().getServiceType(this);
                 String fullName = ps.getCanonicalServiceName(name);
-                Properties prop = ps.getServiceProperties(fullName, (Properties)null);
+                Properties prop = 
+                    ps.getServiceProperties(fullName, (Properties)null);
+
                 StorageFile defaultLogDir = 
-                    storageFactory.newStorageFile( LogFactory.LOG_DIRECTORY_NAME);
+                    storageFactory.newStorageFile(
+                        LogFactory.LOG_DIRECTORY_NAME);
 
                 if (!logdir.equals(defaultLogDir))  
                 {
                     prop.remove(Attribute.LOG_DEVICE);
                     if (SanityManager.DEBUG)
-                        SanityManager.ASSERT(prop.getProperty(Attribute.LOG_DEVICE) == null,
-                                             "cannot get rid of logDevice property");
+                    {
+                        SanityManager.ASSERT(
+                            prop.getProperty(Attribute.LOG_DEVICE) == null,
+                            "cannot get rid of logDevice property");
+                    }
+
                     logHistory(historyFile,
                                MessageService.getTextMessage(
                                MessageId.STORE_EDITED_SERVICEPROPS));
                 }
             
                 // save the service properties into the backup.
-                ps.saveServiceProperties( backupcopy.getPath(), prop, false);
+                ps.saveServiceProperties(backupcopy.getPath(), prop, false);
 
-            }catch(StandardException se) {
-                logHistory(historyFile,
-                           MessageService.getTextMessage(
-                           MessageId.STORE_ERROR_EDIT_SERVICEPROPS)
-                           + se);
+            }
+            catch(StandardException se) 
+            {
+                logHistory(
+                   historyFile,
+                   MessageService.getTextMessage(
+                       MessageId.STORE_ERROR_EDIT_SERVICEPROPS) + se);
 
                 return; // skip the rest and let finally block clean up
             }
 
             // Incase of encrypted database and the key is an external 
             // encryption key, there is an extra file with name  
-            // Attribute.CRYPTO_EXTERNAL_KEY_VERIFY_FILE , this file should be
+            // Attribute.CRYPTO_EXTERNAL_KEY_VERIFY_FILE, this file should be
             // copied in to the backup.
             StorageFile verifyKeyFile = 
                 storageFactory.newStorageFile(
                                  Attribute.CRYPTO_EXTERNAL_KEY_VERIFY_FILE);
-            if (privExists(verifyKeyFile)) {
+            if (privExists(verifyKeyFile)) 
+            {
                 File backupVerifyKeyFile = 
-                    new File(backupcopy, Attribute.CRYPTO_EXTERNAL_KEY_VERIFY_FILE);
+                    new File(
+                        backupcopy, Attribute.CRYPTO_EXTERNAL_KEY_VERIFY_FILE);
+
                 if(!privCopyFile(verifyKeyFile, backupVerifyKeyFile))
                    throw StandardException.
                        newException(SQLState.RAWSTORE_ERROR_COPYING_FILE,
                                     verifyKeyFile, backupVerifyKeyFile);  
             }
                 
-			File logBackup = new File(backupcopy, LogFactory.LOG_DIRECTORY_NAME);
+			File logBackup = 
+                new File(backupcopy, LogFactory.LOG_DIRECTORY_NAME);
 
 			// this is wierd, delete it
             if (privExists(logBackup))
@@ -924,7 +954,6 @@
                     (File) segBackup);
             }
 
-
 			// backup all the information in the data segment.
 			dataFactory.backupDataFiles(t, segBackup);
 
@@ -935,7 +964,8 @@
 
 
             // copy the log that got generated after the backup started to
-			// backup location and tell the logfactory that backup has come to end.
+			// backup location and tell the logfactory that backup has come 
+            // to end.
 			logFactory.endLogBackup(logBackup);
 																		  
 			logHistory(historyFile,

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=420892&r1=420891&r2=420892&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 Tue
Jul 11 08:16:42 2006
@@ -2119,27 +2119,43 @@
 
    
 
-	private long getFirstLogNeeded(CheckpointOperation checkpoint){
-
+    /**
+     * Return the "oldest" log file still needed by recovery. 
+     * <p>
+     * Returns the log file that contains the undoLWM, ie. the oldest
+     * log record of all uncommitted transactions in the given checkpoint.
+     * 
+     * If no checkpoint is given then returns -1, indicating all log records
+     * may be necessary.
+     *
+     **/
+	private long getFirstLogNeeded(CheckpointOperation checkpoint)
+    {
 		long firstLogNeeded;
 
 		// one truncation at a time
 		synchronized (this)
 		{
-			firstLogNeeded = (checkpoint != null ? LogCounter.getLogFileNumber(checkpoint.undoLWM())
: -1);
+			firstLogNeeded = 
+                (checkpoint != null ? 
+                     LogCounter.getLogFileNumber(checkpoint.undoLWM()) : -1);
 
 			if (SanityManager.DEBUG)
 			{
 				if (SanityManager.DEBUG_ON(LogToFile.DBG_FLAG))
-					SanityManager.DEBUG(DBG_FLAG, "truncatLog: undoLWM firstlog needed " + firstLogNeeded);
+					SanityManager.DEBUG(DBG_FLAG, 
+                       "truncatLog: undoLWM firstlog needed " + firstLogNeeded);
 			}
 
 			if (SanityManager.DEBUG)
 			{
 				if (SanityManager.DEBUG_ON(LogToFile.DBG_FLAG))
 				{
-				SanityManager.DEBUG(DBG_FLAG, "truncatLog: checkpoint truncationLWM firstlog needed "
+ firstLogNeeded);
-				SanityManager.DEBUG(DBG_FLAG, "truncatLog: firstLogFileNumber = " + firstLogFileNumber);
+                    SanityManager.DEBUG(DBG_FLAG, 
+                      "truncatLog: checkpoint truncationLWM firstlog needed " +
+                      firstLogNeeded);
+                    SanityManager.DEBUG(DBG_FLAG, 
+                      "truncatLog: firstLogFileNumber = " + firstLogFileNumber);
 				}
 			}
 		}
@@ -4472,24 +4488,27 @@
 
 
 	/*
-	 * start the transaction log backup, transaction log is  is required
-	 * to bring the database to the consistent state on restore. 
-
+	 * Start the transaction log backup.  
+     *
+     * The transaction log is required to bring the database to the consistent 
+     * state on restore. 
+     *
 	 * All the log files that are created after the backup starts 
-	 * should be kept around until they are copied into the backup,
+	 * must be kept around until they are copied into the backup,
 	 * even if there are checkpoints when backup is in progress. 
 	 *
-	 * copy the log control files to the backup (the checkpoint recorded in the
-     * control files is the backup checkpoint), Restore will use the checkpoint 
+	 * Copy the log control files to the backup (the checkpoint recorded in the
+     * control files is the backup checkpoint). Restore will use the checkpoint 
      * info in these control files to perform recovery to bring 
-	 * the database to the consistent state.  and find first log file 
-	 * that need to be copied into the backup to bring the database
-	 * to the consistent state on restore. 
+	 * the database to the consistent state.  
+     *
+     * Find first log file that needs to be copied into the backup to bring 
+     * the database to the consistent state on restore. 
 	 * 
-     * In the end, existing log files that are needed to recover from the backup 
+     * In the end, existing log files that are needed to recover from the backup
      * checkpoint are copied into the backup, any log that gets generated after
-     * this call are copied into the backup after all the all the information 
-     * in the data containers is  written to the backup, when endLogBackup() 
+     * this call are also copied into the backup after all the information 
+     * in the data containers is written to the backup, when endLogBackup() 
      * is called.
 	 *
      * @param toDir - location where the log files should be copied to.
@@ -4528,8 +4547,8 @@
 			toFile = new File(toDir,fromFile.getName());
 			if(!privCopyFile(fromFile, toFile))
 			{
-				throw StandardException.newException(SQLState.RAWSTORE_ERROR_COPYING_FILE,
-													 fromFile, toFile);
+				throw StandardException.newException(
+                    SQLState.RAWSTORE_ERROR_COPYING_FILE, fromFile, toFile);
 			}
 
 			// copy the log mirror control file
@@ -4537,21 +4556,22 @@
 			toFile = new File(toDir,fromFile.getName());
 			if(!privCopyFile(fromFile, toFile))
 			{
-				throw StandardException.newException(SQLState.RAWSTORE_ERROR_COPYING_FILE,
-													 fromFile, toFile);
+				throw StandardException.newException(
+                    SQLState.RAWSTORE_ERROR_COPYING_FILE, fromFile, toFile);
 			}
 
-			// find the first  log file number that is  active
+			// find the first log file number that is active
 			logFileToBackup = getFirstLogNeeded(currentCheckpoint);
 		}
 
-		// copy all the log files that has to go into the backup 
-		backupLogFiles(toDir, getLogFileNumber()-1);
+		// copy all the log files that have to go into the backup 
+		backupLogFiles(toDir, getLogFileNumber() - 1);
 	}	
 
 	/*
 	 * copy the log files into the given backup location
-     * @param toDir - location where the log files should be copied to.
+     *
+     * @param toDir               - location to copy the log files to
      * @param lastLogFileToBackup - last log file that needs to be copied.
 	 **/
 	private void backupLogFiles(File toDir, long lastLogFileToBackup) 
@@ -4564,15 +4584,15 @@
 			File toFile = new File(toDir, fromFile.getName());
 			if(!privCopyFile(fromFile, toFile))
 			{
-				throw StandardException.newException(SQLState.RAWSTORE_ERROR_COPYING_FILE,
-													 fromFile, toFile);
+				throw StandardException.newException(
+                    SQLState.RAWSTORE_ERROR_COPYING_FILE, fromFile, toFile);
 			}
 			logFileToBackup++;
 		}
 	}
 
 	/*
-	 * copy all the log files that has to go into  the backup
+	 * copy all the log files that have to go into the backup
 	 * and mark that backup is compeleted. 
      *
      * @param toDir - location where the log files should be copied to.
@@ -4583,19 +4603,20 @@
 		long lastLogFileToBackup;
 		if (logArchived)
 		{
-			// when the log is being  archived for roll-frward recovery
-			// we would like to switch to  a new log file.
-			// otherwise during restore  logfile in the backup could 
+			// when the log is being archived for roll-forward recovery
+			// we would like to switch to a new log file.
+			// otherwise during restore logfile in the backup could 
 			// overwrite the more uptodate log files in the 
 			// online log path. And also we would like to mark the end
 			// marker for the log file other wise during roll-forward recovery,
-			// if we see a log file with fuzzy end , we think that is the 
+			// if we see a log file with fuzzy end, we think that is the 
 			// end of the recovery.
 			switchLogFile();
-			lastLogFileToBackup = getLogFileNumber()-1 ;
-		}else
+			lastLogFileToBackup = getLogFileNumber() - 1;
+		}
+        else
 		{
-			// for a plain online backup partiall filled up log file is ok, 
+			// for a plain online backup partial filled up log file is ok, 
 			// no need to do a log switch.
 			lastLogFileToBackup = getLogFileNumber();	
 		}



Mime
View raw message