HBASE-9110 Meta region edits not recovered while migrating to 0.96.0

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1518467 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2013-08-29 04:41:14 +00:00
parent 20728884b2
commit fd407f39d4
1 changed files with 52 additions and 23 deletions

View File

@ -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:
* <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 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;
}
}