View Javadoc

1   /**
2    * Copyright 2010 The Apache Software Foundation
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.hadoop.hbase.client;
17  
18  import org.apache.hadoop.hbase.util.Bytes;
19  
20  import java.io.IOException;
21  import java.util.List;
22  
23  /**
24   * Exception thrown by HTable methods when an attempt to do something (like
25   * commit changes) fails after a bunch of retries.
26   */
27  public class RetriesExhaustedException extends IOException {
28    private static final long serialVersionUID = 1876775844L;
29  
30    public RetriesExhaustedException(final String msg) {
31      super(msg);
32    }
33  
34    /**
35     * Create a new RetriesExhaustedException from the list of prior failures.
36     * @param serverName name of HRegionServer
37     * @param regionName name of region
38     * @param row The row we were pursuing when we ran out of retries
39     * @param numTries The number of tries we made
40     * @param exceptions List of exceptions that failed before giving up
41     */
42    public RetriesExhaustedException(String serverName, final byte [] regionName,
43        final byte []  row, int numTries, List<Throwable> exceptions) {
44      super(getMessage(serverName, regionName, row, numTries, exceptions));
45    }
46  
47    private static String getMessage(String serverName, final byte [] regionName,
48        final byte [] row,
49        int numTries, List<Throwable> exceptions) {
50      StringBuilder buffer = new StringBuilder("Trying to contact region server ");
51      buffer.append(serverName);
52      buffer.append(" for region ");
53      buffer.append(regionName == null? "": Bytes.toStringBinary(regionName));
54      buffer.append(", row '");
55      buffer.append(row == null? "": Bytes.toStringBinary(row));
56      buffer.append("', but failed after ");
57      buffer.append(numTries + 1);
58      buffer.append(" attempts.\nExceptions:\n");
59      for (Throwable t : exceptions) {
60        buffer.append(t.toString());
61        buffer.append("\n");
62      }
63      return buffer.toString();
64    }
65  }