Search in sources :

Example 6 with RpcControllerFactory

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

the class TestRpcControllerFactory method testFallbackToDefaultRpcControllerFactory.

@Test
public void testFallbackToDefaultRpcControllerFactory() {
    Configuration conf = new Configuration(UTIL.getConfiguration());
    conf.set(RpcControllerFactory.CUSTOM_CONTROLLER_CONF_KEY, "foo.bar.Baz");
    // Should not fail
    RpcControllerFactory factory = RpcControllerFactory.instantiate(conf);
    assertNotNull(factory);
    assertEquals(factory.getClass(), RpcControllerFactory.class);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) RpcControllerFactory(org.apache.hadoop.hbase.ipc.RpcControllerFactory) Test(org.junit.Test)

Example 7 with RpcControllerFactory

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

the class TestLoadIncrementalHFilesSplitRecovery method testRetryOnIOException.

/**
   * Test that shows that exception thrown from the RS side will result in the
   * expected number of retries set by ${@link HConstants#HBASE_CLIENT_RETRIES_NUMBER}
   * when ${@link LoadIncrementalHFiles#RETRY_ON_IO_EXCEPTION} is set
   */
@Test
public void testRetryOnIOException() throws Exception {
    final TableName table = TableName.valueOf(name.getMethodName());
    final AtomicInteger calls = new AtomicInteger(1);
    final Connection conn = ConnectionFactory.createConnection(util.getConfiguration());
    util.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2);
    util.getConfiguration().setBoolean(LoadIncrementalHFiles.RETRY_ON_IO_EXCEPTION, true);
    final LoadIncrementalHFiles lih = new LoadIncrementalHFiles(util.getConfiguration()) {

        @Override
        protected List<LoadQueueItem> tryAtomicRegionLoad(ClientServiceCallable<byte[]> serverCallable, TableName tableName, final byte[] first, Collection<LoadQueueItem> lqis) throws IOException {
            if (calls.getAndIncrement() < util.getConfiguration().getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER) - 1) {
                ClientServiceCallable<byte[]> newServerCallable = new ClientServiceCallable<byte[]>(conn, tableName, first, new RpcControllerFactory(util.getConfiguration()).newController()) {

                    @Override
                    public byte[] rpcCall() throws Exception {
                        throw new IOException("Error calling something on RegionServer");
                    }
                };
                return super.tryAtomicRegionLoad(newServerCallable, tableName, first, lqis);
            } else {
                return super.tryAtomicRegionLoad(serverCallable, tableName, first, lqis);
            }
        }
    };
    setupTable(conn, table, 10);
    Path dir = buildBulkFiles(table, 1);
    lih.doBulkLoad(dir, conn.getAdmin(), conn.getTable(table), conn.getRegionLocator(table));
    util.getConfiguration().setBoolean(LoadIncrementalHFiles.RETRY_ON_IO_EXCEPTION, false);
}
Also used : Path(org.apache.hadoop.fs.Path) TableName(org.apache.hadoop.hbase.TableName) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClusterConnection(org.apache.hadoop.hbase.client.ClusterConnection) Connection(org.apache.hadoop.hbase.client.Connection) Collection(java.util.Collection) IOException(java.io.IOException) RpcControllerFactory(org.apache.hadoop.hbase.ipc.RpcControllerFactory) ClientServiceCallable(org.apache.hadoop.hbase.client.ClientServiceCallable) Test(org.junit.Test)

Example 8 with RpcControllerFactory

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

the class TestHBaseAdminNoCluster method testMasterOperationIsRetried.

private void testMasterOperationIsRetried(MethodCaller caller) throws Exception {
    Configuration configuration = HBaseConfiguration.create();
    // Set the pause and retry count way down.
    configuration.setLong(HConstants.HBASE_CLIENT_PAUSE, 1);
    final int count = 10;
    configuration.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, count);
    ClusterConnection connection = mock(ClusterConnection.class);
    when(connection.getConfiguration()).thenReturn(configuration);
    MasterKeepAliveConnection masterAdmin = Mockito.mock(MasterKeepAliveConnection.class, new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            if (invocation.getMethod().getName().equals("close")) {
                return null;
            }
            // all methods will throw an exception
            throw new MasterNotRunningException();
        }
    });
    Mockito.when(connection.getKeepAliveMasterService()).thenReturn(masterAdmin);
    RpcControllerFactory rpcControllerFactory = Mockito.mock(RpcControllerFactory.class);
    Mockito.when(connection.getRpcControllerFactory()).thenReturn(rpcControllerFactory);
    Mockito.when(rpcControllerFactory.newController()).thenReturn(Mockito.mock(HBaseRpcController.class));
    // we need a real retrying caller
    RpcRetryingCallerFactory callerFactory = new RpcRetryingCallerFactory(configuration);
    Mockito.when(connection.getRpcRetryingCallerFactory()).thenReturn(callerFactory);
    Admin admin = null;
    try {
        admin = Mockito.spy(new HBaseAdmin(connection));
        // mock the call to getRegion since in the absence of a cluster (which means the meta
        // is not assigned), getRegion can't function
        Mockito.doReturn(null).when(((HBaseAdmin) admin)).getRegion(Matchers.<byte[]>any());
        try {
            // invoke the HBaseAdmin method
            caller.call(admin);
            fail();
        } catch (RetriesExhaustedException e) {
            LOG.info("Expected fail", e);
        }
        // Assert we were called 'count' times.
        caller.verify(masterAdmin, count);
    } finally {
        if (admin != null) {
            admin.close();
        }
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) RpcControllerFactory(org.apache.hadoop.hbase.ipc.RpcControllerFactory) Answer(org.mockito.stubbing.Answer) HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MasterNotRunningException(org.apache.hadoop.hbase.MasterNotRunningException)

Example 9 with RpcControllerFactory

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

the class TestSnapshotFromAdmin method testValidateSnapshotName.

/**
   * Make sure that we validate the snapshot name and the table name before we pass anything across
   * the wire
   * @throws Exception on failure
   */
@Test
public void testValidateSnapshotName() throws Exception {
    ConnectionImplementation mockConnection = Mockito.mock(ConnectionImplementation.class);
    Configuration conf = HBaseConfiguration.create();
    Mockito.when(mockConnection.getConfiguration()).thenReturn(conf);
    // we need a real retrying caller
    RpcRetryingCallerFactory callerFactory = new RpcRetryingCallerFactory(conf);
    RpcControllerFactory controllerFactory = Mockito.mock(RpcControllerFactory.class);
    Mockito.when(controllerFactory.newController()).thenReturn(Mockito.mock(HBaseRpcController.class));
    Mockito.when(mockConnection.getRpcRetryingCallerFactory()).thenReturn(callerFactory);
    Mockito.when(mockConnection.getRpcControllerFactory()).thenReturn(controllerFactory);
    Admin admin = new HBaseAdmin(mockConnection);
    // check that invalid snapshot names fail
    failSnapshotStart(admin, new SnapshotDescription(HConstants.SNAPSHOT_DIR_NAME));
    failSnapshotStart(admin, new SnapshotDescription("-snapshot"));
    failSnapshotStart(admin, new SnapshotDescription("snapshot fails"));
    failSnapshotStart(admin, new SnapshotDescription("snap$hot"));
    failSnapshotStart(admin, new SnapshotDescription("snap:hot"));
    // check the table name also get verified
    failSnapshotDescriptorCreation("snapshot", ".table");
    failSnapshotDescriptorCreation("snapshot", "-table");
    failSnapshotDescriptorCreation("snapshot", "table fails");
    failSnapshotDescriptorCreation("snapshot", "tab%le");
    // mock the master connection
    MasterKeepAliveConnection master = Mockito.mock(MasterKeepAliveConnection.class);
    Mockito.when(mockConnection.getKeepAliveMasterService()).thenReturn(master);
    SnapshotResponse response = SnapshotResponse.newBuilder().setExpectedTimeout(0).build();
    Mockito.when(master.snapshot((RpcController) Mockito.any(), Mockito.any(SnapshotRequest.class))).thenReturn(response);
    IsSnapshotDoneResponse doneResponse = IsSnapshotDoneResponse.newBuilder().setDone(true).build();
    Mockito.when(master.isSnapshotDone((RpcController) Mockito.any(), Mockito.any(IsSnapshotDoneRequest.class))).thenReturn(doneResponse);
    // make sure that we can use valid names
    admin.snapshot(new SnapshotDescription("snapshot", TableName.valueOf(name.getMethodName())));
}
Also used : HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Configuration(org.apache.hadoop.conf.Configuration) RpcControllerFactory(org.apache.hadoop.hbase.ipc.RpcControllerFactory) HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) SnapshotResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.SnapshotResponse) SnapshotRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.SnapshotRequest) IsSnapshotDoneResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsSnapshotDoneResponse) IsSnapshotDoneRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsSnapshotDoneRequest) Test(org.junit.Test)

Aggregations

RpcControllerFactory (org.apache.hadoop.hbase.ipc.RpcControllerFactory)9 Test (org.junit.Test)8 HBaseRpcController (org.apache.hadoop.hbase.ipc.HBaseRpcController)5 Configuration (org.apache.hadoop.conf.Configuration)4 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)3 TableName (org.apache.hadoop.hbase.TableName)3 Path (org.apache.hadoop.fs.Path)2 ClusterConnection (org.apache.hadoop.hbase.client.ClusterConnection)2 IsSnapshotDoneRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsSnapshotDoneRequest)2 IsSnapshotDoneResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsSnapshotDoneResponse)2 SnapshotRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.SnapshotRequest)2 SnapshotResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.SnapshotResponse)2 IOException (java.io.IOException)1 ConnectException (java.net.ConnectException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)1 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)1