Creates callbacks to handle a multi-put and adds them to the request. @param request The request for which we must handle the response.
(final MultiAction request)
| 862 | * @param request The request for which we must handle the response. |
| 863 | */ |
| 864 | private void addMultiActionCallbacks(final MultiAction request) { |
| 865 | final class MultiActionCallback implements Callback<Object, Object> { |
| 866 | public Object call(final Object resp) { |
| 867 | if (!(resp instanceof MultiAction.Response)) { |
| 868 | if (resp instanceof BatchableRpc) { // Single-RPC multi-action? |
| 869 | return null; // Yes, nothing to do. See multiActionToSingleAction. |
| 870 | } else if (resp instanceof Exception) { |
| 871 | return handleException((Exception) resp); |
| 872 | } |
| 873 | throw new InvalidResponseException(MultiAction.Response.class, resp); |
| 874 | } |
| 875 | final MultiAction.Response response = (MultiAction.Response) resp; |
| 876 | final ArrayList<BatchableRpc> batch = request.batch(); |
| 877 | final int n = batch.size(); |
| 878 | for (int i = 0; i < n; i++) { |
| 879 | final BatchableRpc rpc = batch.get(i); |
| 880 | final Object r = response.result(i); |
| 881 | if (r instanceof RecoverableException) { |
| 882 | if (r instanceof NotServingRegionException) { |
| 883 | // We need to do NSRE handling here too, as the response might |
| 884 | // have come back successful, but only some parts of the batch |
| 885 | // could have encountered an NSRE. |
| 886 | hbase_client.handleNSRE(rpc, rpc.getRegion().name(), |
| 887 | (NotServingRegionException) r); |
| 888 | } else { |
| 889 | retryEdit(rpc, (RecoverableException) r); |
| 890 | } |
| 891 | } else { |
| 892 | rpc.callback(r); |
| 893 | } |
| 894 | } |
| 895 | // We're successful. If there was a problem, the exception was |
| 896 | // delivered to the specific RPCs that failed, and they will be |
| 897 | // responsible for retrying. |
| 898 | return null; |
| 899 | } |
| 900 | |
| 901 | private Object handleException(final Exception e) { |
| 902 | if (!(e instanceof RecoverableException)) { |
| 903 | |
| 904 | if (e instanceof HBaseException){ |
| 905 | HBaseException ex = (HBaseException)e; |
| 906 | for (final BatchableRpc rpc : request.batch()) { |
| 907 | rpc.callback(ex.make(ex, rpc)); |
| 908 | } |
| 909 | } else{ |
| 910 | for (final BatchableRpc rpc : request.batch()) { |
| 911 | rpc.callback(e); |
| 912 | } |
| 913 | } |
| 914 | |
| 915 | return e; // Can't recover from this error, let it propagate. |
| 916 | } |
| 917 | if (LOG.isDebugEnabled()) { |
| 918 | LOG.debug("Multi-action request failed, retrying each of the " |
| 919 | + request.size() + " RPCs individually.", e); |
| 920 | } |
| 921 | for (final BatchableRpc rpc : request.batch()) { |