Search in sources :

Example 21 with ServerRpcController

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

the class TestRegionServerCoprocessorEndpoint method testEndpointExceptions.

@Test
public void testEndpointExceptions() throws Exception {
    final ServerName serverName = TEST_UTIL.getHBaseCluster().getRegionServer(0).getServerName();
    final ServerRpcController controller = new ServerRpcController();
    final CoprocessorRpcUtils.BlockingRpcCallback<DummyRegionServerEndpointProtos.DummyResponse> rpcCallback = new CoprocessorRpcUtils.BlockingRpcCallback<>();
    DummyRegionServerEndpointProtos.DummyService service = ProtobufUtil.newServiceStub(DummyRegionServerEndpointProtos.DummyService.class, TEST_UTIL.getAdmin().coprocessorService(serverName));
    service.dummyThrow(controller, DummyRegionServerEndpointProtos.DummyRequest.getDefaultInstance(), rpcCallback);
    assertEquals(null, rpcCallback.get());
    assertTrue(controller.failedOnException());
    assertEquals(WHAT_TO_THROW.getClass().getName().trim(), ((RemoteWithExtrasException) controller.getFailedOn().getCause()).getClassName().trim());
}
Also used : CoprocessorRpcUtils(org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils) DummyResponse(org.apache.hadoop.hbase.coprocessor.protobuf.generated.DummyRegionServerEndpointProtos.DummyResponse) ServerName(org.apache.hadoop.hbase.ServerName) DummyService(org.apache.hadoop.hbase.coprocessor.protobuf.generated.DummyRegionServerEndpointProtos.DummyService) DummyRegionServerEndpointProtos(org.apache.hadoop.hbase.coprocessor.protobuf.generated.DummyRegionServerEndpointProtos) RemoteWithExtrasException(org.apache.hadoop.hbase.ipc.RemoteWithExtrasException) ServerRpcController(org.apache.hadoop.hbase.ipc.ServerRpcController) Test(org.junit.Test)

Example 22 with ServerRpcController

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

the class TestRegionServerCoprocessorEndpoint method testEndpoint.

@Test
public void testEndpoint() throws Exception {
    final ServerName serverName = TEST_UTIL.getHBaseCluster().getRegionServer(0).getServerName();
    final ServerRpcController controller = new ServerRpcController();
    final CoprocessorRpcUtils.BlockingRpcCallback<DummyRegionServerEndpointProtos.DummyResponse> rpcCallback = new CoprocessorRpcUtils.BlockingRpcCallback<>();
    DummyRegionServerEndpointProtos.DummyService service = ProtobufUtil.newServiceStub(DummyRegionServerEndpointProtos.DummyService.class, TEST_UTIL.getAdmin().coprocessorService(serverName));
    service.dummyCall(controller, DummyRegionServerEndpointProtos.DummyRequest.getDefaultInstance(), rpcCallback);
    assertEquals(DUMMY_VALUE, rpcCallback.get().getValue());
    if (controller.failedOnException()) {
        throw controller.getFailedOn();
    }
}
Also used : CoprocessorRpcUtils(org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils) DummyResponse(org.apache.hadoop.hbase.coprocessor.protobuf.generated.DummyRegionServerEndpointProtos.DummyResponse) ServerName(org.apache.hadoop.hbase.ServerName) DummyService(org.apache.hadoop.hbase.coprocessor.protobuf.generated.DummyRegionServerEndpointProtos.DummyService) DummyRegionServerEndpointProtos(org.apache.hadoop.hbase.coprocessor.protobuf.generated.DummyRegionServerEndpointProtos) ServerRpcController(org.apache.hadoop.hbase.ipc.ServerRpcController) Test(org.junit.Test)

Example 23 with ServerRpcController

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

the class HRegionServer method execRegionServerService.

public CoprocessorServiceResponse execRegionServerService(@SuppressWarnings("UnusedParameters") final RpcController controller, final CoprocessorServiceRequest serviceRequest) throws ServiceException {
    try {
        ServerRpcController serviceController = new ServerRpcController();
        CoprocessorServiceCall call = serviceRequest.getCall();
        String serviceName = call.getServiceName();
        com.google.protobuf.Service service = coprocessorServiceHandlers.get(serviceName);
        if (service == null) {
            throw new UnknownProtocolException(null, "No registered coprocessor service found for " + serviceName);
        }
        com.google.protobuf.Descriptors.ServiceDescriptor serviceDesc = service.getDescriptorForType();
        String methodName = call.getMethodName();
        com.google.protobuf.Descriptors.MethodDescriptor methodDesc = serviceDesc.findMethodByName(methodName);
        if (methodDesc == null) {
            throw new UnknownProtocolException(service.getClass(), "Unknown method " + methodName + " called on service " + serviceName);
        }
        com.google.protobuf.Message request = CoprocessorRpcUtils.getRequest(service, methodDesc, call.getRequest());
        final com.google.protobuf.Message.Builder responseBuilder = service.getResponsePrototype(methodDesc).newBuilderForType();
        service.callMethod(methodDesc, serviceController, request, new com.google.protobuf.RpcCallback<com.google.protobuf.Message>() {

            @Override
            public void run(com.google.protobuf.Message message) {
                if (message != null) {
                    responseBuilder.mergeFrom(message);
                }
            }
        });
        IOException exception = CoprocessorRpcUtils.getControllerException(serviceController);
        if (exception != null) {
            throw exception;
        }
        return CoprocessorRpcUtils.getResponse(responseBuilder.build(), HConstants.EMPTY_BYTE_ARRAY);
    } catch (IOException ie) {
        throw new ServiceException(ie);
    }
}
Also used : CoprocessorServiceCall(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.CoprocessorServiceCall) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) ServerRpcController(org.apache.hadoop.hbase.ipc.ServerRpcController) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) UnknownProtocolException(org.apache.hadoop.hbase.exceptions.UnknownProtocolException) TableDescriptors(org.apache.hadoop.hbase.TableDescriptors) FSTableDescriptors(org.apache.hadoop.hbase.util.FSTableDescriptors)

Example 24 with ServerRpcController

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

the class TestFromClientSide3 method testMultiRowMutations.

@Test(timeout = 30000)
public void testMultiRowMutations() throws Exception, Throwable {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    HTableDescriptor desc = new HTableDescriptor(tableName);
    desc.addCoprocessor(MultiRowMutationEndpoint.class.getName());
    desc.addCoprocessor(WatiingForMultiMutationsObserver.class.getName());
    desc.setConfiguration("hbase.rowlock.wait.duration", String.valueOf(5000));
    desc.addFamily(new HColumnDescriptor(FAMILY));
    TEST_UTIL.getAdmin().createTable(desc);
    // new a connection for lower retry number.
    Configuration copy = new Configuration(TEST_UTIL.getConfiguration());
    copy.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2);
    try (Connection con = ConnectionFactory.createConnection(copy)) {
        byte[] row = Bytes.toBytes("ROW-0");
        byte[] rowLocked = Bytes.toBytes("ROW-1");
        byte[] value0 = Bytes.toBytes("VALUE-0");
        byte[] value1 = Bytes.toBytes("VALUE-1");
        byte[] value2 = Bytes.toBytes("VALUE-2");
        assertNoLocks(tableName);
        ExecutorService putService = Executors.newSingleThreadExecutor();
        putService.execute(() -> {
            try (Table table = con.getTable(tableName)) {
                Put put0 = new Put(rowLocked);
                put0.addColumn(FAMILY, QUALIFIER, value0);
                // the put will be blocked by WatiingForMultiMutationsObserver.
                table.put(put0);
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
        });
        ExecutorService cpService = Executors.newSingleThreadExecutor();
        cpService.execute(() -> {
            Put put1 = new Put(row);
            Put put2 = new Put(rowLocked);
            put1.addColumn(FAMILY, QUALIFIER, value1);
            put2.addColumn(FAMILY, QUALIFIER, value2);
            try (Table table = con.getTable(tableName)) {
                MultiRowMutationProtos.MutateRowsRequest request = MultiRowMutationProtos.MutateRowsRequest.newBuilder().addMutationRequest(org.apache.hadoop.hbase.protobuf.ProtobufUtil.toMutation(org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto.MutationType.PUT, put1)).addMutationRequest(org.apache.hadoop.hbase.protobuf.ProtobufUtil.toMutation(org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto.MutationType.PUT, put2)).build();
                table.coprocessorService(MultiRowMutationProtos.MultiRowMutationService.class, ROW, ROW, (MultiRowMutationProtos.MultiRowMutationService exe) -> {
                    ServerRpcController controller = new ServerRpcController();
                    CoprocessorRpcUtils.BlockingRpcCallback<MultiRowMutationProtos.MutateRowsResponse> rpcCallback = new CoprocessorRpcUtils.BlockingRpcCallback<>();
                    exe.mutateRows(controller, request, rpcCallback);
                    return rpcCallback.get();
                });
                fail("This cp should fail because the target lock is blocked by previous put");
            } catch (Throwable ex) {
            }
        });
        cpService.shutdown();
        cpService.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
        WatiingForMultiMutationsObserver observer = find(tableName, WatiingForMultiMutationsObserver.class);
        observer.latch.countDown();
        putService.shutdown();
        putService.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
        try (Table table = con.getTable(tableName)) {
            Get g0 = new Get(row);
            Get g1 = new Get(rowLocked);
            Result r0 = table.get(g0);
            Result r1 = table.get(g1);
            assertTrue(r0.isEmpty());
            assertFalse(r1.isEmpty());
            assertTrue(Bytes.equals(r1.getValue(FAMILY, QUALIFIER), value0));
        }
        assertNoLocks(tableName);
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) MultiRowMutationProtos(org.apache.hadoop.hbase.protobuf.generated.MultiRowMutationProtos) IOException(java.io.IOException) ServerRpcController(org.apache.hadoop.hbase.ipc.ServerRpcController) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) TableName(org.apache.hadoop.hbase.TableName) CoprocessorRpcUtils(org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils) ExecutorService(java.util.concurrent.ExecutorService) MultiRowMutationEndpoint(org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint) Test(org.junit.Test)

Example 25 with ServerRpcController

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

the class VisibilityClient method listLabels.

/**
   * Retrieve the list of visibility labels defined in the system.
   * @param connection The Connection instance to use.
   * @param regex  The regular expression to filter which labels are returned.
   * @return labels The list of visibility labels defined in the system.
   * @throws Throwable
   */
public static ListLabelsResponse listLabels(Connection connection, final String regex) throws Throwable {
    Table table = null;
    try {
        table = connection.getTable(LABELS_TABLE_NAME);
        Batch.Call<VisibilityLabelsService, ListLabelsResponse> callable = new Batch.Call<VisibilityLabelsService, ListLabelsResponse>() {

            ServerRpcController controller = new ServerRpcController();

            CoprocessorRpcUtils.BlockingRpcCallback<ListLabelsResponse> rpcCallback = new CoprocessorRpcUtils.BlockingRpcCallback<>();

            public ListLabelsResponse call(VisibilityLabelsService service) throws IOException {
                ListLabelsRequest.Builder listAuthLabelsReqBuilder = ListLabelsRequest.newBuilder();
                if (regex != null) {
                    // Compile the regex here to catch any regex exception earlier.
                    Pattern pattern = Pattern.compile(regex);
                    listAuthLabelsReqBuilder.setRegex(pattern.toString());
                }
                service.listLabels(controller, listAuthLabelsReqBuilder.build(), rpcCallback);
                ListLabelsResponse response = rpcCallback.get();
                if (controller.failedOnException()) {
                    throw controller.getFailedOn();
                }
                return response;
            }
        };
        Map<byte[], ListLabelsResponse> result = table.coprocessorService(VisibilityLabelsService.class, HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY, callable);
        // There will be exactly one region for labels
        return result.values().iterator().next();
    // table and so one entry in result Map.
    } finally {
        if (table != null) {
            table.close();
        }
        if (connection != null) {
            connection.close();
        }
    }
}
Also used : VisibilityLabelsService(org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsService) Pattern(java.util.regex.Pattern) Table(org.apache.hadoop.hbase.client.Table) ListLabelsRequest(org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest) ListLabelsResponse(org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse) ServerRpcController(org.apache.hadoop.hbase.ipc.ServerRpcController) CoprocessorRpcUtils(org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils) Batch(org.apache.hadoop.hbase.client.coprocessor.Batch)

Aggregations

ServerRpcController (org.apache.hadoop.hbase.ipc.ServerRpcController)31 IOException (java.io.IOException)24 Batch (org.apache.hadoop.hbase.client.coprocessor.Batch)21 BlockingRpcCallback (org.apache.hadoop.hbase.ipc.BlockingRpcCallback)17 MetaDataService (org.apache.phoenix.coprocessor.generated.MetaDataProtos.MetaDataService)15 KeyValueBuilder (org.apache.phoenix.hbase.index.util.KeyValueBuilder)13 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)12 CoprocessorRpcUtils (org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils)12 PhoenixIOException (org.apache.phoenix.exception.PhoenixIOException)12 NonTxIndexBuilder (org.apache.phoenix.hbase.index.covered.NonTxIndexBuilder)12 PhoenixIndexBuilder (org.apache.phoenix.index.PhoenixIndexBuilder)12 MetaDataResponse (org.apache.phoenix.coprocessor.generated.MetaDataProtos.MetaDataResponse)11 Mutation (org.apache.hadoop.hbase.client.Mutation)10 MutationProto (org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto)10 MetaDataMutationResult (org.apache.phoenix.coprocessor.MetaDataProtocol.MetaDataMutationResult)8 Table (org.apache.hadoop.hbase.client.Table)6 SQLException (java.sql.SQLException)5 Map (java.util.Map)5 TreeMap (java.util.TreeMap)5 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)5