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