hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [28/51] [partial] hbase-site git commit: Published site at .
Date Thu, 17 Aug 2017 15:07:38 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/33bc9e06/devapidocs/src-html/org/apache/hadoop/hbase/master/ServerManager.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/master/ServerManager.html b/devapidocs/src-html/org/apache/hadoop/hbase/master/ServerManager.html
index 9112346..dc4506d 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/master/ServerManager.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/master/ServerManager.html
@@ -43,395 +43,395 @@
 <span class="sourceLineNo">035</span>import java.util.concurrent.ConcurrentNavigableMap;<a name="line.35"></a>
 <span class="sourceLineNo">036</span>import java.util.concurrent.ConcurrentSkipListMap;<a name="line.36"></a>
 <span class="sourceLineNo">037</span>import java.util.concurrent.CopyOnWriteArrayList;<a name="line.37"></a>
-<span class="sourceLineNo">038</span>import java.util.function.Predicate;<a name="line.38"></a>
-<span class="sourceLineNo">039</span><a name="line.39"></a>
-<span class="sourceLineNo">040</span>import org.apache.commons.logging.Log;<a name="line.40"></a>
-<span class="sourceLineNo">041</span>import org.apache.commons.logging.LogFactory;<a name="line.41"></a>
-<span class="sourceLineNo">042</span>import org.apache.hadoop.conf.Configuration;<a name="line.42"></a>
-<span class="sourceLineNo">043</span>import org.apache.hadoop.hbase.ClockOutOfSyncException;<a name="line.43"></a>
-<span class="sourceLineNo">044</span>import org.apache.hadoop.hbase.HConstants;<a name="line.44"></a>
-<span class="sourceLineNo">045</span>import org.apache.hadoop.hbase.HRegionInfo;<a name="line.45"></a>
-<span class="sourceLineNo">046</span>import org.apache.hadoop.hbase.NotServingRegionException;<a name="line.46"></a>
-<span class="sourceLineNo">047</span>import org.apache.hadoop.hbase.RegionLoad;<a name="line.47"></a>
-<span class="sourceLineNo">048</span>import org.apache.hadoop.hbase.ServerLoad;<a name="line.48"></a>
-<span class="sourceLineNo">049</span>import org.apache.hadoop.hbase.ServerName;<a name="line.49"></a>
-<span class="sourceLineNo">050</span>import org.apache.hadoop.hbase.YouAreDeadException;<a name="line.50"></a>
-<span class="sourceLineNo">051</span>import org.apache.hadoop.hbase.ZooKeeperConnectionException;<a name="line.51"></a>
-<span class="sourceLineNo">052</span>import org.apache.hadoop.hbase.classification.InterfaceAudience;<a name="line.52"></a>
-<span class="sourceLineNo">053</span>import org.apache.hadoop.hbase.client.ClusterConnection;<a name="line.53"></a>
-<span class="sourceLineNo">054</span>import org.apache.hadoop.hbase.client.RetriesExhaustedException;<a name="line.54"></a>
-<span class="sourceLineNo">055</span>import org.apache.hadoop.hbase.ipc.HBaseRpcController;<a name="line.55"></a>
-<span class="sourceLineNo">056</span>import org.apache.hadoop.hbase.ipc.RpcControllerFactory;<a name="line.56"></a>
-<span class="sourceLineNo">057</span>import org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer;<a name="line.57"></a>
-<span class="sourceLineNo">058</span>import org.apache.hadoop.hbase.monitoring.MonitoredTask;<a name="line.58"></a>
-<span class="sourceLineNo">059</span>import org.apache.hadoop.hbase.regionserver.HRegionServer;<a name="line.59"></a>
-<span class="sourceLineNo">060</span>import org.apache.hadoop.hbase.shaded.com.google.protobuf.UnsafeByteOperations;<a name="line.60"></a>
-<span class="sourceLineNo">061</span>import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;<a name="line.61"></a>
-<span class="sourceLineNo">062</span>import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService;<a name="line.62"></a>
-<span class="sourceLineNo">063</span>import org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos.RegionStoreSequenceIds;<a name="line.63"></a>
-<span class="sourceLineNo">064</span>import org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos.StoreSequenceId;<a name="line.64"></a>
-<span class="sourceLineNo">065</span>import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerStartupRequest;<a name="line.65"></a>
-<span class="sourceLineNo">066</span>import org.apache.hadoop.hbase.util.Bytes;<a name="line.66"></a>
-<span class="sourceLineNo">067</span>import org.apache.hadoop.hbase.zookeeper.ZKUtil;<a name="line.67"></a>
-<span class="sourceLineNo">068</span>import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;<a name="line.68"></a>
-<span class="sourceLineNo">069</span>import org.apache.zookeeper.KeeperException;<a name="line.69"></a>
-<span class="sourceLineNo">070</span><a name="line.70"></a>
-<span class="sourceLineNo">071</span>import org.apache.hadoop.hbase.shaded.com.google.common.annotations.VisibleForTesting;<a name="line.71"></a>
-<span class="sourceLineNo">072</span><a name="line.72"></a>
-<span class="sourceLineNo">073</span>/**<a name="line.73"></a>
-<span class="sourceLineNo">074</span> * The ServerManager class manages info about region servers.<a name="line.74"></a>
-<span class="sourceLineNo">075</span> * &lt;p&gt;<a name="line.75"></a>
-<span class="sourceLineNo">076</span> * Maintains lists of online and dead servers.  Processes the startups,<a name="line.76"></a>
-<span class="sourceLineNo">077</span> * shutdowns, and deaths of region servers.<a name="line.77"></a>
-<span class="sourceLineNo">078</span> * &lt;p&gt;<a name="line.78"></a>
-<span class="sourceLineNo">079</span> * Servers are distinguished in two different ways.  A given server has a<a name="line.79"></a>
-<span class="sourceLineNo">080</span> * location, specified by hostname and port, and of which there can only be one<a name="line.80"></a>
-<span class="sourceLineNo">081</span> * online at any given time.  A server instance is specified by the location<a name="line.81"></a>
-<span class="sourceLineNo">082</span> * (hostname and port) as well as the startcode (timestamp from when the server<a name="line.82"></a>
-<span class="sourceLineNo">083</span> * was started).  This is used to differentiate a restarted instance of a given<a name="line.83"></a>
-<span class="sourceLineNo">084</span> * server from the original instance.<a name="line.84"></a>
-<span class="sourceLineNo">085</span> * &lt;p&gt;<a name="line.85"></a>
-<span class="sourceLineNo">086</span> * If a sever is known not to be running any more, it is called dead. The dead<a name="line.86"></a>
-<span class="sourceLineNo">087</span> * server needs to be handled by a ServerShutdownHandler.  If the handler is not<a name="line.87"></a>
-<span class="sourceLineNo">088</span> * enabled yet, the server can't be handled right away so it is queued up.<a name="line.88"></a>
-<span class="sourceLineNo">089</span> * After the handler is enabled, the server will be submitted to a handler to handle.<a name="line.89"></a>
-<span class="sourceLineNo">090</span> * However, the handler may be just partially enabled.  If so,<a name="line.90"></a>
-<span class="sourceLineNo">091</span> * the server cannot be fully processed, and be queued up for further processing.<a name="line.91"></a>
-<span class="sourceLineNo">092</span> * A server is fully processed only after the handler is fully enabled<a name="line.92"></a>
-<span class="sourceLineNo">093</span> * and has completed the handling.<a name="line.93"></a>
-<span class="sourceLineNo">094</span> */<a name="line.94"></a>
-<span class="sourceLineNo">095</span>@InterfaceAudience.Private<a name="line.95"></a>
-<span class="sourceLineNo">096</span>public class ServerManager {<a name="line.96"></a>
-<span class="sourceLineNo">097</span>  public static final String WAIT_ON_REGIONSERVERS_MAXTOSTART =<a name="line.97"></a>
-<span class="sourceLineNo">098</span>      "hbase.master.wait.on.regionservers.maxtostart";<a name="line.98"></a>
-<span class="sourceLineNo">099</span><a name="line.99"></a>
-<span class="sourceLineNo">100</span>  public static final String WAIT_ON_REGIONSERVERS_MINTOSTART =<a name="line.100"></a>
-<span class="sourceLineNo">101</span>      "hbase.master.wait.on.regionservers.mintostart";<a name="line.101"></a>
-<span class="sourceLineNo">102</span><a name="line.102"></a>
-<span class="sourceLineNo">103</span>  public static final String WAIT_ON_REGIONSERVERS_TIMEOUT =<a name="line.103"></a>
-<span class="sourceLineNo">104</span>      "hbase.master.wait.on.regionservers.timeout";<a name="line.104"></a>
-<span class="sourceLineNo">105</span><a name="line.105"></a>
-<span class="sourceLineNo">106</span>  public static final String WAIT_ON_REGIONSERVERS_INTERVAL =<a name="line.106"></a>
-<span class="sourceLineNo">107</span>      "hbase.master.wait.on.regionservers.interval";<a name="line.107"></a>
-<span class="sourceLineNo">108</span><a name="line.108"></a>
-<span class="sourceLineNo">109</span>  private static final Log LOG = LogFactory.getLog(ServerManager.class);<a name="line.109"></a>
-<span class="sourceLineNo">110</span><a name="line.110"></a>
-<span class="sourceLineNo">111</span>  // Set if we are to shutdown the cluster.<a name="line.111"></a>
-<span class="sourceLineNo">112</span>  private volatile boolean clusterShutdown = false;<a name="line.112"></a>
-<span class="sourceLineNo">113</span><a name="line.113"></a>
-<span class="sourceLineNo">114</span>  /**<a name="line.114"></a>
-<span class="sourceLineNo">115</span>   * The last flushed sequence id for a region.<a name="line.115"></a>
-<span class="sourceLineNo">116</span>   */<a name="line.116"></a>
-<span class="sourceLineNo">117</span>  private final ConcurrentNavigableMap&lt;byte[], Long&gt; flushedSequenceIdByRegion =<a name="line.117"></a>
-<span class="sourceLineNo">118</span>    new ConcurrentSkipListMap&lt;&gt;(Bytes.BYTES_COMPARATOR);<a name="line.118"></a>
-<span class="sourceLineNo">119</span><a name="line.119"></a>
-<span class="sourceLineNo">120</span>  /**<a name="line.120"></a>
-<span class="sourceLineNo">121</span>   * The last flushed sequence id for a store in a region.<a name="line.121"></a>
-<span class="sourceLineNo">122</span>   */<a name="line.122"></a>
-<span class="sourceLineNo">123</span>  private final ConcurrentNavigableMap&lt;byte[], ConcurrentNavigableMap&lt;byte[], Long&gt;&gt;<a name="line.123"></a>
-<span class="sourceLineNo">124</span>    storeFlushedSequenceIdsByRegion = new ConcurrentSkipListMap&lt;&gt;(Bytes.BYTES_COMPARATOR);<a name="line.124"></a>
-<span class="sourceLineNo">125</span><a name="line.125"></a>
-<span class="sourceLineNo">126</span>  /** Map of registered servers to their current load */<a name="line.126"></a>
-<span class="sourceLineNo">127</span>  private final ConcurrentNavigableMap&lt;ServerName, ServerLoad&gt; onlineServers = new ConcurrentSkipListMap&lt;&gt;();<a name="line.127"></a>
-<span class="sourceLineNo">128</span><a name="line.128"></a>
-<span class="sourceLineNo">129</span>  /**<a name="line.129"></a>
-<span class="sourceLineNo">130</span>   * Map of admin interfaces per registered regionserver; these interfaces we use to control<a name="line.130"></a>
-<span class="sourceLineNo">131</span>   * regionservers out on the cluster<a name="line.131"></a>
-<span class="sourceLineNo">132</span>   */<a name="line.132"></a>
-<span class="sourceLineNo">133</span>  private final Map&lt;ServerName, AdminService.BlockingInterface&gt; rsAdmins = new HashMap&lt;&gt;();<a name="line.133"></a>
-<span class="sourceLineNo">134</span><a name="line.134"></a>
-<span class="sourceLineNo">135</span>  /** List of region servers that should not get any more new regions. */<a name="line.135"></a>
-<span class="sourceLineNo">136</span>  private final ArrayList&lt;ServerName&gt; drainingServers = new ArrayList&lt;&gt;();<a name="line.136"></a>
-<span class="sourceLineNo">137</span><a name="line.137"></a>
-<span class="sourceLineNo">138</span>  private final MasterServices master;<a name="line.138"></a>
-<span class="sourceLineNo">139</span>  private final ClusterConnection connection;<a name="line.139"></a>
-<span class="sourceLineNo">140</span><a name="line.140"></a>
-<span class="sourceLineNo">141</span>  private final DeadServer deadservers = new DeadServer();<a name="line.141"></a>
-<span class="sourceLineNo">142</span><a name="line.142"></a>
-<span class="sourceLineNo">143</span>  private final long maxSkew;<a name="line.143"></a>
-<span class="sourceLineNo">144</span>  private final long warningSkew;<a name="line.144"></a>
-<span class="sourceLineNo">145</span><a name="line.145"></a>
-<span class="sourceLineNo">146</span>  private final RpcControllerFactory rpcControllerFactory;<a name="line.146"></a>
-<span class="sourceLineNo">147</span><a name="line.147"></a>
-<span class="sourceLineNo">148</span>  /**<a name="line.148"></a>
-<span class="sourceLineNo">149</span>   * Set of region servers which are dead but not processed immediately. If one<a name="line.149"></a>
-<span class="sourceLineNo">150</span>   * server died before master enables ServerShutdownHandler, the server will be<a name="line.150"></a>
-<span class="sourceLineNo">151</span>   * added to this set and will be processed through calling<a name="line.151"></a>
-<span class="sourceLineNo">152</span>   * {@link ServerManager#processQueuedDeadServers()} by master.<a name="line.152"></a>
-<span class="sourceLineNo">153</span>   * &lt;p&gt;<a name="line.153"></a>
-<span class="sourceLineNo">154</span>   * A dead server is a server instance known to be dead, not listed in the /hbase/rs<a name="line.154"></a>
-<span class="sourceLineNo">155</span>   * znode any more. It may have not been submitted to ServerShutdownHandler yet<a name="line.155"></a>
-<span class="sourceLineNo">156</span>   * because the handler is not enabled.<a name="line.156"></a>
-<span class="sourceLineNo">157</span>   * &lt;p&gt;<a name="line.157"></a>
-<span class="sourceLineNo">158</span>   * A dead server, which has been submitted to ServerShutdownHandler while the<a name="line.158"></a>
-<span class="sourceLineNo">159</span>   * handler is not enabled, is queued up.<a name="line.159"></a>
-<span class="sourceLineNo">160</span>   * &lt;p&gt;<a name="line.160"></a>
-<span class="sourceLineNo">161</span>   * So this is a set of region servers known to be dead but not submitted to<a name="line.161"></a>
-<span class="sourceLineNo">162</span>   * ServerShutdownHandler for processing yet.<a name="line.162"></a>
-<span class="sourceLineNo">163</span>   */<a name="line.163"></a>
-<span class="sourceLineNo">164</span>  private Set&lt;ServerName&gt; queuedDeadServers = new HashSet&lt;&gt;();<a name="line.164"></a>
-<span class="sourceLineNo">165</span><a name="line.165"></a>
-<span class="sourceLineNo">166</span>  /**<a name="line.166"></a>
-<span class="sourceLineNo">167</span>   * Set of region servers which are dead and submitted to ServerShutdownHandler to process but not<a name="line.167"></a>
-<span class="sourceLineNo">168</span>   * fully processed immediately.<a name="line.168"></a>
-<span class="sourceLineNo">169</span>   * &lt;p&gt;<a name="line.169"></a>
-<span class="sourceLineNo">170</span>   * If one server died before assignment manager finished the failover cleanup, the server will be<a name="line.170"></a>
-<span class="sourceLineNo">171</span>   * added to this set and will be processed through calling<a name="line.171"></a>
-<span class="sourceLineNo">172</span>   * {@link ServerManager#processQueuedDeadServers()} by assignment manager.<a name="line.172"></a>
-<span class="sourceLineNo">173</span>   * &lt;p&gt;<a name="line.173"></a>
-<span class="sourceLineNo">174</span>   * The Boolean value indicates whether log split is needed inside ServerShutdownHandler<a name="line.174"></a>
-<span class="sourceLineNo">175</span>   * &lt;p&gt;<a name="line.175"></a>
-<span class="sourceLineNo">176</span>   * ServerShutdownHandler processes a dead server submitted to the handler after the handler is<a name="line.176"></a>
-<span class="sourceLineNo">177</span>   * enabled. It may not be able to complete the processing because meta is not yet online or master<a name="line.177"></a>
-<span class="sourceLineNo">178</span>   * is currently in startup mode. In this case, the dead server will be parked in this set<a name="line.178"></a>
-<span class="sourceLineNo">179</span>   * temporarily.<a name="line.179"></a>
-<span class="sourceLineNo">180</span>   */<a name="line.180"></a>
-<span class="sourceLineNo">181</span>  private Map&lt;ServerName, Boolean&gt; requeuedDeadServers = new ConcurrentHashMap&lt;&gt;();<a name="line.181"></a>
-<span class="sourceLineNo">182</span><a name="line.182"></a>
-<span class="sourceLineNo">183</span>  /** Listeners that are called on server events. */<a name="line.183"></a>
-<span class="sourceLineNo">184</span>  private List&lt;ServerListener&gt; listeners = new CopyOnWriteArrayList&lt;&gt;();<a name="line.184"></a>
-<span class="sourceLineNo">185</span><a name="line.185"></a>
-<span class="sourceLineNo">186</span>  /**<a name="line.186"></a>
-<span class="sourceLineNo">187</span>   * Constructor.<a name="line.187"></a>
-<span class="sourceLineNo">188</span>   * @param master<a name="line.188"></a>
-<span class="sourceLineNo">189</span>   * @throws ZooKeeperConnectionException<a name="line.189"></a>
-<span class="sourceLineNo">190</span>   */<a name="line.190"></a>
-<span class="sourceLineNo">191</span>  public ServerManager(final MasterServices master) {<a name="line.191"></a>
-<span class="sourceLineNo">192</span>    this(master, true);<a name="line.192"></a>
-<span class="sourceLineNo">193</span>  }<a name="line.193"></a>
-<span class="sourceLineNo">194</span><a name="line.194"></a>
-<span class="sourceLineNo">195</span>  ServerManager(final MasterServices master, final boolean connect) {<a name="line.195"></a>
-<span class="sourceLineNo">196</span>    this.master = master;<a name="line.196"></a>
-<span class="sourceLineNo">197</span>    Configuration c = master.getConfiguration();<a name="line.197"></a>
-<span class="sourceLineNo">198</span>    maxSkew = c.getLong("hbase.master.maxclockskew", 30000);<a name="line.198"></a>
-<span class="sourceLineNo">199</span>    warningSkew = c.getLong("hbase.master.warningclockskew", 10000);<a name="line.199"></a>
-<span class="sourceLineNo">200</span>    this.connection = connect ? master.getClusterConnection() : null;<a name="line.200"></a>
-<span class="sourceLineNo">201</span>    this.rpcControllerFactory = this.connection == null<a name="line.201"></a>
-<span class="sourceLineNo">202</span>        ? null<a name="line.202"></a>
-<span class="sourceLineNo">203</span>        : connection.getRpcControllerFactory();<a name="line.203"></a>
-<span class="sourceLineNo">204</span>  }<a name="line.204"></a>
-<span class="sourceLineNo">205</span><a name="line.205"></a>
-<span class="sourceLineNo">206</span>  /**<a name="line.206"></a>
-<span class="sourceLineNo">207</span>   * Add the listener to the notification list.<a name="line.207"></a>
-<span class="sourceLineNo">208</span>   * @param listener The ServerListener to register<a name="line.208"></a>
-<span class="sourceLineNo">209</span>   */<a name="line.209"></a>
-<span class="sourceLineNo">210</span>  public void registerListener(final ServerListener listener) {<a name="line.210"></a>
-<span class="sourceLineNo">211</span>    this.listeners.add(listener);<a name="line.211"></a>
-<span class="sourceLineNo">212</span>  }<a name="line.212"></a>
-<span class="sourceLineNo">213</span><a name="line.213"></a>
-<span class="sourceLineNo">214</span>  /**<a name="line.214"></a>
-<span class="sourceLineNo">215</span>   * Remove the listener from the notification list.<a name="line.215"></a>
-<span class="sourceLineNo">216</span>   * @param listener The ServerListener to unregister<a name="line.216"></a>
-<span class="sourceLineNo">217</span>   */<a name="line.217"></a>
-<span class="sourceLineNo">218</span>  public boolean unregisterListener(final ServerListener listener) {<a name="line.218"></a>
-<span class="sourceLineNo">219</span>    return this.listeners.remove(listener);<a name="line.219"></a>
-<span class="sourceLineNo">220</span>  }<a name="line.220"></a>
-<span class="sourceLineNo">221</span><a name="line.221"></a>
-<span class="sourceLineNo">222</span>  /**<a name="line.222"></a>
-<span class="sourceLineNo">223</span>   * Let the server manager know a new regionserver has come online<a name="line.223"></a>
-<span class="sourceLineNo">224</span>   * @param request the startup request<a name="line.224"></a>
-<span class="sourceLineNo">225</span>   * @param ia the InetAddress from which request is received<a name="line.225"></a>
-<span class="sourceLineNo">226</span>   * @return The ServerName we know this server as.<a name="line.226"></a>
-<span class="sourceLineNo">227</span>   * @throws IOException<a name="line.227"></a>
-<span class="sourceLineNo">228</span>   */<a name="line.228"></a>
-<span class="sourceLineNo">229</span>  ServerName regionServerStartup(RegionServerStartupRequest request, InetAddress ia)<a name="line.229"></a>
-<span class="sourceLineNo">230</span>      throws IOException {<a name="line.230"></a>
-<span class="sourceLineNo">231</span>    // Test for case where we get a region startup message from a regionserver<a name="line.231"></a>
-<span class="sourceLineNo">232</span>    // that has been quickly restarted but whose znode expiration handler has<a name="line.232"></a>
-<span class="sourceLineNo">233</span>    // not yet run, or from a server whose fail we are currently processing.<a name="line.233"></a>
-<span class="sourceLineNo">234</span>    // Test its host+port combo is present in serverAddressToServerInfo.  If it<a name="line.234"></a>
-<span class="sourceLineNo">235</span>    // is, reject the server and trigger its expiration. The next time it comes<a name="line.235"></a>
-<span class="sourceLineNo">236</span>    // in, it should have been removed from serverAddressToServerInfo and queued<a name="line.236"></a>
-<span class="sourceLineNo">237</span>    // for processing by ProcessServerShutdown.<a name="line.237"></a>
-<span class="sourceLineNo">238</span><a name="line.238"></a>
-<span class="sourceLineNo">239</span>    final String hostname = request.hasUseThisHostnameInstead() ?<a name="line.239"></a>
-<span class="sourceLineNo">240</span>        request.getUseThisHostnameInstead() :ia.getHostName();<a name="line.240"></a>
-<span class="sourceLineNo">241</span>    ServerName sn = ServerName.valueOf(hostname, request.getPort(),<a name="line.241"></a>
-<span class="sourceLineNo">242</span>      request.getServerStartCode());<a name="line.242"></a>
-<span class="sourceLineNo">243</span>    checkClockSkew(sn, request.getServerCurrentTime());<a name="line.243"></a>
-<span class="sourceLineNo">244</span>    checkIsDead(sn, "STARTUP");<a name="line.244"></a>
-<span class="sourceLineNo">245</span>    if (!checkAndRecordNewServer(sn, ServerLoad.EMPTY_SERVERLOAD)) {<a name="line.245"></a>
-<span class="sourceLineNo">246</span>      LOG.warn("THIS SHOULD NOT HAPPEN, RegionServerStartup"<a name="line.246"></a>
-<span class="sourceLineNo">247</span>        + " could not record the server: " + sn);<a name="line.247"></a>
-<span class="sourceLineNo">248</span>    }<a name="line.248"></a>
-<span class="sourceLineNo">249</span>    return sn;<a name="line.249"></a>
-<span class="sourceLineNo">250</span>  }<a name="line.250"></a>
-<span class="sourceLineNo">251</span><a name="line.251"></a>
-<span class="sourceLineNo">252</span>  /**<a name="line.252"></a>
-<span class="sourceLineNo">253</span>   * Updates last flushed sequence Ids for the regions on server sn<a name="line.253"></a>
-<span class="sourceLineNo">254</span>   * @param sn<a name="line.254"></a>
-<span class="sourceLineNo">255</span>   * @param hsl<a name="line.255"></a>
-<span class="sourceLineNo">256</span>   */<a name="line.256"></a>
-<span class="sourceLineNo">257</span>  private void updateLastFlushedSequenceIds(ServerName sn, ServerLoad hsl) {<a name="line.257"></a>
-<span class="sourceLineNo">258</span>    Map&lt;byte[], RegionLoad&gt; regionsLoad = hsl.getRegionsLoad();<a name="line.258"></a>
-<span class="sourceLineNo">259</span>    for (Entry&lt;byte[], RegionLoad&gt; entry : regionsLoad.entrySet()) {<a name="line.259"></a>
-<span class="sourceLineNo">260</span>      byte[] encodedRegionName = Bytes.toBytes(HRegionInfo.encodeRegionName(entry.getKey()));<a name="line.260"></a>
-<span class="sourceLineNo">261</span>      Long existingValue = flushedSequenceIdByRegion.get(encodedRegionName);<a name="line.261"></a>
-<span class="sourceLineNo">262</span>      long l = entry.getValue().getCompleteSequenceId();<a name="line.262"></a>
-<span class="sourceLineNo">263</span>      // Don't let smaller sequence ids override greater sequence ids.<a name="line.263"></a>
-<span class="sourceLineNo">264</span>      if (LOG.isTraceEnabled()) {<a name="line.264"></a>
-<span class="sourceLineNo">265</span>        LOG.trace(Bytes.toString(encodedRegionName) + ", existingValue=" + existingValue +<a name="line.265"></a>
-<span class="sourceLineNo">266</span>          ", completeSequenceId=" + l);<a name="line.266"></a>
-<span class="sourceLineNo">267</span>      }<a name="line.267"></a>
-<span class="sourceLineNo">268</span>      if (existingValue == null || (l != HConstants.NO_SEQNUM &amp;&amp; l &gt; existingValue)) {<a name="line.268"></a>
-<span class="sourceLineNo">269</span>        flushedSequenceIdByRegion.put(encodedRegionName, l);<a name="line.269"></a>
-<span class="sourceLineNo">270</span>      } else if (l != HConstants.NO_SEQNUM &amp;&amp; l &lt; existingValue) {<a name="line.270"></a>
-<span class="sourceLineNo">271</span>        LOG.warn("RegionServer " + sn + " indicates a last flushed sequence id ("<a name="line.271"></a>
-<span class="sourceLineNo">272</span>            + l + ") that is less than the previous last flushed sequence id ("<a name="line.272"></a>
-<span class="sourceLineNo">273</span>            + existingValue + ") for region " + Bytes.toString(entry.getKey()) + " Ignoring.");<a name="line.273"></a>
-<span class="sourceLineNo">274</span>      }<a name="line.274"></a>
-<span class="sourceLineNo">275</span>      ConcurrentNavigableMap&lt;byte[], Long&gt; storeFlushedSequenceId =<a name="line.275"></a>
-<span class="sourceLineNo">276</span>          computeIfAbsent(storeFlushedSequenceIdsByRegion, encodedRegionName,<a name="line.276"></a>
-<span class="sourceLineNo">277</span>            () -&gt; new ConcurrentSkipListMap&lt;&gt;(Bytes.BYTES_COMPARATOR));<a name="line.277"></a>
-<span class="sourceLineNo">278</span>      for (StoreSequenceId storeSeqId : entry.getValue().getStoreCompleteSequenceId()) {<a name="line.278"></a>
-<span class="sourceLineNo">279</span>        byte[] family = storeSeqId.getFamilyName().toByteArray();<a name="line.279"></a>
-<span class="sourceLineNo">280</span>        existingValue = storeFlushedSequenceId.get(family);<a name="line.280"></a>
-<span class="sourceLineNo">281</span>        l = storeSeqId.getSequenceId();<a name="line.281"></a>
-<span class="sourceLineNo">282</span>        if (LOG.isTraceEnabled()) {<a name="line.282"></a>
-<span class="sourceLineNo">283</span>          LOG.trace(Bytes.toString(encodedRegionName) + ", family=" + Bytes.toString(family) +<a name="line.283"></a>
-<span class="sourceLineNo">284</span>            ", existingValue=" + existingValue + ", completeSequenceId=" + l);<a name="line.284"></a>
-<span class="sourceLineNo">285</span>        }<a name="line.285"></a>
-<span class="sourceLineNo">286</span>        // Don't let smaller sequence ids override greater sequence ids.<a name="line.286"></a>
-<span class="sourceLineNo">287</span>        if (existingValue == null || (l != HConstants.NO_SEQNUM &amp;&amp; l &gt; existingValue.longValue())) {<a name="line.287"></a>
-<span class="sourceLineNo">288</span>          storeFlushedSequenceId.put(family, l);<a name="line.288"></a>
-<span class="sourceLineNo">289</span>        }<a name="line.289"></a>
-<span class="sourceLineNo">290</span>      }<a name="line.290"></a>
-<span class="sourceLineNo">291</span>    }<a name="line.291"></a>
-<span class="sourceLineNo">292</span>  }<a name="line.292"></a>
-<span class="sourceLineNo">293</span><a name="line.293"></a>
-<span class="sourceLineNo">294</span>  @VisibleForTesting<a name="line.294"></a>
-<span class="sourceLineNo">295</span>  public void regionServerReport(ServerName sn,<a name="line.295"></a>
-<span class="sourceLineNo">296</span>      ServerLoad sl) throws YouAreDeadException {<a name="line.296"></a>
-<span class="sourceLineNo">297</span>    checkIsDead(sn, "REPORT");<a name="line.297"></a>
-<span class="sourceLineNo">298</span>    if (null == this.onlineServers.replace(sn, sl)) {<a name="line.298"></a>
-<span class="sourceLineNo">299</span>      // Already have this host+port combo and its just different start code?<a name="line.299"></a>
-<span class="sourceLineNo">300</span>      // Just let the server in. Presume master joining a running cluster.<a name="line.300"></a>
-<span class="sourceLineNo">301</span>      // recordNewServer is what happens at the end of reportServerStartup.<a name="line.301"></a>
-<span class="sourceLineNo">302</span>      // The only thing we are skipping is passing back to the regionserver<a name="line.302"></a>
-<span class="sourceLineNo">303</span>      // the ServerName to use. Here we presume a master has already done<a name="line.303"></a>
-<span class="sourceLineNo">304</span>      // that so we'll press on with whatever it gave us for ServerName.<a name="line.304"></a>
-<span class="sourceLineNo">305</span>      if (!checkAndRecordNewServer(sn, sl)) {<a name="line.305"></a>
-<span class="sourceLineNo">306</span>        LOG.info("RegionServerReport ignored, could not record the server: " + sn);<a name="line.306"></a>
-<span class="sourceLineNo">307</span>        return; // Not recorded, so no need to move on<a name="line.307"></a>
-<span class="sourceLineNo">308</span>      }<a name="line.308"></a>
-<span class="sourceLineNo">309</span>    }<a name="line.309"></a>
-<span class="sourceLineNo">310</span>    updateLastFlushedSequenceIds(sn, sl);<a name="line.310"></a>
-<span class="sourceLineNo">311</span>  }<a name="line.311"></a>
-<span class="sourceLineNo">312</span><a name="line.312"></a>
-<span class="sourceLineNo">313</span>  /**<a name="line.313"></a>
-<span class="sourceLineNo">314</span>   * Check is a server of same host and port already exists,<a name="line.314"></a>
-<span class="sourceLineNo">315</span>   * if not, or the existed one got a smaller start code, record it.<a name="line.315"></a>
-<span class="sourceLineNo">316</span>   *<a name="line.316"></a>
-<span class="sourceLineNo">317</span>   * @param serverName the server to check and record<a name="line.317"></a>
-<span class="sourceLineNo">318</span>   * @param sl the server load on the server<a name="line.318"></a>
-<span class="sourceLineNo">319</span>   * @return true if the server is recorded, otherwise, false<a name="line.319"></a>
-<span class="sourceLineNo">320</span>   */<a name="line.320"></a>
-<span class="sourceLineNo">321</span>  boolean checkAndRecordNewServer(<a name="line.321"></a>
-<span class="sourceLineNo">322</span>      final ServerName serverName, final ServerLoad sl) {<a name="line.322"></a>
-<span class="sourceLineNo">323</span>    ServerName existingServer = null;<a name="line.323"></a>
-<span class="sourceLineNo">324</span>    synchronized (this.onlineServers) {<a name="line.324"></a>
-<span class="sourceLineNo">325</span>      existingServer = findServerWithSameHostnamePortWithLock(serverName);<a name="line.325"></a>
-<span class="sourceLineNo">326</span>      if (existingServer != null &amp;&amp; (existingServer.getStartcode() &gt; serverName.getStartcode())) {<a name="line.326"></a>
-<span class="sourceLineNo">327</span>        LOG.info("Server serverName=" + serverName + " rejected; we already have "<a name="line.327"></a>
-<span class="sourceLineNo">328</span>            + existingServer.toString() + " registered with same hostname and port");<a name="line.328"></a>
-<span class="sourceLineNo">329</span>        return false;<a name="line.329"></a>
-<span class="sourceLineNo">330</span>      }<a name="line.330"></a>
-<span class="sourceLineNo">331</span>      recordNewServerWithLock(serverName, sl);<a name="line.331"></a>
-<span class="sourceLineNo">332</span>    }<a name="line.332"></a>
-<span class="sourceLineNo">333</span><a name="line.333"></a>
-<span class="sourceLineNo">334</span>    // Tell our listeners that a server was added<a name="line.334"></a>
-<span class="sourceLineNo">335</span>    if (!this.listeners.isEmpty()) {<a name="line.335"></a>
-<span class="sourceLineNo">336</span>      for (ServerListener listener : this.listeners) {<a name="line.336"></a>
-<span class="sourceLineNo">337</span>        listener.serverAdded(serverName);<a name="line.337"></a>
-<span class="sourceLineNo">338</span>      }<a name="line.338"></a>
-<span class="sourceLineNo">339</span>    }<a name="line.339"></a>
-<span class="sourceLineNo">340</span><a name="line.340"></a>
-<span class="sourceLineNo">341</span>    // Note that we assume that same ts means same server, and don't expire in that case.<a name="line.341"></a>
-<span class="sourceLineNo">342</span>    //  TODO: ts can theoretically collide due to clock shifts, so this is a bit hacky.<a name="line.342"></a>
-<span class="sourceLineNo">343</span>    if (existingServer != null &amp;&amp; (existingServer.getStartcode() &lt; serverName.getStartcode())) {<a name="line.343"></a>
-<span class="sourceLineNo">344</span>      LOG.info("Triggering server recovery; existingServer " +<a name="line.344"></a>
-<span class="sourceLineNo">345</span>          existingServer + " looks stale, new server:" + serverName);<a name="line.345"></a>
-<span class="sourceLineNo">346</span>      expireServer(existingServer);<a name="line.346"></a>
-<span class="sourceLineNo">347</span>    }<a name="line.347"></a>
-<span class="sourceLineNo">348</span>    return true;<a name="line.348"></a>
-<span class="sourceLineNo">349</span>  }<a name="line.349"></a>
-<span class="sourceLineNo">350</span><a name="line.350"></a>
-<span class="sourceLineNo">351</span>  /**<a name="line.351"></a>
-<span class="sourceLineNo">352</span>   * Checks if the clock skew between the server and the master. If the clock skew exceeds the<a name="line.352"></a>
-<span class="sourceLineNo">353</span>   * configured max, it will throw an exception; if it exceeds the configured warning threshold,<a name="line.353"></a>
-<span class="sourceLineNo">354</span>   * it will log a warning but start normally.<a name="line.354"></a>
-<span class="sourceLineNo">355</span>   * @param serverName Incoming servers's name<a name="line.355"></a>
-<span class="sourceLineNo">356</span>   * @param serverCurrentTime<a name="line.356"></a>
-<span class="sourceLineNo">357</span>   * @throws ClockOutOfSyncException if the skew exceeds the configured max value<a name="line.357"></a>
-<span class="sourceLineNo">358</span>   */<a name="line.358"></a>
-<span class="sourceLineNo">359</span>  private void checkClockSkew(final ServerName serverName, final long serverCurrentTime)<a name="line.359"></a>
-<span class="sourceLineNo">360</span>  throws ClockOutOfSyncException {<a name="line.360"></a>
-<span class="sourceLineNo">361</span>    long skew = Math.abs(System.currentTimeMillis() - serverCurrentTime);<a name="line.361"></a>
-<span class="sourceLineNo">362</span>    if (skew &gt; maxSkew) {<a name="line.362"></a>
-<span class="sourceLineNo">363</span>      String message = "Server " + serverName + " has been " +<a name="line.363"></a>
-<span class="sourceLineNo">364</span>        "rejected; Reported time is too far out of sync with master.  " +<a name="line.364"></a>
-<span class="sourceLineNo">365</span>        "Time difference of " + skew + "ms &gt; max allowed of " + maxSkew + "ms";<a name="line.365"></a>
-<span class="sourceLineNo">366</span>      LOG.warn(message);<a name="line.366"></a>
-<span class="sourceLineNo">367</span>      throw new ClockOutOfSyncException(message);<a name="line.367"></a>
-<span class="sourceLineNo">368</span>    } else if (skew &gt; warningSkew){<a name="line.368"></a>
-<span class="sourceLineNo">369</span>      String message = "Reported time for server " + serverName + " is out of sync with master " +<a name="line.369"></a>
-<span class="sourceLineNo">370</span>        "by " + skew + "ms. (Warning threshold is " + warningSkew + "ms; " +<a name="line.370"></a>
-<span class="sourceLineNo">371</span>        "error threshold is " + maxSkew + "ms)";<a name="line.371"></a>
-<span class="sourceLineNo">372</span>      LOG.warn(message);<a name="line.372"></a>
-<span class="sourceLineNo">373</span>    }<a name="line.373"></a>
-<span class="sourceLineNo">374</span>  }<a name="line.374"></a>
-<span class="sourceLineNo">375</span><a name="line.375"></a>
-<span class="sourceLineNo">376</span>  /**<a name="line.376"></a>
-<span class="sourceLineNo">377</span>   * If this server is on the dead list, reject it with a YouAreDeadException.<a name="line.377"></a>
-<span class="sourceLineNo">378</span>   * If it was dead but came back with a new start code, remove the old entry<a name="line.378"></a>
-<span class="sourceLineNo">379</span>   * from the dead list.<a name="line.379"></a>
-<span class="sourceLineNo">380</span>   * @param serverName<a name="line.380"></a>
-<span class="sourceLineNo">381</span>   * @param what START or REPORT<a name="line.381"></a>
-<span class="sourceLineNo">382</span>   * @throws org.apache.hadoop.hbase.YouAreDeadException<a name="line.382"></a>
-<span class="sourceLineNo">383</span>   */<a name="line.383"></a>
-<span class="sourceLineNo">384</span>  private void checkIsDead(final ServerName serverName, final String what)<a name="line.384"></a>
-<span class="sourceLineNo">385</span>      throws YouAreDeadException {<a name="line.385"></a>
-<span class="sourceLineNo">386</span>    if (this.deadservers.isDeadServer(serverName)) {<a name="line.386"></a>
-<span class="sourceLineNo">387</span>      // host name, port and start code all match with existing one of the<a name="line.387"></a>
-<span class="sourceLineNo">388</span>      // dead servers. So, this server must be dead.<a name="line.388"></a>
-<span class="sourceLineNo">389</span>      String message = "Server " + what + " rejected; currently processing " +<a name="line.389"></a>
-<span class="sourceLineNo">390</span>          serverName + " as dead server";<a name="line.390"></a>
-<span class="sourceLineNo">391</span>      LOG.debug(message);<a name="line.391"></a>
-<span class="sourceLineNo">392</span>      throw new YouAreDeadException(message);<a name="line.392"></a>
-<span class="sourceLineNo">393</span>    }<a name="line.393"></a>
-<span class="sourceLineNo">394</span>    // remove dead server with same hostname and port of newly checking in rs after master<a name="line.394"></a>
-<span class="sourceLineNo">395</span>    // initialization.See HBASE-5916 for more information.<a name="line.395"></a>
-<span class="sourceLineNo">396</span>    if ((this.master == null || this.master.isInitialized())<a name="line.396"></a>
-<span class="sourceLineNo">397</span>        &amp;&amp; this.deadservers.cleanPreviousInstance(serverName)) {<a name="line.397"></a>
-<span class="sourceLineNo">398</span>      // This server has now become alive after we marked it as dead.<a name="line.398"></a>
-<span class="sourceLineNo">399</span>      // We removed it's previous entry from the dead list to reflect it.<a name="line.399"></a>
-<span class="sourceLineNo">400</span>      LOG.debug(what + ":" + " Server " + serverName + " came back up," +<a name="line.400"></a>
-<span class="sourceLineNo">401</span>          " removed it from the dead servers list");<a name="line.401"></a>
-<span class="sourceLineNo">402</span>    }<a name="line.402"></a>
-<span class="sourceLineNo">403</span>  }<a name="line.403"></a>
-<span class="sourceLineNo">404</span><a name="line.404"></a>
-<span class="sourceLineNo">405</span>  /**<a name="line.405"></a>
-<span class="sourceLineNo">406</span>   * Assumes onlineServers is locked.<a name="line.406"></a>
-<span class="sourceLineNo">407</span>   * @return ServerName with matching hostname and port.<a name="line.407"></a>
-<span class="sourceLineNo">408</span>   */<a name="line.408"></a>
-<span class="sourceLineNo">409</span>  private ServerName findServerWithSameHostnamePortWithLock(<a name="line.409"></a>
-<span class="sourceLineNo">410</span>      final ServerName serverName) {<a name="line.410"></a>
-<span class="sourceLineNo">411</span>    ServerName end = ServerName.valueOf(serverName.getHostname(), serverName.getPort(),<a name="line.411"></a>
-<span class="sourceLineNo">412</span>        Long.MAX_VALUE);<a name="line.412"></a>
-<span class="sourceLineNo">413</span><a name="line.413"></a>
-<span class="sourceLineNo">414</span>    ServerName r = onlineServers.lowerKey(end);<a name="line.414"></a>
-<span class="sourceLineNo">415</span>    if (r != null) {<a name="line.415"></a>
-<span class="sourceLineNo">416</span>      if (ServerName.isSameHostnameAndPort(r, serverName)) {<a name="line.416"></a>
-<span class="sourceLineNo">417</span>        return r;<a name="line.417"></a>
-<span class="sourceLineNo">418</span>      }<a name="line.418"></a>
-<span class="sourceLineNo">419</span>    }<a name="line.419"></a>
-<span class="sourceLineNo">420</span>    return null;<a name="line.420"></a>
-<span class="sourceLineNo">421</span>  }<a name="line.421"></a>
-<span class="sourceLineNo">422</span><a name="line.422"></a>
-<span class="sourceLineNo">423</span>  /**<a name="line.423"></a>
-<span class="sourceLineNo">424</span>   * Adds the onlineServers list. onlineServers should be locked.<a name="line.424"></a>
-<span class="sourceLineNo">425</span>   * @param serverName The remote servers name.<a name="line.425"></a>
-<span class="sourceLineNo">426</span>   * @param sl<a name="line.426"></a>
+<span class="sourceLineNo">038</span>import java.util.concurrent.atomic.AtomicBoolean;<a name="line.38"></a>
+<span class="sourceLineNo">039</span>import java.util.function.Predicate;<a name="line.39"></a>
+<span class="sourceLineNo">040</span><a name="line.40"></a>
+<span class="sourceLineNo">041</span>import org.apache.commons.logging.Log;<a name="line.41"></a>
+<span class="sourceLineNo">042</span>import org.apache.commons.logging.LogFactory;<a name="line.42"></a>
+<span class="sourceLineNo">043</span>import org.apache.hadoop.conf.Configuration;<a name="line.43"></a>
+<span class="sourceLineNo">044</span>import org.apache.hadoop.hbase.ClockOutOfSyncException;<a name="line.44"></a>
+<span class="sourceLineNo">045</span>import org.apache.hadoop.hbase.HConstants;<a name="line.45"></a>
+<span class="sourceLineNo">046</span>import org.apache.hadoop.hbase.HRegionInfo;<a name="line.46"></a>
+<span class="sourceLineNo">047</span>import org.apache.hadoop.hbase.NotServingRegionException;<a name="line.47"></a>
+<span class="sourceLineNo">048</span>import org.apache.hadoop.hbase.RegionLoad;<a name="line.48"></a>
+<span class="sourceLineNo">049</span>import org.apache.hadoop.hbase.ServerLoad;<a name="line.49"></a>
+<span class="sourceLineNo">050</span>import org.apache.hadoop.hbase.ServerName;<a name="line.50"></a>
+<span class="sourceLineNo">051</span>import org.apache.hadoop.hbase.YouAreDeadException;<a name="line.51"></a>
+<span class="sourceLineNo">052</span>import org.apache.hadoop.hbase.ZooKeeperConnectionException;<a name="line.52"></a>
+<span class="sourceLineNo">053</span>import org.apache.hadoop.hbase.classification.InterfaceAudience;<a name="line.53"></a>
+<span class="sourceLineNo">054</span>import org.apache.hadoop.hbase.client.ClusterConnection;<a name="line.54"></a>
+<span class="sourceLineNo">055</span>import org.apache.hadoop.hbase.client.RetriesExhaustedException;<a name="line.55"></a>
+<span class="sourceLineNo">056</span>import org.apache.hadoop.hbase.ipc.HBaseRpcController;<a name="line.56"></a>
+<span class="sourceLineNo">057</span>import org.apache.hadoop.hbase.ipc.RpcControllerFactory;<a name="line.57"></a>
+<span class="sourceLineNo">058</span>import org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer;<a name="line.58"></a>
+<span class="sourceLineNo">059</span>import org.apache.hadoop.hbase.monitoring.MonitoredTask;<a name="line.59"></a>
+<span class="sourceLineNo">060</span>import org.apache.hadoop.hbase.regionserver.HRegionServer;<a name="line.60"></a>
+<span class="sourceLineNo">061</span>import org.apache.hadoop.hbase.shaded.com.google.protobuf.UnsafeByteOperations;<a name="line.61"></a>
+<span class="sourceLineNo">062</span>import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;<a name="line.62"></a>
+<span class="sourceLineNo">063</span>import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService;<a name="line.63"></a>
+<span class="sourceLineNo">064</span>import org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos.RegionStoreSequenceIds;<a name="line.64"></a>
+<span class="sourceLineNo">065</span>import org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos.StoreSequenceId;<a name="line.65"></a>
+<span class="sourceLineNo">066</span>import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerStartupRequest;<a name="line.66"></a>
+<span class="sourceLineNo">067</span>import org.apache.hadoop.hbase.util.Bytes;<a name="line.67"></a>
+<span class="sourceLineNo">068</span>import org.apache.hadoop.hbase.zookeeper.ZKUtil;<a name="line.68"></a>
+<span class="sourceLineNo">069</span>import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;<a name="line.69"></a>
+<span class="sourceLineNo">070</span>import org.apache.zookeeper.KeeperException;<a name="line.70"></a>
+<span class="sourceLineNo">071</span><a name="line.71"></a>
+<span class="sourceLineNo">072</span>import org.apache.hadoop.hbase.shaded.com.google.common.annotations.VisibleForTesting;<a name="line.72"></a>
+<span class="sourceLineNo">073</span><a name="line.73"></a>
+<span class="sourceLineNo">074</span>/**<a name="line.74"></a>
+<span class="sourceLineNo">075</span> * The ServerManager class manages info about region servers.<a name="line.75"></a>
+<span class="sourceLineNo">076</span> * &lt;p&gt;<a name="line.76"></a>
+<span class="sourceLineNo">077</span> * Maintains lists of online and dead servers.  Processes the startups,<a name="line.77"></a>
+<span class="sourceLineNo">078</span> * shutdowns, and deaths of region servers.<a name="line.78"></a>
+<span class="sourceLineNo">079</span> * &lt;p&gt;<a name="line.79"></a>
+<span class="sourceLineNo">080</span> * Servers are distinguished in two different ways.  A given server has a<a name="line.80"></a>
+<span class="sourceLineNo">081</span> * location, specified by hostname and port, and of which there can only be one<a name="line.81"></a>
+<span class="sourceLineNo">082</span> * online at any given time.  A server instance is specified by the location<a name="line.82"></a>
+<span class="sourceLineNo">083</span> * (hostname and port) as well as the startcode (timestamp from when the server<a name="line.83"></a>
+<span class="sourceLineNo">084</span> * was started).  This is used to differentiate a restarted instance of a given<a name="line.84"></a>
+<span class="sourceLineNo">085</span> * server from the original instance.<a name="line.85"></a>
+<span class="sourceLineNo">086</span> * &lt;p&gt;<a name="line.86"></a>
+<span class="sourceLineNo">087</span> * If a sever is known not to be running any more, it is called dead. The dead<a name="line.87"></a>
+<span class="sourceLineNo">088</span> * server needs to be handled by a ServerShutdownHandler.  If the handler is not<a name="line.88"></a>
+<span class="sourceLineNo">089</span> * enabled yet, the server can't be handled right away so it is queued up.<a name="line.89"></a>
+<span class="sourceLineNo">090</span> * After the handler is enabled, the server will be submitted to a handler to handle.<a name="line.90"></a>
+<span class="sourceLineNo">091</span> * However, the handler may be just partially enabled.  If so,<a name="line.91"></a>
+<span class="sourceLineNo">092</span> * the server cannot be fully processed, and be queued up for further processing.<a name="line.92"></a>
+<span class="sourceLineNo">093</span> * A server is fully processed only after the handler is fully enabled<a name="line.93"></a>
+<span class="sourceLineNo">094</span> * and has completed the handling.<a name="line.94"></a>
+<span class="sourceLineNo">095</span> */<a name="line.95"></a>
+<span class="sourceLineNo">096</span>@InterfaceAudience.Private<a name="line.96"></a>
+<span class="sourceLineNo">097</span>public class ServerManager {<a name="line.97"></a>
+<span class="sourceLineNo">098</span>  public static final String WAIT_ON_REGIONSERVERS_MAXTOSTART =<a name="line.98"></a>
+<span class="sourceLineNo">099</span>      "hbase.master.wait.on.regionservers.maxtostart";<a name="line.99"></a>
+<span class="sourceLineNo">100</span><a name="line.100"></a>
+<span class="sourceLineNo">101</span>  public static final String WAIT_ON_REGIONSERVERS_MINTOSTART =<a name="line.101"></a>
+<span class="sourceLineNo">102</span>      "hbase.master.wait.on.regionservers.mintostart";<a name="line.102"></a>
+<span class="sourceLineNo">103</span><a name="line.103"></a>
+<span class="sourceLineNo">104</span>  public static final String WAIT_ON_REGIONSERVERS_TIMEOUT =<a name="line.104"></a>
+<span class="sourceLineNo">105</span>      "hbase.master.wait.on.regionservers.timeout";<a name="line.105"></a>
+<span class="sourceLineNo">106</span><a name="line.106"></a>
+<span class="sourceLineNo">107</span>  public static final String WAIT_ON_REGIONSERVERS_INTERVAL =<a name="line.107"></a>
+<span class="sourceLineNo">108</span>      "hbase.master.wait.on.regionservers.interval";<a name="line.108"></a>
+<span class="sourceLineNo">109</span><a name="line.109"></a>
+<span class="sourceLineNo">110</span>  private static final Log LOG = LogFactory.getLog(ServerManager.class);<a name="line.110"></a>
+<span class="sourceLineNo">111</span><a name="line.111"></a>
+<span class="sourceLineNo">112</span>  // Set if we are to shutdown the cluster.<a name="line.112"></a>
+<span class="sourceLineNo">113</span>  private AtomicBoolean clusterShutdown = new AtomicBoolean(false);<a name="line.113"></a>
+<span class="sourceLineNo">114</span><a name="line.114"></a>
+<span class="sourceLineNo">115</span>  /**<a name="line.115"></a>
+<span class="sourceLineNo">116</span>   * The last flushed sequence id for a region.<a name="line.116"></a>
+<span class="sourceLineNo">117</span>   */<a name="line.117"></a>
+<span class="sourceLineNo">118</span>  private final ConcurrentNavigableMap&lt;byte[], Long&gt; flushedSequenceIdByRegion =<a name="line.118"></a>
+<span class="sourceLineNo">119</span>    new ConcurrentSkipListMap&lt;&gt;(Bytes.BYTES_COMPARATOR);<a name="line.119"></a>
+<span class="sourceLineNo">120</span><a name="line.120"></a>
+<span class="sourceLineNo">121</span>  /**<a name="line.121"></a>
+<span class="sourceLineNo">122</span>   * The last flushed sequence id for a store in a region.<a name="line.122"></a>
+<span class="sourceLineNo">123</span>   */<a name="line.123"></a>
+<span class="sourceLineNo">124</span>  private final ConcurrentNavigableMap&lt;byte[], ConcurrentNavigableMap&lt;byte[], Long&gt;&gt;<a name="line.124"></a>
+<span class="sourceLineNo">125</span>    storeFlushedSequenceIdsByRegion = new ConcurrentSkipListMap&lt;&gt;(Bytes.BYTES_COMPARATOR);<a name="line.125"></a>
+<span class="sourceLineNo">126</span><a name="line.126"></a>
+<span class="sourceLineNo">127</span>  /** Map of registered servers to their current load */<a name="line.127"></a>
+<span class="sourceLineNo">128</span>  private final ConcurrentNavigableMap&lt;ServerName, ServerLoad&gt; onlineServers = new ConcurrentSkipListMap&lt;&gt;();<a name="line.128"></a>
+<span class="sourceLineNo">129</span><a name="line.129"></a>
+<span class="sourceLineNo">130</span>  /**<a name="line.130"></a>
+<span class="sourceLineNo">131</span>   * Map of admin interfaces per registered regionserver; these interfaces we use to control<a name="line.131"></a>
+<span class="sourceLineNo">132</span>   * regionservers out on the cluster<a name="line.132"></a>
+<span class="sourceLineNo">133</span>   */<a name="line.133"></a>
+<span class="sourceLineNo">134</span>  private final Map&lt;ServerName, AdminService.BlockingInterface&gt; rsAdmins = new HashMap&lt;&gt;();<a name="line.134"></a>
+<span class="sourceLineNo">135</span><a name="line.135"></a>
+<span class="sourceLineNo">136</span>  /** List of region servers that should not get any more new regions. */<a name="line.136"></a>
+<span class="sourceLineNo">137</span>  private final ArrayList&lt;ServerName&gt; drainingServers = new ArrayList&lt;&gt;();<a name="line.137"></a>
+<span class="sourceLineNo">138</span><a name="line.138"></a>
+<span class="sourceLineNo">139</span>  private final MasterServices master;<a name="line.139"></a>
+<span class="sourceLineNo">140</span>  private final ClusterConnection connection;<a name="line.140"></a>
+<span class="sourceLineNo">141</span><a name="line.141"></a>
+<span class="sourceLineNo">142</span>  private final DeadServer deadservers = new DeadServer();<a name="line.142"></a>
+<span class="sourceLineNo">143</span><a name="line.143"></a>
+<span class="sourceLineNo">144</span>  private final long maxSkew;<a name="line.144"></a>
+<span class="sourceLineNo">145</span>  private final long warningSkew;<a name="line.145"></a>
+<span class="sourceLineNo">146</span><a name="line.146"></a>
+<span class="sourceLineNo">147</span>  private final RpcControllerFactory rpcControllerFactory;<a name="line.147"></a>
+<span class="sourceLineNo">148</span><a name="line.148"></a>
+<span class="sourceLineNo">149</span>  /**<a name="line.149"></a>
+<span class="sourceLineNo">150</span>   * Set of region servers which are dead but not processed immediately. If one<a name="line.150"></a>
+<span class="sourceLineNo">151</span>   * server died before master enables ServerShutdownHandler, the server will be<a name="line.151"></a>
+<span class="sourceLineNo">152</span>   * added to this set and will be processed through calling<a name="line.152"></a>
+<span class="sourceLineNo">153</span>   * {@link ServerManager#processQueuedDeadServers()} by master.<a name="line.153"></a>
+<span class="sourceLineNo">154</span>   * &lt;p&gt;<a name="line.154"></a>
+<span class="sourceLineNo">155</span>   * A dead server is a server instance known to be dead, not listed in the /hbase/rs<a name="line.155"></a>
+<span class="sourceLineNo">156</span>   * znode any more. It may have not been submitted to ServerShutdownHandler yet<a name="line.156"></a>
+<span class="sourceLineNo">157</span>   * because the handler is not enabled.<a name="line.157"></a>
+<span class="sourceLineNo">158</span>   * &lt;p&gt;<a name="line.158"></a>
+<span class="sourceLineNo">159</span>   * A dead server, which has been submitted to ServerShutdownHandler while the<a name="line.159"></a>
+<span class="sourceLineNo">160</span>   * handler is not enabled, is queued up.<a name="line.160"></a>
+<span class="sourceLineNo">161</span>   * &lt;p&gt;<a name="line.161"></a>
+<span class="sourceLineNo">162</span>   * So this is a set of region servers known to be dead but not submitted to<a name="line.162"></a>
+<span class="sourceLineNo">163</span>   * ServerShutdownHandler for processing yet.<a name="line.163"></a>
+<span class="sourceLineNo">164</span>   */<a name="line.164"></a>
+<span class="sourceLineNo">165</span>  private Set&lt;ServerName&gt; queuedDeadServers = new HashSet&lt;&gt;();<a name="line.165"></a>
+<span class="sourceLineNo">166</span><a name="line.166"></a>
+<span class="sourceLineNo">167</span>  /**<a name="line.167"></a>
+<span class="sourceLineNo">168</span>   * Set of region servers which are dead and submitted to ServerShutdownHandler to process but not<a name="line.168"></a>
+<span class="sourceLineNo">169</span>   * fully processed immediately.<a name="line.169"></a>
+<span class="sourceLineNo">170</span>   * &lt;p&gt;<a name="line.170"></a>
+<span class="sourceLineNo">171</span>   * If one server died before assignment manager finished the failover cleanup, the server will be<a name="line.171"></a>
+<span class="sourceLineNo">172</span>   * added to this set and will be processed through calling<a name="line.172"></a>
+<span class="sourceLineNo">173</span>   * {@link ServerManager#processQueuedDeadServers()} by assignment manager.<a name="line.173"></a>
+<span class="sourceLineNo">174</span>   * &lt;p&gt;<a name="line.174"></a>
+<span class="sourceLineNo">175</span>   * The Boolean value indicates whether log split is needed inside ServerShutdownHandler<a name="line.175"></a>
+<span class="sourceLineNo">176</span>   * &lt;p&gt;<a name="line.176"></a>
+<span class="sourceLineNo">177</span>   * ServerShutdownHandler processes a dead server submitted to the handler after the handler is<a name="line.177"></a>
+<span class="sourceLineNo">178</span>   * enabled. It may not be able to complete the processing because meta is not yet online or master<a name="line.178"></a>
+<span class="sourceLineNo">179</span>   * is currently in startup mode. In this case, the dead server will be parked in this set<a name="line.179"></a>
+<span class="sourceLineNo">180</span>   * temporarily.<a name="line.180"></a>
+<span class="sourceLineNo">181</span>   */<a name="line.181"></a>
+<span class="sourceLineNo">182</span>  private Map&lt;ServerName, Boolean&gt; requeuedDeadServers = new ConcurrentHashMap&lt;&gt;();<a name="line.182"></a>
+<span class="sourceLineNo">183</span><a name="line.183"></a>
+<span class="sourceLineNo">184</span>  /** Listeners that are called on server events. */<a name="line.184"></a>
+<span class="sourceLineNo">185</span>  private List&lt;ServerListener&gt; listeners = new CopyOnWriteArrayList&lt;&gt;();<a name="line.185"></a>
+<span class="sourceLineNo">186</span><a name="line.186"></a>
+<span class="sourceLineNo">187</span>  /**<a name="line.187"></a>
+<span class="sourceLineNo">188</span>   * Constructor.<a name="line.188"></a>
+<span class="sourceLineNo">189</span>   * @param master<a name="line.189"></a>
+<span class="sourceLineNo">190</span>   * @throws ZooKeeperConnectionException<a name="line.190"></a>
+<span class="sourceLineNo">191</span>   */<a name="line.191"></a>
+<span class="sourceLineNo">192</span>  public ServerManager(final MasterServices master) {<a name="line.192"></a>
+<span class="sourceLineNo">193</span>    this(master, true);<a name="line.193"></a>
+<span class="sourceLineNo">194</span>  }<a name="line.194"></a>
+<span class="sourceLineNo">195</span><a name="line.195"></a>
+<span class="sourceLineNo">196</span>  ServerManager(final MasterServices master, final boolean connect) {<a name="line.196"></a>
+<span class="sourceLineNo">197</span>    this.master = master;<a name="line.197"></a>
+<span class="sourceLineNo">198</span>    Configuration c = master.getConfiguration();<a name="line.198"></a>
+<span class="sourceLineNo">199</span>    maxSkew = c.getLong("hbase.master.maxclockskew", 30000);<a name="line.199"></a>
+<span class="sourceLineNo">200</span>    warningSkew = c.getLong("hbase.master.warningclockskew", 10000);<a name="line.200"></a>
+<span class="sourceLineNo">201</span>    this.connection = connect ? master.getClusterConnection() : null;<a name="line.201"></a>
+<span class="sourceLineNo">202</span>    this.rpcControllerFactory = this.connection == null<a name="line.202"></a>
+<span class="sourceLineNo">203</span>        ? null<a name="line.203"></a>
+<span class="sourceLineNo">204</span>        : connection.getRpcControllerFactory();<a name="line.204"></a>
+<span class="sourceLineNo">205</span>  }<a name="line.205"></a>
+<span class="sourceLineNo">206</span><a name="line.206"></a>
+<span class="sourceLineNo">207</span>  /**<a name="line.207"></a>
+<span class="sourceLineNo">208</span>   * Add the listener to the notification list.<a name="line.208"></a>
+<span class="sourceLineNo">209</span>   * @param listener The ServerListener to register<a name="line.209"></a>
+<span class="sourceLineNo">210</span>   */<a name="line.210"></a>
+<span class="sourceLineNo">211</span>  public void registerListener(final ServerListener listener) {<a name="line.211"></a>
+<span class="sourceLineNo">212</span>    this.listeners.add(listener);<a name="line.212"></a>
+<span class="sourceLineNo">213</span>  }<a name="line.213"></a>
+<span class="sourceLineNo">214</span><a name="line.214"></a>
+<span class="sourceLineNo">215</span>  /**<a name="line.215"></a>
+<span class="sourceLineNo">216</span>   * Remove the listener from the notification list.<a name="line.216"></a>
+<span class="sourceLineNo">217</span>   * @param listener The ServerListener to unregister<a name="line.217"></a>
+<span class="sourceLineNo">218</span>   */<a name="line.218"></a>
+<span class="sourceLineNo">219</span>  public boolean unregisterListener(final ServerListener listener) {<a name="line.219"></a>
+<span class="sourceLineNo">220</span>    return this.listeners.remove(listener);<a name="line.220"></a>
+<span class="sourceLineNo">221</span>  }<a name="line.221"></a>
+<span class="sourceLineNo">222</span><a name="line.222"></a>
+<span class="sourceLineNo">223</span>  /**<a name="line.223"></a>
+<span class="sourceLineNo">224</span>   * Let the server manager know a new regionserver has come online<a name="line.224"></a>
+<span class="sourceLineNo">225</span>   * @param request the startup request<a name="line.225"></a>
+<span class="sourceLineNo">226</span>   * @param ia the InetAddress from which request is received<a name="line.226"></a>
+<span class="sourceLineNo">227</span>   * @return The ServerName we know this server as.<a name="line.227"></a>
+<span class="sourceLineNo">228</span>   * @throws IOException<a name="line.228"></a>
+<span class="sourceLineNo">229</span>   */<a name="line.229"></a>
+<span class="sourceLineNo">230</span>  ServerName regionServerStartup(RegionServerStartupRequest request, InetAddress ia)<a name="line.230"></a>
+<span class="sourceLineNo">231</span>      throws IOException {<a name="line.231"></a>
+<span class="sourceLineNo">232</span>    // Test for case where we get a region startup message from a regionserver<a name="line.232"></a>
+<span class="sourceLineNo">233</span>    // that has been quickly restarted but whose znode expiration handler has<a name="line.233"></a>
+<span class="sourceLineNo">234</span>    // not yet run, or from a server whose fail we are currently processing.<a name="line.234"></a>
+<span class="sourceLineNo">235</span>    // Test its host+port combo is present in serverAddressToServerInfo.  If it<a name="line.235"></a>
+<span class="sourceLineNo">236</span>    // is, reject the server and trigger its expiration. The next time it comes<a name="line.236"></a>
+<span class="sourceLineNo">237</span>    // in, it should have been removed from serverAddressToServerInfo and queued<a name="line.237"></a>
+<span class="sourceLineNo">238</span>    // for processing by ProcessServerShutdown.<a name="line.238"></a>
+<span class="sourceLineNo">239</span><a name="line.239"></a>
+<span class="sourceLineNo">240</span>    final String hostname = request.hasUseThisHostnameInstead() ?<a name="line.240"></a>
+<span class="sourceLineNo">241</span>        request.getUseThisHostnameInstead() :ia.getHostName();<a name="line.241"></a>
+<span class="sourceLineNo">242</span>    ServerName sn = ServerName.valueOf(hostname, request.getPort(),<a name="line.242"></a>
+<span class="sourceLineNo">243</span>      request.getServerStartCode());<a name="line.243"></a>
+<span class="sourceLineNo">244</span>    checkClockSkew(sn, request.getServerCurrentTime());<a name="line.244"></a>
+<span class="sourceLineNo">245</span>    checkIsDead(sn, "STARTUP");<a name="line.245"></a>
+<span class="sourceLineNo">246</span>    if (!checkAndRecordNewServer(sn, ServerLoad.EMPTY_SERVERLOAD)) {<a name="line.246"></a>
+<span class="sourceLineNo">247</span>      LOG.warn("THIS SHOULD NOT HAPPEN, RegionServerStartup"<a name="line.247"></a>
+<span class="sourceLineNo">248</span>        + " could not record the server: " + sn);<a name="line.248"></a>
+<span class="sourceLineNo">249</span>    }<a name="line.249"></a>
+<span class="sourceLineNo">250</span>    return sn;<a name="line.250"></a>
+<span class="sourceLineNo">251</span>  }<a name="line.251"></a>
+<span class="sourceLineNo">252</span><a name="line.252"></a>
+<span class="sourceLineNo">253</span>  /**<a name="line.253"></a>
+<span class="sourceLineNo">254</span>   * Updates last flushed sequence Ids for the regions on server sn<a name="line.254"></a>
+<span class="sourceLineNo">255</span>   * @param sn<a name="line.255"></a>
+<span class="sourceLineNo">256</span>   * @param hsl<a name="line.256"></a>
+<span class="sourceLineNo">257</span>   */<a name="line.257"></a>
+<span class="sourceLineNo">258</span>  private void updateLastFlushedSequenceIds(ServerName sn, ServerLoad hsl) {<a name="line.258"></a>
+<span class="sourceLineNo">259</span>    Map&lt;byte[], RegionLoad&gt; regionsLoad = hsl.getRegionsLoad();<a name="line.259"></a>
+<span class="sourceLineNo">260</span>    for (Entry&lt;byte[], RegionLoad&gt; entry : regionsLoad.entrySet()) {<a name="line.260"></a>
+<span class="sourceLineNo">261</span>      byte[] encodedRegionName = Bytes.toBytes(HRegionInfo.encodeRegionName(entry.getKey()));<a name="line.261"></a>
+<span class="sourceLineNo">262</span>      Long existingValue = flushedSequenceIdByRegion.get(encodedRegionName);<a name="line.262"></a>
+<span class="sourceLineNo">263</span>      long l = entry.getValue().getCompleteSequenceId();<a name="line.263"></a>
+<span class="sourceLineNo">264</span>      // Don't let smaller sequence ids override greater sequence ids.<a name="line.264"></a>
+<span class="sourceLineNo">265</span>      if (LOG.isTraceEnabled()) {<a name="line.265"></a>
+<span class="sourceLineNo">266</span>        LOG.trace(Bytes.toString(encodedRegionName) + ", existingValue=" + existingValue +<a name="line.266"></a>
+<span class="sourceLineNo">267</span>          ", completeSequenceId=" + l);<a name="line.267"></a>
+<span class="sourceLineNo">268</span>      }<a name="line.268"></a>
+<span class="sourceLineNo">269</span>      if (existingValue == null || (l != HConstants.NO_SEQNUM &amp;&amp; l &gt; existingValue)) {<a name="line.269"></a>
+<span class="sourceLineNo">270</span>        flushedSequenceIdByRegion.put(encodedRegionName, l);<a name="line.270"></a>
+<span class="sourceLineNo">271</span>      } else if (l != HConstants.NO_SEQNUM &amp;&amp; l &lt; existingValue) {<a name="line.271"></a>
+<span class="sourceLineNo">272</span>        LOG.warn("RegionServer " + sn + " indicates a last flushed sequence id ("<a name="line.272"></a>
+<span class="sourceLineNo">273</span>            + l + ") that is less than the previous last flushed sequence id ("<a name="line.273"></a>
+<span class="sourceLineNo">274</span>            + existingValue + ") for region " + Bytes.toString(entry.getKey()) + " Ignoring.");<a name="line.274"></a>
+<span class="sourceLineNo">275</span>      }<a name="line.275"></a>
+<span class="sourceLineNo">276</span>      ConcurrentNavigableMap&lt;byte[], Long&gt; storeFlushedSequenceId =<a name="line.276"></a>
+<span class="sourceLineNo">277</span>          computeIfAbsent(storeFlushedSequenceIdsByRegion, encodedRegionName,<a name="line.277"></a>
+<span class="sourceLineNo">278</span>            () -&gt; new ConcurrentSkipListMap&lt;&gt;(Bytes.BYTES_COMPARATOR));<a name="line.278"></a>
+<span class="sourceLineNo">279</span>      for (StoreSequenceId storeSeqId : entry.getValue().getStoreCompleteSequenceId()) {<a name="line.279"></a>
+<span class="sourceLineNo">280</span>        byte[] family = storeSeqId.getFamilyName().toByteArray();<a name="line.280"></a>
+<span class="sourceLineNo">281</span>        existingValue = storeFlushedSequenceId.get(family);<a name="line.281"></a>
+<span class="sourceLineNo">282</span>        l = storeSeqId.getSequenceId();<a name="line.282"></a>
+<span class="sourceLineNo">283</span>        if (LOG.isTraceEnabled()) {<a name="line.283"></a>
+<span class="sourceLineNo">284</span>          LOG.trace(Bytes.toString(encodedRegionName) + ", family=" + Bytes.toString(family) +<a name="line.284"></a>
+<span class="sourceLineNo">285</span>            ", existingValue=" + existingValue + ", completeSequenceId=" + l);<a name="line.285"></a>
+<span class="sourceLineNo">286</span>        }<a name="line.286"></a>
+<span class="sourceLineNo">287</span>        // Don't let smaller sequence ids override greater sequence ids.<a name="line.287"></a>
+<span class="sourceLineNo">288</span>        if (existingValue == null || (l != HConstants.NO_SEQNUM &amp;&amp; l &gt; existingValue.longValue())) {<a name="line.288"></a>
+<span class="sourceLineNo">289</span>          storeFlushedSequenceId.put(family, l);<a name="line.289"></a>
+<span class="sourceLineNo">290</span>        }<a name="line.290"></a>
+<span class="sourceLineNo">291</span>      }<a name="line.291"></a>
+<span class="sourceLineNo">292</span>    }<a name="line.292"></a>
+<span class="sourceLineNo">293</span>  }<a name="line.293"></a>
+<span class="sourceLineNo">294</span><a name="line.294"></a>
+<span class="sourceLineNo">295</span>  @VisibleForTesting<a name="line.295"></a>
+<span class="sourceLineNo">296</span>  public void regionServerReport(ServerName sn,<a name="line.296"></a>
+<span class="sourceLineNo">297</span>      ServerLoad sl) throws YouAreDeadException {<a name="line.297"></a>
+<span class="sourceLineNo">298</span>    checkIsDead(sn, "REPORT");<a name="line.298"></a>
+<span class="sourceLineNo">299</span>    if (null == this.onlineServers.replace(sn, sl)) {<a name="line.299"></a>
+<span class="sourceLineNo">300</span>      // Already have this host+port combo and its just different start code?<a name="line.300"></a>
+<span class="sourceLineNo">301</span>      // Just let the server in. Presume master joining a running cluster.<a name="line.301"></a>
+<span class="sourceLineNo">302</span>      // recordNewServer is what happens at the end of reportServerStartup.<a name="line.302"></a>
+<span class="sourceLineNo">303</span>      // The only thing we are skipping is passing back to the regionserver<a name="line.303"></a>
+<span class="sourceLineNo">304</span>      // the ServerName to use. Here we presume a master has already done<a name="line.304"></a>
+<span class="sourceLineNo">305</span>      // that so we'll press on with whatever it gave us for ServerName.<a name="line.305"></a>
+<span class="sourceLineNo">306</span>      if (!checkAndRecordNewServer(sn, sl)) {<a name="line.306"></a>
+<span class="sourceLineNo">307</span>        LOG.info("RegionServerReport ignored, could not record the server: " + sn);<a name="line.307"></a>
+<span class="sourceLineNo">308</span>        return; // Not recorded, so no need to move on<a name="line.308"></a>
+<span class="sourceLineNo">309</span>      }<a name="line.309"></a>
+<span class="sourceLineNo">310</span>    }<a name="line.310"></a>
+<span class="sourceLineNo">311</span>    updateLastFlushedSequenceIds(sn, sl);<a name="line.311"></a>
+<span class="sourceLineNo">312</span>  }<a name="line.312"></a>
+<span class="sourceLineNo">313</span><a name="line.313"></a>
+<span class="sourceLineNo">314</span>  /**<a name="line.314"></a>
+<span class="sourceLineNo">315</span>   * Check is a server of same host and port already exists,<a name="line.315"></a>
+<span class="sourceLineNo">316</span>   * if not, or the existed one got a smaller start code, record it.<a name="line.316"></a>
+<span class="sourceLineNo">317</span>   *<a name="line.317"></a>
+<span class="sourceLineNo">318</span>   * @param serverName the server to check and record<a name="line.318"></a>
+<span class="sourceLineNo">319</span>   * @param sl the server load on the server<a name="line.319"></a>
+<span class="sourceLineNo">320</span>   * @return true if the server is recorded, otherwise, false<a name="line.320"></a>
+<span class="sourceLineNo">321</span>   */<a name="line.321"></a>
+<span class="sourceLineNo">322</span>  boolean checkAndRecordNewServer(<a name="line.322"></a>
+<span class="sourceLineNo">323</span>      final ServerName serverName, final ServerLoad sl) {<a name="line.323"></a>
+<span class="sourceLineNo">324</span>    ServerName existingServer = null;<a name="line.324"></a>
+<span class="sourceLineNo">325</span>    synchronized (this.onlineServers) {<a name="line.325"></a>
+<span class="sourceLineNo">326</span>      existingServer = findServerWithSameHostnamePortWithLock(serverName);<a name="line.326"></a>
+<span class="sourceLineNo">327</span>      if (existingServer != null &amp;&amp; (existingServer.getStartcode() &gt; serverName.getStartcode())) {<a name="line.327"></a>
+<span class="sourceLineNo">328</span>        LOG.info("Server serverName=" + serverName + " rejected; we already have "<a name="line.328"></a>
+<span class="sourceLineNo">329</span>            + existingServer.toString() + " registered with same hostname and port");<a name="line.329"></a>
+<span class="sourceLineNo">330</span>        return false;<a name="line.330"></a>
+<span class="sourceLineNo">331</span>      }<a name="line.331"></a>
+<span class="sourceLineNo">332</span>      recordNewServerWithLock(serverName, sl);<a name="line.332"></a>
+<span class="sourceLineNo">333</span>    }<a name="line.333"></a>
+<span class="sourceLineNo">334</span><a name="line.334"></a>
+<span class="sourceLineNo">335</span>    // Tell our listeners that a server was added<a name="line.335"></a>
+<span class="sourceLineNo">336</span>    if (!this.listeners.isEmpty()) {<a name="line.336"></a>
+<span class="sourceLineNo">337</span>      for (ServerListener listener : this.listeners) {<a name="line.337"></a>
+<span class="sourceLineNo">338</span>        listener.serverAdded(serverName);<a name="line.338"></a>
+<span class="sourceLineNo">339</span>      }<a name="line.339"></a>
+<span class="sourceLineNo">340</span>    }<a name="line.340"></a>
+<span class="sourceLineNo">341</span><a name="line.341"></a>
+<span class="sourceLineNo">342</span>    // Note that we assume that same ts means same server, and don't expire in that case.<a name="line.342"></a>
+<span class="sourceLineNo">343</span>    //  TODO: ts can theoretically collide due to clock shifts, so this is a bit hacky.<a name="line.343"></a>
+<span class="sourceLineNo">344</span>    if (existingServer != null &amp;&amp; (existingServer.getStartcode() &lt; serverName.getStartcode())) {<a name="line.344"></a>
+<span class="sourceLineNo">345</span>      LOG.info("Triggering server recovery; existingServer " +<a name="line.345"></a>
+<span class="sourceLineNo">346</span>          existingServer + " looks stale, new server:" + serverName);<a name="line.346"></a>
+<span class="sourceLineNo">347</span>      expireServer(existingServer);<a name="line.347"></a>
+<span class="sourceLineNo">348</span>    }<a name="line.348"></a>
+<span class="sourceLineNo">349</span>    return true;<a name="line.349"></a>
+<span class="sourceLineNo">350</span>  }<a name="line.350"></a>
+<span class="sourceLineNo">351</span><a name="line.351"></a>
+<span class="sourceLineNo">352</span>  /**<a name="line.352"></a>
+<span class="sourceLineNo">353</span>   * Checks if the clock skew between the server and the master. If the clock skew exceeds the<a name="line.353"></a>
+<span class="sourceLineNo">354</span>   * configured max, it will throw an exception; if it exceeds the configured warning threshold,<a name="line.354"></a>
+<span class="sourceLineNo">355</span>   * it will log a warning but start normally.<a name="line.355"></a>
+<span class="sourceLineNo">356</span>   * @param serverName Incoming servers's name<a name="line.356"></a>
+<span class="sourceLineNo">357</span>   * @param serverCurrentTime<a name="line.357"></a>
+<span class="sourceLineNo">358</span>   * @throws ClockOutOfSyncException if the skew exceeds the configured max value<a name="line.358"></a>
+<span class="sourceLineNo">359</span>   */<a name="line.359"></a>
+<span class="sourceLineNo">360</span>  private void checkClockSkew(final ServerName serverName, final long serverCurrentTime)<a name="line.360"></a>
+<span class="sourceLineNo">361</span>  throws ClockOutOfSyncException {<a name="line.361"></a>
+<span class="sourceLineNo">362</span>    long skew = Math.abs(System.currentTimeMillis() - serverCurrentTime);<a name="line.362"></a>
+<span class="sourceLineNo">363</span>    if (skew &gt; maxSkew) {<a name="line.363"></a>
+<span class="sourceLineNo">364</span>      String message = "Server " + serverName + " has been " +<a name="line.364"></a>
+<span class="sourceLineNo">365</span>        "rejected; Reported time is too far out of sync with master.  " +<a name="line.365"></a>
+<span class="sourceLineNo">366</span>        "Time difference of " + skew + "ms &gt; max allowed of " + maxSkew + "ms";<a name="line.366"></a>
+<span class="sourceLineNo">367</span>      LOG.warn(message);<a name="line.367"></a>
+<span class="sourceLineNo">368</span>      throw new ClockOutOfSyncException(message);<a name="line.368"></a>
+<span class="sourceLineNo">369</span>    } else if (skew &gt; warningSkew){<a name="line.369"></a>
+<span class="sourceLineNo">370</span>      String message = "Reported time for server " + serverName + " is out of sync with master " +<a name="line.370"></a>
+<span class="sourceLineNo">371</span>        "by " + skew + "ms. (Warning threshold is " + warningSkew + "ms; " +<a name="line.371"></a>
+<span class="sourceLineNo">372</span>        "error threshold is " + maxSkew + "ms)";<a name="line.372"></a>
+<span class="sourceLineNo">373</span>      LOG.warn(message);<a name="line.373"></a>
+<span class="sourceLineNo">374</span>    }<a name="line.374"></a>
+<span class="sourceLineNo">375</span>  }<a name="line.375"></a>
+<span class="sourceLineNo">376</span><a name="line.376"></a>
+<span class="sourceLineNo">377</span>  /**<a name="line.377"></a>
+<span class="sourceLineNo">378</span>   * If this server is on the dead list, reject it with a YouAreDeadException.<a name="line.378"></a>
+<span class="sourceLineNo">379</span>   * If it was dead but came back with a new start code, remove the old entry<a name="line.379"></a>
+<span class="sourceLineNo">380</span>   * from the dead list.<a name="line.380"></a>
+<span class="sourceLineNo">381</span>   * @param serverName<a name="line.381"></a>
+<span class="sourceLineNo">382</span>   * @param what START or REPORT<a name="line.382"></a>
+<span class="sourceLineNo">383</span>   * @throws org.apache.hadoop.hbase.YouAreDeadException<a name="line.383"></a>
+<span class="sourceLineNo">384</span>   */<a name="line.384"></a>
+<span class="sourceLineNo">385</span>  private void checkIsDead(final ServerName serverName, final String what)<a name="line.385"></a>
+<span class="sourceLineNo">386</span>      throws YouAreDeadException {<a name="line.386"></a>
+<span class="sourceLineNo">387</span>    if (this.deadservers.isDeadServer(serverName)) {<a name="line.387"></a>
+<span class="sourceLineNo">388</span>      // host name, port and start code all match with existing one of the<a name="line.388"></a>
+<span class="sourceLineNo">389</span>      // dead servers. So, this server must be dead.<a name="line.389"></a>
+<span class="sourceLineNo">390</span>      String message = "Server " + what + " rejected; currently processing " +<a name="line.390"></a>
+<span class="sourceLineNo">391</span>          serverName + " as dead server";<a name="line.391"></a>
+<span class="sourceLineNo">392</span>      LOG.debug(message);<a name="line.392"></a>
+<span class="sourceLineNo">393</span>      throw new YouAreDeadException(message);<a name="line.393"></a>
+<span class="sourceLineNo">394</span>    }<a name="line.394"></a>
+<span class="sourceLineNo">395</span>    // remove dead server with same hostname and port of newly checking in rs after master<a name="line.395"></a>
+<span class="sourceLineNo">396</span>    // initialization.See HBASE-5916 for more information.<a name="line.396"></a>
+<span class="sourceLineNo">397</span>    if ((this.master == null || this.master.isInitialized())<a name="line.397"></a>
+<span class="sourceLineNo">398</span>        &amp;&amp; this.deadservers.cleanPreviousInstance(serverName)) {<a name="line.398"></a>
+<span class="sourceLineNo">399</span>      // This server has now become alive after we marked it as dead.<a name="line.399"></a>
+<span class="sourceLineNo">400</span>      // We removed it's previous entry from the dead list to reflect it.<a name="line.400"></a>
+<span class="sourceLineNo">401</span>      LOG.debug(what + ":" + " Server " + serverName + " came back up," +<a name="line.401"></a>
+<span class="sourceLineNo">402</span>          " removed it from the dead servers list");<a name="line.402"></a>
+<span class="sourceLineNo">403</span>    }<a name="line.403"></a>
+<span class="sourceLineNo">404</span>  }<a name="line.404"></a>
+<span class="sourceLineNo">405</span><a name="line.405"></a>
+<span class="sourceLineNo">406</span>  /**<a name="line.406"></a>
+<span class="sourceLineNo">407</span>   * Assumes onlineServers is locked.<a name="line.407"></a>
+<span class="sourceLineNo">408</span>   * @return ServerName with matching hostname and port.<a name="line.408"></a>
+<span class="sourceLineNo">409</span>   */<a name="line.409"></a>
+<span class="sourceLineNo">410</span>  private ServerName findServerWithSameHostnamePortWithLock(<a name="line.410"></a>
+<span class="sourceLineNo">411</span>      final ServerName serverName) {<a name="line.411"></a>
+<span class="sourceLineNo">412</span>    ServerName end = ServerName.valueOf(serverName.getHostname(), serverName.getPort(),<a name="line.412"></a>
+<span class="sourceLineNo">413</span>        Long.MAX_VALUE);<a name="line.413"></a>
+<span class="sourceLineNo">414</span><a name="line.414"></a>
+<span class="sourceLineNo">415</span>    ServerName r = onlineServers.lowerKey(end);<a name="line.415"></a>
+<span class="sourceLineNo">416</span>    if (r != null) {<a name="line.416"></a>
+<span class="sourceLineNo">417</span>      if (ServerName.isSameHostnameAndPort(r, serverName)) {<a name="line.417"></a>
+<span class="sourceLineNo">418</span>        return r;<a name="line.418"></a>
+<span class="sourceLineNo">419</span>      }<a name="line.419"></a>
+<span class="sourceLineNo">420</span>    }<a name="line.420"></a>
+<span class="sourceLineNo">421</span>    return null;<a name="line.421"></a>
+<span class="sourceLineNo">422</span>  }<a name="line.422"></a>
+<span class="sourceLineNo">423</span><a name="line.423"></a>
+<span class="sourceLineNo">424</span>  /**<a name="line.424"></a>
+<span class="sourceLineNo">425</span>   * Adds the onlineServers list. onlineServers should be locked.<a name="line.425"></a>
+<span class="sourceLineNo">426</span>   * @param serverName The remote servers name.<a name="line.426"></a>
 <span class="sourceLineNo">427</span>   */<a name="line.427"></a>
 <span class="sourceLineNo">428</span>  @VisibleForTesting<a name="line.428"></a>
 <span class="sourceLineNo">429</span>  void recordNewServerWithLock(final ServerName serverName, final ServerLoad sl) {<a name="line.429"></a>
@@ -591,7 +591,7 @@
 <span class="sourceLineNo">583</span><a name="line.583"></a>
 <span class="sourceLineNo">584</span>    // If cluster is going down, yes, servers are going to be expiring; don't<a name="line.584"></a>
 <span class="sourceLineNo">585</span>    // process as a dead server<a name="line.585"></a>
-<span class="sourceLineNo">586</span>    if (this.clusterShutdown) {<a name="line.586"></a>
+<span class="sourceLineNo">586</span>    if (this.clusterShutdown.get()) {<a name="line.586"></a>
 <span class="sourceLineNo">587</span>      LOG.info("Cluster shutdown set; " + serverName +<a name="line.587"></a>
 <span class="sourceLineNo">588</span>        " expired; onlineServers=" + this.onlineServers.size());<a name="line.588"></a>
 <span class="sourceLineNo">589</span>      if (this.onlineServers.isEmpty()) {<a name="line.589"></a>
@@ -599,7 +599,7 @@
 <span class="sourceLineNo">591</span>      }<a name="line.591"></a>
 <span class="sourceLineNo">592</span>      return;<a name="line.592"></a>
 <span class="sourceLineNo">593</span>    }<a name="line.593"></a>
-<span class="sourceLineNo">594</span><a name="line.594"></a>
+<span class="sourceLineNo">594</span>    LOG.info("Processing expiration of " + serverName + " on " + this.master.getServerName());<a name="line.594"></a>
 <span class="sourceLineNo">595</span>    master.getAssignmentManager().submitServerCrash(serverName, true);<a name="line.595"></a>
 <span class="sourceLineNo">596</span><a name="line.596"></a>
 <span class="sourceLineNo">597</span>    // Tell our listeners that a server was removed<a name="line.597"></a>
@@ -798,12 +798,12 @@
 <span class="sourceLineNo">790</span>  private int getMinToStart() {<a name="line.790"></a>
 <span class="sourceLineNo">791</span>    // One server should be enough to get us off the ground.<a name="line.791"></a>
 <span class="sourceLineNo">792</span>    int requiredMinToStart = 1;<a name="line.792"></a>
-<span class="sourceLineNo">793</span>    if (BaseLoadBalancer.tablesOnMaster(master.getConfiguration())) {<a name="line.793"></a>
-<span class="sourceLineNo">794</span>      if (!BaseLoadBalancer.userTablesOnMaster(master.getConfiguration())) {<a name="line.794"></a>
-<span class="sourceLineNo">795</span>        // If Master is carrying regions but NOT user-space regions (the current default),<a name="line.795"></a>
-<span class="sourceLineNo">796</span>        // since the Master shows as a 'server', we need at least one more server to check<a name="line.796"></a>
-<span class="sourceLineNo">797</span>        // in before we can start up so up defaultMinToStart to 2.<a name="line.797"></a>
-<span class="sourceLineNo">798</span>        requiredMinToStart = 2;<a name="line.798"></a>
+<span class="sourceLineNo">793</span>    if (LoadBalancer.isTablesOnMaster(master.getConfiguration())) {<a name="line.793"></a>
+<span class="sourceLineNo">794</span>      if (LoadBalancer.isSystemTablesOnlyOnMaster(master.getConfiguration())) {<a name="line.794"></a>
+<span class="sourceLineNo">795</span>        // If Master is carrying regions but NOT user-space regions, it<a name="line.795"></a>
+<span class="sourceLineNo">796</span>        // still shows as a 'server'. We need at least one more server to check<a name="line.796"></a>
+<span class="sourceLineNo">797</span>        // in before we can start up so set defaultMinToStart to 2.<a name="line.797"></a>
+<span class="sourceLineNo">798</span>        requiredMinToStart = requiredMinToStart + 1;<a name="line.798"></a>
 <span class="sourceLineNo">799</span>      }<a name="line.799"></a>
 <span class="sourceLineNo">800</span>    }<a name="line.800"></a>
 <span class="sourceLineNo">801</span>    int minToStart = this.master.getConfiguration().getInt(WAIT_ON_REGIONSERVERS_MINTOSTART, -1);<a name="line.801"></a>
@@ -952,106 +952,108 @@
 <span class="sourceLineNo">944</span>  }<a name="line.944"></a>
 <span class="sourceLineNo">945</span><a name="line.945"></a>
 <span class="sourceLineNo">946</span>  public void shutdownCluster() {<a name="line.946"></a>
-<span class="sourceLineNo">947</span>    this.clusterShutdown = true;<a name="line.947"></a>
-<span class="sourceLineNo">948</span>    this.master.stop("Cluster shutdown requested");<a name="line.948"></a>
-<span class="sourceLineNo">949</span>  }<a name="line.949"></a>
-<span class="sourceLineNo">950</span><a name="line.950"></a>
-<span class="sourceLineNo">951</span>  public boolean isClusterShutdown() {<a name="line.951"></a>
-<span class="sourceLineNo">952</span>    return this.clusterShutdown;<a name="line.952"></a>
-<span class="sourceLineNo">953</span>  }<a name="line.953"></a>
-<span class="sourceLineNo">954</span><a name="line.954"></a>
-<span class="sourceLineNo">955</span>  /**<a name="line.955"></a>
-<span class="sourceLineNo">956</span>   * Stop the ServerManager.  Currently closes the connection to the master.<a name="line.956"></a>
-<span class="sourceLineNo">957</span>   */<a name="line.957"></a>
-<span class="sourceLineNo">958</span>  public void stop() {<a name="line.958"></a>
-<span class="sourceLineNo">959</span>    if (connection != null) {<a name="line.959"></a>
-<span class="sourceLineNo">960</span>      try {<a name="line.960"></a>
-<span class="sourceLineNo">961</span>        connection.close();<a name="line.961"></a>
-<span class="sourceLineNo">962</span>      } catch (IOException e) {<a name="line.962"></a>
-<span class="sourceLineNo">963</span>        LOG.error("Attempt to close connection to master failed", e);<a name="line.963"></a>
-<span class="sourceLineNo">964</span>      }<a name="line.964"></a>
-<span class="sourceLineN

<TRUNCATED>

Mime
View raw message