View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  package org.apache.hadoop.hbase.master;
20  
21  import java.io.IOException;
22  import java.net.InetAddress;
23  import java.util.ArrayList;
24  import java.util.Collections;
25  import java.util.HashMap;
26  import java.util.HashSet;
27  import java.util.Iterator;
28  import java.util.List;
29  import java.util.Map;
30  import java.util.Map.Entry;
31  import java.util.Set;
32  import java.util.concurrent.ConcurrentHashMap;
33  import java.util.concurrent.ConcurrentNavigableMap;
34  import java.util.concurrent.ConcurrentSkipListMap;
35  import java.util.concurrent.CopyOnWriteArrayList;
36  
37  import org.apache.commons.logging.Log;
38  import org.apache.commons.logging.LogFactory;
39  import org.apache.hadoop.conf.Configuration;
40  import org.apache.hadoop.hbase.ClockOutOfSyncException;
41  import org.apache.hadoop.hbase.HConstants;
42  import org.apache.hadoop.hbase.HRegionInfo;
43  import org.apache.hadoop.hbase.NotServingRegionException;
44  import org.apache.hadoop.hbase.RegionLoad;
45  import org.apache.hadoop.hbase.Server;
46  import org.apache.hadoop.hbase.ServerLoad;
47  import org.apache.hadoop.hbase.ServerName;
48  import org.apache.hadoop.hbase.YouAreDeadException;
49  import org.apache.hadoop.hbase.ZooKeeperConnectionException;
50  import org.apache.hadoop.hbase.classification.InterfaceAudience;
51  import org.apache.hadoop.hbase.client.ClusterConnection;
52  import org.apache.hadoop.hbase.client.ConnectionFactory;
53  import org.apache.hadoop.hbase.client.RetriesExhaustedException;
54  import org.apache.hadoop.hbase.ipc.PayloadCarryingRpcController;
55  import org.apache.hadoop.hbase.ipc.RpcControllerFactory;
56  import org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer;
57  import org.apache.hadoop.hbase.master.handler.MetaServerShutdownHandler;
58  import org.apache.hadoop.hbase.master.handler.ServerShutdownHandler;
59  import org.apache.hadoop.hbase.monitoring.MonitoredTask;
60  import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
61  import org.apache.hadoop.hbase.protobuf.RequestConverter;
62  import org.apache.hadoop.hbase.protobuf.ResponseConverter;
63  import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.AdminService;
64  import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.OpenRegionRequest;
65  import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.OpenRegionResponse;
66  import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.ServerInfo;
67  import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos.RegionServerStartupRequest;
68  import org.apache.hadoop.hbase.protobuf.generated.ClusterStatusProtos.RegionStoreSequenceIds;
69  import org.apache.hadoop.hbase.protobuf.generated.ClusterStatusProtos.StoreSequenceId;
70  import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos.SplitLogTask.RecoveryMode;
71  import org.apache.hadoop.hbase.regionserver.HRegionServer;
72  import org.apache.hadoop.hbase.regionserver.RegionOpeningState;
73  import org.apache.hadoop.hbase.util.Bytes;
74  import org.apache.hadoop.hbase.util.Triple;
75  import org.apache.hadoop.hbase.util.RetryCounter;
76  import org.apache.hadoop.hbase.util.RetryCounterFactory;
77  import org.apache.hadoop.hbase.zookeeper.ZKUtil;
78  import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
79  import org.apache.zookeeper.KeeperException;
80  
81  import com.google.common.annotations.VisibleForTesting;
82  import com.google.protobuf.ByteString;
83  import com.google.protobuf.ServiceException;
84  
85  /**
86   * The ServerManager class manages info about region servers.
87   * <p>
88   * Maintains lists of online and dead servers.  Processes the startups,
89   * shutdowns, and deaths of region servers.
90   * <p>
91   * Servers are distinguished in two different ways.  A given server has a
92   * location, specified by hostname and port, and of which there can only be one
93   * online at any given time.  A server instance is specified by the location
94   * (hostname and port) as well as the startcode (timestamp from when the server
95   * was started).  This is used to differentiate a restarted instance of a given
96   * server from the original instance.
97   * <p>
98   * If a sever is known not to be running any more, it is called dead. The dead
99   * server needs to be handled by a ServerShutdownHandler.  If the handler is not
100  * enabled yet, the server can't be handled right away so it is queued up.
101  * After the handler is enabled, the server will be submitted to a handler to handle.
102  * However, the handler may be just partially enabled.  If so,
103  * the server cannot be fully processed, and be queued up for further processing.
104  * A server is fully processed only after the handler is fully enabled
105  * and has completed the handling.
106  */
107 @InterfaceAudience.Private
108 public class ServerManager {
109   public static final String WAIT_ON_REGIONSERVERS_MAXTOSTART =
110       "hbase.master.wait.on.regionservers.maxtostart";
111 
112   public static final String WAIT_ON_REGIONSERVERS_MINTOSTART =
113       "hbase.master.wait.on.regionservers.mintostart";
114 
115   public static final String WAIT_ON_REGIONSERVERS_TIMEOUT =
116       "hbase.master.wait.on.regionservers.timeout";
117 
118   public static final String WAIT_ON_REGIONSERVERS_INTERVAL =
119       "hbase.master.wait.on.regionservers.interval";
120 
121   private static final Log LOG = LogFactory.getLog(ServerManager.class);
122 
123   // Set if we are to shutdown the cluster.
124   private volatile boolean clusterShutdown = false;
125 
126   private final ConcurrentNavigableMap<byte[], Long> flushedSequenceIdByRegion =
127     new ConcurrentSkipListMap<byte[], Long>(Bytes.BYTES_COMPARATOR);
128 
129   private final ConcurrentNavigableMap<byte[], ConcurrentNavigableMap<byte[], Long>>
130     storeFlushedSequenceIdsByRegion =
131     new ConcurrentSkipListMap<byte[], ConcurrentNavigableMap<byte[], Long>>(Bytes.BYTES_COMPARATOR);
132 
133   /** Map of registered servers to their current load */
134   private final ConcurrentHashMap<ServerName, ServerLoad> onlineServers =
135     new ConcurrentHashMap<ServerName, ServerLoad>();
136 
137   /**
138    * Map of admin interfaces per registered regionserver; these interfaces we use to control
139    * regionservers out on the cluster
140    */
141   private final Map<ServerName, AdminService.BlockingInterface> rsAdmins =
142     new HashMap<ServerName, AdminService.BlockingInterface>();
143 
144   /**
145    * List of region servers <ServerName> that should not get any more new
146    * regions.
147    */
148   private final ArrayList<ServerName> drainingServers =
149     new ArrayList<ServerName>();
150 
151   private final Server master;
152   private final MasterServices services;
153   private final ClusterConnection connection;
154 
155   private final DeadServer deadservers = new DeadServer();
156 
157   private final long maxSkew;
158   private final long warningSkew;
159 
160   private final RetryCounterFactory pingRetryCounterFactory;
161   private final RpcControllerFactory rpcControllerFactory;
162 
163   /**
164    * Set of region servers which are dead but not processed immediately. If one
165    * server died before master enables ServerShutdownHandler, the server will be
166    * added to this set and will be processed through calling
167    * {@link ServerManager#processQueuedDeadServers()} by master.
168    * <p>
169    * A dead server is a server instance known to be dead, not listed in the /hbase/rs
170    * znode any more. It may have not been submitted to ServerShutdownHandler yet
171    * because the handler is not enabled.
172    * <p>
173    * A dead server, which has been submitted to ServerShutdownHandler while the
174    * handler is not enabled, is queued up.
175    * <p>
176    * So this is a set of region servers known to be dead but not submitted to
177    * ServerShutdownHander for processing yet.
178    */
179   private Set<ServerName> queuedDeadServers = new HashSet<ServerName>();
180 
181   /**
182    * Set of region servers which are dead and submitted to ServerShutdownHandler to process but not
183    * fully processed immediately.
184    * <p>
185    * If one server died before assignment manager finished the failover cleanup, the server will be
186    * added to this set and will be processed through calling
187    * {@link ServerManager#processQueuedDeadServers()} by assignment manager.
188    * <p>
189    * The Boolean value indicates whether log split is needed inside ServerShutdownHandler
190    * <p>
191    * ServerShutdownHandler processes a dead server submitted to the handler after the handler is
192    * enabled. It may not be able to complete the processing because meta is not yet online or master
193    * is currently in startup mode. In this case, the dead server will be parked in this set
194    * temporarily.
195    */
196   private Map<ServerName, Boolean> requeuedDeadServers
197     = new ConcurrentHashMap<ServerName, Boolean>();
198 
199   /** Listeners that are called on server events. */
200   private List<ServerListener> listeners = new CopyOnWriteArrayList<ServerListener>();
201 
202   /**
203    * Constructor.
204    * @param master
205    * @param services
206    * @throws ZooKeeperConnectionException
207    */
208   public ServerManager(final Server master, final MasterServices services)
209       throws IOException {
210     this(master, services, true);
211   }
212 
213   ServerManager(final Server master, final MasterServices services,
214       final boolean connect) throws IOException {
215     this.master = master;
216     this.services = services;
217     Configuration c = master.getConfiguration();
218     maxSkew = c.getLong("hbase.master.maxclockskew", 30000);
219     warningSkew = c.getLong("hbase.master.warningclockskew", 10000);
220     this.connection = connect ? (ClusterConnection)ConnectionFactory.createConnection(c) : null;
221     int pingMaxAttempts = Math.max(1, master.getConfiguration().getInt(
222       "hbase.master.maximum.ping.server.attempts", 10));
223     int pingSleepInterval = Math.max(1, master.getConfiguration().getInt(
224       "hbase.master.ping.server.retry.sleep.interval", 100));
225     this.pingRetryCounterFactory = new RetryCounterFactory(pingMaxAttempts, pingSleepInterval);
226     this.rpcControllerFactory = this.connection == null
227         ? null
228         : connection.getRpcControllerFactory();
229   }
230 
231   /**
232    * Add the listener to the notification list.
233    * @param listener The ServerListener to register
234    */
235   public void registerListener(final ServerListener listener) {
236     this.listeners.add(listener);
237   }
238 
239   /**
240    * Remove the listener from the notification list.
241    * @param listener The ServerListener to unregister
242    */
243   public boolean unregisterListener(final ServerListener listener) {
244     return this.listeners.remove(listener);
245   }
246 
247   /**
248    * Let the server manager know a new regionserver has come online
249    * @param request the startup request
250    * @param ia the InetAddress from which request is received
251    * @return The ServerName we know this server as.
252    * @throws IOException
253    */
254   ServerName regionServerStartup(RegionServerStartupRequest request, InetAddress ia)
255       throws IOException {
256     // Test for case where we get a region startup message from a regionserver
257     // that has been quickly restarted but whose znode expiration handler has
258     // not yet run, or from a server whose fail we are currently processing.
259     // Test its host+port combo is present in serverAddresstoServerInfo.  If it
260     // is, reject the server and trigger its expiration. The next time it comes
261     // in, it should have been removed from serverAddressToServerInfo and queued
262     // for processing by ProcessServerShutdown.
263 
264     final String hostname = request.hasUseThisHostnameInstead() ?
265         request.getUseThisHostnameInstead() :ia.getHostName();
266     ServerName sn = ServerName.valueOf(hostname, request.getPort(),
267       request.getServerStartCode());
268     checkClockSkew(sn, request.getServerCurrentTime());
269     checkIsDead(sn, "STARTUP");
270     if (!checkAndRecordNewServer(sn, ServerLoad.EMPTY_SERVERLOAD)) {
271       LOG.warn("THIS SHOULD NOT HAPPEN, RegionServerStartup"
272         + " could not record the server: " + sn);
273     }
274     return sn;
275   }
276 
277   private ConcurrentNavigableMap<byte[], Long> getOrCreateStoreFlushedSequenceId(
278     byte[] regionName) {
279     ConcurrentNavigableMap<byte[], Long> storeFlushedSequenceId =
280         storeFlushedSequenceIdsByRegion.get(regionName);
281     if (storeFlushedSequenceId != null) {
282       return storeFlushedSequenceId;
283     }
284     storeFlushedSequenceId = new ConcurrentSkipListMap<byte[], Long>(Bytes.BYTES_COMPARATOR);
285     ConcurrentNavigableMap<byte[], Long> alreadyPut =
286         storeFlushedSequenceIdsByRegion.putIfAbsent(regionName, storeFlushedSequenceId);
287     return alreadyPut == null ? storeFlushedSequenceId : alreadyPut;
288   }
289   /**
290    * Updates last flushed sequence Ids for the regions on server sn
291    * @param sn
292    * @param hsl
293    */
294   private void updateLastFlushedSequenceIds(ServerName sn, ServerLoad hsl) {
295     Map<byte[], RegionLoad> regionsLoad = hsl.getRegionsLoad();
296     for (Entry<byte[], RegionLoad> entry : regionsLoad.entrySet()) {
297       byte[] encodedRegionName = Bytes.toBytes(HRegionInfo.encodeRegionName(entry.getKey()));
298       Long existingValue = flushedSequenceIdByRegion.get(encodedRegionName);
299       long l = entry.getValue().getCompleteSequenceId();
300       // Don't let smaller sequence ids override greater sequence ids.
301       if (existingValue == null || (l != HConstants.NO_SEQNUM && l > existingValue)) {
302         flushedSequenceIdByRegion.put(encodedRegionName, l);
303       } else if (l != HConstants.NO_SEQNUM && l < existingValue) {
304         LOG.warn("RegionServer " + sn + " indicates a last flushed sequence id ("
305             + l + ") that is less than the previous last flushed sequence id ("
306             + existingValue + ") for region " + Bytes.toString(entry.getKey()) + " Ignoring.");
307       }
308       ConcurrentNavigableMap<byte[], Long> storeFlushedSequenceId =
309           getOrCreateStoreFlushedSequenceId(encodedRegionName);
310       for (StoreSequenceId storeSeqId : entry.getValue().getStoreCompleteSequenceId()) {
311         byte[] family = storeSeqId.getFamilyName().toByteArray();
312         existingValue = storeFlushedSequenceId.get(family);
313         l = storeSeqId.getSequenceId();
314         // Don't let smaller sequence ids override greater sequence ids.
315         if (existingValue == null || (l != HConstants.NO_SEQNUM && l > existingValue.longValue())) {
316           storeFlushedSequenceId.put(family, l);
317         }
318       }
319     }
320   }
321 
322   void regionServerReport(ServerName sn,
323       ServerLoad sl) throws YouAreDeadException {
324     checkIsDead(sn, "REPORT");
325     if (null == this.onlineServers.replace(sn, sl)) {
326       // Already have this host+port combo and its just different start code?
327       // Just let the server in. Presume master joining a running cluster.
328       // recordNewServer is what happens at the end of reportServerStartup.
329       // The only thing we are skipping is passing back to the regionserver
330       // the ServerName to use. Here we presume a master has already done
331       // that so we'll press on with whatever it gave us for ServerName.
332       if (!checkAndRecordNewServer(sn, sl)) {
333         LOG.info("RegionServerReport ignored, could not record the server: " + sn);
334         return; // Not recorded, so no need to move on
335       }
336     }
337     updateLastFlushedSequenceIds(sn, sl);
338   }
339 
340   /**
341    * Check is a server of same host and port already exists,
342    * if not, or the existed one got a smaller start code, record it.
343    *
344    * @param sn the server to check and record
345    * @param sl the server load on the server
346    * @return true if the server is recorded, otherwise, false
347    */
348   boolean checkAndRecordNewServer(
349       final ServerName serverName, final ServerLoad sl) {
350     ServerName existingServer = null;
351     synchronized (this.onlineServers) {
352       existingServer = findServerWithSameHostnamePortWithLock(serverName);
353       if (existingServer != null && (existingServer.getStartcode() > serverName.getStartcode())) {
354         LOG.info("Server serverName=" + serverName + " rejected; we already have "
355             + existingServer.toString() + " registered with same hostname and port");
356         return false;
357       }
358       recordNewServerWithLock(serverName, sl);
359     }
360 
361     // Tell our listeners that a server was added
362     if (!this.listeners.isEmpty()) {
363       for (ServerListener listener : this.listeners) {
364         listener.serverAdded(serverName);
365       }
366     }
367 
368     // Note that we assume that same ts means same server, and don't expire in that case.
369     //  TODO: ts can theoretically collide due to clock shifts, so this is a bit hacky.
370     if (existingServer != null && (existingServer.getStartcode() < serverName.getStartcode())) {
371       LOG.info("Triggering server recovery; existingServer " +
372           existingServer + " looks stale, new server:" + serverName);
373       expireServer(existingServer);
374     }
375     return true;
376   }
377 
378   /**
379    * Checks if the clock skew between the server and the master. If the clock skew exceeds the
380    * configured max, it will throw an exception; if it exceeds the configured warning threshold,
381    * it will log a warning but start normally.
382    * @param serverName Incoming servers's name
383    * @param serverCurrentTime
384    * @throws ClockOutOfSyncException if the skew exceeds the configured max value
385    */
386   private void checkClockSkew(final ServerName serverName, final long serverCurrentTime)
387   throws ClockOutOfSyncException {
388     long skew = Math.abs(System.currentTimeMillis() - serverCurrentTime);
389     if (skew > maxSkew) {
390       String message = "Server " + serverName + " has been " +
391         "rejected; Reported time is too far out of sync with master.  " +
392         "Time difference of " + skew + "ms > max allowed of " + maxSkew + "ms";
393       LOG.warn(message);
394       throw new ClockOutOfSyncException(message);
395     } else if (skew > warningSkew){
396       String message = "Reported time for server " + serverName + " is out of sync with master " +
397         "by " + skew + "ms. (Warning threshold is " + warningSkew + "ms; " +
398         "error threshold is " + maxSkew + "ms)";
399       LOG.warn(message);
400     }
401   }
402 
403   /**
404    * If this server is on the dead list, reject it with a YouAreDeadException.
405    * If it was dead but came back with a new start code, remove the old entry
406    * from the dead list.
407    * @param serverName
408    * @param what START or REPORT
409    * @throws org.apache.hadoop.hbase.YouAreDeadException
410    */
411   private void checkIsDead(final ServerName serverName, final String what)
412       throws YouAreDeadException {
413     if (this.deadservers.isDeadServer(serverName)) {
414       // host name, port and start code all match with existing one of the
415       // dead servers. So, this server must be dead.
416       String message = "Server " + what + " rejected; currently processing " +
417           serverName + " as dead server";
418       LOG.debug(message);
419       throw new YouAreDeadException(message);
420     }
421     // remove dead server with same hostname and port of newly checking in rs after master
422     // initialization.See HBASE-5916 for more information.
423     if ((this.services == null || ((HMaster) this.services).isInitialized())
424         && this.deadservers.cleanPreviousInstance(serverName)) {
425       // This server has now become alive after we marked it as dead.
426       // We removed it's previous entry from the dead list to reflect it.
427       LOG.debug(what + ":" + " Server " + serverName + " came back up," +
428           " removed it from the dead servers list");
429     }
430   }
431 
432   /**
433    * Assumes onlineServers is locked.
434    * @return ServerName with matching hostname and port.
435    */
436   private ServerName findServerWithSameHostnamePortWithLock(
437       final ServerName serverName) {
438     for (ServerName sn: this.onlineServers.keySet()) {
439       if (ServerName.isSameHostnameAndPort(serverName, sn)) return sn;
440     }
441     return null;
442   }
443 
444   /**
445    * Adds the onlineServers list. onlineServers should be locked.
446    * @param serverName The remote servers name.
447    * @param sl
448    * @return Server load from the removed server, if any.
449    */
450   @VisibleForTesting
451   void recordNewServerWithLock(final ServerName serverName, final ServerLoad sl) {
452     LOG.info("Registering server=" + serverName);
453     this.onlineServers.put(serverName, sl);
454     this.rsAdmins.remove(serverName);
455   }
456 
457   public RegionStoreSequenceIds getLastFlushedSequenceId(byte[] encodedRegionName) {
458     RegionStoreSequenceIds.Builder builder = RegionStoreSequenceIds.newBuilder();
459     Long seqId = flushedSequenceIdByRegion.get(encodedRegionName);
460     builder.setLastFlushedSequenceId(seqId != null ? seqId.longValue() : HConstants.NO_SEQNUM);
461     Map<byte[], Long> storeFlushedSequenceId =
462         storeFlushedSequenceIdsByRegion.get(encodedRegionName);
463     if (storeFlushedSequenceId != null) {
464       for (Map.Entry<byte[], Long> entry : storeFlushedSequenceId.entrySet()) {
465         builder.addStoreSequenceId(StoreSequenceId.newBuilder()
466             .setFamilyName(ByteString.copyFrom(entry.getKey()))
467             .setSequenceId(entry.getValue().longValue()).build());
468       }
469     }
470     return builder.build();
471   }
472 
473   /**
474    * @param serverName
475    * @return ServerLoad if serverName is known else null
476    */
477   public ServerLoad getLoad(final ServerName serverName) {
478     return this.onlineServers.get(serverName);
479   }
480 
481   /**
482    * Compute the average load across all region servers.
483    * Currently, this uses a very naive computation - just uses the number of
484    * regions being served, ignoring stats about number of requests.
485    * @return the average load
486    */
487   public double getAverageLoad() {
488     int totalLoad = 0;
489     int numServers = 0;
490     for (ServerLoad sl: this.onlineServers.values()) {
491         numServers++;
492         totalLoad += sl.getNumberOfRegions();
493     }
494     return numServers == 0 ? 0 :
495       (double)totalLoad / (double)numServers;
496   }
497 
498   /** @return the count of active regionservers */
499   public int countOfRegionServers() {
500     // Presumes onlineServers is a concurrent map
501     return this.onlineServers.size();
502   }
503 
504   /**
505    * @return Read-only map of servers to serverinfo
506    */
507   public Map<ServerName, ServerLoad> getOnlineServers() {
508     // Presumption is that iterating the returned Map is OK.
509     synchronized (this.onlineServers) {
510       return Collections.unmodifiableMap(this.onlineServers);
511     }
512   }
513 
514 
515   public DeadServer getDeadServers() {
516     return this.deadservers;
517   }
518 
519   /**
520    * Checks if any dead servers are currently in progress.
521    * @return true if any RS are being processed as dead, false if not
522    */
523   public boolean areDeadServersInProgress() {
524     return this.deadservers.areDeadServersInProgress();
525   }
526 
527   void letRegionServersShutdown() {
528     long previousLogTime = 0;
529     ServerName sn = master.getServerName();
530     ZooKeeperWatcher zkw = master.getZooKeeper();
531     int onlineServersCt;
532     while ((onlineServersCt = onlineServers.size()) > 0){
533 
534       if (System.currentTimeMillis() > (previousLogTime + 1000)) {
535         Set<ServerName> remainingServers = onlineServers.keySet();
536         synchronized (onlineServers) {
537           if (remainingServers.size() == 1 && remainingServers.contains(sn)) {
538             // Master will delete itself later.
539             return;
540           }
541         }
542         StringBuilder sb = new StringBuilder();
543         // It's ok here to not sync on onlineServers - merely logging
544         for (ServerName key : remainingServers) {
545           if (sb.length() > 0) {
546             sb.append(", ");
547           }
548           sb.append(key);
549         }
550         LOG.info("Waiting on regionserver(s) to go down " + sb.toString());
551         previousLogTime = System.currentTimeMillis();
552       }
553 
554       try {
555         List<String> servers = ZKUtil.listChildrenNoWatch(zkw, zkw.rsZNode);
556         if (servers == null || servers.size() == 0 || (servers.size() == 1
557             && servers.contains(sn.toString()))) {
558           LOG.info("ZK shows there is only the master self online, exiting now");
559           // Master could have lost some ZK events, no need to wait more.
560           break;
561         }
562       } catch (KeeperException ke) {
563         LOG.warn("Failed to list regionservers", ke);
564         // ZK is malfunctioning, don't hang here
565         break;
566       }
567       synchronized (onlineServers) {
568         try {
569           if (onlineServersCt == onlineServers.size()) onlineServers.wait(100);
570         } catch (InterruptedException ignored) {
571           // continue
572         }
573       }
574     }
575   }
576 
577   /*
578    * Expire the passed server.  Add it to list of dead servers and queue a
579    * shutdown processing.
580    */
581   public synchronized void expireServer(final ServerName serverName) {
582     if (serverName.equals(master.getServerName())) {
583       if (!(master.isAborted() || master.isStopped())) {
584         master.stop("We lost our znode?");
585       }
586       return;
587     }
588     if (!services.isServerShutdownHandlerEnabled()) {
589       LOG.info("Master doesn't enable ServerShutdownHandler during initialization, "
590           + "delay expiring server " + serverName);
591       this.queuedDeadServers.add(serverName);
592       return;
593     }
594     if (this.deadservers.isDeadServer(serverName)) {
595       // TODO: Can this happen?  It shouldn't be online in this case?
596       LOG.warn("Expiration of " + serverName +
597           " but server shutdown already in progress");
598       return;
599     }
600     synchronized (onlineServers) {
601       if (!this.onlineServers.containsKey(serverName)) {
602         LOG.warn("Expiration of " + serverName + " but server not online");
603       }
604       // Remove the server from the known servers lists and update load info BUT
605       // add to deadservers first; do this so it'll show in dead servers list if
606       // not in online servers list.
607       this.deadservers.add(serverName);
608       this.onlineServers.remove(serverName);
609       onlineServers.notifyAll();
610     }
611     this.rsAdmins.remove(serverName);
612     // If cluster is going down, yes, servers are going to be expiring; don't
613     // process as a dead server
614     if (this.clusterShutdown) {
615       LOG.info("Cluster shutdown set; " + serverName +
616         " expired; onlineServers=" + this.onlineServers.size());
617       if (this.onlineServers.isEmpty()) {
618         master.stop("Cluster shutdown set; onlineServer=0");
619       }
620       return;
621     }
622 
623     boolean carryingMeta = services.getAssignmentManager().isCarryingMeta(serverName) ==
624         AssignmentManager.ServerHostRegion.HOSTING_REGION;
625     if (carryingMeta) {
626       this.services.getExecutorService().submit(new MetaServerShutdownHandler(this.master,
627         this.services, this.deadservers, serverName));
628     } else {
629       this.services.getExecutorService().submit(new ServerShutdownHandler(this.master,
630         this.services, this.deadservers, serverName, true));
631     }
632     LOG.debug("Added=" + serverName +
633       " to dead servers, submitted shutdown handler to be executed meta=" + carryingMeta);
634 
635     // Tell our listeners that a server was removed
636     if (!this.listeners.isEmpty()) {
637       for (ServerListener listener : this.listeners) {
638         listener.serverRemoved(serverName);
639       }
640     }
641   }
642 
643   public synchronized void processDeadServer(final ServerName serverName) {
644     this.processDeadServer(serverName, false);
645   }
646 
647   public synchronized void processDeadServer(final ServerName serverName, boolean shouldSplitWal) {
648     // When assignment manager is cleaning up the zookeeper nodes and rebuilding the
649     // in-memory region states, region servers could be down. Meta table can and
650     // should be re-assigned, log splitting can be done too. However, it is better to
651     // wait till the cleanup is done before re-assigning user regions.
652     //
653     // We should not wait in the server shutdown handler thread since it can clog
654     // the handler threads and meta table could not be re-assigned in case
655     // the corresponding server is down. So we queue them up here instead.
656     if (!services.getAssignmentManager().isFailoverCleanupDone()) {
657       requeuedDeadServers.put(serverName, shouldSplitWal);
658       return;
659     }
660 
661     this.deadservers.add(serverName);
662     this.services.getExecutorService().submit(
663       new ServerShutdownHandler(this.master, this.services, this.deadservers, serverName,
664           shouldSplitWal));
665   }
666 
667   /**
668    * Process the servers which died during master's initialization. It will be
669    * called after HMaster#assignMeta and AssignmentManager#joinCluster.
670    * */
671   synchronized void processQueuedDeadServers() {
672     if (!services.isServerShutdownHandlerEnabled()) {
673       LOG.info("Master hasn't enabled ServerShutdownHandler");
674     }
675     Iterator<ServerName> serverIterator = queuedDeadServers.iterator();
676     while (serverIterator.hasNext()) {
677       ServerName tmpServerName = serverIterator.next();
678       expireServer(tmpServerName);
679       serverIterator.remove();
680       requeuedDeadServers.remove(tmpServerName);
681     }
682 
683     if (!services.getAssignmentManager().isFailoverCleanupDone()) {
684       LOG.info("AssignmentManager hasn't finished failover cleanup; waiting");
685     }
686 
687     for(ServerName tmpServerName : requeuedDeadServers.keySet()){
688       processDeadServer(tmpServerName, requeuedDeadServers.get(tmpServerName));
689     }
690     requeuedDeadServers.clear();
691   }
692 
693   /*
694    * Remove the server from the drain list.
695    */
696   public boolean removeServerFromDrainList(final ServerName sn) {
697     // Warn if the server (sn) is not online.  ServerName is of the form:
698     // <hostname> , <port> , <startcode>
699 
700     if (!this.isServerOnline(sn)) {
701       LOG.warn("Server " + sn + " is not currently online. " +
702                "Removing from draining list anyway, as requested.");
703     }
704     // Remove the server from the draining servers lists.
705     return this.drainingServers.remove(sn);
706   }
707 
708   /*
709    * Add the server to the drain list.
710    */
711   public boolean addServerToDrainList(final ServerName sn) {
712     // Warn if the server (sn) is not online.  ServerName is of the form:
713     // <hostname> , <port> , <startcode>
714 
715     if (!this.isServerOnline(sn)) {
716       LOG.warn("Server " + sn + " is not currently online. " +
717                "Ignoring request to add it to draining list.");
718       return false;
719     }
720     // Add the server to the draining servers lists, if it's not already in
721     // it.
722     if (this.drainingServers.contains(sn)) {
723       LOG.warn("Server " + sn + " is already in the draining server list." +
724                "Ignoring request to add it again.");
725       return false;
726     }
727     return this.drainingServers.add(sn);
728   }
729 
730   // RPC methods to region servers
731 
732   /**
733    * Sends an OPEN RPC to the specified server to open the specified region.
734    * <p>
735    * Open should not fail but can if server just crashed.
736    * <p>
737    * @param server server to open a region
738    * @param region region to open
739    * @param versionOfOfflineNode that needs to be present in the offline node
740    * when RS tries to change the state from OFFLINE to other states.
741    * @param favoredNodes
742    */
743   public RegionOpeningState sendRegionOpen(final ServerName server,
744       HRegionInfo region, int versionOfOfflineNode, List<ServerName> favoredNodes)
745   throws IOException {
746     AdminService.BlockingInterface admin = getRsAdmin(server);
747     if (admin == null) {
748       LOG.warn("Attempting to send OPEN RPC to server " + server.toString() +
749         " failed because no RPC connection found to this server");
750       return RegionOpeningState.FAILED_OPENING;
751     }
752     OpenRegionRequest request = RequestConverter.buildOpenRegionRequest(server, 
753       region, versionOfOfflineNode, favoredNodes, 
754       (RecoveryMode.LOG_REPLAY == this.services.getMasterFileSystem().getLogRecoveryMode()));
755     try {
756       OpenRegionResponse response = admin.openRegion(null, request);
757       return ResponseConverter.getRegionOpeningState(response);
758     } catch (ServiceException se) {
759       throw ProtobufUtil.getRemoteException(se);
760     }
761   }
762 
763   /**
764    * Sends an OPEN RPC to the specified server to open the specified region.
765    * <p>
766    * Open should not fail but can if server just crashed.
767    * <p>
768    * @param server server to open a region
769    * @param regionOpenInfos info of a list of regions to open
770    * @return a list of region opening states
771    */
772   public List<RegionOpeningState> sendRegionOpen(ServerName server,
773       List<Triple<HRegionInfo, Integer, List<ServerName>>> regionOpenInfos)
774   throws IOException {
775     AdminService.BlockingInterface admin = getRsAdmin(server);
776     if (admin == null) {
777       LOG.warn("Attempting to send OPEN RPC to server " + server.toString() +
778         " failed because no RPC connection found to this server");
779       return null;
780     }
781 
782     OpenRegionRequest request = RequestConverter.buildOpenRegionRequest(server, regionOpenInfos,
783       (RecoveryMode.LOG_REPLAY == this.services.getMasterFileSystem().getLogRecoveryMode()));
784     try {
785       OpenRegionResponse response = admin.openRegion(null, request);
786       return ResponseConverter.getRegionOpeningStateList(response);
787     } catch (ServiceException se) {
788       throw ProtobufUtil.getRemoteException(se);
789     }
790   }
791 
792   private PayloadCarryingRpcController newRpcController() {
793     return rpcControllerFactory == null ? null : rpcControllerFactory.newController();
794   }
795 
796   /**
797    * Sends an CLOSE RPC to the specified server to close the specified region.
798    * <p>
799    * A region server could reject the close request because it either does not
800    * have the specified region or the region is being split.
801    * @param server server to open a region
802    * @param region region to open
803    * @param versionOfClosingNode
804    *   the version of znode to compare when RS transitions the znode from
805    *   CLOSING state.
806    * @param dest - if the region is moved to another server, the destination server. null otherwise.
807    * @return true if server acknowledged close, false if not
808    * @throws IOException
809    */
810   public boolean sendRegionClose(ServerName server, HRegionInfo region,
811     int versionOfClosingNode, ServerName dest, boolean transitionInZK) throws IOException {
812     if (server == null) throw new NullPointerException("Passed server is null");
813     AdminService.BlockingInterface admin = getRsAdmin(server);
814     if (admin == null) {
815       throw new IOException("Attempting to send CLOSE RPC to server " +
816         server.toString() + " for region " +
817         region.getRegionNameAsString() +
818         " failed because no RPC connection found to this server");
819     }
820     PayloadCarryingRpcController controller = newRpcController();
821     return ProtobufUtil.closeRegion(controller, admin, server, region.getRegionName(),
822       versionOfClosingNode, dest, transitionInZK);
823   }
824 
825   public boolean sendRegionClose(ServerName server,
826       HRegionInfo region, int versionOfClosingNode) throws IOException {
827     return sendRegionClose(server, region, versionOfClosingNode, null, true);
828   }
829 
830   /**
831    * Sends a WARMUP RPC to the specified server to warmup the specified region.
832    * <p>
833    * A region server could reject the close request because it either does not
834    * have the specified region or the region is being split.
835    * @param server server to warmup a region
836    * @param region region to  warmup
837    */
838   public void sendRegionWarmup(ServerName server,
839       HRegionInfo region) {
840     if (server == null) return;
841     try {
842       AdminService.BlockingInterface admin = getRsAdmin(server);
843       PayloadCarryingRpcController controller = newRpcController();
844       ProtobufUtil.warmupRegion(controller, admin, region);
845     } catch (IOException e) {
846       LOG.error("Received exception in RPC for warmup server:" +
847         server + "region: " + region +
848         "exception: " + e);
849     }
850   }
851 
852   /**
853    * Contacts a region server and waits up to timeout ms
854    * to close the region.  This bypasses the active hmaster.
855    */
856   public static void closeRegionSilentlyAndWait(ClusterConnection connection,
857     ServerName server, HRegionInfo region, long timeout) throws IOException, InterruptedException {
858     AdminService.BlockingInterface rs = connection.getAdmin(server);
859     PayloadCarryingRpcController controller = connection.getRpcControllerFactory().newController();
860     try {
861       ProtobufUtil.closeRegion(controller, rs, server, region.getRegionName(), false);
862     } catch (IOException e) {
863       LOG.warn("Exception when closing region: " + region.getRegionNameAsString(), e);
864     }
865     long expiration = timeout + System.currentTimeMillis();
866     while (System.currentTimeMillis() < expiration) {
867       try {
868         HRegionInfo rsRegion =
869           ProtobufUtil.getRegionInfo(controller, rs, region.getRegionName());
870         if (rsRegion == null) return;
871       } catch (IOException ioe) {
872         if (ioe instanceof NotServingRegionException) // no need to retry again
873           return;
874         LOG.warn("Exception when retrieving regioninfo from: "
875           + region.getRegionNameAsString(), ioe);
876       }
877       Thread.sleep(1000);
878     }
879     throw new IOException("Region " + region + " failed to close within"
880         + " timeout " + timeout);
881   }
882 
883   /**
884    * Sends an MERGE REGIONS RPC to the specified server to merge the specified
885    * regions.
886    * <p>
887    * A region server could reject the close request because it either does not
888    * have the specified region.
889    * @param server server to merge regions
890    * @param region_a region to merge
891    * @param region_b region to merge
892    * @param forcible true if do a compulsory merge, otherwise we will only merge
893    *          two adjacent regions
894    * @throws IOException
895    */
896   public void sendRegionsMerge(ServerName server, HRegionInfo region_a,
897       HRegionInfo region_b, boolean forcible) throws IOException {
898     if (server == null)
899       throw new NullPointerException("Passed server is null");
900     if (region_a == null || region_b == null)
901       throw new NullPointerException("Passed region is null");
902     AdminService.BlockingInterface admin = getRsAdmin(server);
903     if (admin == null) {
904       throw new IOException("Attempting to send MERGE REGIONS RPC to server "
905           + server.toString() + " for region "
906           + region_a.getRegionNameAsString() + ","
907           + region_b.getRegionNameAsString()
908           + " failed because no RPC connection found to this server");
909     }
910     PayloadCarryingRpcController controller = newRpcController();
911     ProtobufUtil.mergeRegions(controller, admin, region_a, region_b, forcible);
912   }
913 
914   /**
915    * Check if a region server is reachable and has the expected start code
916    */
917   public boolean isServerReachable(ServerName server) {
918     if (server == null) throw new NullPointerException("Passed server is null");
919 
920 
921     RetryCounter retryCounter = pingRetryCounterFactory.create();
922     while (retryCounter.shouldRetry()) {
923       synchronized (this.onlineServers) {
924         if (this.deadservers.isDeadServer(server)) {
925           return false;
926         }
927       }
928       try {
929         PayloadCarryingRpcController controller = newRpcController();
930         AdminService.BlockingInterface admin = getRsAdmin(server);
931         if (admin != null) {
932           ServerInfo info = ProtobufUtil.getServerInfo(controller, admin);
933           return info != null && info.hasServerName()
934             && server.getStartcode() == info.getServerName().getStartCode();
935         }
936       } catch (IOException ioe) {
937         if (LOG.isDebugEnabled()) {
938           LOG.debug("Couldn't reach " + server + ", try=" + retryCounter.getAttemptTimes() + " of "
939               + retryCounter.getMaxAttempts(), ioe);
940         }
941         try {
942           retryCounter.sleepUntilNextRetry();
943         } catch(InterruptedException ie) {
944           Thread.currentThread().interrupt();
945           break;
946         }
947       }
948     }
949     return false;
950   }
951 
952     /**
953     * @param sn
954     * @return Admin interface for the remote regionserver named <code>sn</code>
955     * @throws IOException
956     * @throws RetriesExhaustedException wrapping a ConnectException if failed
957     */
958   private AdminService.BlockingInterface getRsAdmin(final ServerName sn)
959   throws IOException {
960     AdminService.BlockingInterface admin = this.rsAdmins.get(sn);
961     if (admin == null) {
962       LOG.debug("New admin connection to " + sn.toString());
963       if (sn.equals(master.getServerName()) && master instanceof HRegionServer) {
964         // A master is also a region server now, see HBASE-10569 for details
965         admin = ((HRegionServer)master).getRSRpcServices();
966       } else {
967         admin = this.connection.getAdmin(sn);
968       }
969       this.rsAdmins.put(sn, admin);
970     }
971     return admin;
972   }
973 
974   /**
975    * Wait for the region servers to report in.
976    * We will wait until one of this condition is met:
977    *  - the master is stopped
978    *  - the 'hbase.master.wait.on.regionservers.maxtostart' number of
979    *    region servers is reached
980    *  - the 'hbase.master.wait.on.regionservers.mintostart' is reached AND
981    *   there have been no new region server in for
982    *      'hbase.master.wait.on.regionservers.interval' time AND
983    *   the 'hbase.master.wait.on.regionservers.timeout' is reached
984    *
985    * @throws InterruptedException
986    */
987   public void waitForRegionServers(MonitoredTask status)
988   throws InterruptedException {
989     final long interval = this.master.getConfiguration().
990       getLong(WAIT_ON_REGIONSERVERS_INTERVAL, 1500);
991     final long timeout = this.master.getConfiguration().
992       getLong(WAIT_ON_REGIONSERVERS_TIMEOUT, 4500);
993     int defaultMinToStart = 1;
994     if (BaseLoadBalancer.tablesOnMaster(master.getConfiguration())) {
995       // If we assign regions to master, we'd like to start
996       // at least another region server so that we don't
997       // assign all regions to master if other region servers
998       // don't come up in time.
999       defaultMinToStart = 2;
1000     }
1001     int minToStart = this.master.getConfiguration().
1002       getInt(WAIT_ON_REGIONSERVERS_MINTOSTART, defaultMinToStart);
1003     if (minToStart < 1) {
1004       LOG.warn(String.format(
1005         "The value of '%s' (%d) can not be less than 1, ignoring.",
1006         WAIT_ON_REGIONSERVERS_MINTOSTART, minToStart));
1007       minToStart = 1;
1008     }
1009     int maxToStart = this.master.getConfiguration().
1010       getInt(WAIT_ON_REGIONSERVERS_MAXTOSTART, Integer.MAX_VALUE);
1011     if (maxToStart < minToStart) {
1012         LOG.warn(String.format(
1013             "The value of '%s' (%d) is set less than '%s' (%d), ignoring.",
1014             WAIT_ON_REGIONSERVERS_MAXTOSTART, maxToStart,
1015             WAIT_ON_REGIONSERVERS_MINTOSTART, minToStart));
1016         maxToStart = Integer.MAX_VALUE;
1017     }
1018 
1019     long now =  System.currentTimeMillis();
1020     final long startTime = now;
1021     long slept = 0;
1022     long lastLogTime = 0;
1023     long lastCountChange = startTime;
1024     int count = countOfRegionServers();
1025     int oldCount = 0;
1026     while (!this.master.isStopped() && count < maxToStart
1027         && (lastCountChange+interval > now || timeout > slept || count < minToStart)) {
1028       // Log some info at every interval time or if there is a change
1029       if (oldCount != count || lastLogTime+interval < now){
1030         lastLogTime = now;
1031         String msg =
1032           "Waiting for region servers count to settle; currently"+
1033             " checked in " + count + ", slept for " + slept + " ms," +
1034             " expecting minimum of " + minToStart + ", maximum of "+ maxToStart+
1035             ", timeout of "+timeout+" ms, interval of "+interval+" ms.";
1036         LOG.info(msg);
1037         status.setStatus(msg);
1038       }
1039 
1040       // We sleep for some time
1041       final long sleepTime = 50;
1042       Thread.sleep(sleepTime);
1043       now =  System.currentTimeMillis();
1044       slept = now - startTime;
1045 
1046       oldCount = count;
1047       count = countOfRegionServers();
1048       if (count != oldCount) {
1049         lastCountChange = now;
1050       }
1051     }
1052 
1053     LOG.info("Finished waiting for region servers count to settle;" +
1054       " checked in " + count + ", slept for " + slept + " ms," +
1055       " expecting minimum of " + minToStart + ", maximum of "+ maxToStart+","+
1056       " master is "+ (this.master.isStopped() ? "stopped.": "running")
1057     );
1058   }
1059 
1060   /**
1061    * @return A copy of the internal list of online servers.
1062    */
1063   public List<ServerName> getOnlineServersList() {
1064     // TODO: optimize the load balancer call so we don't need to make a new list
1065     // TODO: FIX. THIS IS POPULAR CALL.
1066     return new ArrayList<ServerName>(this.onlineServers.keySet());
1067   }
1068 
1069   /**
1070    * @return A copy of the internal list of draining servers.
1071    */
1072   public List<ServerName> getDrainingServersList() {
1073     return new ArrayList<ServerName>(this.drainingServers);
1074   }
1075 
1076   /**
1077    * @return A copy of the internal set of deadNotExpired servers.
1078    */
1079   Set<ServerName> getDeadNotExpiredServers() {
1080     return new HashSet<ServerName>(this.queuedDeadServers);
1081   }
1082 
1083   /**
1084    * During startup, if we figure it is not a failover, i.e. there is
1085    * no more WAL files to split, we won't try to recover these dead servers.
1086    * So we just remove them from the queue. Use caution in calling this.
1087    */
1088   void removeRequeuedDeadServers() {
1089     requeuedDeadServers.clear();
1090   }
1091 
1092   /**
1093    * @return A copy of the internal map of requeuedDeadServers servers and their corresponding
1094    *         splitlog need flag.
1095    */
1096   Map<ServerName, Boolean> getRequeuedDeadServers() {
1097     return Collections.unmodifiableMap(this.requeuedDeadServers);
1098   }
1099 
1100   public boolean isServerOnline(ServerName serverName) {
1101     return serverName != null && onlineServers.containsKey(serverName);
1102   }
1103 
1104   /**
1105    * Check if a server is known to be dead.  A server can be online,
1106    * or known to be dead, or unknown to this manager (i.e, not online,
1107    * not known to be dead either. it is simply not tracked by the
1108    * master any more, for example, a very old previous instance).
1109    */
1110   public synchronized boolean isServerDead(ServerName serverName) {
1111     return serverName == null || deadservers.isDeadServer(serverName)
1112       || queuedDeadServers.contains(serverName)
1113       || requeuedDeadServers.containsKey(serverName);
1114   }
1115 
1116   public void shutdownCluster() {
1117     this.clusterShutdown = true;
1118     this.master.stop("Cluster shutdown requested");
1119   }
1120 
1121   public boolean isClusterShutdown() {
1122     return this.clusterShutdown;
1123   }
1124 
1125   /**
1126    * Stop the ServerManager.  Currently closes the connection to the master.
1127    */
1128   public void stop() {
1129     if (connection != null) {
1130       try {
1131         connection.close();
1132       } catch (IOException e) {
1133         LOG.error("Attempt to close connection to master failed", e);
1134       }
1135     }
1136   }
1137 
1138   /**
1139    * Creates a list of possible destinations for a region. It contains the online servers, but not
1140    *  the draining or dying servers.
1141    *  @param serverToExclude can be null if there is no server to exclude
1142    */
1143   public List<ServerName> createDestinationServersList(final ServerName serverToExclude){
1144     final List<ServerName> destServers = getOnlineServersList();
1145 
1146     if (serverToExclude != null){
1147       destServers.remove(serverToExclude);
1148     }
1149 
1150     // Loop through the draining server list and remove them from the server list
1151     final List<ServerName> drainingServersCopy = getDrainingServersList();
1152     if (!drainingServersCopy.isEmpty()) {
1153       for (final ServerName server: drainingServersCopy) {
1154         destServers.remove(server);
1155       }
1156     }
1157 
1158     // Remove the deadNotExpired servers from the server list.
1159     removeDeadNotExpiredServers(destServers);
1160     return destServers;
1161   }
1162 
1163   /**
1164    * Calls {@link #createDestinationServersList} without server to exclude.
1165    */
1166   public List<ServerName> createDestinationServersList(){
1167     return createDestinationServersList(null);
1168   }
1169 
1170     /**
1171     * Loop through the deadNotExpired server list and remove them from the
1172     * servers.
1173     * This function should be used carefully outside of this class. You should use a high level
1174     *  method such as {@link #createDestinationServersList()} instead of managing you own list.
1175     */
1176   void removeDeadNotExpiredServers(List<ServerName> servers) {
1177     Set<ServerName> deadNotExpiredServersCopy = this.getDeadNotExpiredServers();
1178     if (!deadNotExpiredServersCopy.isEmpty()) {
1179       for (ServerName server : deadNotExpiredServersCopy) {
1180         LOG.debug("Removing dead but not expired server: " + server
1181           + " from eligible server pool.");
1182         servers.remove(server);
1183       }
1184     }
1185   }
1186 
1187   /**
1188    * To clear any dead server with same host name and port of any online server
1189    */
1190   void clearDeadServersWithSameHostNameAndPortOfOnlineServer() {
1191     for (ServerName serverName : getOnlineServersList()) {
1192       deadservers.cleanAllPreviousInstances(serverName);
1193     }
1194   }
1195 
1196   /**
1197    * Called by delete table and similar to notify the ServerManager that a region was removed.
1198    */
1199   public void removeRegion(final HRegionInfo regionInfo) {
1200     final byte[] encodedName = regionInfo.getEncodedNameAsBytes();
1201     storeFlushedSequenceIdsByRegion.remove(encodedName);
1202     flushedSequenceIdByRegion.remove(encodedName);
1203   }
1204 
1205   /**
1206    * Called by delete table and similar to notify the ServerManager that a region was removed.
1207    */
1208   public void removeRegions(final List<HRegionInfo> regions) {
1209     for (HRegionInfo hri: regions) {
1210       removeRegion(hri);
1211     }
1212   }
1213 }