Search in sources :

Example 1 with CoprocessorRpcChannel

use of org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel in project hbase by apache.

the class MetaTableAccessor method multiMutate.

/**
   * Performs an atomic multi-mutate operation against the given table.
   */
// Used by the RSGroup Coprocessor Endpoint. It had a copy/paste of the below. Need to reveal
// this facility for CPEP use or at least those CPEPs that are on their way to becoming part of
// core as is the intent for RSGroup eventually.
public static void multiMutate(Connection connection, final Table table, byte[] row, final List<Mutation> mutations) throws IOException {
    if (METALOG.isDebugEnabled()) {
        METALOG.debug(mutationsToString(mutations));
    }
    // TODO: Need rollback!!!!
    // TODO: Need Retry!!!
    // TODO: What for a timeout? Default write timeout? GET FROM HTABLE?
    // TODO: Review when we come through with ProcedureV2.
    RegionServerCallable<MutateRowsResponse, MultiRowMutationProtos.MultiRowMutationService.BlockingInterface> callable = new RegionServerCallable<MutateRowsResponse, MultiRowMutationProtos.MultiRowMutationService.BlockingInterface>(connection, table.getName(), row, null) {

        /*RpcController not used in this CPEP!*/
        @Override
        protected MutateRowsResponse rpcCall() throws Exception {
            final MutateRowsRequest.Builder builder = MutateRowsRequest.newBuilder();
            for (Mutation mutation : mutations) {
                if (mutation instanceof Put) {
                    builder.addMutationRequest(ProtobufUtil.toMutation(ClientProtos.MutationProto.MutationType.PUT, mutation));
                } else if (mutation instanceof Delete) {
                    builder.addMutationRequest(ProtobufUtil.toMutation(ClientProtos.MutationProto.MutationType.DELETE, mutation));
                } else {
                    throw new DoNotRetryIOException("multi in MetaEditor doesn't support " + mutation.getClass().getName());
                }
            }
            // The call to #prepare that ran before this invocation will have populated HRegionLocation.
            HRegionLocation hrl = getLocation();
            RegionSpecifier region = ProtobufUtil.buildRegionSpecifier(RegionSpecifierType.REGION_NAME, hrl.getRegionInfo().getRegionName());
            builder.setRegion(region);
            // that makes com.google.protobuf.RpcController and then copy into it configs.
            return getStub().mutateRows(null, builder.build());
        }

        @Override
        protected // Called on the end of the super.prepare call. Set the stub.
        void setStubByServiceName(ServerName serviceName) throws /*Ignored*/
        IOException {
            CoprocessorRpcChannel channel = table.coprocessorService(getRow());
            setStub(MultiRowMutationProtos.MultiRowMutationService.newBlockingStub(channel));
        }
    };
    int writeTimeout = connection.getConfiguration().getInt(HConstants.HBASE_RPC_WRITE_TIMEOUT_KEY, connection.getConfiguration().getInt(HConstants.HBASE_RPC_TIMEOUT_KEY, HConstants.DEFAULT_HBASE_RPC_TIMEOUT));
    // The region location should be cached in connection. Call prepare so this callable picks
    // up the region location (see super.prepare method).
    callable.prepare(false);
    callable.call(writeTimeout);
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) CoprocessorRpcChannel(org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel) MultiRowMutationProtos(org.apache.hadoop.hbase.protobuf.generated.MultiRowMutationProtos) Put(org.apache.hadoop.hbase.client.Put) RegionSpecifier(org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionSpecifier) RegionServerCallable(org.apache.hadoop.hbase.client.RegionServerCallable) MutateRowsResponse(org.apache.hadoop.hbase.protobuf.generated.MultiRowMutationProtos.MutateRowsResponse) MutateRowsRequest(org.apache.hadoop.hbase.protobuf.generated.MultiRowMutationProtos.MutateRowsRequest) Mutation(org.apache.hadoop.hbase.client.Mutation)

Example 2 with CoprocessorRpcChannel

use of org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel in project hbase by apache.

the class TestRowProcessorEndpoint method testTimeout.

@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);
}
Also used : 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) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with CoprocessorRpcChannel

use of org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel in project hbase by apache.

the class TestRowProcessorEndpoint method swapRows.

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);
}
Also used : 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)

Example 4 with CoprocessorRpcChannel

use of org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel in project hbase by apache.

the class SecureBulkLoadEndpointClient method bulkLoadHFiles.

public boolean bulkLoadHFiles(final List<Pair<byte[], String>> familyPaths, final Token<?> userToken, final String bulkToken, final byte[] startRow) throws IOException {
    // HTable#coprocessorService methods that take start and end rowkeys; see HBASE-9639
    try {
        CoprocessorRpcChannel channel = table.coprocessorService(startRow);
        SecureBulkLoadProtos.SecureBulkLoadService instance = ProtobufUtil.newServiceStub(SecureBulkLoadProtos.SecureBulkLoadService.class, channel);
        DelegationToken protoDT = DelegationToken.newBuilder().build();
        if (userToken != null) {
            protoDT = DelegationToken.newBuilder().setIdentifier(ByteStringer.wrap(userToken.getIdentifier())).setPassword(ByteStringer.wrap(userToken.getPassword())).setKind(userToken.getKind().toString()).setService(userToken.getService().toString()).build();
        }
        List<ClientProtos.BulkLoadHFileRequest.FamilyPath> protoFamilyPaths = new ArrayList<>(familyPaths.size());
        for (Pair<byte[], String> el : familyPaths) {
            protoFamilyPaths.add(ClientProtos.BulkLoadHFileRequest.FamilyPath.newBuilder().setFamily(ByteStringer.wrap(el.getFirst())).setPath(el.getSecond()).build());
        }
        SecureBulkLoadProtos.SecureBulkLoadHFilesRequest request = SecureBulkLoadProtos.SecureBulkLoadHFilesRequest.newBuilder().setFsToken(protoDT).addAllFamilyPath(protoFamilyPaths).setBulkToken(bulkToken).build();
        ServerRpcController controller = new ServerRpcController();
        CoprocessorRpcUtils.BlockingRpcCallback<SecureBulkLoadProtos.SecureBulkLoadHFilesResponse> rpcCallback = new CoprocessorRpcUtils.BlockingRpcCallback<>();
        instance.secureBulkLoadHFiles(controller, request, rpcCallback);
        SecureBulkLoadProtos.SecureBulkLoadHFilesResponse response = rpcCallback.get();
        if (controller.failedOnException()) {
            throw controller.getFailedOn();
        }
        return response.getLoaded();
    } catch (Throwable throwable) {
        throw new IOException(throwable);
    }
}
Also used : CoprocessorRpcChannel(org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel) DelegationToken(org.apache.hadoop.hbase.protobuf.generated.ClientProtos.DelegationToken) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ServerRpcController(org.apache.hadoop.hbase.ipc.ServerRpcController) SecureBulkLoadProtos(org.apache.hadoop.hbase.protobuf.generated.SecureBulkLoadProtos) CoprocessorRpcUtils(org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils) ClientProtos(org.apache.hadoop.hbase.protobuf.generated.ClientProtos)

Example 5 with CoprocessorRpcChannel

use of org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel 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)

Aggregations

CoprocessorRpcChannel (org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel)18 ServiceException (com.google.protobuf.ServiceException)5 Table (org.apache.hadoop.hbase.client.Table)5 Test (org.junit.Test)5 IOException (java.io.IOException)4 Mutation (org.apache.hadoop.hbase.client.Mutation)4 MutateRowsRequest (org.apache.hadoop.hbase.protobuf.generated.MultiRowMutationProtos.MutateRowsRequest)4 ProcessRequest (org.apache.hadoop.hbase.protobuf.generated.RowProcessorProtos.ProcessRequest)4 RowProcessorService (org.apache.hadoop.hbase.protobuf.generated.RowProcessorProtos.RowProcessorService)4 Put (org.apache.hadoop.hbase.client.Put)3 CoprocessorRpcUtils (org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils)3 ServerRpcController (org.apache.hadoop.hbase.ipc.ServerRpcController)3 MultiRowMutationService (org.apache.hadoop.hbase.protobuf.generated.MultiRowMutationProtos.MultiRowMutationService)3 SecureBulkLoadProtos (org.apache.hadoop.hbase.protobuf.generated.SecureBulkLoadProtos)3 ArrayList (java.util.ArrayList)2 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)2 TableName (org.apache.hadoop.hbase.TableName)2 Admin (org.apache.hadoop.hbase.client.Admin)2 Connection (org.apache.hadoop.hbase.client.Connection)2 Delete (org.apache.hadoop.hbase.client.Delete)2