1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.replication;
20
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24
25 import org.apache.hadoop.hbase.classification.InterfaceAudience;
26 import org.apache.hadoop.hbase.ServerName;
27
28 import java.util.ArrayList;
29 import java.util.Collections;
30 import java.util.List;
31
32
33
34
35
36
37 @InterfaceAudience.Private
38 public class ReplicationQueueInfo {
39 private static final Log LOG = LogFactory.getLog(ReplicationQueueInfo.class);
40
41 private final String peerId;
42 private final String peerClusterZnode;
43 private boolean queueRecovered;
44
45 private List<String> deadRegionServers = new ArrayList<String>();
46
47
48
49
50
51 public ReplicationQueueInfo(String znode) {
52 this.peerClusterZnode = znode;
53 String[] parts = znode.split("-", 2);
54 this.queueRecovered = parts.length != 1;
55 this.peerId = this.queueRecovered ?
56 parts[0] : peerClusterZnode;
57 if (parts.length >= 2) {
58
59 extractDeadServersFromZNodeString(parts[1], this.deadRegionServers);
60 }
61 }
62
63
64
65
66
67
68 private static void
69 extractDeadServersFromZNodeString(String deadServerListStr, List<String> result) {
70
71 if(deadServerListStr == null || result == null || deadServerListStr.isEmpty()) return;
72
73
74 int seenCommaCnt = 0;
75 int startIndex = 0;
76 int len = deadServerListStr.length();
77
78 for (int i = 0; i < len; i++) {
79 switch (deadServerListStr.charAt(i)) {
80 case ',':
81 seenCommaCnt += 1;
82 break;
83 case '-':
84 if(seenCommaCnt>=2) {
85 if (i > startIndex) {
86 String serverName = deadServerListStr.substring(startIndex, i);
87 if(ServerName.isFullServerName(serverName)){
88 result.add(serverName);
89 } else {
90 LOG.error("Found invalid server name:" + serverName);
91 }
92 startIndex = i + 1;
93 }
94 seenCommaCnt = 0;
95 }
96 break;
97 default:
98 break;
99 }
100 }
101
102
103 if(startIndex < len - 1){
104 String serverName = deadServerListStr.substring(startIndex, len);
105 if(ServerName.isFullServerName(serverName)){
106 result.add(serverName);
107 } else {
108 LOG.error("Found invalid server name at the end:" + serverName);
109 }
110 }
111
112 LOG.debug("Found dead servers:" + result);
113 }
114
115 public List<String> getDeadRegionServers() {
116 return Collections.unmodifiableList(this.deadRegionServers);
117 }
118
119 public String getPeerId() {
120 return this.peerId;
121 }
122
123 public String getPeerClusterZnode() {
124 return this.peerClusterZnode;
125 }
126
127 public boolean isQueueRecovered() {
128 return queueRecovered;
129 }
130 }