@Test public void testBalance() throws IOException, KeeperException, DeserializationException, InterruptedException, CoordinatedStateException { ExecutorService executor = startupMasterExecutor("testBalanceExecutor"); CatalogTracker ct = Mockito.mock(CatalogTracker.class); LoadBalancer balancer = LoadBalancerFactory.getLoadBalancer(server .getConfiguration()); AssignmentManager am = new AssignmentManager(this.server, this.serverManager, ct, balancer, executor, null, master.getTableLockManager()); am.failoverCleanupDone.set(true); try { this.watcher.registerListenerFirst(am); am.regionOnline(REGIONINFO, SERVERNAME_A); RegionPlan plan = new RegionPlan(REGIONINFO, SERVERNAME_A, SERVERNAME_B); am.balance(plan); RegionStates regionStates = am.getRegionStates(); assertTrue(regionStates.isRegionInTransition(REGIONINFO) && regionStates.isRegionInState(REGIONINFO, State.FAILED_CLOSE)); regionStates.updateRegionState(REGIONINFO, State.PENDING_CLOSE); int versionid = ZKAssign.transitionNodeClosed(this.watcher, REGIONINFO, SERVERNAME_A, -1); assertNotSame(versionid, -1); Mocking.waitForRegionPendingOpenInRIT(am, REGIONINFO.getEncodedName()); versionid = ZKAssign.getVersion(this.watcher, REGIONINFO); assertNotSame(-1, versionid); versionid = ZKAssign.transitionNode(server.getZooKeeper(), REGIONINFO, SERVERNAME_B, EventType.M_ZK_REGION_OFFLINE, EventType.RS_ZK_REGION_OPENING, versionid); assertNotSame(-1, versionid); versionid = ZKAssign.transitionNodeOpened(this.watcher, REGIONINFO, SERVERNAME_B, versionid); assertNotSame(-1, versionid); while(regionStates.isRegionInTransition(REGIONINFO)) Threads.sleep(1); } finally { executor.shutdown(); am.shutdown(); ZKAssign.deleteAllNodes(this.watcher); } }
public void balance(final RegionPlan plan) { HRegionInfo hri = plan.getRegionInfo(); TableName tableName = hri.getTable(); if (tableStateManager.isTableState(tableName, ZooKeeperProtos.Table.State.DISABLED, ZooKeeperProtos.Table.State.DISABLING)) { LOG.info("Ignored moving region of disabling/disabled table " + tableName); return; } String encodedName = hri.getEncodedName(); ReentrantLock lock = locker.acquireLock(encodedName); try { if (!regionStates.isRegionOnline(hri)) { RegionState state = regionStates.getRegionState(encodedName); LOG.info("Ignored moving region not assigned: " + hri + ", " + (state == null ? "not in region states" : state)); return; } synchronized (this.regionPlans) { this.regionPlans.put(plan.getRegionName(), plan); } unassign(hri, false, plan.getDestination()); } finally { lock.unlock(); } }
AssignmentManager extends ZooKeeperListener { public void balance(final RegionPlan plan) { HRegionInfo hri = plan.getRegionInfo(); TableName tableName = hri.getTable(); if (tableStateManager.isTableState(tableName, ZooKeeperProtos.Table.State.DISABLED, ZooKeeperProtos.Table.State.DISABLING)) { LOG.info("Ignored moving region of disabling/disabled table " + tableName); return; } String encodedName = hri.getEncodedName(); ReentrantLock lock = locker.acquireLock(encodedName); try { if (!regionStates.isRegionOnline(hri)) { RegionState state = regionStates.getRegionState(encodedName); LOG.info("Ignored moving region not assigned: " + hri + ", " + (state == null ? "not in region states" : state)); return; } synchronized (this.regionPlans) { this.regionPlans.put(plan.getRegionName(), plan); } unassign(hri, false, plan.getDestination()); } finally { lock.unlock(); } } }
AssignmentManager extends ZooKeeperListener { public void balance(final RegionPlan plan) { HRegionInfo hri = plan.getRegionInfo(); TableName tableName = hri.getTable(); if (tableStateManager.isTableState(tableName, ZooKeeperProtos.Table.State.DISABLED, ZooKeeperProtos.Table.State.DISABLING)) { LOG.info("Ignored moving region of disabling/disabled table " + tableName); return; } String encodedName = hri.getEncodedName(); ReentrantLock lock = locker.acquireLock(encodedName); try { if (!regionStates.isRegionOnline(hri)) { RegionState state = regionStates.getRegionState(encodedName); LOG.info("Ignored moving region not assigned: " + hri + ", " + (state == null ? "not in region states" : state)); return; } synchronized (this.regionPlans) { this.regionPlans.put(plan.getRegionName(), plan); } unassign(hri, false, plan.getDestination()); } finally { lock.unlock(); } } AssignmentManager(Server server, ServerManager serverManager,
      CatalogTracker catalogTracker, final LoadBalancer balancer,
      final ExecutorService service, MetricsMaster metricsMaster,
      final TableLockManager tableLockManager); }
AssignmentManager extends ZooKeeperListener { public void balance(final RegionPlan plan) { HRegionInfo hri = plan.getRegionInfo(); TableName tableName = hri.getTable(); if (tableStateManager.isTableState(tableName, ZooKeeperProtos.Table.State.DISABLED, ZooKeeperProtos.Table.State.DISABLING)) { LOG.info("Ignored moving region of disabling/disabled table " + tableName); return; } String encodedName = hri.getEncodedName(); ReentrantLock lock = locker.acquireLock(encodedName); try { if (!regionStates.isRegionOnline(hri)) { RegionState state = regionStates.getRegionState(encodedName); LOG.info("Ignored moving region not assigned: " + hri + ", " + (state == null ? "not in region states" : state)); return; } synchronized (this.regionPlans) { this.regionPlans.put(plan.getRegionName(), plan); } unassign(hri, false, plan.getDestination()); } finally { lock.unlock(); } } AssignmentManager(Server server, ServerManager serverManager,
      CatalogTracker catalogTracker, final LoadBalancer balancer,
      final ExecutorService service, MetricsMaster metricsMaster,
      final TableLockManager tableLockManager); void registerListener(final AssignmentListener listener); boolean unregisterListener(final AssignmentListener listener); TableStateManager getTableStateManager(); RegionStates getRegionStates(); RegionPlan getRegionReopenPlan(HRegionInfo hri); void addPlan(String encodedName, RegionPlan plan); void addPlans(Map<String, RegionPlan> plans); void setRegionsToReopen(List <HRegionInfo> regions); Pair<Integer, Integer> getReopenStatus(TableName tableName); boolean isFailoverCleanupDone(); Lock acquireRegionLock(final String encodedName); void removeClosedRegion(HRegionInfo hri); @Override void nodeCreated(String path); @Override void nodeDataChanged(String path); @Override void nodeDeleted(final String path); @Override void nodeChildrenChanged(String path); void regionOffline(final HRegionInfo regionInfo); void offlineDisabledRegion(HRegionInfo regionInfo); void assign(HRegionInfo region, boolean setOfflineInZK); void assign(HRegionInfo region,
      boolean setOfflineInZK, boolean forceNewPlan); void unassign(HRegionInfo region); void unassign(HRegionInfo region, boolean force, ServerName dest); void unassign(HRegionInfo region, boolean force); void deleteClosingOrClosedNode(HRegionInfo region, ServerName sn); int getNumRegionsOpened(); boolean waitForAssignment(HRegionInfo regionInfo); void assignMeta(); void assign(Map<HRegionInfo, ServerName> regions); void assign(List<HRegionInfo> regions); void updateRegionsInTransitionMetrics(); void waitOnRegionToClearRegionsInTransition(final HRegionInfo hri); boolean waitOnRegionToClearRegionsInTransition(final HRegionInfo hri, long timeOut); boolean isCarryingMeta(ServerName serverName); List<HRegionInfo> processServerShutdown(final ServerName sn); void balance(final RegionPlan plan); void stop(); void shutdown(); LoadBalancer getBalancer(); }
AssignmentManager extends ZooKeeperListener { public void balance(final RegionPlan plan) { HRegionInfo hri = plan.getRegionInfo(); TableName tableName = hri.getTable(); if (tableStateManager.isTableState(tableName, ZooKeeperProtos.Table.State.DISABLED, ZooKeeperProtos.Table.State.DISABLING)) { LOG.info("Ignored moving region of disabling/disabled table " + tableName); return; } String encodedName = hri.getEncodedName(); ReentrantLock lock = locker.acquireLock(encodedName); try { if (!regionStates.isRegionOnline(hri)) { RegionState state = regionStates.getRegionState(encodedName); LOG.info("Ignored moving region not assigned: " + hri + ", " + (state == null ? "not in region states" : state)); return; } synchronized (this.regionPlans) { this.regionPlans.put(plan.getRegionName(), plan); } unassign(hri, false, plan.getDestination()); } finally { lock.unlock(); } } AssignmentManager(Server server, ServerManager serverManager,
      CatalogTracker catalogTracker, final LoadBalancer balancer,
      final ExecutorService service, MetricsMaster metricsMaster,
      final TableLockManager tableLockManager); void registerListener(final AssignmentListener listener); boolean unregisterListener(final AssignmentListener listener); TableStateManager getTableStateManager(); RegionStates getRegionStates(); RegionPlan getRegionReopenPlan(HRegionInfo hri); void addPlan(String encodedName, RegionPlan plan); void addPlans(Map<String, RegionPlan> plans); void setRegionsToReopen(List <HRegionInfo> regions); Pair<Integer, Integer> getReopenStatus(TableName tableName); boolean isFailoverCleanupDone(); Lock acquireRegionLock(final String encodedName); void removeClosedRegion(HRegionInfo hri); @Override void nodeCreated(String path); @Override void nodeDataChanged(String path); @Override void nodeDeleted(final String path); @Override void nodeChildrenChanged(String path); void regionOffline(final HRegionInfo regionInfo); void offlineDisabledRegion(HRegionInfo regionInfo); void assign(HRegionInfo region, boolean setOfflineInZK); void assign(HRegionInfo region,
      boolean setOfflineInZK, boolean forceNewPlan); void unassign(HRegionInfo region); void unassign(HRegionInfo region, boolean force, ServerName dest); void unassign(HRegionInfo region, boolean force); void deleteClosingOrClosedNode(HRegionInfo region, ServerName sn); int getNumRegionsOpened(); boolean waitForAssignment(HRegionInfo regionInfo); void assignMeta(); void assign(Map<HRegionInfo, ServerName> regions); void assign(List<HRegionInfo> regions); void updateRegionsInTransitionMetrics(); void waitOnRegionToClearRegionsInTransition(final HRegionInfo hri); boolean waitOnRegionToClearRegionsInTransition(final HRegionInfo hri, long timeOut); boolean isCarryingMeta(ServerName serverName); List<HRegionInfo> processServerShutdown(final ServerName sn); void balance(final RegionPlan plan); void stop(); void shutdown(); LoadBalancer getBalancer(); static final ServerName HBCK_CODE_SERVERNAME; @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="MS_SHOULD_BE_FINAL")
  static boolean TEST_SKIP_SPLIT_HANDLING; }