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.lang.StringUtils;
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.apache.hadoop.hbase.classification.InterfaceAudience;
26 import org.apache.hadoop.hbase.classification.InterfaceStability;
27 import org.apache.hadoop.conf.Configuration;
28 import org.apache.hadoop.fs.Path;
29 import org.apache.hadoop.hbase.HBaseConfiguration;
30 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
31 import org.apache.hadoop.hbase.util.FSUtils;
32 import org.apache.hadoop.hbase.util.HBaseFsck;
33 import org.apache.hadoop.io.MultipleIOException;
34
35
36
37
38
39
40
41
42
43
44
45
46 @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.TOOLS)
47 @InterfaceStability.Evolving
48 public class OfflineMetaRepair {
49 private static final Log LOG = LogFactory.getLog(OfflineMetaRepair.class.getName());
50
51 protected static void printUsageAndExit() {
52 StringBuilder sb = new StringBuilder();
53 sb.append("Usage: OfflineMetaRepair [opts]\n").
54 append(" where [opts] are:\n").
55 append(" -details Display full report of all regions.\n").
56 append(" -base <hdfs://> Base Hbase Data directory.\n").
57 append(" -sidelineDir <hdfs://> HDFS path to backup existing meta and root.\n").
58 append(" -fix Auto fix as many problems as possible.\n").
59 append(" -fixHoles Auto fix as region holes.");
60 System.err.println(sb.toString());
61 Runtime.getRuntime().exit(-2);
62 }
63
64
65
66
67
68
69
70 public static void main(String[] args) throws Exception {
71
72
73 Configuration conf = HBaseConfiguration.create();
74
75
76 FSUtils.setFsDefault(conf, FSUtils.getRootDir(conf));
77 HBaseFsck fsck = new HBaseFsck(conf);
78 boolean fixHoles = false;
79
80
81 for (int i = 0; i < args.length; i++) {
82 String cmd = args[i];
83 if (cmd.equals("-details")) {
84 fsck.setDisplayFullReport();
85 } else if (cmd.equals("-base")) {
86 if (i == args.length - 1) {
87 System.err.println("OfflineMetaRepair: -base needs an HDFS path.");
88 printUsageAndExit();
89 }
90
91 i++;
92 FSUtils.setRootDir(conf, new Path(args[i]));
93 FSUtils.setFsDefault(conf, FSUtils.getRootDir(conf));
94 } else if (cmd.equals("-sidelineDir")) {
95 if (i == args.length - 1) {
96 System.err.println("OfflineMetaRepair: -sidelineDir needs an HDFS path.");
97 printUsageAndExit();
98 }
99
100 i++;
101 fsck.setSidelineDir(args[i]);
102 } else if (cmd.equals("-fixHoles")) {
103 fixHoles = true;
104 } else if (cmd.equals("-fix")) {
105
106 fixHoles = true;
107 } else {
108 String str = "Unknown command line option : " + cmd;
109 LOG.info(str);
110 System.out.println(str);
111 printUsageAndExit();
112 }
113 }
114
115 System.out.println("OfflineMetaRepair command line options: " + StringUtils.join(args, " "));
116
117
118
119 boolean success = false;
120 try {
121 success = fsck.rebuildMeta(fixHoles);
122 } catch (MultipleIOException mioes) {
123 for (IOException ioe : mioes.getExceptions()) {
124 LOG.error("Bailed out due to:", ioe);
125 }
126 } catch (Exception e) {
127 LOG.error("Bailed out due to: ", e);
128 } finally {
129 System.exit(success ? 0 : 1);
130 }
131 }
132 }