Search in sources :

Example 1 with EMPTY_START_ROW

use of org.apache.hadoop.hbase.HConstants.EMPTY_START_ROW in project hbase by apache.

the class TestAsyncNonMetaRegionLocator method testLocateAfter.

// usually locate after will return the same result, so we add a test to make it return different
// result.
@Test
public void testLocateAfter() throws IOException, InterruptedException, ExecutionException {
    byte[] row = Bytes.toBytes("1");
    byte[] splitKey = Arrays.copyOf(row, 2);
    TEST_UTIL.createTable(TABLE_NAME, FAMILY, new byte[][] { splitKey });
    TEST_UTIL.waitTableAvailable(TABLE_NAME);
    HRegionLocation currentLoc = getDefaultRegionLocation(TABLE_NAME, row, RegionLocateType.CURRENT, false).get();
    ServerName currentServerName = TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME).getServerName();
    assertLocEquals(EMPTY_START_ROW, splitKey, currentServerName, currentLoc);
    HRegionLocation afterLoc = getDefaultRegionLocation(TABLE_NAME, row, RegionLocateType.AFTER, false).get();
    ServerName afterServerName = TEST_UTIL.getHBaseCluster().getRegionServerThreads().stream().map(t -> t.getRegionServer()).filter(rs -> rs.getRegions(TABLE_NAME).stream().anyMatch(r -> Bytes.equals(splitKey, r.getRegionInfo().getStartKey()))).findAny().get().getServerName();
    assertLocEquals(splitKey, EMPTY_END_ROW, afterServerName, afterLoc);
    assertSame(afterLoc, getDefaultRegionLocation(TABLE_NAME, row, RegionLocateType.AFTER, false).get());
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) BeforeClass(org.junit.BeforeClass) RegionLocations(org.apache.hadoop.hbase.RegionLocations) RunWith(org.junit.runner.RunWith) EMPTY_START_ROW(org.apache.hadoop.hbase.HConstants.EMPTY_START_ROW) CompletableFuture(java.util.concurrent.CompletableFuture) ClientTests(org.apache.hadoop.hbase.testclassification.ClientTests) User(org.apache.hadoop.hbase.security.User) ServerRegionReplicaUtil(org.apache.hadoop.hbase.util.ServerRegionReplicaUtil) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Assert.assertSame(org.junit.Assert.assertSame) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Configuration(org.apache.hadoop.conf.Configuration) After(org.junit.After) Locator(org.apache.hadoop.hbase.client.RegionReplicaTestHelper.Locator) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Closeables(org.apache.hbase.thirdparty.com.google.common.io.Closeables) ClassRule(org.junit.ClassRule) ServerName(org.apache.hadoop.hbase.ServerName) Parameterized(org.junit.runners.Parameterized) Bytes(org.apache.hadoop.hbase.util.Bytes) Before(org.junit.Before) TableName(org.apache.hadoop.hbase.TableName) AfterClass(org.junit.AfterClass) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) MediumTests(org.apache.hadoop.hbase.testclassification.MediumTests) Parameter(org.junit.runners.Parameterized.Parameter) Collection(java.util.Collection) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) IOException(java.io.IOException) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) RegionReplicaTestHelper.testLocator(org.apache.hadoop.hbase.client.RegionReplicaTestHelper.testLocator) ExecutionException(java.util.concurrent.ExecutionException) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) EMPTY_END_ROW(org.apache.hadoop.hbase.HConstants.EMPTY_END_ROW) ExplainingPredicate(org.apache.hadoop.hbase.Waiter.ExplainingPredicate) Assert.assertEquals(org.junit.Assert.assertEquals) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ServerName(org.apache.hadoop.hbase.ServerName) Test(org.junit.Test)

Example 2 with EMPTY_START_ROW

use of org.apache.hadoop.hbase.HConstants.EMPTY_START_ROW in project hbase by apache.

the class TestAsyncNonMetaRegionLocator method testReload.

@Test
public void testReload() throws Exception {
    createSingleRegionTable();
    ServerName serverName = TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME).getServerName();
    for (RegionLocateType locateType : RegionLocateType.values()) {
        assertLocEquals(EMPTY_START_ROW, EMPTY_END_ROW, serverName, getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, locateType, false).get());
    }
    ServerName newServerName = TEST_UTIL.getHBaseCluster().getRegionServerThreads().stream().map(t -> t.getRegionServer().getServerName()).filter(sn -> !sn.equals(serverName)).findAny().get();
    Admin admin = TEST_UTIL.getAdmin();
    RegionInfo region = admin.getRegions(TABLE_NAME).stream().findAny().get();
    admin.move(region.getEncodedNameAsBytes(), newServerName);
    TEST_UTIL.waitFor(30000, new ExplainingPredicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            ServerName newServerName = TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME).getServerName();
            return newServerName != null && !newServerName.equals(serverName);
        }

        @Override
        public String explainFailure() throws Exception {
            return region.getRegionNameAsString() + " is still on " + serverName;
        }
    });
    // The cached location will not change
    for (RegionLocateType locateType : RegionLocateType.values()) {
        assertLocEquals(EMPTY_START_ROW, EMPTY_END_ROW, serverName, getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, locateType, false).get());
    }
    // should get the new location when reload = true
    // when meta replica LoadBalance mode is enabled, it may delay a bit.
    TEST_UTIL.waitFor(3000, new ExplainingPredicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            HRegionLocation loc = getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, RegionLocateType.CURRENT, true).get();
            return newServerName.equals(loc.getServerName());
        }

        @Override
        public String explainFailure() throws Exception {
            return "New location does not show up in meta (replica) region";
        }
    });
    // the cached location should be replaced
    for (RegionLocateType locateType : RegionLocateType.values()) {
        assertLocEquals(EMPTY_START_ROW, EMPTY_END_ROW, newServerName, getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, locateType, false).get());
    }
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) BeforeClass(org.junit.BeforeClass) RegionLocations(org.apache.hadoop.hbase.RegionLocations) RunWith(org.junit.runner.RunWith) EMPTY_START_ROW(org.apache.hadoop.hbase.HConstants.EMPTY_START_ROW) CompletableFuture(java.util.concurrent.CompletableFuture) ClientTests(org.apache.hadoop.hbase.testclassification.ClientTests) User(org.apache.hadoop.hbase.security.User) ServerRegionReplicaUtil(org.apache.hadoop.hbase.util.ServerRegionReplicaUtil) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Assert.assertSame(org.junit.Assert.assertSame) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Configuration(org.apache.hadoop.conf.Configuration) After(org.junit.After) Locator(org.apache.hadoop.hbase.client.RegionReplicaTestHelper.Locator) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Closeables(org.apache.hbase.thirdparty.com.google.common.io.Closeables) ClassRule(org.junit.ClassRule) ServerName(org.apache.hadoop.hbase.ServerName) Parameterized(org.junit.runners.Parameterized) Bytes(org.apache.hadoop.hbase.util.Bytes) Before(org.junit.Before) TableName(org.apache.hadoop.hbase.TableName) AfterClass(org.junit.AfterClass) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) MediumTests(org.apache.hadoop.hbase.testclassification.MediumTests) Parameter(org.junit.runners.Parameterized.Parameter) Collection(java.util.Collection) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) IOException(java.io.IOException) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) RegionReplicaTestHelper.testLocator(org.apache.hadoop.hbase.client.RegionReplicaTestHelper.testLocator) ExecutionException(java.util.concurrent.ExecutionException) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) EMPTY_END_ROW(org.apache.hadoop.hbase.HConstants.EMPTY_END_ROW) ExplainingPredicate(org.apache.hadoop.hbase.Waiter.ExplainingPredicate) Assert.assertEquals(org.junit.Assert.assertEquals) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ServerName(org.apache.hadoop.hbase.ServerName) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 3 with EMPTY_START_ROW

use of org.apache.hadoop.hbase.HConstants.EMPTY_START_ROW in project hbase by apache.

the class TestAsyncNonMetaRegionLocator method testRegionMove.

@Test
public void testRegionMove() throws IOException, InterruptedException, ExecutionException {
    createSingleRegionTable();
    ServerName serverName = TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME).getServerName();
    HRegionLocation loc = getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, RegionLocateType.CURRENT, false).get();
    assertLocEquals(EMPTY_START_ROW, EMPTY_END_ROW, serverName, loc);
    ServerName newServerName = TEST_UTIL.getHBaseCluster().getRegionServerThreads().stream().map(t -> t.getRegionServer().getServerName()).filter(sn -> !sn.equals(serverName)).findAny().get();
    TEST_UTIL.getAdmin().move(Bytes.toBytes(loc.getRegion().getEncodedName()), newServerName);
    while (!TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME).getServerName().equals(newServerName)) {
        Thread.sleep(100);
    }
    // Should be same as it is in cache
    assertSame(loc, getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, RegionLocateType.CURRENT, false).get());
    locator.updateCachedLocationOnError(loc, null);
    // null error will not trigger a cache cleanup
    assertSame(loc, getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, RegionLocateType.CURRENT, false).get());
    locator.updateCachedLocationOnError(loc, new NotServingRegionException());
    assertLocEquals(EMPTY_START_ROW, EMPTY_END_ROW, newServerName, getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, RegionLocateType.CURRENT, false).get());
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) BeforeClass(org.junit.BeforeClass) RegionLocations(org.apache.hadoop.hbase.RegionLocations) RunWith(org.junit.runner.RunWith) EMPTY_START_ROW(org.apache.hadoop.hbase.HConstants.EMPTY_START_ROW) CompletableFuture(java.util.concurrent.CompletableFuture) ClientTests(org.apache.hadoop.hbase.testclassification.ClientTests) User(org.apache.hadoop.hbase.security.User) ServerRegionReplicaUtil(org.apache.hadoop.hbase.util.ServerRegionReplicaUtil) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Assert.assertSame(org.junit.Assert.assertSame) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Configuration(org.apache.hadoop.conf.Configuration) After(org.junit.After) Locator(org.apache.hadoop.hbase.client.RegionReplicaTestHelper.Locator) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Closeables(org.apache.hbase.thirdparty.com.google.common.io.Closeables) ClassRule(org.junit.ClassRule) ServerName(org.apache.hadoop.hbase.ServerName) Parameterized(org.junit.runners.Parameterized) Bytes(org.apache.hadoop.hbase.util.Bytes) Before(org.junit.Before) TableName(org.apache.hadoop.hbase.TableName) AfterClass(org.junit.AfterClass) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) MediumTests(org.apache.hadoop.hbase.testclassification.MediumTests) Parameter(org.junit.runners.Parameterized.Parameter) Collection(java.util.Collection) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) IOException(java.io.IOException) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) RegionReplicaTestHelper.testLocator(org.apache.hadoop.hbase.client.RegionReplicaTestHelper.testLocator) ExecutionException(java.util.concurrent.ExecutionException) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) EMPTY_END_ROW(org.apache.hadoop.hbase.HConstants.EMPTY_END_ROW) ExplainingPredicate(org.apache.hadoop.hbase.Waiter.ExplainingPredicate) Assert.assertEquals(org.junit.Assert.assertEquals) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) ServerName(org.apache.hadoop.hbase.ServerName) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)3 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 List (java.util.List)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ExecutionException (java.util.concurrent.ExecutionException)3 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)3 Collectors.toList (java.util.stream.Collectors.toList)3 IntStream (java.util.stream.IntStream)3 Configuration (org.apache.hadoop.conf.Configuration)3 HBaseClassTestRule (org.apache.hadoop.hbase.HBaseClassTestRule)3 HBaseTestingUtil (org.apache.hadoop.hbase.HBaseTestingUtil)3 EMPTY_END_ROW (org.apache.hadoop.hbase.HConstants.EMPTY_END_ROW)3 EMPTY_START_ROW (org.apache.hadoop.hbase.HConstants.EMPTY_START_ROW)3 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)3 NotServingRegionException (org.apache.hadoop.hbase.NotServingRegionException)3 RegionLocations (org.apache.hadoop.hbase.RegionLocations)3 ServerName (org.apache.hadoop.hbase.ServerName)3 TableName (org.apache.hadoop.hbase.TableName)3 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)3