/** * Load the meta region state from the meta server ZNode. */ public static RegionState getMetaRegionState(ZKWatcher zkw) throws KeeperException { return getMetaRegionState(zkw, RegionInfo.DEFAULT_REPLICA_ID); }
/** * Gets the meta region location, if available. Does not block. * @param zkw zookeeper connection to use * @return server name or null if we failed to get the data. */ public static ServerName getMetaRegionLocation(final ZKWatcher zkw) { try { RegionState state = getMetaRegionState(zkw); return state.isOpened() ? state.getServerName() : null; } catch (KeeperException ke) { return null; } }
/** * Gets the meta region location, if available. Does not block. * @param zkw reference to the {@link ZKWatcher} which also contains configuration and operation * @param replicaId the ID of the replica * @return server name */ public static ServerName getMetaRegionLocation(final ZKWatcher zkw, int replicaId) { try { RegionState state = getMetaRegionState(zkw, replicaId); return state.isOpened() ? state.getServerName() : null; } catch (KeeperException ke) { return null; } }
private void unassignExcessMetaReplica(int numMetaReplicasConfigured) { final ZKWatcher zooKeeper = master.getZooKeeper(); // unassign the unneeded replicas (for e.g., if the previous master was configured // with a replication of 3 and now it is 2, we need to unassign the 1 unneeded replica) try { List<String> metaReplicaZnodes = zooKeeper.getMetaReplicaNodes(); for (String metaReplicaZnode : metaReplicaZnodes) { int replicaId = zooKeeper.getZNodePaths().getMetaReplicaIdFromZnode(metaReplicaZnode); if (replicaId >= numMetaReplicasConfigured) { RegionState r = MetaTableLocator.getMetaRegionState(zooKeeper, replicaId); LOG.info("Closing excess replica of meta region " + r.getRegion()); // send a close and wait for a max of 30 seconds ServerManager.closeRegionSilentlyAndWait(master.getClusterConnection(), r.getServerName(), r.getRegion(), 30000); ZKUtil.deleteNode(zooKeeper, zooKeeper.getZNodePaths().getZNodeForReplica(replicaId)); } } } catch (Exception ex) { // ignore the exception since we don't want the master to be wedged due to potential // issues in the cleanup of the extra regions. We can do that cleanup via hbck or manually LOG.warn("Ignoring exception " + ex); } } }
public void start() throws IOException, KeeperException { if (!running.compareAndSet(false, true)) { return; } LOG.trace("Starting assignment manager"); // Start the Assignment Thread startAssignmentThread(); // load meta region state ZKWatcher zkw = master.getZooKeeper(); // it could be null in some tests if (zkw != null) { RegionState regionState = MetaTableLocator.getMetaRegionState(zkw); RegionStateNode regionNode = regionStates.getOrCreateRegionStateNode(RegionInfoBuilder.FIRST_META_REGIONINFO); regionNode.lock(); try { regionNode.setRegionLocation(regionState.getServerName()); regionNode.setState(regionState.getState()); setMetaAssigned(regionState.getRegion(), regionState.getState() == State.OPEN); } finally { regionNode.unlock(); } } }
for (int i = 1; i < numReplicas; i++) { RegionState metaState = MetaTableLocator.getMetaRegionState(master.getZooKeeper(), i); RegionInfo hri = RegionReplicaUtil.getRegionInfoForReplica( RegionInfoBuilder.FIRST_META_REGIONINFO, i);
/** * Test normal operations */ @Test public void testMetaLookup() throws IOException, InterruptedException, ServiceException, KeeperException { final ClientProtos.ClientService.BlockingInterface client = Mockito.mock(ClientProtos.ClientService.BlockingInterface.class); Mockito.when(client.get((RpcController) Mockito.any(), (GetRequest) Mockito.any())) .thenReturn(GetResponse.newBuilder().build()); assertNull(MetaTableLocator.getMetaRegionLocation(this.watcher)); for (RegionState.State state : RegionState.State.values()) { if (state.equals(RegionState.State.OPEN)) { continue; } MetaTableLocator.setMetaLocation(this.watcher, SN, state); assertNull(MetaTableLocator.getMetaRegionLocation(this.watcher)); assertEquals(state, MetaTableLocator.getMetaRegionState(this.watcher).getState()); } MetaTableLocator.setMetaLocation(this.watcher, SN, RegionState.State.OPEN); assertEquals(SN, MetaTableLocator.getMetaRegionLocation(this.watcher)); assertEquals(RegionState.State.OPEN, MetaTableLocator.getMetaRegionState(this.watcher).getState()); MetaTableLocator.deleteMetaLocation(this.watcher); assertNull(MetaTableLocator.getMetaRegionState(this.watcher).getServerName()); assertEquals(RegionState.State.OFFLINE, MetaTableLocator.getMetaRegionState(this.watcher).getState()); assertNull(MetaTableLocator.getMetaRegionLocation(this.watcher)); }
RegionState metaState = MetaTableLocator.getMetaRegionState(hrs.getZooKeeper()); assertEquals("hbase:meta should be online on RS", metaState.getServerName(), metaServerName); metaState = MetaTableLocator.getMetaRegionState(activeMaster.getZooKeeper()); assertEquals("hbase:meta should be online on RS", metaState.getServerName(), metaServerName);
metaServerName = regionStates.getRegionServerOfRegion(HRegionInfo.FIRST_META_REGIONINFO); RegionState metaState = MetaTableLocator.getMetaRegionState(master.getZooKeeper()); assertEquals("Wrong state for meta!", RegionState.State.OPEN, metaState.getState()); assertNotEquals("Meta is on master!", metaServerName, master.getServerName()); regionStates.isRegionOnline(HRegionInfo.FIRST_META_REGIONINFO)); metaState = MetaTableLocator.getMetaRegionState(master.getZooKeeper()); assertEquals("Meta should not be in transition", RegionState.State.OPEN, metaState.getState());
/** * Load the meta region state from the meta server ZNode. */ public static RegionState getMetaRegionState(ZKWatcher zkw) throws KeeperException { return getMetaRegionState(zkw, RegionInfo.DEFAULT_REPLICA_ID); }
/** * Load the meta region state from the meta server ZNode. */ public static RegionState getMetaRegionState(ZooKeeperWatcher zkw) throws KeeperException { return getMetaRegionState(zkw, HRegionInfo.DEFAULT_REPLICA_ID); }
/** * Gets the meta region location, if available. Does not block. * @param zkw reference to the {@link ZKWatcher} which also contains configuration and operation * @param replicaId the ID of the replica * @return server name */ public ServerName getMetaRegionLocation(final ZKWatcher zkw, int replicaId) { try { RegionState state = getMetaRegionState(zkw, replicaId); return state.isOpened() ? state.getServerName() : null; } catch (KeeperException ke) { return null; } }
/** * Gets the meta region location, if available. Does not block. * @param zkw zookeeper connection to use * @return server name or null if we failed to get the data. */ public ServerName getMetaRegionLocation(final ZKWatcher zkw) { try { RegionState state = getMetaRegionState(zkw); return state.isOpened() ? state.getServerName() : null; } catch (KeeperException ke) { return null; } }
/** * Gets the meta region location, if available. Does not block. * @param zkw zookeeper connection to use * @return server name or null if we failed to get the data. */ public ServerName getMetaRegionLocation(final ZooKeeperWatcher zkw) { try { RegionState state = getMetaRegionState(zkw); return state.isOpened() ? state.getServerName() : null; } catch (KeeperException ke) { return null; } }
/** * Gets the meta region location, if available. Does not block. * @param zkw * @param replicaId * @return server name */ public ServerName getMetaRegionLocation(final ZooKeeperWatcher zkw, int replicaId) { try { RegionState state = getMetaRegionState(zkw, replicaId); return state.isOpened() ? state.getServerName() : null; } catch (KeeperException ke) { return null; } }
/** * Test normal operations */ @Test public void testMetaLookup() throws IOException, InterruptedException, ServiceException, KeeperException { final ClientProtos.ClientService.BlockingInterface client = Mockito.mock(ClientProtos.ClientService.BlockingInterface.class); Mockito.when(client.get((RpcController)Mockito.any(), (GetRequest)Mockito.any())). thenReturn(GetResponse.newBuilder().build()); final MetaTableLocator mtl = new MetaTableLocator(); assertNull(mtl.getMetaRegionLocation(this.watcher)); for (RegionState.State state : RegionState.State.values()) { if (state.equals(RegionState.State.OPEN)) continue; MetaTableLocator.setMetaLocation(this.watcher, SN, state); assertNull(mtl.getMetaRegionLocation(this.watcher)); assertEquals(state, MetaTableLocator.getMetaRegionState(this.watcher).getState()); } MetaTableLocator.setMetaLocation(this.watcher, SN, RegionState.State.OPEN); assertEquals(SN, mtl.getMetaRegionLocation(this.watcher)); assertEquals(RegionState.State.OPEN, MetaTableLocator.getMetaRegionState(this.watcher).getState()); mtl.deleteMetaLocation(this.watcher); assertNull(MetaTableLocator.getMetaRegionState(this.watcher).getServerName()); assertEquals(RegionState.State.OFFLINE, MetaTableLocator.getMetaRegionState(this.watcher).getState()); assertNull(mtl.getMetaRegionLocation(this.watcher)); }
private void unassignExcessMetaReplica(ZooKeeperWatcher zkw, int numMetaReplicasConfigured) { // unassign the unneeded replicas (for e.g., if the previous master was configured // with a replication of 3 and now it is 2, we need to unassign the 1 unneeded replica) try { List<String> metaReplicaZnodes = zooKeeper.getMetaReplicaNodes(); for (String metaReplicaZnode : metaReplicaZnodes) { int replicaId = zooKeeper.getMetaReplicaIdFromZnode(metaReplicaZnode); if (replicaId >= numMetaReplicasConfigured) { RegionState r = MetaTableLocator.getMetaRegionState(zkw, replicaId); LOG.info("Closing excess replica of meta region " + r.getRegion()); // send a close and wait for a max of 30 seconds ServerManager.closeRegionSilentlyAndWait(getConnection(), r.getServerName(), r.getRegion(), 30000); ZKUtil.deleteNode(zkw, zkw.getZNodeForReplica(replicaId)); } } } catch (Exception ex) { // ignore the exception since we don't want the master to be wedged due to potential // issues in the cleanup of the extra regions. We can do that cleanup via hbck or manually LOG.warn("Ignoring exception " + ex); } }
RegionState metaState = MetaTableLocator.getMetaRegionState(hrs.getZooKeeper()); assertEquals("hbase:meta should be online on RS", metaState.getServerName(), metaServerName); metaState = MetaTableLocator.getMetaRegionState(activeMaster.getZooKeeper()); assertEquals("hbase:meta should be online on RS", metaState.getServerName(), metaServerName);
RegionState metaState = MetaTableLocator.getMetaRegionState(getZooKeeper(), replicaId); HRegionInfo hri = RegionReplicaUtil.getRegionInfoForReplica(HRegionInfo.FIRST_META_REGIONINFO, replicaId);
metaServerName = regionStates.getRegionServerOfRegion(HRegionInfo.FIRST_META_REGIONINFO); RegionState metaState = MetaTableLocator.getMetaRegionState(master.getZooKeeper()); assertEquals("Wrong state for meta!", RegionState.State.OPEN, metaState.getState()); assertNotEquals("Meta is on master!", metaServerName, master.getServerName()); regionStates.isRegionOnline(HRegionInfo.FIRST_META_REGIONINFO)); metaState = MetaTableLocator.getMetaRegionState(master.getZooKeeper()); assertEquals("Meta should not be in transition", RegionState.State.OPEN, metaState.getState());