Search in sources :

Example 16 with RegionLocations

use of org.apache.hadoop.hbase.RegionLocations in project hbase by apache.

the class MetaCache method cacheLocation.

/**
   * Put a newly discovered HRegionLocation into the cache.
   * @param tableName The table name.
   * @param locations the new locations
   */
public void cacheLocation(final TableName tableName, final RegionLocations locations) {
    byte[] startKey = locations.getRegionLocation().getRegionInfo().getStartKey();
    ConcurrentMap<byte[], RegionLocations> tableLocations = getTableLocations(tableName);
    RegionLocations oldLocation = tableLocations.putIfAbsent(startKey, locations);
    boolean isNewCacheEntry = (oldLocation == null);
    if (isNewCacheEntry) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Cached location: " + locations);
        }
        addToCachedServers(locations);
        return;
    }
    // merge old and new locations and add it to the cache
    // Meta record might be stale - some (probably the same) server has closed the region
    // with later seqNum and told us about the new location.
    RegionLocations mergedLocation = oldLocation.mergeLocations(locations);
    boolean replaced = tableLocations.replace(startKey, oldLocation, mergedLocation);
    if (replaced && LOG.isTraceEnabled()) {
        LOG.trace("Merged cached locations: " + mergedLocation);
    }
    addToCachedServers(locations);
}
Also used : RegionLocations(org.apache.hadoop.hbase.RegionLocations)

Example 17 with RegionLocations

use of org.apache.hadoop.hbase.RegionLocations in project hbase by apache.

the class TestMetaWithReplicas method testHBaseFsckWithFewerMetaReplicaZnodes.

@Test
public void testHBaseFsckWithFewerMetaReplicaZnodes() throws Exception {
    ClusterConnection c = (ClusterConnection) ConnectionFactory.createConnection(TEST_UTIL.getConfiguration());
    RegionLocations rl = c.locateRegion(TableName.META_TABLE_NAME, HConstants.EMPTY_START_ROW, false, false);
    HBaseFsckRepair.closeRegionSilentlyAndWait(c, rl.getRegionLocation(2).getServerName(), rl.getRegionLocation(2).getRegionInfo());
    ZooKeeperWatcher zkw = TEST_UTIL.getZooKeeperWatcher();
    ZKUtil.deleteNode(zkw, zkw.znodePaths.getZNodeForReplica(2));
    // check that problem exists
    HBaseFsck hbck = doFsck(TEST_UTIL.getConfiguration(), false);
    assertErrors(hbck, new ERROR_CODE[] { ERROR_CODE.UNKNOWN, ERROR_CODE.NO_META_REGION });
    // fix the problem
    hbck = doFsck(TEST_UTIL.getConfiguration(), true);
    // run hbck again to make sure we don't see any errors
    hbck = doFsck(TEST_UTIL.getConfiguration(), false);
    assertErrors(hbck, new ERROR_CODE[] {});
}
Also used : RegionLocations(org.apache.hadoop.hbase.RegionLocations) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher) HBaseFsck(org.apache.hadoop.hbase.util.HBaseFsck) Test(org.junit.Test)

Example 18 with RegionLocations

use of org.apache.hadoop.hbase.RegionLocations in project hbase by apache.

the class TestMetaWithReplicas method testShutdownOfReplicaHolder.

@Test
public void testShutdownOfReplicaHolder() throws Exception {
    // can be recovered
    try (ClusterConnection conn = (ClusterConnection) ConnectionFactory.createConnection(TEST_UTIL.getConfiguration())) {
        RegionLocations rl = conn.locateRegion(TableName.META_TABLE_NAME, Bytes.toBytes(""), false, true);
        HRegionLocation hrl = rl.getRegionLocation(1);
        ServerName oldServer = hrl.getServerName();
        TEST_UTIL.getHBaseClusterInterface().killRegionServer(oldServer);
        int i = 0;
        do {
            LOG.debug("Waiting for the replica " + hrl.getRegionInfo() + " to come up");
            //wait for the detection/recovery
            Thread.sleep(30000);
            rl = conn.locateRegion(TableName.META_TABLE_NAME, Bytes.toBytes(""), false, true);
            hrl = rl.getRegionLocation(1);
            i++;
        } while ((hrl == null || hrl.getServerName().equals(oldServer)) && i < 3);
        assertTrue(i != 3);
    }
}
Also used : RegionLocations(org.apache.hadoop.hbase.RegionLocations) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ServerName(org.apache.hadoop.hbase.ServerName) Test(org.junit.Test)

Example 19 with RegionLocations

use of org.apache.hadoop.hbase.RegionLocations in project hbase by apache.

the class TestZKAsyncRegistry method test.

@Test
public void test() throws InterruptedException, ExecutionException, IOException {
    assertEquals(TEST_UTIL.getHBaseCluster().getClusterStatus().getClusterId(), REGISTRY.getClusterId().get());
    assertEquals(TEST_UTIL.getHBaseCluster().getClusterStatus().getServersSize(), REGISTRY.getCurrentNrHRS().get().intValue());
    assertEquals(TEST_UTIL.getHBaseCluster().getMaster().getServerName(), REGISTRY.getMasterAddress().get());
    assertEquals(-1, REGISTRY.getMasterInfoPort().get().intValue());
    waitUntilAllReplicasHavingRegionLocation(TableName.META_TABLE_NAME);
    RegionLocations locs = REGISTRY.getMetaRegionLocation().get();
    assertEquals(3, locs.getRegionLocations().length);
    IntStream.range(0, 3).forEach(i -> {
        HRegionLocation loc = locs.getRegionLocation(i);
        assertNotNull("Replica " + i + " doesn't have location", loc);
        assertTrue(loc.getRegionInfo().getTable().equals(TableName.META_TABLE_NAME));
        assertEquals(i, loc.getRegionInfo().getReplicaId());
    });
}
Also used : RegionLocations(org.apache.hadoop.hbase.RegionLocations) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) Test(org.junit.Test)

Example 20 with RegionLocations

use of org.apache.hadoop.hbase.RegionLocations in project hbase by apache.

the class MasterProcedureTestingUtility method countMetaRegions.

private static int countMetaRegions(final HMaster master, final TableName tableName) throws IOException {
    final AtomicInteger actualRegCount = new AtomicInteger(0);
    final MetaTableAccessor.Visitor visitor = new MetaTableAccessor.Visitor() {

        @Override
        public boolean visit(Result rowResult) throws IOException {
            RegionLocations list = MetaTableAccessor.getRegionLocations(rowResult);
            if (list == null) {
                LOG.warn("No serialized HRegionInfo in " + rowResult);
                return true;
            }
            HRegionLocation l = list.getRegionLocation();
            if (l == null) {
                return true;
            }
            if (!l.getRegionInfo().getTable().equals(tableName)) {
                return false;
            }
            if (l.getRegionInfo().isOffline() || l.getRegionInfo().isSplit())
                return true;
            HRegionLocation[] locations = list.getRegionLocations();
            for (HRegionLocation location : locations) {
                if (location == null)
                    continue;
                ServerName serverName = location.getServerName();
                // Make sure that regions are assigned to server
                if (serverName != null && serverName.getHostAndPort() != null) {
                    actualRegCount.incrementAndGet();
                }
            }
            return true;
        }
    };
    MetaTableAccessor.scanMetaForTableRegions(master.getConnection(), visitor, tableName);
    return actualRegCount.get();
}
Also used : RegionLocations(org.apache.hadoop.hbase.RegionLocations) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServerName(org.apache.hadoop.hbase.ServerName) MetaTableAccessor(org.apache.hadoop.hbase.MetaTableAccessor) Result(org.apache.hadoop.hbase.client.Result)

Aggregations

RegionLocations (org.apache.hadoop.hbase.RegionLocations)47 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)28 ServerName (org.apache.hadoop.hbase.ServerName)18 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)13 Test (org.junit.Test)9 IOException (java.io.IOException)8 InterruptedIOException (java.io.InterruptedIOException)7 ArrayList (java.util.ArrayList)6 Result (org.apache.hadoop.hbase.client.Result)6 TableName (org.apache.hadoop.hbase.TableName)5 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)4 MetaTableAccessor (org.apache.hadoop.hbase.MetaTableAccessor)4 Pair (org.apache.hadoop.hbase.util.Pair)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)2 CancellationException (java.util.concurrent.CancellationException)2 ExecutionException (java.util.concurrent.ExecutionException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)2 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)2