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