You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2013/08/29 06:41:15 UTC

svn commit: r1518467 - /hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/migration/UpgradeTo96.java

Author: stack
Date: Thu Aug 29 04:41:14 2013
New Revision: 1518467

URL: http://svn.apache.org/r1518467
Log:
HBASE-9110 Meta region edits not recovered while migrating to 0.96.0

Modified:
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/migration/UpgradeTo96.java

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/migration/UpgradeTo96.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/migration/UpgradeTo96.java?rev=1518467&r1=1518466&r2=1518467&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/migration/UpgradeTo96.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/migration/UpgradeTo96.java Thu Aug 29 04:41:14 2013
@@ -30,10 +30,15 @@ import org.apache.commons.cli.ParseExcep
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configured;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.hbase.Abortable;
 import org.apache.hadoop.hbase.HBaseConfiguration;
 import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.regionserver.wal.HLogSplitter;
 import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.FSUtils;
 import org.apache.hadoop.hbase.util.HFileV1Detector;
 import org.apache.hadoop.hbase.util.ZKDataMigrator;
 import org.apache.hadoop.hbase.zookeeper.ZKUtil;
@@ -126,7 +131,7 @@ public class UpgradeTo96 extends Configu
             + "Please stop them before upgrade or try after some time.");
         throw new IOException("Some HBase processes are still alive, or znodes not expired yet");
       }
-      return upgradeNamespaceAndZnodes();
+      return executeUpgrade();
     }
     return -1;
   }
@@ -194,35 +199,59 @@ public class UpgradeTo96 extends Configu
     return ToolRunner.run(getConf(), new HFileV1Detector(), args);
   }
 
-  private int upgradeNamespaceAndZnodes() throws Exception {
-    int res = upgradeNamespace();
-    if (res == 0) return upgradeZnodes();//upgrade znodes only if we succeed in first step.
-    else {
-      LOG.warn("Namespace upgrade returned: "+res +", expected 0. Aborting the upgrade");
-      throw new Exception("Unexpected return code from Namespace upgrade");
+  /**
+   * Executes the upgrade process. It involves:
+   * <ul>
+   * <li> Upgrading Namespace
+   * <li> Upgrading Znodes
+   * <li> Log splitting
+   * </ul>
+   * @return
+   * @throws Exception
+   */
+  private int executeUpgrade() throws Exception {
+    executeTool("Namespace upgrade", new NamespaceUpgrade(),
+      new String[] { "--upgrade" }, 0);
+    executeTool("Znode upgrade", new ZKDataMigrator(), null, 0);
+    doOfflineLogSplitting();
+    return 0;
+  }
+
+  private void executeTool(String toolMessage, Tool tool, String[] args, int expectedResult)
+      throws Exception {
+    LOG.info("Starting " + toolMessage);
+    int res = ToolRunner.run(getConf(), tool, new String[] { "--upgrade" });
+    if (res != expectedResult) {
+      LOG.error(toolMessage + "returned " + res + ", expected " + expectedResult);
+      throw new Exception("Unexpected return code from " + toolMessage);
     }
+    LOG.info("Successfully completed " + toolMessage);
   }
 
-  private int upgradeNamespace() throws Exception {
-    LOG.info("Upgrading Namespace");
-    try {
-      int res = ToolRunner.run(getConf(), new NamespaceUpgrade(), new String[] { "--upgrade" });
-      LOG.info("Successfully Upgraded NameSpace.");
-      return res;
-    } catch (Exception e) {
-      LOG.error("Got exception while upgrading Namespace", e);
-      throw e;
+  /**
+   * Performs log splitting for all regionserver directories.
+   * @return
+   * @throws Exception
+   */
+  private void doOfflineLogSplitting() throws Exception {
+    LOG.info("Starting Log splitting");
+    final Path rootDir = FSUtils.getRootDir(getConf());
+    final Path oldLogDir = new Path(rootDir, HConstants.HREGION_OLDLOGDIR_NAME);
+    FileSystem fs = FSUtils.getCurrentFileSystem(getConf());
+    Path logDir = new Path(rootDir, HConstants.HREGION_LOGDIR_NAME);
+    FileStatus[] regionServerLogDirs = FSUtils.listStatus(fs, logDir);
+    if (regionServerLogDirs == null || regionServerLogDirs.length == 0) {
+      LOG.info("No log directories to split, returning");
+      return;
     }
-  }
-
-  private int upgradeZnodes() throws Exception {
-    LOG.info("Upgrading Znodes");
     try {
-      int res = ToolRunner.run(getConf(), new ZKDataMigrator(), null);
-      LOG.info("Succesfully upgraded znodes.");
-      return res;
+      for (FileStatus regionServerLogDir : regionServerLogDirs) {
+        // split its log dir, if exists
+        HLogSplitter.split(rootDir, regionServerLogDir.getPath(), oldLogDir, fs, getConf());
+      }
+      LOG.info("Successfully completed Log splitting");
     } catch (Exception e) {
-      LOG.error("Got exception while upgrading Znodes", e);
+      LOG.error("Got exception while doing Log splitting ", e);
       throw e;
     }
   }