[rhmessaging-commits] rhmessaging commits: r2609 - store/branches/java/broker-queue-refactor/java/bdbstore/src/tools/java/org/apache/qpid/server/store/berkeleydb.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Thu Oct 9 10:46:28 EDT 2008


Author: ritchiem
Date: 2008-10-09 10:46:28 -0400 (Thu, 09 Oct 2008)
New Revision: 2609

Modified:
   store/branches/java/broker-queue-refactor/java/bdbstore/src/tools/java/org/apache/qpid/server/store/berkeleydb/BDBStoreUpgrade.java
Log:
Updated tool to allow inplace upgrades. This works by upgrading to a temporary store in the same directory as the requested upgrade directory then replacing the specified input with the newly upgraded store.

Modified: store/branches/java/broker-queue-refactor/java/bdbstore/src/tools/java/org/apache/qpid/server/store/berkeleydb/BDBStoreUpgrade.java
===================================================================
--- store/branches/java/broker-queue-refactor/java/bdbstore/src/tools/java/org/apache/qpid/server/store/berkeleydb/BDBStoreUpgrade.java	2008-10-08 21:10:44 UTC (rev 2608)
+++ store/branches/java/broker-queue-refactor/java/bdbstore/src/tools/java/org/apache/qpid/server/store/berkeleydb/BDBStoreUpgrade.java	2008-10-09 14:46:28 UTC (rev 2609)
@@ -101,6 +101,7 @@
     private static final String OPTION_QUIET = "quiet";
     private static final String OPTION_FORCE_SHORT = "f";
     private static final String OPTION_FORCE = "force";
+    private boolean _inplace = false;
 
     public BDBStoreUpgrade(String fromDir, String toDir, String backupDir, boolean interactive, boolean force)
     {
@@ -119,10 +120,19 @@
             throw new IllegalArgumentException("Specified directory '" + fromDir + "' does not contain a valid BDBMessageStore.");
         }
 
-        _toDir = new File(toDir);
+        if (toDir == null)
+        {
+            _inplace = true;
+            _toDir = new File(fromDir+"-Inplace");
+        }
+        else
+        {
+            _toDir = new File(toDir);
+        }
+        
         if (_toDir.exists())
         {
-            if (interactive)
+            if (_interactive)
             {
                 System.out.println("Upgrade destination: '" + toDir + "'");
 
@@ -140,7 +150,7 @@
             }
             else
             {
-                if (force)
+                if (_force)
                 {
                     if (!FileUtils.delete(_toDir, true))
                     {
@@ -239,7 +249,8 @@
      */
     public void upgradeFromVersion(int version) throws Exception
     {
-        upgradeFromVersion(version, _fromDir, _toDir, _backupDir, _force);
+        upgradeFromVersion(version, _fromDir, _toDir, _backupDir, _force,
+                           _inplace);
     }
 
     /**
@@ -248,15 +259,22 @@
      * @param version the version of the current store
      * @param fromDir the directory with the old Store
      * @param toDir   the directrory to hold the newly Upgraded Store
+     * @param backupDir the directrory to backup to if required
+     * @param force   suppress all questions
+     * @param inplace replace the from dir with the upgraded result in toDir 
      *
-     * @throws Exception         due to Virtualhost/MessageStore.close() being rather poor at exception handling
+     * @throws Exception         due to Virtualhost/MessageStore.close() being
+     *                              rather poor at exception handling
      * @throws DatabaseException if there is a problem with the store formats
-     * @throws AMQException      if there is an issue creating Qpid data structures
+     * @throws AMQException   if there is an issue creating Qpid data structures
      */
-    public void upgradeFromVersion(int version, File fromDir, File toDir, File backupDir, boolean force) throws Exception
+    public void upgradeFromVersion(int version, File fromDir, File toDir,
+                                   File backupDir, boolean force,
+                                   boolean inplace) throws Exception
     {
         _logger.info("Located store to upgrade at '" + fromDir + "'");
 
+        // Verify user has created a backup, giving option to perform backup
         if (_interactive)
         {
             if (!userInteract("Have you performed a DB backup of this store."))
@@ -336,6 +354,25 @@
 
             //Shutdown the AR that the Vhosts will have created.
             ApplicationRegistry.remove(1);
+
+            // if we are running inplace then swap fromDir and toDir
+            if (inplace)
+            {
+                // Remove original copy
+                if (FileUtils.delete(fromDir, true))
+                {
+                    // Rename upgraded store
+                    toDir.renameTo(fromDir);
+                }
+                else
+                {
+                    throw new RuntimeException("Unable to upgrade inplace as " +
+                                               "unable to delete source '"
+                                               +fromDir+"', Store upgrade " +
+                                               "successfully performed to :"
+                                               +toDir);
+                }
+            }
         }
     }
 
@@ -636,8 +673,14 @@
 
         for (File store : stores)
         {
-            // Check to see if we are upgrading a store specified in fromDir or if the directories are nested.
-            if (stores.length > 0 && stores[0].toString().length() == fromDir.length())
+
+            // if toDir is null then we are upgrading inplace so we don't need
+            // to provide an upgraded toDir when upgrading multiple stores.
+            if (toDir == null ||
+                // Check to see if we are upgrading a store specified in
+                // fromDir or if the directories are nested.
+                (stores.length > 0
+                 && stores[0].toString().length() == fromDir.length()))
             {
                 upgrade(store, toDir, backupDir, interactive, force);
             }
@@ -657,7 +700,7 @@
                         .create(OPTION_INPUT_SHORT);
 
         Option output =
-                OptionBuilder.isRequired().hasArg().withDescription("Location (Path) for the upgraded-db to be written.").withLongOpt(OPTION_OUTPUT)
+                OptionBuilder.hasArg().withDescription("Location (Path) for the upgraded-db to be written.").withLongOpt(OPTION_OUTPUT)
                         .create(OPTION_OUTPUT_SHORT);
 
         Option quiet = new Option(OPTION_QUIET_SHORT, OPTION_QUIET, false, "Disable interactive options.");
@@ -696,7 +739,7 @@
         }
         catch (Exception e)
         {
-            _logger.error("Upgrade Failed: " + e.getMessage());
+            _logger.error("Upgrade Failed: " + e.getMessage());            
         }
     }
 




More information about the rhmessaging-commits mailing list