From 4df029fcca85789e567ad71eb7eb854ad9f2967b Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Thu, 29 Aug 2013 04:42:45 +0000 Subject: [PATCH] HBASE-9110 Meta region edits not recovered while migrating to 0.96.0; PUT BACK git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1518470 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop/hbase/migration/UpgradeTo96.java | 75 +++++++++++++------ 1 file changed, 52 insertions(+), 23 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/migration/UpgradeTo96.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/migration/UpgradeTo96.java index b3676aa9a84..40c2d8bf2b6 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/migration/UpgradeTo96.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/migration/UpgradeTo96.java @@ -30,10 +30,15 @@ import org.apache.commons.cli.ParseException; 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 Configured implements Tool { + "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 Configured implements Tool { 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: + * + * @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 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; + 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 upgradeZnodes() throws Exception { - LOG.info("Upgrading Znodes"); + /** + * 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; + } 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; } }