1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.util.hbck;
19
20 import java.io.IOException;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.hbase.HBaseConfiguration;
26 import org.apache.hadoop.hbase.HConstants;
27 import org.apache.hadoop.hbase.util.HBaseFsck;
28 import org.apache.hadoop.io.MultipleIOException;
29
30
31
32
33
34
35
36
37
38
39
40
41 public class OfflineMetaRepair {
42 private static final Log LOG = LogFactory.getLog(HBaseFsck.class.getName());
43 HBaseFsck fsck;
44
45 protected static void printUsageAndExit() {
46 System.err.println("Usage: OfflineMetaRepair [opts] ");
47 System.err.println(" where [opts] are:");
48 System.err
49 .println(" -details Display full report of all regions.");
50 System.err.println(" -base <hdfs://> Base Hbase Data directory");
51 Runtime.getRuntime().exit(-2);
52 }
53
54
55
56
57
58
59
60 public static void main(String[] args) throws Exception {
61
62
63 Configuration conf = HBaseConfiguration.create();
64 conf.set("fs.defaultFS", conf.get(HConstants.HBASE_DIR));
65 HBaseFsck fsck = new HBaseFsck(conf);
66
67
68 for (int i = 0; i < args.length; i++) {
69 String cmd = args[i];
70 if (cmd.equals("-details")) {
71 fsck.displayFullReport();
72 } else if (cmd.equals("-base")) {
73
74 i++;
75 String path = args[i];
76 conf.set(HConstants.HBASE_DIR, path);
77 conf.set("fs.defaultFS", conf.get(HConstants.HBASE_DIR));
78 } else {
79 String str = "Unknown command line option : " + cmd;
80 LOG.info(str);
81 System.out.println(str);
82 printUsageAndExit();
83 }
84 }
85
86
87
88 boolean success = false;
89 try {
90 success = fsck.rebuildMeta();
91 } catch (MultipleIOException mioes) {
92 for (IOException ioe : mioes.getExceptions()) {
93 LOG.error("Bailed out due to:", ioe);
94 }
95 } catch (Exception e) {
96 LOG.error("Bailed out due to: ", e);
97 } finally {
98 System.exit(success ? 0 : 1);
99 }
100 }
101 }