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 static org.junit.Assert.assertEquals;
21
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.List;
25 import java.util.concurrent.ExecutorService;
26 import java.util.concurrent.ScheduledThreadPoolExecutor;
27
28 import com.google.common.collect.Lists;
29 import org.apache.hadoop.conf.Configuration;
30 import org.apache.hadoop.hbase.TableName;
31 import org.apache.hadoop.hbase.util.HBaseFsck;
32 import org.apache.hadoop.hbase.util.HBaseFsck.ErrorReporter.ERROR_CODE;
33
34 public class HbckTestingUtil {
35 private static ExecutorService exec = new ScheduledThreadPoolExecutor(10);
36 public static HBaseFsck doFsck(
37 Configuration conf, boolean fix) throws Exception {
38 return doFsck(conf, fix, null);
39 }
40
41 public static HBaseFsck doFsck(
42 Configuration conf, boolean fix, TableName table) throws Exception {
43 return doFsck(conf, fix, fix, fix, fix,fix, fix, fix, fix, fix, fix, fix, table);
44 }
45
46 public static HBaseFsck doFsck(Configuration conf, boolean fixAssignments,
47 boolean fixMeta, boolean fixHdfsHoles, boolean fixHdfsOverlaps,
48 boolean fixHdfsOrphans, boolean fixTableOrphans, boolean fixVersionFile,
49 boolean fixReferenceFiles, boolean fixEmptyMetaRegionInfo, boolean fixTableLocks,
50 boolean fixTableZnodes,
51 TableName table) throws Exception {
52 HBaseFsck fsck = new HBaseFsck(conf, exec);
53 fsck.connect();
54 fsck.setDisplayFullReport();
55 fsck.setTimeLag(0);
56 fsck.setFixAssignments(fixAssignments);
57 fsck.setFixMeta(fixMeta);
58 fsck.setFixHdfsHoles(fixHdfsHoles);
59 fsck.setFixHdfsOverlaps(fixHdfsOverlaps);
60 fsck.setFixHdfsOrphans(fixHdfsOrphans);
61 fsck.setFixTableOrphans(fixTableOrphans);
62 fsck.setFixVersionFile(fixVersionFile);
63 fsck.setFixReferenceFiles(fixReferenceFiles);
64 fsck.setFixEmptyMetaCells(fixEmptyMetaRegionInfo);
65 fsck.setFixTableLocks(fixTableLocks);
66 fsck.setFixTableZNodes(fixTableZnodes);
67 if (table != null) {
68 fsck.includeTable(table);
69 }
70 fsck.onlineHbck();
71 return fsck;
72 }
73
74
75
76
77
78
79
80
81 public static HBaseFsck doHFileQuarantine(Configuration conf, TableName table) throws Exception {
82 String[] args = {"-sidelineCorruptHFiles", "-ignorePreCheckPermission", table.getNameAsString()};
83 HBaseFsck hbck = new HBaseFsck(conf, exec);
84 hbck.exec(exec, args);
85 return hbck;
86 }
87
88 public static void assertNoErrors(HBaseFsck fsck) throws Exception {
89 List<ERROR_CODE> errs = fsck.getErrors().getErrorList();
90 assertEquals(new ArrayList<ERROR_CODE>(), errs);
91 }
92
93 public static void assertErrors(HBaseFsck fsck, ERROR_CODE[] expectedErrors) {
94 List<ERROR_CODE> errs = fsck.getErrors().getErrorList();
95 Collections.sort(errs);
96 List<ERROR_CODE> expErrs = Lists.newArrayList(expectedErrors);
97 Collections.sort(expErrs);
98 assertEquals(expErrs, errs);
99 }
100 }