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