private MultiResponse buildMultiResponse(MultiRequest req) { MultiResponse.Builder builder = MultiResponse.newBuilder(); RegionActionResult.Builder regionActionResultBuilder = RegionActionResult.newBuilder(); ResultOrException.Builder roeBuilder = ResultOrException.newBuilder(); for (RegionAction regionAction: req.getRegionActionList()) { regionActionResultBuilder.clear(); for (ClientProtos.Action action: regionAction.getActionList()) { roeBuilder.clear(); roeBuilder.setResult(ClientProtos.Result.getDefaultInstance()); roeBuilder.setIndex(action.getIndex()); regionActionResultBuilder.addResultOrException(roeBuilder.build()); } builder.addRegionActionResult(regionActionResultBuilder.build()); } return builder.build(); }
static MultiResponse doMultiResponse(final SortedMap<byte [], Pair<HRegionInfo, ServerName>> meta, final AtomicLong sequenceids, final MultiRequest request) { // Make a response to match the request. Act like there were no failures. ClientProtos.MultiResponse.Builder builder = ClientProtos.MultiResponse.newBuilder(); // Per Region. RegionActionResult.Builder regionActionResultBuilder = RegionActionResult.newBuilder(); ResultOrException.Builder roeBuilder = ResultOrException.newBuilder(); for (RegionAction regionAction: request.getRegionActionList()) { regionActionResultBuilder.clear(); // Per Action in a Region. for (ClientProtos.Action action: regionAction.getActionList()) { roeBuilder.clear(); // Return empty Result and proper index as result. roeBuilder.setResult(ClientProtos.Result.getDefaultInstance()); roeBuilder.setIndex(action.getIndex()); regionActionResultBuilder.addResultOrException(roeBuilder.build()); } builder.addRegionActionResult(regionActionResultBuilder.build()); } return builder.build(); }
private boolean isWriteRequest(final RequestHeader header, final Message param) { // TODO: Is there a better way to do this? String methodName = header.getMethodName(); if (methodName.equalsIgnoreCase("multi") && param instanceof MultiRequest) { MultiRequest multi = (MultiRequest)param; for (RegionAction regionAction : multi.getRegionActionList()) { for (Action action: regionAction.getActionList()) { if (action.hasMutation()) { return true; } } } } if (methodName.equalsIgnoreCase("mutate")) { return true; } return false; }
@Test public void testPriority() { Configuration conf = HBaseConfiguration.create(); RSRpcServices rpcServices = Mockito.mock(RSRpcServices.class); when(rpcServices.getConfiguration()).thenReturn(conf); AnnotationReadingPriorityFunction qosFunction = new AnnotationReadingPriorityFunction(rpcServices); // Set method name in pb style with the method name capitalized. checkMethod("ReplicateWALEntry", HConstants.REPLICATION_QOS, qosFunction); // Set method name in pb style with the method name capitalized. checkMethod("OpenRegion", HConstants.ADMIN_QOS, qosFunction); // Check multi works. checkMethod("Multi", HConstants.NORMAL_QOS, qosFunction, MultiRequest.getDefaultInstance()); }
/** * {@inheritDoc} */ @Override public void mutateRow(final RowMutations rm) throws IOException { RegionServerCallable<Void> callable = new RegionServerCallable<Void>(connection, getName(), rm.getRow()) { @Override public Void call(int callTimeout) throws IOException { PayloadCarryingRpcController controller = rpcControllerFactory.newController(); controller.setPriority(tableName); controller.setCallTimeout(callTimeout); try { RegionAction.Builder regionMutationBuilder = RequestConverter.buildRegionAction( getLocation().getRegionInfo().getRegionName(), rm); regionMutationBuilder.setAtomic(true); MultiRequest request = MultiRequest.newBuilder().addRegionAction(regionMutationBuilder.build()).build(); getStub().multi(controller, request); } catch (ServiceException se) { throw ProtobufUtil.getRemoteException(se); } return null; } }; rpcCallerFactory.<Void> newCaller().callWithRetries(callable, this.operationTimeout); }
/** * {@inheritDoc} */ @Override public boolean checkAndMutate(final byte [] row, final byte [] family, final byte [] qualifier, final CompareOp compareOp, final byte [] value, final RowMutations rm) throws IOException { RegionServerCallable<Boolean> callable = new RegionServerCallable<Boolean>(connection, getName(), row) { @Override public Boolean call(int callTimeout) throws IOException { PayloadCarryingRpcController controller = rpcControllerFactory.newController(); controller.setPriority(tableName); controller.setCallTimeout(callTimeout); try { CompareType compareType = CompareType.valueOf(compareOp.name()); MultiRequest request = RequestConverter.buildMutateRequest( getLocation().getRegionInfo().getRegionName(), row, family, qualifier, new BinaryComparator(value), compareType, rm); ClientProtos.MultiResponse response = getStub().multi(controller, request); return Boolean.valueOf(response.getProcessed()); } catch (ServiceException se) { throw ProtobufUtil.getRemoteException(se); } } }; return rpcCallerFactory.<Boolean> newCaller().callWithRetries(callable, this.operationTimeout); }
/** * {@inheritDoc} */ @Override public void mutateRow(final RowMutations rm) throws IOException { RegionServerCallable<Void> callable = new RegionServerCallable<Void>(connection, getName(), rm.getRow()) { public Void call() throws IOException { try { RegionAction.Builder regionMutationBuilder = RequestConverter.buildRegionAction( getLocation().getRegionInfo().getRegionName(), rm); regionMutationBuilder.setAtomic(true); MultiRequest request = MultiRequest.newBuilder().addRegionAction(regionMutationBuilder.build()).build(); PayloadCarryingRpcController pcrc = rpcControllerFactory.newController(); pcrc.setPriority(tableName); getStub().multi(pcrc, request); } catch (ServiceException se) { throw ProtobufUtil.getRemoteException(se); } return null; } }; rpcCallerFactory.<Void> newCaller().callWithRetries(callable, this.operationTimeout); }
@Test public void testPriority() { Configuration conf = HBaseConfiguration.create(); RSRpcServices rpcServices = Mockito.mock(RSRpcServices.class); when(rpcServices.getConfiguration()).thenReturn(conf); AnnotationReadingPriorityFunction qosFunction = new AnnotationReadingPriorityFunction(rpcServices); // Set method name in pb style with the method name capitalized. checkMethod("ReplicateWALEntry", HConstants.REPLICATION_QOS, qosFunction); // Set method name in pb style with the method name capitalized. checkMethod("OpenRegion", HConstants.HIGH_QOS, qosFunction); // Check multi works. checkMethod("Multi", HConstants.NORMAL_QOS, qosFunction, MultiRequest.getDefaultInstance()); }
/** * {@inheritDoc} */ @Override public void mutateRow(final RowMutations rm) throws IOException { RegionServerCallable<Void> callable = new RegionServerCallable<Void>(connection, getName(), rm.getRow()) { public Void call(int callTimeout) throws IOException { PayloadCarryingRpcController controller = rpcControllerFactory.newController(); controller.setPriority(tableName); controller.setCallTimeout(callTimeout); try { RegionAction.Builder regionMutationBuilder = RequestConverter.buildRegionAction( getLocation().getRegionInfo().getRegionName(), rm); regionMutationBuilder.setAtomic(true); MultiRequest request = MultiRequest.newBuilder().addRegionAction(regionMutationBuilder.build()).build(); getStub().multi(controller, request); } catch (ServiceException se) { throw ProtobufUtil.getRemoteException(se); } return null; } }; rpcCallerFactory.<Void> newCaller().callWithRetries(callable, this.operationTimeout); }
/** * {@inheritDoc} */ @Override public void mutateRow(final RowMutations rm) throws IOException { RegionServerCallable<Void> callable = new RegionServerCallable<Void>(connection, getName(), rm.getRow()) { public Void call() throws IOException { try { RegionAction.Builder regionMutationBuilder = RequestConverter.buildRegionAction( getLocation().getRegionInfo().getRegionName(), rm); regionMutationBuilder.setAtomic(true); MultiRequest request = MultiRequest.newBuilder().addRegionAction(regionMutationBuilder.build()).build(); PayloadCarryingRpcController pcrc = new PayloadCarryingRpcController(); pcrc.setPriority(tableName); getStub().multi(null, request); } catch (ServiceException se) { throw ProtobufUtil.getRemoteException(se); } return null; } }; rpcCallerFactory.<Void> newCaller().callWithRetries(callable, this.operationTimeout); }
/** * Create a protocol buffer MultiRequest for a row mutations * * @param regionName * @param rowMutations * @return a multi request * @throws IOException */ public static MultiRequest buildMultiRequest(final byte[] regionName, final RowMutations rowMutations) throws IOException { MultiRequest.Builder builder = MultiRequest.newBuilder(); RegionSpecifier region = buildRegionSpecifier( RegionSpecifierType.REGION_NAME, regionName); builder.setRegion(region); builder.setAtomic(true); for (Mutation mutation: rowMutations.getMutations()) { MutateType mutateType = null; if (mutation instanceof Put) { mutateType = MutateType.PUT; } else if (mutation instanceof Delete) { mutateType = MutateType.DELETE; } else { throw new DoNotRetryIOException( "RowMutations supports only put and delete, not " + mutation.getClass().getName()); } Mutate mutate = ProtobufUtil.toMutate(mutateType, mutation); builder.addAction(MultiAction.newBuilder().setMutate(mutate).build()); } return builder.build(); }
/** * {@inheritDoc} */ @Override public void mutateRow(final RowMutations rm) throws IOException { new ServerCallable<Void>(connection, tableName, rm.getRow(), operationTimeout) { public Void call() throws IOException { try { MultiRequest request = RequestConverter.buildMultiRequest( location.getRegionInfo().getRegionName(), rm); server.multi(null, request); } catch (ServiceException se) { throw ProtobufUtil.getRemoteException(se); } return null; } }.withRetries(); }
private boolean isWriteRequest(final RequestHeader header, final Message param) { // TODO: Is there a better way to do this? if (param instanceof MultiRequest) { MultiRequest multi = (MultiRequest)param; for (RegionAction regionAction : multi.getRegionActionList()) { for (Action action: regionAction.getActionList()) { if (action.hasMutation()) { return true; } } } } if (param instanceof MutateRequest) { return true; } // Below here are methods for master. It's a pretty brittle version of this. // Not sure that master actually needs a read/write queue since 90% of requests to // master are writing to status or changing the meta table. // All other read requests are admin generated and can be processed whenever. // However changing that would require a pretty drastic change and should be done for // the next major release and not as a fix for HBASE-14239 if (param instanceof RegionServerStatusProtos.ReportRegionStateTransitionRequest) { return true; } if (param instanceof RegionServerStatusProtos.RegionServerStartupRequest) { return true; } if (param instanceof RegionServerStatusProtos.RegionServerReportRequest) { return true; } return false; }
@Test public void testPriority() { // Set method name in pb style with the method name capitalized. checkMethod(conf, "ReplicateWALEntry", HConstants.REPLICATION_QOS, qosFunction); // Set method name in pb style with the method name capitalized. checkMethod(conf, "OpenRegion", HConstants.ADMIN_QOS, qosFunction); // Check multi works. checkMethod(conf, "Multi", HConstants.NORMAL_QOS, qosFunction, MultiRequest.getDefaultInstance()); }
/** * {@inheritDoc} */ @Override public void mutateRow(final RowMutations rm) throws IOException { RegionServerCallable<Void> callable = new RegionServerCallable<Void>(connection, getName(), rm.getRow()) { @Override public Void call(int callTimeout) throws IOException { PayloadCarryingRpcController controller = rpcControllerFactory.newController(); controller.setPriority(tableName); controller.setCallTimeout(callTimeout); try { RegionAction.Builder regionMutationBuilder = RequestConverter.buildRegionAction( getLocation().getRegionInfo().getRegionName(), rm); regionMutationBuilder.setAtomic(true); MultiRequest request = MultiRequest.newBuilder().addRegionAction(regionMutationBuilder.build()).build(); ClientProtos.MultiResponse response = getStub().multi(controller, request); ClientProtos.RegionActionResult res = response.getRegionActionResultList().get(0); if (res.hasException()) { Throwable ex = ProtobufUtil.toException(res.getException()); if(ex instanceof IOException) { throw (IOException)ex; } throw new IOException("Failed to mutate row: "+Bytes.toStringBinary(rm.getRow()), ex); } } catch (ServiceException se) { throw ProtobufUtil.getRemoteException(se); } return null; } }; rpcCallerFactory.<Void> newCaller().callWithRetries(callable, this.operationTimeout); }
/** * {@inheritDoc} */ @Override public boolean checkAndMutate(final byte [] row, final byte [] family, final byte [] qualifier, final CompareOp compareOp, final byte [] value, final RowMutations rm) throws IOException { RegionServerCallable<Boolean> callable = new RegionServerCallable<Boolean>(connection, getName(), row) { @Override public Boolean call(int callTimeout) throws IOException { PayloadCarryingRpcController controller = rpcControllerFactory.newController(); controller.setPriority(tableName); controller.setCallTimeout(callTimeout); try { CompareType compareType = CompareType.valueOf(compareOp.name()); MultiRequest request = RequestConverter.buildMutateRequest( getLocation().getRegionInfo().getRegionName(), row, family, qualifier, new BinaryComparator(value), compareType, rm); ClientProtos.MultiResponse response = getStub().multi(controller, request); ClientProtos.RegionActionResult res = response.getRegionActionResultList().get(0); if (res.hasException()) { Throwable ex = ProtobufUtil.toException(res.getException()); if(ex instanceof IOException) { throw (IOException)ex; } throw new IOException("Failed to checkAndMutate row: "+ Bytes.toStringBinary(rm.getRow()), ex); } return Boolean.valueOf(response.getProcessed()); } catch (ServiceException se) { throw ProtobufUtil.getRemoteException(se); } } }; return rpcCallerFactory.<Boolean> newCaller().callWithRetries(callable, this.operationTimeout); }
@Override public MultiResponse multi(RpcController controller, MultiRequest request) throws ServiceException { int concurrentInvocations = this.multiInvocationsCount.incrementAndGet(); try { if (concurrentInvocations >= tooManyMultiRequests) { throw new ServiceException(new RegionTooBusyException("concurrentInvocations=" + concurrentInvocations)); } Threads.sleep(multiPause); return doMultiResponse(meta, sequenceids, request); } finally { this.multiInvocationsCount.decrementAndGet(); } }
@Test public void testPriority() { HRegionServer hrs = Mockito.mock(HRegionServer.class); AnnotationReadingPriorityFunction qosFunction = new AnnotationReadingPriorityFunction(hrs); // Set method name in pb style with the method name capitalized. checkMethod("ReplicateWALEntry", HConstants.REPLICATION_QOS, qosFunction); // Set method name in pb style with the method name capitalized. checkMethod("OpenRegion", HConstants.HIGH_QOS, qosFunction); // Check multi works. checkMethod("Multi", HConstants.NORMAL_QOS, qosFunction, MultiRequest.getDefaultInstance()); }
/** * Create a protocol buffer multi request for a list of actions. * RowMutations in the list (if any) will be ignored. * * @param regionName * @param actions * @return a multi request * @throws IOException */ public static <R> MultiRequest buildMultiRequest(final byte[] regionName, final List<Action<R>> actions) throws IOException { MultiRequest.Builder builder = MultiRequest.newBuilder(); RegionSpecifier region = buildRegionSpecifier( RegionSpecifierType.REGION_NAME, regionName); builder.setRegion(region); for (Action<R> action: actions) { MultiAction.Builder protoAction = MultiAction.newBuilder(); Row row = action.getAction(); if (row instanceof Get) { protoAction.setGet(ProtobufUtil.toGet((Get)row)); } else if (row instanceof Put) { protoAction.setMutate(ProtobufUtil.toMutate(MutateType.PUT, (Put)row)); } else if (row instanceof Delete) { protoAction.setMutate(ProtobufUtil.toMutate(MutateType.DELETE, (Delete)row)); } else if (row instanceof Append) { protoAction.setMutate(ProtobufUtil.toMutate(MutateType.APPEND, (Append)row)); } else if (row instanceof Increment) { protoAction.setMutate(ProtobufUtil.toMutate((Increment)row)); } else if (row instanceof RowMutations) { continue; // ignore RowMutations } else { throw new DoNotRetryIOException( "multi doesn't support " + row.getClass().getName()); } builder.addAction(protoAction.build()); } return builder.build(); }
@Override public org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MultiResponse multi( RpcController controller, MultiRequest request) throws ServiceException { // TODO Auto-generated method stub return null; }
/** * Get the results from a protocol buffer MultiResponse * * @param request the protocol buffer MultiResponse to convert * @param cells Cells to go with the passed in <code>proto</code>. Can be null. * @return the results that were in the MultiResponse (a Result or an Exception). * @throws IOException */ public static org.apache.hadoop.hbase.client.MultiResponse getResults(final MultiRequest request, final MultiResponse response, final CellScanner cells) throws IOException { int requestRegionActionCount = request.getRegionActionCount(); int responseRegionActionResultCount = response.getRegionActionResultCount(); if (requestRegionActionCount != responseRegionActionResultCount) { throw new IllegalStateException("Request mutation count=" + responseRegionActionResultCount + " does not match response mutation result count=" + responseRegionActionResultCount); } org.apache.hadoop.hbase.client.MultiResponse results = new org.apache.hadoop.hbase.client.MultiResponse(); for (int i = 0; i < responseRegionActionResultCount; i++) { RegionAction actions = request.getRegionAction(i); RegionActionResult actionResult = response.getRegionActionResult(i); HBaseProtos.RegionSpecifier rs = actions.getRegion(); if (rs.hasType() && (rs.getType() != HBaseProtos.RegionSpecifier.RegionSpecifierType.REGION_NAME)){ throw new IllegalArgumentException( "We support only encoded types for protobuf multi response."); } byte[] regionName = rs.getValue().toByteArray(); if (actionResult.hasException()) { Throwable regionException = ProtobufUtil.toException(actionResult.getException()); results.addException(regionName, regionException); continue; } if (actions.getActionCount() != actionResult.getResultOrExceptionCount()) { throw new IllegalStateException("actions.getActionCount=" + actions.getActionCount() + ", actionResult.getResultOrExceptionCount=" + actionResult.getResultOrExceptionCount() + " for region " + actions.getRegion()); } for (ResultOrException roe : actionResult.getResultOrExceptionList()) { Object responseValue; if (roe.hasException()) { responseValue = ProtobufUtil.toException(roe.getException()); } else if (roe.hasResult()) { responseValue = ProtobufUtil.toResult(roe.getResult(), cells); // add the load stats, if we got any if (roe.hasLoadStats()) { ((Result) responseValue).addResults(roe.getLoadStats()); } } else if (roe.hasServiceResult()) { responseValue = roe.getServiceResult(); } else { // no result & no exception. Unexpected. throw new IllegalStateException("No result & no exception roe=" + roe + " for region " + actions.getRegion()); } results.add(regionName, roe.getIndex(), responseValue); } } return results; }
@Test public void testStaticMetrics() throws IOException { final byte[] foo = Bytes.toBytes("foo"); final RegionSpecifier region = RegionSpecifier.newBuilder() .setValue(ByteString.EMPTY) .setType(RegionSpecifierType.REGION_NAME) .build(); final int loop = 5; for (int i = 0; i < loop; i++) { METRICS.updateRpc( ClientService.getDescriptor().findMethodByName("Get"), GetRequest.getDefaultInstance(), MetricsConnection.newCallStats()); METRICS.updateRpc( ClientService.getDescriptor().findMethodByName("Scan"), ScanRequest.getDefaultInstance(), MetricsConnection.newCallStats()); METRICS.updateRpc( ClientService.getDescriptor().findMethodByName("Multi"), MultiRequest.getDefaultInstance(), MetricsConnection.newCallStats()); METRICS.updateRpc( ClientService.getDescriptor().findMethodByName("Mutate"), MutateRequest.newBuilder() .setMutation(ProtobufUtil.toMutation(MutationType.APPEND, new Append(foo))) .setRegion(region) .build(), MetricsConnection.newCallStats()); METRICS.updateRpc( ClientService.getDescriptor().findMethodByName("Mutate"), MutateRequest.newBuilder() .setMutation(ProtobufUtil.toMutation(MutationType.DELETE, new Delete(foo))) .setRegion(region) .build(), MetricsConnection.newCallStats()); METRICS.updateRpc( ClientService.getDescriptor().findMethodByName("Mutate"), MutateRequest.newBuilder() .setMutation(ProtobufUtil.toMutation(MutationType.INCREMENT, new Increment(foo))) .setRegion(region) .build(), MetricsConnection.newCallStats()); METRICS.updateRpc( ClientService.getDescriptor().findMethodByName("Mutate"), MutateRequest.newBuilder() .setMutation(ProtobufUtil.toMutation(MutationType.PUT, new Put(foo))) .setRegion(region) .build(), MetricsConnection.newCallStats()); } for (MetricsConnection.CallTracker t : new MetricsConnection.CallTracker[] { METRICS.getTracker, METRICS.scanTracker, METRICS.multiTracker, METRICS.appendTracker, METRICS.deleteTracker, METRICS.incrementTracker, METRICS.putTracker }) { Assert.assertEquals("Failed to invoke callTimer on " + t, loop, t.callTimer.count()); Assert.assertEquals("Failed to invoke reqHist on " + t, loop, t.reqHist.count()); Assert.assertEquals("Failed to invoke respHist on " + t, loop, t.respHist.count()); } }
/** * Get the results from a protocol buffer MultiResponse * * @param request the protocol buffer MultiResponse to convert * @param cells Cells to go with the passed in <code>proto</code>. Can be null. * @return the results that were in the MultiResponse (a Result or an Exception). * @throws IOException */ public static org.apache.hadoop.hbase.client.MultiResponse getResults(final MultiRequest request, final MultiResponse response, final CellScanner cells) throws IOException { int requestRegionActionCount = request.getRegionActionCount(); int responseRegionActionResultCount = response.getRegionActionResultCount(); if (requestRegionActionCount != responseRegionActionResultCount) { throw new IllegalStateException("Request mutation count=" + responseRegionActionResultCount + " does not match response mutation result count=" + responseRegionActionResultCount); } org.apache.hadoop.hbase.client.MultiResponse results = new org.apache.hadoop.hbase.client.MultiResponse(); for (int i = 0; i < responseRegionActionResultCount; i++) { RegionAction actions = request.getRegionAction(i); RegionActionResult actionResult = response.getRegionActionResult(i); HBaseProtos.RegionSpecifier rs = actions.getRegion(); if (rs.hasType() && (rs.getType() != HBaseProtos.RegionSpecifier.RegionSpecifierType.REGION_NAME)){ throw new IllegalArgumentException( "We support only encoded types for protobuf multi response."); } byte[] regionName = rs.getValue().toByteArray(); if (actionResult.hasException()){ Throwable regionException = ProtobufUtil.toException(actionResult.getException()); results.addException(regionName, regionException); continue; } if (actions.getActionCount() != actionResult.getResultOrExceptionCount()) { throw new IllegalStateException("actions.getActionCount=" + actions.getActionCount() + ", actionResult.getResultOrExceptionCount=" + actionResult.getResultOrExceptionCount() + " for region " + actions.getRegion()); } for (ResultOrException roe : actionResult.getResultOrExceptionList()) { if (roe.hasException()) { results.add(regionName, new Pair<Integer, Object>(roe.getIndex(), ProtobufUtil.toException(roe.getException()))); } else if (roe.hasResult()) { results.add(regionName, new Pair<Integer, Object>(roe.getIndex(), ProtobufUtil.toResult(roe.getResult(), cells))); } else if (roe.hasServiceResult()) { results.add(regionName, roe.getIndex(), roe.getServiceResult()); } else { // no result & no exception. Unexpected. throw new IllegalStateException("No result & no exception roe=" + roe + " for region " + actions.getRegion()); } } } return results; }
/** * Get the results from a protocol buffer MultiResponse * * @param request the protocol buffer MultiResponse to convert * @param cells Cells to go with the passed in <code>proto</code>. Can be null. * @return the results that were in the MultiResponse (a Result or an Exception). * @throws IOException */ public static org.apache.hadoop.hbase.client.MultiResponse getResults(final MultiRequest request, final MultiResponse response, final CellScanner cells) throws IOException { int requestRegionActionCount = request.getRegionActionCount(); int responseRegionActionResultCount = response.getRegionActionResultCount(); if (requestRegionActionCount != responseRegionActionResultCount) { throw new IllegalStateException("Request mutation count=" + responseRegionActionResultCount + " does not match response mutation result count=" + responseRegionActionResultCount); } org.apache.hadoop.hbase.client.MultiResponse results = new org.apache.hadoop.hbase.client.MultiResponse(); for (int i = 0; i < responseRegionActionResultCount; i++) { RegionAction actions = request.getRegionAction(i); RegionActionResult actionResult = response.getRegionActionResult(i); HBaseProtos.RegionSpecifier rs = actions.getRegion(); if (rs.hasType() && (rs.getType() != HBaseProtos.RegionSpecifier.RegionSpecifierType.REGION_NAME)){ throw new IllegalArgumentException( "We support only encoded types for protobuf multi response."); } byte[] regionName = rs.getValue().toByteArray(); if (actionResult.hasException()) { Throwable regionException = ProtobufUtil.toException(actionResult.getException()); results.addException(regionName, regionException); continue; } if (actions.getActionCount() != actionResult.getResultOrExceptionCount()) { throw new IllegalStateException("actions.getActionCount=" + actions.getActionCount() + ", actionResult.getResultOrExceptionCount=" + actionResult.getResultOrExceptionCount() + " for region " + actions.getRegion()); } for (ResultOrException roe : actionResult.getResultOrExceptionList()) { if (roe.hasException()) { results.add(regionName, roe.getIndex(), ProtobufUtil.toException(roe.getException())); } else if (roe.hasResult()) { results.add(regionName, roe.getIndex(), ProtobufUtil.toResult(roe.getResult(), cells)); } else if (roe.hasServiceResult()) { results.add(regionName, roe.getIndex(), roe.getServiceResult()); } else { // no result & no exception. Unexpected. throw new IllegalStateException("No result & no exception roe=" + roe + " for region " + actions.getRegion()); } } } return results; }
/** * Get the results from a protocol buffer MultiResponse * * @param request the protocol buffer MultiResponse to convert * @param cells Cells to go with the passed in <code>proto</code>. Can be null. * @return the results that were in the MultiResponse (a Result or an Exception). * @throws IOException */ public static org.apache.hadoop.hbase.client.MultiResponse getResults(final MultiRequest request, final MultiResponse response, final CellScanner cells) throws IOException { int requestRegionActionCount = request.getRegionActionCount(); int responseRegionActionResultCount = response.getRegionActionResultCount(); if (requestRegionActionCount != responseRegionActionResultCount) { throw new IllegalStateException("Request mutation count=" + responseRegionActionResultCount + " does not match response mutation result count=" + responseRegionActionResultCount); } org.apache.hadoop.hbase.client.MultiResponse results = new org.apache.hadoop.hbase.client.MultiResponse(); for (int i = 0; i < responseRegionActionResultCount; i++) { RegionAction actions = request.getRegionAction(i); RegionActionResult actionResult = response.getRegionActionResult(i); HBaseProtos.RegionSpecifier rs = actions.getRegion(); if (rs.hasType() && (rs.getType() != HBaseProtos.RegionSpecifier.RegionSpecifierType.REGION_NAME)){ throw new IllegalArgumentException( "We support only encoded types for protobuf multi response."); } byte[] regionName = rs.getValue().toByteArray(); if (actionResult.hasException()){ Throwable regionException = ProtobufUtil.toException(actionResult.getException()); results.addException(regionName, regionException); continue; } if (actions.getActionCount() != actionResult.getResultOrExceptionCount()) { throw new IllegalStateException("actions.getActionCount=" + actions.getActionCount() + ", actionResult.getResultOrExceptionCount=" + actionResult.getResultOrExceptionCount() + " for region " + actions.getRegion()); } for (ResultOrException roe : actionResult.getResultOrExceptionList()) { if (roe.hasException()) { results.add(regionName, new Pair<Integer, Object>(roe.getIndex(), ProtobufUtil.toException(roe.getException()))); } else if (roe.hasResult()) { results.add(regionName, new Pair<Integer, Object>(roe.getIndex(), ProtobufUtil.toResult(roe.getResult(), cells))); } else { // no result & no exception. Unexpected. throw new IllegalStateException("No result & no exception roe=" + roe + " for region " + actions.getRegion()); } } } return results; }