Search in sources :

Example 1 with ProcessResponse

use of org.apache.hadoop.hbase.protobuf.generated.RowProcessorProtos.ProcessResponse in project hbase by apache.

the class TestRowProcessorEndpoint method incrementCounter.

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;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RowProcessorService(org.apache.hadoop.hbase.protobuf.generated.RowProcessorProtos.RowProcessorService) CoprocessorRpcChannel(org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel) ProcessRequest(org.apache.hadoop.hbase.protobuf.generated.RowProcessorProtos.ProcessRequest) IncCounterProcessorResponse(org.apache.hadoop.hbase.coprocessor.protobuf.generated.IncrementCounterProcessorTestProtos.IncCounterProcessorResponse) ProcessResponse(org.apache.hadoop.hbase.protobuf.generated.RowProcessorProtos.ProcessResponse)

Example 2 with ProcessResponse

use of org.apache.hadoop.hbase.protobuf.generated.RowProcessorProtos.ProcessResponse in project hbase by apache.

the class TestRowProcessorEndpoint method testDoubleScan.

@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);
}
Also used : CoprocessorRpcChannel(org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel) ProcessRequest(org.apache.hadoop.hbase.protobuf.generated.RowProcessorProtos.ProcessRequest) FriendsOfFriendsProcessorResponse(org.apache.hadoop.hbase.coprocessor.protobuf.generated.IncrementCounterProcessorTestProtos.FriendsOfFriendsProcessorResponse) ProcessResponse(org.apache.hadoop.hbase.protobuf.generated.RowProcessorProtos.ProcessResponse) RowProcessorService(org.apache.hadoop.hbase.protobuf.generated.RowProcessorProtos.RowProcessorService) Get(org.apache.hadoop.hbase.client.Get) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with ProcessResponse

use of org.apache.hadoop.hbase.protobuf.generated.RowProcessorProtos.ProcessResponse in project hbase by apache.

the class BaseRowProcessorEndpoint method process.

/**
   * 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);
}
Also used : Region(org.apache.hadoop.hbase.regionserver.Region) IOException(java.io.IOException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ProcessResponse(org.apache.hadoop.hbase.protobuf.generated.RowProcessorProtos.ProcessResponse)

Aggregations

ProcessResponse (org.apache.hadoop.hbase.protobuf.generated.RowProcessorProtos.ProcessResponse)3 CoprocessorRpcChannel (org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel)2 ProcessRequest (org.apache.hadoop.hbase.protobuf.generated.RowProcessorProtos.ProcessRequest)2 RowProcessorService (org.apache.hadoop.hbase.protobuf.generated.RowProcessorProtos.RowProcessorService)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashSet (java.util.HashSet)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Get (org.apache.hadoop.hbase.client.Get)1 FriendsOfFriendsProcessorResponse (org.apache.hadoop.hbase.coprocessor.protobuf.generated.IncrementCounterProcessorTestProtos.FriendsOfFriendsProcessorResponse)1 IncCounterProcessorResponse (org.apache.hadoop.hbase.coprocessor.protobuf.generated.IncrementCounterProcessorTestProtos.IncCounterProcessorResponse)1 Region (org.apache.hadoop.hbase.regionserver.Region)1 Test (org.junit.Test)1