Search in sources :

Example 6 with AsyncAdmin

use of org.apache.hadoop.hbase.client.AsyncAdmin in project hbase by apache.

the class TestProcedurePriority method setUp.

@BeforeClass
public static void setUp() throws Exception {
    UTIL.getConfiguration().setLong(ProcedureExecutor.WORKER_KEEP_ALIVE_TIME_CONF_KEY, 5000);
    UTIL.getConfiguration().setInt(MasterProcedureConstants.MASTER_PROCEDURE_THREADS, 4);
    UTIL.getConfiguration().set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, MyCP.class.getName());
    UTIL.startMiniCluster(3);
    CORE_POOL_SIZE = UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor().getCorePoolSize();
    TABLE_COUNT = 50 * CORE_POOL_SIZE;
    List<Future<?>> futures = new ArrayList<>();
    AsyncAdmin admin = UTIL.getAsyncConnection().getAdmin();
    Semaphore concurrency = new Semaphore(10);
    for (int i = 0; i < TABLE_COUNT; i++) {
        concurrency.acquire();
        futures.add(admin.createTable(TableDescriptorBuilder.newBuilder(TableName.valueOf(TABLE_NAME_PREFIX + i)).setColumnFamily(ColumnFamilyDescriptorBuilder.of(CF)).build()).whenComplete((r, e) -> concurrency.release()));
    }
    for (Future<?> future : futures) {
        future.get(3, TimeUnit.MINUTES);
    }
    UTIL.getAdmin().balance(BalanceRequest.newBuilder().setIgnoreRegionsInTransition(true).build());
    UTIL.waitUntilNoRegionsInTransition();
}
Also used : RegionCoprocessor(org.apache.hadoop.hbase.coprocessor.RegionCoprocessor) BeforeClass(org.junit.BeforeClass) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) ProcedureExecutor(org.apache.hadoop.hbase.procedure2.ProcedureExecutor) ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) WALEdit(org.apache.hadoop.hbase.wal.WALEdit) Durability(org.apache.hadoop.hbase.client.Durability) RegionCoprocessorEnvironment(org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment) ClassRule(org.junit.ClassRule) Cell(org.apache.hadoop.hbase.Cell) Bytes(org.apache.hadoop.hbase.util.Bytes) TableName(org.apache.hadoop.hbase.TableName) AfterClass(org.junit.AfterClass) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) RegionObserver(org.apache.hadoop.hbase.coprocessor.RegionObserver) Semaphore(java.util.concurrent.Semaphore) RegionServerThread(org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread) AsyncAdmin(org.apache.hadoop.hbase.client.AsyncAdmin) Put(org.apache.hadoop.hbase.client.Put) Get(org.apache.hadoop.hbase.client.Get) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) LargeTests(org.apache.hadoop.hbase.testclassification.LargeTests) IOException(java.io.IOException) BalanceRequest(org.apache.hadoop.hbase.client.BalanceRequest) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) TimeUnit(java.util.concurrent.TimeUnit) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) List(java.util.List) ObserverContext(org.apache.hadoop.hbase.coprocessor.ObserverContext) MasterTests(org.apache.hadoop.hbase.testclassification.MasterTests) Optional(java.util.Optional) Table(org.apache.hadoop.hbase.client.Table) CoprocessorHost(org.apache.hadoop.hbase.coprocessor.CoprocessorHost) ExplainingPredicate(org.apache.hadoop.hbase.Waiter.ExplainingPredicate) AsyncAdmin(org.apache.hadoop.hbase.client.AsyncAdmin) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Semaphore(java.util.concurrent.Semaphore) BeforeClass(org.junit.BeforeClass)

Example 7 with AsyncAdmin

use of org.apache.hadoop.hbase.client.AsyncAdmin in project hbase by apache.

the class TestShellExecEndpointCoprocessor method testShellExecBackground.

@Test
public void testShellExecBackground() throws IOException {
    final AsyncConnection conn = connectionRule.getConnection();
    final AsyncAdmin admin = conn.getAdmin();
    final File testDataDir = ensureTestDataDirExists(miniClusterRule.getTestingUtility());
    final File testFile = new File(testDataDir, "shell_exec_background.txt");
    assertTrue(testFile.createNewFile());
    assertEquals(0, testFile.length());
    final String command = "echo \"hello world\" >> " + testFile.getAbsolutePath();
    final ShellExecRequest req = ShellExecRequest.newBuilder().setCommand(command).setAwaitResponse(false).build();
    final ShellExecResponse resp = admin.<ShellExecService.Stub, ShellExecResponse>coprocessorService(ShellExecService::newStub, (stub, controller, callback) -> stub.shellExec(controller, req, callback)).join();
    assertFalse("the response from a background task should have no exit code", resp.hasExitCode());
    assertFalse("the response from a background task should have no stdout", resp.hasStdout());
    assertFalse("the response from a background task should have no stderr", resp.hasStderr());
    Waiter.waitFor(conn.getConfiguration(), 5_000, () -> testFile.length() > 0);
    final String content = new String(Files.readAllBytes(testFile.toPath())).trim();
    assertEquals("hello world", content);
}
Also used : ShellExecService(org.apache.hadoop.hbase.coprocessor.protobuf.generated.ShellExecEndpoint.ShellExecService) Files(java.nio.file.Files) MediumTests(org.apache.hadoop.hbase.testclassification.MediumTests) AsyncAdmin(org.apache.hadoop.hbase.client.AsyncAdmin) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) File(java.io.File) Consumer(java.util.function.Consumer) AsyncConnection(org.apache.hadoop.hbase.client.AsyncConnection) ShellExecResponse(org.apache.hadoop.hbase.coprocessor.protobuf.generated.ShellExecEndpoint.ShellExecResponse) Rule(org.junit.Rule) Paths(java.nio.file.Paths) Assert.assertFalse(org.junit.Assert.assertFalse) Configuration(org.apache.hadoop.conf.Configuration) Optional(java.util.Optional) ClassRule(org.junit.ClassRule) Path(java.nio.file.Path) Assert.assertEquals(org.junit.Assert.assertEquals) ShellExecRequest(org.apache.hadoop.hbase.coprocessor.protobuf.generated.ShellExecEndpoint.ShellExecRequest) AsyncAdmin(org.apache.hadoop.hbase.client.AsyncAdmin) ShellExecResponse(org.apache.hadoop.hbase.coprocessor.protobuf.generated.ShellExecEndpoint.ShellExecResponse) AsyncConnection(org.apache.hadoop.hbase.client.AsyncConnection) ShellExecRequest(org.apache.hadoop.hbase.coprocessor.protobuf.generated.ShellExecEndpoint.ShellExecRequest) ShellExecService(org.apache.hadoop.hbase.coprocessor.protobuf.generated.ShellExecEndpoint.ShellExecService) File(java.io.File) Test(org.junit.Test)

Example 8 with AsyncAdmin

use of org.apache.hadoop.hbase.client.AsyncAdmin in project hbase by apache.

the class TestOpenRegionProcedureBackoff method testBackoff.

@Test
public void testBackoff() throws IOException, InterruptedException, ExecutionException {
    FAIL = true;
    AsyncAdmin admin = UTIL.getAsyncConnection().getAdminBuilder().setRpcTimeout(5, TimeUnit.MINUTES).setOperationTimeout(10, TimeUnit.MINUTES).build();
    CompletableFuture<?> future = admin.createTable(TableDescriptorBuilder.newBuilder(NAME).setColumnFamily(ColumnFamilyDescriptorBuilder.of(CF)).build());
    assertBackoffIncrease();
    FAIL = false;
    future.get();
    UTIL.waitTableAvailable(NAME);
}
Also used : AsyncAdmin(org.apache.hadoop.hbase.client.AsyncAdmin) Test(org.junit.Test)

Example 9 with AsyncAdmin

use of org.apache.hadoop.hbase.client.AsyncAdmin in project hbase by apache.

the class TestServerCrashProcedureCarryingMetaStuck method test.

@Test
public void test() throws Exception {
    RegionServerThread rsThread = null;
    for (RegionServerThread t : UTIL.getMiniHBaseCluster().getRegionServerThreads()) {
        if (!t.getRegionServer().getRegions(TableName.META_TABLE_NAME).isEmpty()) {
            rsThread = t;
            break;
        }
    }
    HRegionServer rs = rsThread.getRegionServer();
    RegionInfo hri = rs.getRegions(TableName.META_TABLE_NAME).get(0).getRegionInfo();
    HMaster master = UTIL.getMiniHBaseCluster().getMaster();
    ProcedureExecutor<MasterProcedureEnv> executor = master.getMasterProcedureExecutor();
    DummyRegionProcedure proc = new DummyRegionProcedure(executor.getEnvironment(), hri);
    long procId = master.getMasterProcedureExecutor().submitProcedure(proc);
    proc.waitUntilArrive();
    try (AsyncConnection conn = ConnectionFactory.createAsyncConnection(UTIL.getConfiguration()).get()) {
        AsyncAdmin admin = conn.getAdmin();
        CompletableFuture<Void> future = admin.move(hri.getRegionName());
        rs.abort("For testing!");
        UTIL.waitFor(30000, () -> executor.getProcedures().stream().filter(p -> p instanceof TransitRegionStateProcedure).map(p -> (TransitRegionStateProcedure) p).anyMatch(p -> Bytes.equals(hri.getRegionName(), p.getRegion().getRegionName())));
        proc.resume();
        UTIL.waitFor(30000, () -> executor.isFinished(procId));
        // see whether the move region procedure can finish properly
        future.get(30, TimeUnit.SECONDS);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) MediumTests(org.apache.hadoop.hbase.testclassification.MediumTests) RegionServerThread(org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread) AsyncAdmin(org.apache.hadoop.hbase.client.AsyncAdmin) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.Test) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) Category(org.junit.experimental.categories.Category) ConnectionFactory(org.apache.hadoop.hbase.client.ConnectionFactory) TimeUnit(java.util.concurrent.TimeUnit) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) AsyncConnection(org.apache.hadoop.hbase.client.AsyncConnection) ProcedureExecutor(org.apache.hadoop.hbase.procedure2.ProcedureExecutor) TransitRegionStateProcedure(org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure) MasterTests(org.apache.hadoop.hbase.testclassification.MasterTests) ClassRule(org.junit.ClassRule) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Bytes(org.apache.hadoop.hbase.util.Bytes) AsyncAdmin(org.apache.hadoop.hbase.client.AsyncAdmin) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) TransitRegionStateProcedure(org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure) AsyncConnection(org.apache.hadoop.hbase.client.AsyncConnection) RegionServerThread(org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread) Test(org.junit.Test)

Aggregations

AsyncAdmin (org.apache.hadoop.hbase.client.AsyncAdmin)9 Test (org.junit.Test)8 AsyncConnection (org.apache.hadoop.hbase.client.AsyncConnection)7 ClassRule (org.junit.ClassRule)6 Category (org.junit.experimental.categories.Category)6 MediumTests (org.apache.hadoop.hbase.testclassification.MediumTests)5 IOException (java.io.IOException)4 Optional (java.util.Optional)4 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)4 Bytes (org.apache.hadoop.hbase.util.Bytes)4 RegionServerThread (org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread)4 AfterClass (org.junit.AfterClass)4 BeforeClass (org.junit.BeforeClass)4 CompletableFuture (java.util.concurrent.CompletableFuture)3 TimeUnit (java.util.concurrent.TimeUnit)3 Configuration (org.apache.hadoop.conf.Configuration)3 HBaseClassTestRule (org.apache.hadoop.hbase.HBaseClassTestRule)3 HBaseTestingUtil (org.apache.hadoop.hbase.HBaseTestingUtil)3 TableName (org.apache.hadoop.hbase.TableName)3 ConnectionFactory (org.apache.hadoop.hbase.client.ConnectionFactory)3