@Test(timeout = 60000) public void testProcessDeadServersAndRegionsInTransitionShouldNotFailWithNPE() throws IOException, KeeperException, CoordinatedStateException, InterruptedException, ServiceException { final RecoverableZooKeeper recoverableZk = Mockito .mock(RecoverableZooKeeper.class); AssignmentManagerWithExtrasForTesting am = setUpMockedAssignmentManager( this.server, this.serverManager); Watcher zkw = new ZooKeeperWatcher(HBaseConfiguration.create(), "unittest", null) { @Override public RecoverableZooKeeper getRecoverableZooKeeper() { return recoverableZk; } }; ((ZooKeeperWatcher) zkw).registerListener(am); Mockito.doThrow(new InterruptedException()).when(recoverableZk) .getChildren("/hbase/region-in-transition", null); am.setWatcher((ZooKeeperWatcher) zkw); try { am.processDeadServersAndRegionsInTransition(null); fail("Expected to abort"); } catch (NullPointerException e) { fail("Should not throw NPE"); } catch (RuntimeException e) { assertEquals("Aborted", e.getLocalizedMessage()); } }
void processDeadServersAndRegionsInTransition( final Map<ServerName, List<HRegionInfo>> deadServers) throws KeeperException, IOException, InterruptedException, CoordinatedStateException { List<String> nodes = ZKUtil.listChildrenNoWatch(watcher, watcher.assignmentZNode); if (nodes == null) { String errorMessage = "Failed to get the children from ZK"; server.abort(errorMessage, new IOException(errorMessage)); return; } boolean failover = (!serverManager.getDeadServers().isEmpty() || !serverManager .getRequeuedDeadServers().isEmpty()); if (!failover) { Map<HRegionInfo, ServerName> regions = regionStates.getRegionAssignments(); for (HRegionInfo hri: regions.keySet()) { if (!hri.isMetaTable()) { LOG.debug("Found " + hri + " out on cluster"); failover = true; break; } } if (!failover) { for (String encodedName: nodes) { RegionState state = regionStates.getRegionState(encodedName); if (state != null && !state.getRegion().isMetaRegion()) { LOG.debug("Found " + state.getRegion().getRegionNameAsString() + " in RITs"); failover = true; break; } } } } if (failover) { LOG.info("Found regions out on cluster or in RIT; presuming failover"); processDeadServersAndRecoverLostRegions(deadServers); } else { LOG.info("Clean cluster startup. Assigning userregions"); assignAllUserRegions(); } }
AssignmentManager extends ZooKeeperListener { void processDeadServersAndRegionsInTransition( final Map<ServerName, List<HRegionInfo>> deadServers) throws KeeperException, IOException, InterruptedException, CoordinatedStateException { List<String> nodes = ZKUtil.listChildrenNoWatch(watcher, watcher.assignmentZNode); if (nodes == null) { String errorMessage = "Failed to get the children from ZK"; server.abort(errorMessage, new IOException(errorMessage)); return; } boolean failover = (!serverManager.getDeadServers().isEmpty() || !serverManager .getRequeuedDeadServers().isEmpty()); if (!failover) { Map<HRegionInfo, ServerName> regions = regionStates.getRegionAssignments(); for (HRegionInfo hri: regions.keySet()) { if (!hri.isMetaTable()) { LOG.debug("Found " + hri + " out on cluster"); failover = true; break; } } if (!failover) { for (String encodedName: nodes) { RegionState state = regionStates.getRegionState(encodedName); if (state != null && !state.getRegion().isMetaRegion()) { LOG.debug("Found " + state.getRegion().getRegionNameAsString() + " in RITs"); failover = true; break; } } } } if (failover) { LOG.info("Found regions out on cluster or in RIT; presuming failover"); processDeadServersAndRecoverLostRegions(deadServers); } else { LOG.info("Clean cluster startup. Assigning userregions"); assignAllUserRegions(); } } }
AssignmentManager extends ZooKeeperListener { void processDeadServersAndRegionsInTransition( final Map<ServerName, List<HRegionInfo>> deadServers) throws KeeperException, IOException, InterruptedException, CoordinatedStateException { List<String> nodes = ZKUtil.listChildrenNoWatch(watcher, watcher.assignmentZNode); if (nodes == null) { String errorMessage = "Failed to get the children from ZK"; server.abort(errorMessage, new IOException(errorMessage)); return; } boolean failover = (!serverManager.getDeadServers().isEmpty() || !serverManager .getRequeuedDeadServers().isEmpty()); if (!failover) { Map<HRegionInfo, ServerName> regions = regionStates.getRegionAssignments(); for (HRegionInfo hri: regions.keySet()) { if (!hri.isMetaTable()) { LOG.debug("Found " + hri + " out on cluster"); failover = true; break; } } if (!failover) { for (String encodedName: nodes) { RegionState state = regionStates.getRegionState(encodedName); if (state != null && !state.getRegion().isMetaRegion()) { LOG.debug("Found " + state.getRegion().getRegionNameAsString() + " in RITs"); failover = true; break; } } } } if (failover) { LOG.info("Found regions out on cluster or in RIT; presuming failover"); processDeadServersAndRecoverLostRegions(deadServers); } else { LOG.info("Clean cluster startup. Assigning userregions"); assignAllUserRegions(); } } AssignmentManager(Server server, ServerManager serverManager,
      CatalogTracker catalogTracker, final LoadBalancer balancer,
      final ExecutorService service, MetricsMaster metricsMaster,
      final TableLockManager tableLockManager); }
AssignmentManager extends ZooKeeperListener { void processDeadServersAndRegionsInTransition( final Map<ServerName, List<HRegionInfo>> deadServers) throws KeeperException, IOException, InterruptedException, CoordinatedStateException { List<String> nodes = ZKUtil.listChildrenNoWatch(watcher, watcher.assignmentZNode); if (nodes == null) { String errorMessage = "Failed to get the children from ZK"; server.abort(errorMessage, new IOException(errorMessage)); return; } boolean failover = (!serverManager.getDeadServers().isEmpty() || !serverManager .getRequeuedDeadServers().isEmpty()); if (!failover) { Map<HRegionInfo, ServerName> regions = regionStates.getRegionAssignments(); for (HRegionInfo hri: regions.keySet()) { if (!hri.isMetaTable()) { LOG.debug("Found " + hri + " out on cluster"); failover = true; break; } } if (!failover) { for (String encodedName: nodes) { RegionState state = regionStates.getRegionState(encodedName); if (state != null && !state.getRegion().isMetaRegion()) { LOG.debug("Found " + state.getRegion().getRegionNameAsString() + " in RITs"); failover = true; break; } } } } if (failover) { LOG.info("Found regions out on cluster or in RIT; presuming failover"); processDeadServersAndRecoverLostRegions(deadServers); } else { LOG.info("Clean cluster startup. Assigning userregions"); assignAllUserRegions(); } } AssignmentManager(Server server, ServerManager serverManager,
      CatalogTracker catalogTracker, final LoadBalancer balancer,
      final ExecutorService service, MetricsMaster metricsMaster,
      final TableLockManager tableLockManager); 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 { void processDeadServersAndRegionsInTransition( final Map<ServerName, List<HRegionInfo>> deadServers) throws KeeperException, IOException, InterruptedException, CoordinatedStateException { List<String> nodes = ZKUtil.listChildrenNoWatch(watcher, watcher.assignmentZNode); if (nodes == null) { String errorMessage = "Failed to get the children from ZK"; server.abort(errorMessage, new IOException(errorMessage)); return; } boolean failover = (!serverManager.getDeadServers().isEmpty() || !serverManager .getRequeuedDeadServers().isEmpty()); if (!failover) { Map<HRegionInfo, ServerName> regions = regionStates.getRegionAssignments(); for (HRegionInfo hri: regions.keySet()) { if (!hri.isMetaTable()) { LOG.debug("Found " + hri + " out on cluster"); failover = true; break; } } if (!failover) { for (String encodedName: nodes) { RegionState state = regionStates.getRegionState(encodedName); if (state != null && !state.getRegion().isMetaRegion()) { LOG.debug("Found " + state.getRegion().getRegionNameAsString() + " in RITs"); failover = true; break; } } } } if (failover) { LOG.info("Found regions out on cluster or in RIT; presuming failover"); processDeadServersAndRecoverLostRegions(deadServers); } else { LOG.info("Clean cluster startup. Assigning userregions"); assignAllUserRegions(); } } AssignmentManager(Server server, ServerManager serverManager,
      CatalogTracker catalogTracker, final LoadBalancer balancer,
      final ExecutorService service, MetricsMaster metricsMaster,
      final TableLockManager tableLockManager); 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; }