1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.util.hbck;
20
21 import java.io.IOException;
22 import java.util.HashMap;
23 import java.util.HashSet;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.Map.Entry;
27 import java.util.Set;
28
29 import org.apache.hadoop.conf.Configuration;
30 import org.apache.hadoop.hbase.classification.InterfaceAudience;
31 import org.apache.hadoop.hbase.client.HConnection;
32 import org.apache.hadoop.hbase.master.cleaner.ReplicationZKNodeCleaner;
33 import org.apache.hadoop.hbase.replication.ReplicationQueueInfo;
34 import org.apache.hadoop.hbase.util.HBaseFsck;
35 import org.apache.hadoop.hbase.util.HBaseFsck.ErrorReporter;
36 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
37
38
39
40
41 @InterfaceAudience.Private
42 public class ReplicationChecker {
43 private final ErrorReporter errorReporter;
44
45 private Map<String, List<String>> undeletedQueueIds = new HashMap<String, List<String>>();
46
47 private Set<String> undeletedHFileRefsQueueIds = new HashSet<>();
48 private final ReplicationZKNodeCleaner cleaner;
49
50 public ReplicationChecker(Configuration conf, ZooKeeperWatcher zkw, HConnection connection,
51 ErrorReporter errorReporter) throws IOException {
52 this.cleaner = new ReplicationZKNodeCleaner(conf, zkw, connection);
53 this.errorReporter = errorReporter;
54 }
55
56 public boolean hasUnDeletedQueues() {
57 return errorReporter.getErrorList().contains(
58 HBaseFsck.ErrorReporter.ERROR_CODE.UNDELETED_REPLICATION_QUEUE);
59 }
60
61 public void checkUnDeletedQueues() throws IOException {
62 undeletedQueueIds = cleaner.getUnDeletedQueues();
63 for (Entry<String, List<String>> replicatorAndQueueIds : undeletedQueueIds.entrySet()) {
64 String replicator = replicatorAndQueueIds.getKey();
65 for (String queueId : replicatorAndQueueIds.getValue()) {
66 ReplicationQueueInfo queueInfo = new ReplicationQueueInfo(queueId);
67 String msg = "Undeleted replication queue for removed peer found: "
68 + String.format("[removedPeerId=%s, replicator=%s, queueId=%s]", queueInfo.getPeerId(),
69 replicator, queueId);
70 errorReporter.reportError(HBaseFsck.ErrorReporter.ERROR_CODE.UNDELETED_REPLICATION_QUEUE,
71 msg);
72 }
73 }
74
75 checkUnDeletedHFileRefsQueues();
76 }
77
78 private void checkUnDeletedHFileRefsQueues() throws IOException {
79 undeletedHFileRefsQueueIds = cleaner.getUnDeletedHFileRefsQueues();
80 if (undeletedHFileRefsQueueIds != null && !undeletedHFileRefsQueueIds.isEmpty()) {
81 String msg = "Undeleted replication hfile-refs queue for removed peer found: "
82 + undeletedHFileRefsQueueIds + " under hfile-refs node";
83 errorReporter
84 .reportError(HBaseFsck.ErrorReporter.ERROR_CODE.UNDELETED_REPLICATION_QUEUE, msg);
85 }
86 }
87
88 public void fixUnDeletedQueues() throws IOException {
89 if (!undeletedQueueIds.isEmpty()) {
90 cleaner.removeQueues(undeletedQueueIds);
91 }
92 fixUnDeletedHFileRefsQueue();
93 }
94
95 private void fixUnDeletedHFileRefsQueue() throws IOException {
96 if (undeletedHFileRefsQueueIds != null && !undeletedHFileRefsQueueIds.isEmpty()) {
97 cleaner.removeHFileRefsQueues(undeletedHFileRefsQueueIds);
98 }
99 }
100 }