Search in sources :

Example 21 with Store

use of org.apache.hadoop.hbase.regionserver.Store in project hbase by apache.

the class TestStoreHotnessProtector method testPreparePutCounter.

@Test
public void testPreparePutCounter() throws Exception {
    ExecutorService executorService = Executors.newFixedThreadPool(10);
    Configuration conf = new Configuration();
    conf.setInt(PARALLEL_PUT_STORE_THREADS_LIMIT_MIN_COLUMN_COUNT, 0);
    conf.setInt(PARALLEL_PUT_STORE_THREADS_LIMIT, 10);
    conf.setInt(PARALLEL_PREPARE_PUT_STORE_MULTIPLIER, 3);
    Region mockRegion = mock(Region.class);
    StoreHotnessProtector storeHotnessProtector = new StoreHotnessProtector(mockRegion, conf);
    Store mockStore1 = mock(Store.class);
    RegionInfo mockRegionInfo = mock(RegionInfo.class);
    byte[] family = Bytes.toBytes("testF1");
    when(mockRegion.getStore(family)).thenReturn(mockStore1);
    when(mockRegion.getRegionInfo()).thenReturn(mockRegionInfo);
    when(mockRegionInfo.getRegionNameAsString()).thenReturn("test_region_1");
    when(mockStore1.getCurrentParallelPutCount()).thenReturn(1);
    when(mockStore1.getColumnFamilyName()).thenReturn("test_Family_1");
    final Map<byte[], List<Cell>> familyMaps = new HashMap<>();
    familyMaps.put(family, Lists.newArrayList(mock(Cell.class), mock(Cell.class)));
    final AtomicReference<Exception> exception = new AtomicReference<>();
    // PreparePutCounter not access limit
    int threadCount = conf.getInt(PARALLEL_PUT_STORE_THREADS_LIMIT, 10) * conf.getInt(PARALLEL_PREPARE_PUT_STORE_MULTIPLIER, 3);
    CountDownLatch countDownLatch = new CountDownLatch(threadCount);
    for (int i = 0; i < threadCount; i++) {
        executorService.execute(() -> {
            try {
                storeHotnessProtector.start(familyMaps);
            } catch (RegionTooBusyException e) {
                e.printStackTrace();
                exception.set(e);
            } finally {
                countDownLatch.countDown();
            }
        });
    }
    countDownLatch.await(60, TimeUnit.SECONDS);
    // no exception
    Assert.assertEquals(exception.get(), null);
    Assert.assertEquals(storeHotnessProtector.getPreparePutToStoreMap().size(), 1);
    Assert.assertEquals(storeHotnessProtector.getPreparePutToStoreMap().get(family).get(), threadCount);
    try {
        storeHotnessProtector.start(familyMaps);
    } catch (RegionTooBusyException e) {
        e.printStackTrace();
        exception.set(e);
    }
    Assert.assertEquals(exception.get().getClass(), RegionTooBusyException.class);
    Assert.assertEquals(storeHotnessProtector.getPreparePutToStoreMap().size(), 1);
    // when access limit, counter will not changed.
    Assert.assertEquals(storeHotnessProtector.getPreparePutToStoreMap().get(family).get(), threadCount + 1);
    storeHotnessProtector.finish(familyMaps);
    Assert.assertEquals(storeHotnessProtector.getPreparePutToStoreMap().get(family).get(), threadCount);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HashMap(java.util.HashMap) Store(org.apache.hadoop.hbase.regionserver.Store) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) RegionTooBusyException(org.apache.hadoop.hbase.RegionTooBusyException) RegionTooBusyException(org.apache.hadoop.hbase.RegionTooBusyException) ExecutorService(java.util.concurrent.ExecutorService) Region(org.apache.hadoop.hbase.regionserver.Region) List(java.util.List) Test(org.junit.Test)

Aggregations

Store (org.apache.hadoop.hbase.regionserver.Store)21 Region (org.apache.hadoop.hbase.regionserver.Region)7 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 Configuration (org.apache.hadoop.conf.Configuration)4 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)4 InternalScanner (org.apache.hadoop.hbase.regionserver.InternalScanner)4 List (java.util.List)3 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)3 RegionCoprocessorEnvironment (org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment)3 Test (org.junit.jupiter.api.Test)3 IOException (java.io.IOException)2 RegionTooBusyException (org.apache.hadoop.hbase.RegionTooBusyException)2 TableName (org.apache.hadoop.hbase.TableName)2 Table (org.apache.hadoop.hbase.client.Table)2 BlockCache (org.apache.hadoop.hbase.io.hfile.BlockCache)2 CacheConfig (org.apache.hadoop.hbase.io.hfile.CacheConfig)2 StoreScanner (uk.gov.gchq.gaffer.hbasestore.coprocessor.scanner.StoreScanner)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1