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
26 import java.util.Collection;
27 import java.util.HashMap;
28 import java.util.HashSet;
29 import java.util.List;
30 import java.util.Map;
31 import java.util.Set;
32
33
34
35
36
37
38
39
40
41
42 public class RetriesExhaustedWithDetailsException extends RetriesExhaustedException {
43
44 List<Throwable> exceptions;
45 List<Row> actions;
46 List<HServerAddress> addresses;
47
48 public RetriesExhaustedWithDetailsException(List<Throwable> exceptions,
49 List<Row> actions,
50 List<HServerAddress> addresses) {
51 super("Failed " + exceptions.size() + " action" +
52 pluralize(exceptions) + ": " +
53 getDesc(exceptions,actions,addresses));
54
55 this.exceptions = exceptions;
56 this.actions = actions;
57 this.addresses = addresses;
58 }
59
60 public List<Throwable> getCauses() {
61 return exceptions;
62 }
63
64 public int getNumExceptions() {
65 return exceptions.size();
66 }
67
68 public Throwable getCause(int i) {
69 return exceptions.get(i);
70 }
71
72 public Row getRow(int i) {
73 return actions.get(i);
74 }
75
76 public HServerAddress getAddress(int i) {
77 return addresses.get(i);
78 }
79
80 public boolean mayHaveClusterIssues() {
81 boolean res = false;
82
83
84 for (Throwable t : exceptions) {
85 if ( !(t instanceof DoNotRetryIOException)) {
86 res = true;
87 }
88 }
89 return res;
90 }
91
92
93 public static String pluralize(Collection<?> c) {
94 return pluralize(c.size());
95 }
96
97 public static String pluralize(int c) {
98 return c > 1 ? "s" : "";
99 }
100
101 public static String getDesc(List<Throwable> exceptions,
102 List<Row> actions,
103 List<HServerAddress> addresses) {
104 String s = getDesc(classifyExs(exceptions));
105 s += "servers with issues: ";
106 Set<HServerAddress> uniqAddr = new HashSet<HServerAddress>();
107 uniqAddr.addAll(addresses);
108 for(HServerAddress addr : uniqAddr) {
109 s += addr + ", ";
110 }
111 return s;
112 }
113
114 public static Map<String, Integer> classifyExs(List<Throwable> ths) {
115 Map<String, Integer> cls = new HashMap<String, Integer>();
116 for (Throwable t : ths) {
117 if (t == null) continue;
118 String name = t.getClass().getSimpleName();
119 Integer i = cls.get(name);
120 if (i == null) {
121 i = 0;
122 }
123 i += 1;
124 cls.put(name, i);
125 }
126 return cls;
127 }
128
129 public static String getDesc(Map<String,Integer> classificaton) {
130 String s = "";
131 for (Map.Entry<String, Integer> e : classificaton.entrySet()) {
132 s += e.getKey() + ": " + e.getValue() + " time" +
133 pluralize(e.getValue()) + ", ";
134 }
135 return s;
136 }
137
138 }