/** * Pass a processor to region to process multiple rows atomically. * * The RowProcessor implementations should be the inner classes of your * RowProcessorEndpoint. This way the RowProcessor can be class-loaded with * the Coprocessor endpoint together. * * See {@code TestRowProcessorEndpoint} for example. * * The request contains information for constructing processor * (see {@link #constructRowProcessorFromRequest}. The processor object defines * the read-modify-write procedure. */ @Override public void process(RpcController controller, ProcessRequest request, RpcCallback<ProcessResponse> done) { ProcessResponse resultProto = null; try { RowProcessor<S,T> processor = constructRowProcessorFromRequest(request); Region region = env.getRegion(); long nonceGroup = request.hasNonceGroup() ? request.getNonceGroup() : HConstants.NO_NONCE; long nonce = request.hasNonce() ? request.getNonce() : HConstants.NO_NONCE; region.processRowsWithLocks(processor, nonceGroup, nonce); T result = processor.getResult(); ProcessResponse.Builder b = ProcessResponse.newBuilder(); b.setRowProcessorResult(result.toByteString()); resultProto = b.build(); } catch (Exception e) { ResponseConverter.setControllerException(controller, new IOException(e)); } done.run(resultProto); }
@Test public void testDoubleScan() throws Throwable { prepareTestData(); CoprocessorRpcChannel channel = table.coprocessorService(ROW); RowProcessorEndpoint.FriendsOfFriendsProcessor processor = new RowProcessorEndpoint.FriendsOfFriendsProcessor(ROW, A); RowProcessorService.BlockingInterface service = RowProcessorService.newBlockingStub(channel); ProcessRequest request = RowProcessorClient.getRowProcessorPB(processor); ProcessResponse protoResult = service.process(null, request); FriendsOfFriendsProcessorResponse response = FriendsOfFriendsProcessorResponse.parseFrom(protoResult.getRowProcessorResult()); Set<String> result = new HashSet<String>(); result.addAll(response.getResultList()); Set<String> expected = new HashSet<String>(Arrays.asList(new String[]{"d", "e", "f", "g"})); Get get = new Get(ROW); LOG.debug("row keyvalues:" + stringifyKvs(table.get(get).listCells())); assertEquals(expected, result); }
@Test public void testTimeout() throws Throwable { prepareTestData(); CoprocessorRpcChannel channel = table.coprocessorService(ROW); RowProcessorEndpoint.TimeoutProcessor processor = new RowProcessorEndpoint.TimeoutProcessor(ROW); RowProcessorService.BlockingInterface service = RowProcessorService.newBlockingStub(channel); ProcessRequest request = RowProcessorClient.getRowProcessorPB(processor); boolean exceptionCaught = false; try { service.process(null, request); } catch (Exception e) { exceptionCaught = true; } assertTrue(exceptionCaught); }
/** * Pass a processor to HRegion to process multiple rows atomically. * * The RowProcessor implementations should be the inner classes of your * RowProcessorEndpoint. This way the RowProcessor can be class-loaded with * the Coprocessor endpoint together. * * See {@code TestRowProcessorEndpoint} for example. * * The request contains information for constructing processor * (see {@link #constructRowProcessorFromRequest}. The processor object defines * the read-modify-write procedure. */ @Override public void process(RpcController controller, ProcessRequest request, RpcCallback<ProcessResponse> done) { ProcessResponse resultProto = null; try { RowProcessor<S,T> processor = constructRowProcessorFromRequest(request); HRegion region = env.getRegion(); long nonceGroup = request.hasNonceGroup() ? request.getNonceGroup() : HConstants.NO_NONCE; long nonce = request.hasNonce() ? request.getNonce() : HConstants.NO_NONCE; region.processRowsWithLocks(processor, nonceGroup, nonce); T result = processor.getResult(); ProcessResponse.Builder b = ProcessResponse.newBuilder(); b.setRowProcessorResult(result.toByteString()); resultProto = b.build(); } catch (Exception e) { ResponseConverter.setControllerException(controller, new IOException(e)); } done.run(resultProto); }
@Test public void testDoubleScan() throws Throwable { prepareTestData(); CoprocessorRpcChannel channel = table.coprocessorService(ROW); RowProcessorEndpoint.FriendsOfFriendsProcessor processor = new RowProcessorEndpoint.FriendsOfFriendsProcessor(ROW, A); RowProcessorService.BlockingInterface service = RowProcessorService.newBlockingStub(channel); ProcessRequest request = RowProcessorClient.getRowProcessorPB(processor); ProcessResponse protoResult = service.process(null, request); FriendsOfFriendsProcessorResponse response = FriendsOfFriendsProcessorResponse.parseFrom(protoResult.getRowProcessorResult()); Set<String> result = new HashSet<>(); result.addAll(response.getResultList()); Set<String> expected = new HashSet<>(Arrays.asList(new String[]{"d", "e", "f", "g"})); Get get = new Get(ROW); LOG.debug("row keyvalues:" + stringifyKvs(table.get(get).listCells())); assertEquals(expected, result); }
/** * Pass a processor to region to process multiple rows atomically. * * The RowProcessor implementations should be the inner classes of your * RowProcessorEndpoint. This way the RowProcessor can be class-loaded with * the Coprocessor endpoint together. * * See {@code TestRowProcessorEndpoint} for example. * * The request contains information for constructing processor * (see {@link #constructRowProcessorFromRequest}. The processor object defines * the read-modify-write procedure. */ @Override public void process(RpcController controller, ProcessRequest request, RpcCallback<ProcessResponse> done) { ProcessResponse resultProto = null; try { RowProcessor<S,T> processor = constructRowProcessorFromRequest(request); Region region = env.getRegion(); long nonceGroup = request.hasNonceGroup() ? request.getNonceGroup() : HConstants.NO_NONCE; long nonce = request.hasNonce() ? request.getNonce() : HConstants.NO_NONCE; region.processRowsWithLocks(processor, nonceGroup, nonce); T result = processor.getResult(); ProcessResponse.Builder b = ProcessResponse.newBuilder(); b.setRowProcessorResult(result.toByteString()); resultProto = b.build(); } catch (Exception e) { CoprocessorRpcUtils.setControllerException(controller, new IOException(e)); } done.run(resultProto); }
/** * Pass a processor to HRegion to process multiple rows atomically. * * The RowProcessor implementations should be the inner classes of your * RowProcessorEndpoint. This way the RowProcessor can be class-loaded with * the Coprocessor endpoint together. * * See {@code TestRowProcessorEndpoint} for example. * * The request contains information for constructing processor * (see {@link #constructRowProcessorFromRequest}. The processor object defines * the read-modify-write procedure. */ @Override public void process(RpcController controller, ProcessRequest request, RpcCallback<ProcessResponse> done) { ProcessResponse resultProto = null; try { RowProcessor<S,T> processor = constructRowProcessorFromRequest(request); HRegion region = env.getRegion(); region.processRowsWithLocks(processor); T result = processor.getResult(); ProcessResponse.Builder b = ProcessResponse.newBuilder(); b.setRowProcessorResult(result.toByteString()); resultProto = b.build(); } catch (Exception e) { ResponseConverter.setControllerException(controller, new IOException(e)); } done.run(resultProto); }
public static <S extends Message, T extends Message> ProcessRequest getRowProcessorPB(RowProcessor<S,T> r) throws IOException { final ProcessRequest.Builder requestBuilder = ProcessRequest.newBuilder(); requestBuilder.setRowProcessorClassName(r.getClass().getName()); S s = r.getRequestData(); if (s != null) { requestBuilder.setRowProcessorInitializerMessageName(s.getClass().getName()); requestBuilder.setRowProcessorInitializerMessage(s.toByteString()); } return requestBuilder.build(); }
private int incrementCounter(Table table) throws Throwable { CoprocessorRpcChannel channel = table.coprocessorService(ROW); RowProcessorEndpoint.IncrementCounterProcessor processor = new RowProcessorEndpoint.IncrementCounterProcessor(ROW); RowProcessorService.BlockingInterface service = RowProcessorService.newBlockingStub(channel); ProcessRequest request = RowProcessorClient.getRowProcessorPB(processor); ProcessResponse protoResult = service.process(null, request); IncCounterProcessorResponse response = IncCounterProcessorResponse .parseFrom(protoResult.getRowProcessorResult()); Integer result = response.getResponse(); return result; }
private void swapRows(Table table) throws Throwable { CoprocessorRpcChannel channel = table.coprocessorService(ROW); RowProcessorEndpoint.RowSwapProcessor processor = new RowProcessorEndpoint.RowSwapProcessor(ROW, ROW2); RowProcessorService.BlockingInterface service = RowProcessorService.newBlockingStub(channel); ProcessRequest request = RowProcessorClient.getRowProcessorPB(processor); service.process(null, request); }
private int incrementCounter(HTable table) throws Throwable { CoprocessorRpcChannel channel = table.coprocessorService(ROW); RowProcessorEndpoint.IncrementCounterProcessor processor = new RowProcessorEndpoint.IncrementCounterProcessor(ROW); RowProcessorService.BlockingInterface service = RowProcessorService.newBlockingStub(channel); ProcessRequest request = RowProcessorClient.getRowProcessorPB(processor); ProcessResponse protoResult = service.process(null, request); IncCounterProcessorResponse response = IncCounterProcessorResponse .parseFrom(protoResult.getRowProcessorResult()); Integer result = response.getResponse(); return result; }
private void swapRows(HTable table) throws Throwable { CoprocessorRpcChannel channel = table.coprocessorService(ROW); RowProcessorEndpoint.RowSwapProcessor processor = new RowProcessorEndpoint.RowSwapProcessor(ROW, ROW2); RowProcessorService.BlockingInterface service = RowProcessorService.newBlockingStub(channel); ProcessRequest request = RowProcessorClient.getRowProcessorPB(processor); service.process(null, request); }