1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.hadoop.hbase.client;
22
23 import org.apache.hadoop.hbase.DoNotRetryIOException;
24 import org.apache.hadoop.hbase.HServerAddress;
25 import org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException;
26 import org.apache.hadoop.hbase.util.Addressing;
27
28 import java.util.Collection;
29 import java.util.HashMap;
30 import java.util.HashSet;
31 import java.util.List;
32 import java.util.Map;
33 import java.util.Set;
34
35
36
37
38
39
40
41
42
43
44 @SuppressWarnings("serial")
45 public class RetriesExhaustedWithDetailsException
46 extends RetriesExhaustedException {
47 List<Throwable> exceptions;
48 List<Row> actions;
49 List<String> hostnameAndPort;
50
51 public RetriesExhaustedWithDetailsException(List<Throwable> exceptions,
52 List<Row> actions,
53 List<String> hostnameAndPort) {
54 super("Failed " + exceptions.size() + " action" +
55 pluralize(exceptions) + ": " +
56 getDesc(exceptions, actions, hostnameAndPort));
57
58 this.exceptions = exceptions;
59 this.actions = actions;
60 this.hostnameAndPort = hostnameAndPort;
61 }
62
63 public List<Throwable> getCauses() {
64 return exceptions;
65 }
66
67 public int getNumExceptions() {
68 return exceptions.size();
69 }
70
71 public Throwable getCause(int i) {
72 return exceptions.get(i);
73 }
74
75 public Row getRow(int i) {
76 return actions.get(i);
77 }
78
79 public HServerAddress getAddress(int i) {
80 return new HServerAddress(Addressing.createInetSocketAddressFromHostAndPortStr(getHostnamePort(i)));
81 }
82
83 public String getHostnamePort(final int i) {
84 return this.hostnameAndPort.get(i);
85 }
86
87 public boolean mayHaveClusterIssues() {
88 boolean res = false;
89
90
91 for (Throwable t : exceptions) {
92 if ( !(t instanceof DoNotRetryIOException)) {
93 res = true;
94 }
95 }
96 return res;
97 }
98
99
100 public static String pluralize(Collection<?> c) {
101 return pluralize(c.size());
102 }
103
104 public static String pluralize(int c) {
105 return c > 1 ? "s" : "";
106 }
107
108 public static String getDesc(List<Throwable> exceptions,
109 List<Row> actions,
110 List<String> hostnamePort) {
111 String s = getDesc(classifyExs(exceptions));
112 s += "servers with issues: ";
113 Set<String> uniqAddr = new HashSet<String>();
114 uniqAddr.addAll(hostnamePort);
115 for(String addr : uniqAddr) {
116 s += addr + ", ";
117 }
118 return s;
119 }
120
121 public static Map<String, Integer> classifyExs(List<Throwable> ths) {
122 Map<String, Integer> cls = new HashMap<String, Integer>();
123 for (Throwable t : ths) {
124 if (t == null) continue;
125 String name = "";
126 if (t instanceof DoNotRetryIOException) {
127 name = t.getMessage();
128 } else {
129 name = t.getClass().getSimpleName();
130 }
131 Integer i = cls.get(name);
132 if (i == null) {
133 i = 0;
134 }
135 i += 1;
136 cls.put(name, i);
137 }
138 return cls;
139 }
140
141 public static String getDesc(Map<String,Integer> classificaton) {
142 String s = "";
143 for (Map.Entry<String, Integer> e : classificaton.entrySet()) {
144 s += e.getKey() + ": " + e.getValue() + " time" +
145 pluralize(e.getValue()) + ", ";
146 }
147 return s;
148 }
149
150 }