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.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configured; 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.Abortable;
import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HConstants; 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.Bytes;
import org.apache.hadoop.hbase.util.FSUtils;
import org.apache.hadoop.hbase.util.HFileV1Detector; import org.apache.hadoop.hbase.util.HFileV1Detector;
import org.apache.hadoop.hbase.util.ZKDataMigrator; import org.apache.hadoop.hbase.util.ZKDataMigrator;
import org.apache.hadoop.hbase.zookeeper.ZKUtil; 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."); + "Please stop them before upgrade or try after some time.");
throw new IOException("Some HBase processes are still alive, or znodes not expired yet"); throw new IOException("Some HBase processes are still alive, or znodes not expired yet");
} }
return upgradeNamespaceAndZnodes(); return executeUpgrade();
} }
return -1; return -1;
} }
@ -194,35 +199,59 @@ public class UpgradeTo96 extends Configured implements Tool {
return ToolRunner.run(getConf(), new HFileV1Detector(), args); return ToolRunner.run(getConf(), new HFileV1Detector(), args);
} }
private int upgradeNamespaceAndZnodes() throws Exception { /**
int res = upgradeNamespace(); * Executes the upgrade process. It involves:
if (res == 0) return upgradeZnodes();//upgrade znodes only if we succeed in first step. * <ul>
else { * <li> Upgrading Namespace
LOG.warn("Namespace upgrade returned: "+res +", expected 0. Aborting the upgrade"); * <li> Upgrading Znodes
throw new Exception("Unexpected return code from Namespace upgrade"); * <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 { private void executeTool(String toolMessage, Tool tool, String[] args, int expectedResult)
LOG.info("Upgrading Namespace"); throws Exception {
try { LOG.info("Starting " + toolMessage);
int res = ToolRunner.run(getConf(), new NamespaceUpgrade(), new String[] { "--upgrade" }); int res = ToolRunner.run(getConf(), tool, new String[] { "--upgrade" });
LOG.info("Successfully Upgraded NameSpace."); if (res != expectedResult) {
return res; LOG.error(toolMessage + "returned " + res + ", expected " + expectedResult);
} catch (Exception e) { throw new Exception("Unexpected return code from " + toolMessage);
LOG.error("Got exception while upgrading Namespace", e);
throw e;
} }
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 { try {
int res = ToolRunner.run(getConf(), new ZKDataMigrator(), null); for (FileStatus regionServerLogDir : regionServerLogDirs) {
LOG.info("Succesfully upgraded znodes."); // split its log dir, if exists
return res; HLogSplitter.split(rootDir, regionServerLogDir.getPath(), oldLogDir, fs, getConf());
}
LOG.info("Successfully completed Log splitting");
} catch (Exception e) { } catch (Exception e) {
LOG.error("Got exception while upgrading Znodes", e); LOG.error("Got exception while doing Log splitting ", e);
throw e; throw e;
} }
} }