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