Index: src/main/java/org/apache/hadoop/hbase/HConstants.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/HConstants.java (revision 1353063) +++ src/main/java/org/apache/hadoop/hbase/HConstants.java (working copy) @@ -223,6 +223,9 @@ /** Like the previous, but for old logs that are about to be deleted */ public static final String HREGION_OLDLOGDIR_NAME = ".oldlogs"; + /** Used by HBCK to sideline backup data */ + public static final String HBCK_SIDELINEDIR_NAME = ".hbck"; + /** Used to construct the name of the compaction directory during compaction */ public static final String HREGION_COMPACTIONDIR_NAME = "compaction.dir"; @@ -586,7 +589,8 @@ public static final List HBASE_NON_USER_TABLE_DIRS = new ArrayList( Arrays.asList(new String[]{ HREGION_LOGDIR_NAME, HREGION_OLDLOGDIR_NAME, CORRUPT_DIR_NAME, Bytes.toString(META_TABLE_NAME), - Bytes.toString(ROOT_TABLE_NAME), SPLIT_LOGDIR_NAME })); + Bytes.toString(ROOT_TABLE_NAME), SPLIT_LOGDIR_NAME, + HBCK_SIDELINEDIR_NAME })); public static final Pattern CP_HTD_ATTR_KEY_PATTERN = Pattern.compile ("^coprocessor\\$([0-9]+)$", Pattern.CASE_INSENSITIVE); Index: src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java (revision 1353063) +++ src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java (working copy) @@ -176,6 +176,7 @@ private int maxMerge = DEFAULT_MAX_MERGE; // maximum number of overlapping regions to merge private int maxOverlapsToSideline = DEFAULT_OVERLAPS_TO_SIDELINE; // maximum number of overlapping regions to sideline private boolean sidelineBigOverlaps = false; // sideline overlaps with >maxMerge regions + private Path sidelineDir = null; private boolean rerun = false; // if we tried to fix something, rerun hbck private static boolean summary = false; // if we want to print less output @@ -820,7 +821,7 @@ // we can rebuild, move old root and meta out of the way and start LOG.info("HDFS regioninfo's seems good. Sidelining old .META."); - sidelineOldRootAndMeta(); + Path backupDir = sidelineOldRootAndMeta(); LOG.info("Creating new .META."); HRegion meta = createNewRootAndMeta(); @@ -836,6 +837,7 @@ meta.close(); meta.getLog().closeAndDelete(); LOG.info("Success! .META. table rebuilt."); + LOG.info("Old -ROOT- and .META. are moved into " + backupDir); return true; } @@ -859,11 +861,13 @@ } private Path getSidelineDir() throws IOException { - Path hbaseDir = FSUtils.getRootDir(conf); - Path hbckDir = new Path(hbaseDir.getParent(), "hbck"); - Path backupDir = new Path(hbckDir, hbaseDir.getName() + "-" - + startMillis); - return backupDir; + if (sidelineDir == null) { + Path hbaseDir = FSUtils.getRootDir(conf); + Path hbckDir = new Path(hbaseDir, HConstants.HBCK_SIDELINEDIR_NAME); + sidelineDir = new Path(hbckDir, hbaseDir.getName() + "-" + + startMillis); + } + return sidelineDir; } /** @@ -961,8 +965,7 @@ // put current -ROOT- and .META. aside. Path hbaseDir = new Path(conf.get(HConstants.HBASE_DIR)); FileSystem fs = hbaseDir.getFileSystem(conf); - Path backupDir = new Path(hbaseDir.getParent(), hbaseDir.getName() + "-" - + startMillis); + Path backupDir = getSidelineDir(); fs.mkdirs(backupDir); sidelineTable(fs, HConstants.ROOT_TABLE_NAME, hbaseDir, backupDir); @@ -2984,6 +2987,14 @@ timelag = seconds * 1000; // convert to milliseconds } + /** + * + * @param sidelineDir - HDFS path to sideline data + */ + public void setSidelineDir(String sidelineDir) { + this.sidelineDir = new Path(sidelineDir); + } + protected static void printUsageAndExit() { System.err.println("Usage: fsck [opts] {only tables}"); System.err.println(" where [opts] are:"); Index: src/main/java/org/apache/hadoop/hbase/util/hbck/OfflineMetaRepair.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/util/hbck/OfflineMetaRepair.java (revision 1353063) +++ src/main/java/org/apache/hadoop/hbase/util/hbck/OfflineMetaRepair.java (working copy) @@ -42,13 +42,15 @@ private static final Log LOG = LogFactory.getLog(HBaseFsck.class.getName()); protected static void printUsageAndExit() { - System.err.println("Usage: OfflineMetaRepair [opts] "); - System.err.println(" where [opts] are:"); - System.err - .println(" -details Display full report of all regions."); - System.err.println(" -base Base Hbase Data directory"); - System.err.println(" -fix Auto fix as many problems as possible"); - System.err.println(" -fixHoles Auto fix as region holes"); + StringBuilder sb = new StringBuilder(); + sb.append("Usage: OfflineMetaRepair [opts]\n"). + append(" where [opts] are:\n"). + append(" -details Display full report of all regions.\n"). + append(" -base Base Hbase Data directory.\n"). + append(" -sidelineDir HDFS path to backup existing meta and root.\n"). + append(" -fix Auto fix as many problems as possible.\n"). + append(" -fixHoles Auto fix as region holes."); + System.err.println(sb.toString()); Runtime.getRuntime().exit(-2); } @@ -75,12 +77,24 @@ if (cmd.equals("-details")) { fsck.setDisplayFullReport(); } else if (cmd.equals("-base")) { + if (i == args.length - 1) { + System.err.println("OfflineMetaRepair: -base needs an HDFS path."); + printUsageAndExit(); + } // update hbase root dir to user-specified base i++; String path = args[i]; conf.set(HConstants.HBASE_DIR, path); conf.set("fs.defaultFS", conf.get(HConstants.HBASE_DIR)); conf.set("fs.default.name", conf.get(HConstants.HBASE_DIR)); + } else if (cmd.equals("-sidelineDir")) { + if (i == args.length - 1) { + System.err.println("OfflineMetaRepair: -sidelineDir needs an HDFS path."); + printUsageAndExit(); + } + // set the hbck sideline dir to user-specified one + i++; + fsck.setSidelineDir(args[i]); } else if (cmd.equals("-fixHoles")) { fixHoles = true; } else if (cmd.equals("-fix")) {