Search in sources :

Example 1 with ExecutorConfig

use of org.apache.hadoop.hbase.executor.ExecutorService.ExecutorConfig in project hbase by apache.

the class RegionServicesForStores method getInMemoryCompactionPool.

ThreadPoolExecutor getInMemoryCompactionPool() {
    if (rsServices != null) {
        ExecutorService executorService = rsServices.getExecutorService();
        ExecutorConfig config = executorService.new ExecutorConfig().setExecutorType(ExecutorType.RS_IN_MEMORY_COMPACTION).setCorePoolSize(inMemoryPoolSize);
        return executorService.getExecutorLazily(config);
    } else {
        // this could only happen in tests
        return getInMemoryCompactionPoolForTest();
    }
}
Also used : ExecutorService(org.apache.hadoop.hbase.executor.ExecutorService) ExecutorConfig(org.apache.hadoop.hbase.executor.ExecutorService.ExecutorConfig)

Example 2 with ExecutorConfig

use of org.apache.hadoop.hbase.executor.ExecutorService.ExecutorConfig in project hbase by apache.

the class TestExecutorStatusChore method testMetricsCollect.

@Test
public void testMetricsCollect() throws Exception {
    int maxThreads = 5;
    int maxTries = 10;
    int sleepInterval = 1000;
    Server mockedServer = mock(Server.class);
    when(mockedServer.getConfiguration()).thenReturn(HBaseConfiguration.create());
    // Start an executor service pool with max 5 threads
    ExecutorService executorService = new ExecutorService("unit_test");
    executorService.startExecutorService(executorService.new ExecutorConfig().setExecutorType(ExecutorType.RS_PARALLEL_SEEK).setCorePoolSize(maxThreads));
    MetricsRegionServerSource serverSource = CompatibilitySingletonFactory.getInstance(MetricsRegionServerSourceFactory.class).createServer(null);
    assertTrue(serverSource instanceof MetricsRegionServerSourceImpl);
    ExecutorStatusChore statusChore = new ExecutorStatusChore(60000, mockedServer, executorService, serverSource);
    AtomicBoolean lock = new AtomicBoolean(true);
    AtomicInteger counter = new AtomicInteger(0);
    for (int i = 0; i < maxThreads + 1; i++) {
        executorService.submit(new TestEventHandler(mockedServer, EventType.RS_PARALLEL_SEEK, lock, counter));
    }
    // The TestEventHandler will increment counter when it starts.
    int tries = 0;
    while (counter.get() < maxThreads && tries < maxTries) {
        LOG.info("Waiting for all event handlers to start...");
        Thread.sleep(sleepInterval);
        tries++;
    }
    // Assert that pool is at max threads.
    assertEquals(maxThreads, counter.get());
    statusChore.chore();
    Pair<Long, Long> executorStatus = statusChore.getExecutorStatus("RS_PARALLEL_SEEK");
    // running
    assertEquals(maxThreads, executorStatus.getFirst().intValue());
    // pending
    assertEquals(1, executorStatus.getSecond().intValue());
    // Now interrupt the running Executor
    synchronized (lock) {
        lock.set(false);
        lock.notifyAll();
    }
    executorService.shutdown();
}
Also used : MetricsRegionServerSource(org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource) MetricsRegionServerSourceFactory(org.apache.hadoop.hbase.regionserver.MetricsRegionServerSourceFactory) TestEventHandler(org.apache.hadoop.hbase.executor.TestExecutorService.TestEventHandler) ExecutorConfig(org.apache.hadoop.hbase.executor.ExecutorService.ExecutorConfig) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MetricsRegionServerSourceImpl(org.apache.hadoop.hbase.regionserver.MetricsRegionServerSourceImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(org.apache.hadoop.hbase.executor.ExecutorService) Test(org.junit.Test)

Example 3 with ExecutorConfig

use of org.apache.hadoop.hbase.executor.ExecutorService.ExecutorConfig in project hbase by apache.

the class TestExecutorService method testSnapshotHandlers.

@Test
public void testSnapshotHandlers() throws Exception {
    final Configuration conf = HBaseConfiguration.create();
    final Server server = mock(Server.class);
    when(server.getConfiguration()).thenReturn(conf);
    ExecutorService executorService = new ExecutorService("testSnapshotHandlers");
    executorService.startExecutorService(executorService.new ExecutorConfig().setExecutorType(ExecutorType.MASTER_SNAPSHOT_OPERATIONS).setCorePoolSize(1));
    CountDownLatch latch = new CountDownLatch(1);
    CountDownLatch waitForEventToStart = new CountDownLatch(1);
    executorService.submit(new EventHandler(server, EventType.C_M_SNAPSHOT_TABLE) {

        @Override
        public void process() throws IOException {
            waitForEventToStart.countDown();
            try {
                latch.await();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
    });
    // Wait EventHandler to start
    waitForEventToStart.await(10, TimeUnit.SECONDS);
    int activeCount = executorService.getExecutor(ExecutorType.MASTER_SNAPSHOT_OPERATIONS).getThreadPoolExecutor().getActiveCount();
    Assert.assertEquals(1, activeCount);
    latch.countDown();
    Waiter.waitFor(conf, 3000, () -> {
        int count = executorService.getExecutor(ExecutorType.MASTER_SNAPSHOT_OPERATIONS).getThreadPoolExecutor().getActiveCount();
        return count == 0;
    });
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Server(org.apache.hadoop.hbase.Server) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutorConfig(org.apache.hadoop.hbase.executor.ExecutorService.ExecutorConfig) Test(org.junit.Test)

Example 4 with ExecutorConfig

use of org.apache.hadoop.hbase.executor.ExecutorService.ExecutorConfig in project hbase by apache.

the class TestExecutorService method testExecutorService.

@Test
public void testExecutorService() throws Exception {
    int maxThreads = 5;
    int maxTries = 10;
    int sleepInterval = 10;
    Server mockedServer = mock(Server.class);
    when(mockedServer.getConfiguration()).thenReturn(HBaseConfiguration.create());
    // Start an executor service pool with max 5 threads
    ExecutorService executorService = new ExecutorService("unit_test");
    executorService.startExecutorService(executorService.new ExecutorConfig().setExecutorType(ExecutorType.MASTER_SERVER_OPERATIONS).setCorePoolSize(maxThreads));
    Executor executor = executorService.getExecutor(ExecutorType.MASTER_SERVER_OPERATIONS);
    ThreadPoolExecutor pool = executor.threadPoolExecutor;
    // Assert no threads yet
    assertEquals(0, pool.getPoolSize());
    AtomicBoolean lock = new AtomicBoolean(true);
    AtomicInteger counter = new AtomicInteger(0);
    // Submit maxThreads executors.
    for (int i = 0; i < maxThreads; i++) {
        executorService.submit(new TestEventHandler(mockedServer, EventType.M_SERVER_SHUTDOWN, lock, counter));
    }
    // The TestEventHandler will increment counter when it starts.
    int tries = 0;
    while (counter.get() < maxThreads && tries < maxTries) {
        LOG.info("Waiting for all event handlers to start...");
        Thread.sleep(sleepInterval);
        tries++;
    }
    // Assert that pool is at max threads.
    assertEquals(maxThreads, counter.get());
    assertEquals(maxThreads, pool.getPoolSize());
    ExecutorStatus status = executor.getStatus();
    assertTrue(status.queuedEvents.isEmpty());
    assertEquals(5, status.running.size());
    checkStatusDump(status);
    // Now interrupt the running Executor
    synchronized (lock) {
        lock.set(false);
        lock.notifyAll();
    }
    // Executor increments counter again on way out so.... test that happened.
    while (counter.get() < (maxThreads * 2) && tries < maxTries) {
        System.out.println("Waiting for all event handlers to finish...");
        Thread.sleep(sleepInterval);
        tries++;
    }
    assertEquals(maxThreads * 2, counter.get());
    assertEquals(maxThreads, pool.getPoolSize());
    // Make sure we don't get RejectedExecutionException.
    for (int i = 0; i < (2 * maxThreads); i++) {
        executorService.submit(new TestEventHandler(mockedServer, EventType.M_SERVER_SHUTDOWN, lock, counter));
    }
    // Now interrupt the running Executor
    synchronized (lock) {
        lock.set(false);
        lock.notifyAll();
    }
    // Make sure threads are still around even after their timetolive expires.
    Thread.sleep(ExecutorConfig.KEEP_ALIVE_TIME_MILLIS_DEFAULT * 2);
    assertEquals(maxThreads, pool.getPoolSize());
    executorService.shutdown();
    assertEquals(0, executorService.getAllExecutorStatuses().size());
    // Test that submit doesn't throw NPEs
    executorService.submit(new TestEventHandler(mockedServer, EventType.M_SERVER_SHUTDOWN, lock, counter));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Executor(org.apache.hadoop.hbase.executor.ExecutorService.Executor) Server(org.apache.hadoop.hbase.Server) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ExecutorStatus(org.apache.hadoop.hbase.executor.ExecutorService.ExecutorStatus) ExecutorConfig(org.apache.hadoop.hbase.executor.ExecutorService.ExecutorConfig) Test(org.junit.Test)

Example 5 with ExecutorConfig

use of org.apache.hadoop.hbase.executor.ExecutorService.ExecutorConfig in project hbase by apache.

the class TestExecutorService method testAborting.

@Test
public void testAborting() throws Exception {
    final Configuration conf = HBaseConfiguration.create();
    final Server server = mock(Server.class);
    when(server.getConfiguration()).thenReturn(conf);
    ExecutorService executorService = new ExecutorService("unit_test");
    executorService.startExecutorService(executorService.new ExecutorConfig().setExecutorType(ExecutorType.MASTER_SERVER_OPERATIONS).setCorePoolSize(1));
    executorService.submit(new EventHandler(server, EventType.M_SERVER_SHUTDOWN) {

        @Override
        public void process() throws IOException {
            throw new RuntimeException("Should cause abort");
        }
    });
    Waiter.waitFor(conf, 30000, new Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            try {
                verify(server, times(1)).abort(anyString(), (Throwable) anyObject());
                return true;
            } catch (Throwable t) {
                return false;
            }
        }
    });
    executorService.shutdown();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Server(org.apache.hadoop.hbase.Server) IOException(java.io.IOException) IOException(java.io.IOException) ExecutorConfig(org.apache.hadoop.hbase.executor.ExecutorService.ExecutorConfig) Test(org.junit.Test)

Aggregations

ExecutorConfig (org.apache.hadoop.hbase.executor.ExecutorService.ExecutorConfig)5 Test (org.junit.Test)4 Server (org.apache.hadoop.hbase.Server)3 IOException (java.io.IOException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Configuration (org.apache.hadoop.conf.Configuration)2 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)2 ExecutorService (org.apache.hadoop.hbase.executor.ExecutorService)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 Executor (org.apache.hadoop.hbase.executor.ExecutorService.Executor)1 ExecutorStatus (org.apache.hadoop.hbase.executor.ExecutorService.ExecutorStatus)1 TestEventHandler (org.apache.hadoop.hbase.executor.TestExecutorService.TestEventHandler)1 MetricsRegionServerSource (org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource)1 MetricsRegionServerSourceFactory (org.apache.hadoop.hbase.regionserver.MetricsRegionServerSourceFactory)1 MetricsRegionServerSourceImpl (org.apache.hadoop.hbase.regionserver.MetricsRegionServerSourceImpl)1