http://git-wip-us.apache.org/repos/asf/hbase-site/blob/b9b09fec/devapidocs/src-html/org/apache/hadoop/hbase/master/assignment/AssignmentManager.RegionInTransitionStat.html ---------------------------------------------------------------------- diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/master/assignment/AssignmentManager.RegionInTransitionStat.html b/devapidocs/src-html/org/apache/hadoop/hbase/master/assignment/AssignmentManager.RegionInTransitionStat.html index 8ef8fea..57d590b 100644 --- a/devapidocs/src-html/org/apache/hadoop/hbase/master/assignment/AssignmentManager.RegionInTransitionStat.html +++ b/devapidocs/src-html/org/apache/hadoop/hbase/master/assignment/AssignmentManager.RegionInTransitionStat.html @@ -47,130 +47,130 @@ <span class="sourceLineNo">039</span>import org.apache.hadoop.hbase.ServerName;<a name="line.39"></a> <span class="sourceLineNo">040</span>import org.apache.hadoop.hbase.TableName;<a name="line.40"></a> <span class="sourceLineNo">041</span>import org.apache.hadoop.hbase.UnknownRegionException;<a name="line.41"></a> -<span class="sourceLineNo">042</span>import org.apache.hadoop.hbase.YouAreDeadException;<a name="line.42"></a> -<span class="sourceLineNo">043</span>import org.apache.hadoop.hbase.client.DoNotRetryRegionException;<a name="line.43"></a> -<span class="sourceLineNo">044</span>import org.apache.hadoop.hbase.client.RegionInfo;<a name="line.44"></a> -<span class="sourceLineNo">045</span>import org.apache.hadoop.hbase.client.RegionInfoBuilder;<a name="line.45"></a> -<span class="sourceLineNo">046</span>import org.apache.hadoop.hbase.client.Result;<a name="line.46"></a> -<span class="sourceLineNo">047</span>import org.apache.hadoop.hbase.client.TableState;<a name="line.47"></a> -<span class="sourceLineNo">048</span>import org.apache.hadoop.hbase.exceptions.UnexpectedStateException;<a name="line.48"></a> -<span class="sourceLineNo">049</span>import org.apache.hadoop.hbase.favored.FavoredNodesManager;<a name="line.49"></a> -<span class="sourceLineNo">050</span>import org.apache.hadoop.hbase.favored.FavoredNodesPromoter;<a name="line.50"></a> -<span class="sourceLineNo">051</span>import org.apache.hadoop.hbase.master.LoadBalancer;<a name="line.51"></a> -<span class="sourceLineNo">052</span>import org.apache.hadoop.hbase.master.MasterServices;<a name="line.52"></a> -<span class="sourceLineNo">053</span>import org.apache.hadoop.hbase.master.MetricsAssignmentManager;<a name="line.53"></a> -<span class="sourceLineNo">054</span>import org.apache.hadoop.hbase.master.RegionPlan;<a name="line.54"></a> -<span class="sourceLineNo">055</span>import org.apache.hadoop.hbase.master.RegionState;<a name="line.55"></a> -<span class="sourceLineNo">056</span>import org.apache.hadoop.hbase.master.RegionState.State;<a name="line.56"></a> -<span class="sourceLineNo">057</span>import org.apache.hadoop.hbase.master.ServerListener;<a name="line.57"></a> -<span class="sourceLineNo">058</span>import org.apache.hadoop.hbase.master.TableStateManager;<a name="line.58"></a> -<span class="sourceLineNo">059</span>import org.apache.hadoop.hbase.master.balancer.FavoredStochasticBalancer;<a name="line.59"></a> -<span class="sourceLineNo">060</span>import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;<a name="line.60"></a> -<span class="sourceLineNo">061</span>import org.apache.hadoop.hbase.master.procedure.MasterProcedureScheduler;<a name="line.61"></a> -<span class="sourceLineNo">062</span>import org.apache.hadoop.hbase.master.procedure.ProcedureSyncWait;<a name="line.62"></a> -<span class="sourceLineNo">063</span>import org.apache.hadoop.hbase.master.procedure.ServerCrashProcedure;<a name="line.63"></a> -<span class="sourceLineNo">064</span>import org.apache.hadoop.hbase.procedure2.Procedure;<a name="line.64"></a> -<span class="sourceLineNo">065</span>import org.apache.hadoop.hbase.procedure2.ProcedureEvent;<a name="line.65"></a> -<span class="sourceLineNo">066</span>import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;<a name="line.66"></a> -<span class="sourceLineNo">067</span>import org.apache.hadoop.hbase.procedure2.ProcedureInMemoryChore;<a name="line.67"></a> -<span class="sourceLineNo">068</span>import org.apache.hadoop.hbase.procedure2.util.StringUtils;<a name="line.68"></a> -<span class="sourceLineNo">069</span>import org.apache.hadoop.hbase.regionserver.SequenceId;<a name="line.69"></a> -<span class="sourceLineNo">070</span>import org.apache.hadoop.hbase.util.Bytes;<a name="line.70"></a> -<span class="sourceLineNo">071</span>import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;<a name="line.71"></a> -<span class="sourceLineNo">072</span>import org.apache.hadoop.hbase.util.HasThread;<a name="line.72"></a> -<span class="sourceLineNo">073</span>import org.apache.hadoop.hbase.util.Pair;<a name="line.73"></a> -<span class="sourceLineNo">074</span>import org.apache.hadoop.hbase.util.Threads;<a name="line.74"></a> -<span class="sourceLineNo">075</span>import org.apache.hadoop.hbase.util.VersionInfo;<a name="line.75"></a> -<span class="sourceLineNo">076</span>import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;<a name="line.76"></a> -<span class="sourceLineNo">077</span>import org.apache.hadoop.hbase.zookeeper.ZKWatcher;<a name="line.77"></a> -<span class="sourceLineNo">078</span>import org.apache.yetus.audience.InterfaceAudience;<a name="line.78"></a> -<span class="sourceLineNo">079</span>import org.apache.zookeeper.KeeperException;<a name="line.79"></a> -<span class="sourceLineNo">080</span>import org.slf4j.Logger;<a name="line.80"></a> -<span class="sourceLineNo">081</span>import org.slf4j.LoggerFactory;<a name="line.81"></a> -<span class="sourceLineNo">082</span><a name="line.82"></a> -<span class="sourceLineNo">083</span>import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting;<a name="line.83"></a> -<span class="sourceLineNo">084</span><a name="line.84"></a> -<span class="sourceLineNo">085</span>import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;<a name="line.85"></a> -<span class="sourceLineNo">086</span>import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionStateTransition;<a name="line.86"></a> -<span class="sourceLineNo">087</span>import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionStateTransition.TransitionCode;<a name="line.87"></a> -<span class="sourceLineNo">088</span>import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.ReportRegionStateTransitionRequest;<a name="line.88"></a> -<span class="sourceLineNo">089</span>import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.ReportRegionStateTransitionResponse;<a name="line.89"></a> -<span class="sourceLineNo">090</span><a name="line.90"></a> -<span class="sourceLineNo">091</span>/**<a name="line.91"></a> -<span class="sourceLineNo">092</span> * The AssignmentManager is the coordinator for region assign/unassign operations.<a name="line.92"></a> -<span class="sourceLineNo">093</span> * <ul><a name="line.93"></a> -<span class="sourceLineNo">094</span> * <li>In-memory states of regions and servers are stored in {@link RegionStates}.</li><a name="line.94"></a> -<span class="sourceLineNo">095</span> * <li>hbase:meta state updates are handled by {@link RegionStateStore}.</li><a name="line.95"></a> -<span class="sourceLineNo">096</span> * </ul><a name="line.96"></a> -<span class="sourceLineNo">097</span> * Regions are created by CreateTable, Split, Merge.<a name="line.97"></a> -<span class="sourceLineNo">098</span> * Regions are deleted by DeleteTable, Split, Merge.<a name="line.98"></a> -<span class="sourceLineNo">099</span> * Assigns are triggered by CreateTable, EnableTable, Split, Merge, ServerCrash.<a name="line.99"></a> -<span class="sourceLineNo">100</span> * Unassigns are triggered by DisableTable, Split, Merge<a name="line.100"></a> -<span class="sourceLineNo">101</span> */<a name="line.101"></a> -<span class="sourceLineNo">102</span>@InterfaceAudience.Private<a name="line.102"></a> -<span class="sourceLineNo">103</span>public class AssignmentManager implements ServerListener {<a name="line.103"></a> -<span class="sourceLineNo">104</span> private static final Logger LOG = LoggerFactory.getLogger(AssignmentManager.class);<a name="line.104"></a> -<span class="sourceLineNo">105</span><a name="line.105"></a> -<span class="sourceLineNo">106</span> // TODO: AMv2<a name="line.106"></a> -<span class="sourceLineNo">107</span> // - handle region migration from hbase1 to hbase2.<a name="line.107"></a> -<span class="sourceLineNo">108</span> // - handle sys table assignment first (e.g. acl, namespace)<a name="line.108"></a> -<span class="sourceLineNo">109</span> // - handle table priorities<a name="line.109"></a> -<span class="sourceLineNo">110</span> // - If ServerBusyException trying to update hbase:meta, we abort the Master<a name="line.110"></a> -<span class="sourceLineNo">111</span> // See updateRegionLocation in RegionStateStore.<a name="line.111"></a> -<span class="sourceLineNo">112</span> //<a name="line.112"></a> -<span class="sourceLineNo">113</span> // See also<a name="line.113"></a> -<span class="sourceLineNo">114</span> // https://docs.google.com/document/d/1eVKa7FHdeoJ1-9o8yZcOTAQbv0u0bblBlCCzVSIn69g/edit#heading=h.ystjyrkbtoq5<a name="line.114"></a> -<span class="sourceLineNo">115</span> // for other TODOs.<a name="line.115"></a> -<span class="sourceLineNo">116</span><a name="line.116"></a> -<span class="sourceLineNo">117</span> public static final String BOOTSTRAP_THREAD_POOL_SIZE_CONF_KEY =<a name="line.117"></a> -<span class="sourceLineNo">118</span> "hbase.assignment.bootstrap.thread.pool.size";<a name="line.118"></a> -<span class="sourceLineNo">119</span><a name="line.119"></a> -<span class="sourceLineNo">120</span> public static final String ASSIGN_DISPATCH_WAIT_MSEC_CONF_KEY =<a name="line.120"></a> -<span class="sourceLineNo">121</span> "hbase.assignment.dispatch.wait.msec";<a name="line.121"></a> -<span class="sourceLineNo">122</span> private static final int DEFAULT_ASSIGN_DISPATCH_WAIT_MSEC = 150;<a name="line.122"></a> -<span class="sourceLineNo">123</span><a name="line.123"></a> -<span class="sourceLineNo">124</span> public static final String ASSIGN_DISPATCH_WAITQ_MAX_CONF_KEY =<a name="line.124"></a> -<span class="sourceLineNo">125</span> "hbase.assignment.dispatch.wait.queue.max.size";<a name="line.125"></a> -<span class="sourceLineNo">126</span> private static final int DEFAULT_ASSIGN_DISPATCH_WAITQ_MAX = 100;<a name="line.126"></a> -<span class="sourceLineNo">127</span><a name="line.127"></a> -<span class="sourceLineNo">128</span> public static final String RIT_CHORE_INTERVAL_MSEC_CONF_KEY =<a name="line.128"></a> -<span class="sourceLineNo">129</span> "hbase.assignment.rit.chore.interval.msec";<a name="line.129"></a> -<span class="sourceLineNo">130</span> private static final int DEFAULT_RIT_CHORE_INTERVAL_MSEC = 60 * 1000;<a name="line.130"></a> -<span class="sourceLineNo">131</span><a name="line.131"></a> -<span class="sourceLineNo">132</span> public static final String ASSIGN_MAX_ATTEMPTS =<a name="line.132"></a> -<span class="sourceLineNo">133</span> "hbase.assignment.maximum.attempts";<a name="line.133"></a> -<span class="sourceLineNo">134</span> private static final int DEFAULT_ASSIGN_MAX_ATTEMPTS = Integer.MAX_VALUE;<a name="line.134"></a> -<span class="sourceLineNo">135</span><a name="line.135"></a> -<span class="sourceLineNo">136</span> /** Region in Transition metrics threshold time */<a name="line.136"></a> -<span class="sourceLineNo">137</span> public static final String METRICS_RIT_STUCK_WARNING_THRESHOLD =<a name="line.137"></a> -<span class="sourceLineNo">138</span> "hbase.metrics.rit.stuck.warning.threshold";<a name="line.138"></a> -<span class="sourceLineNo">139</span> private static final int DEFAULT_RIT_STUCK_WARNING_THRESHOLD = 60 * 1000;<a name="line.139"></a> -<span class="sourceLineNo">140</span><a name="line.140"></a> -<span class="sourceLineNo">141</span> private final ProcedureEvent<?> metaAssignEvent = new ProcedureEvent<>("meta assign");<a name="line.141"></a> -<span class="sourceLineNo">142</span> private final ProcedureEvent<?> metaLoadEvent = new ProcedureEvent<>("meta load");<a name="line.142"></a> -<span class="sourceLineNo">143</span><a name="line.143"></a> -<span class="sourceLineNo">144</span> private final MetricsAssignmentManager metrics;<a name="line.144"></a> -<span class="sourceLineNo">145</span> private final RegionInTransitionChore ritChore;<a name="line.145"></a> -<span class="sourceLineNo">146</span> private final MasterServices master;<a name="line.146"></a> -<span class="sourceLineNo">147</span><a name="line.147"></a> -<span class="sourceLineNo">148</span> private final AtomicBoolean running = new AtomicBoolean(false);<a name="line.148"></a> -<span class="sourceLineNo">149</span> private final RegionStates regionStates = new RegionStates();<a name="line.149"></a> -<span class="sourceLineNo">150</span> private final RegionStateStore regionStateStore;<a name="line.150"></a> -<span class="sourceLineNo">151</span><a name="line.151"></a> -<span class="sourceLineNo">152</span> private final boolean shouldAssignRegionsWithFavoredNodes;<a name="line.152"></a> -<span class="sourceLineNo">153</span> private final int assignDispatchWaitQueueMaxSize;<a name="line.153"></a> -<span class="sourceLineNo">154</span> private final int assignDispatchWaitMillis;<a name="line.154"></a> -<span class="sourceLineNo">155</span> private final int assignMaxAttempts;<a name="line.155"></a> -<span class="sourceLineNo">156</span><a name="line.156"></a> -<span class="sourceLineNo">157</span> private final Object checkIfShouldMoveSystemRegionLock = new Object();<a name="line.157"></a> -<span class="sourceLineNo">158</span><a name="line.158"></a> -<span class="sourceLineNo">159</span> private Thread assignThread;<a name="line.159"></a> -<span class="sourceLineNo">160</span><a name="line.160"></a> -<span class="sourceLineNo">161</span> public AssignmentManager(final MasterServices master) {<a name="line.161"></a> -<span class="sourceLineNo">162</span> this(master, new RegionStateStore(master));<a name="line.162"></a> -<span class="sourceLineNo">163</span> }<a name="line.163"></a> -<span class="sourceLineNo">164</span><a name="line.164"></a> -<span class="sourceLineNo">165</span> public AssignmentManager(final MasterServices master, final RegionStateStore stateStore) {<a name="line.165"></a> +<span class="sourceLineNo">042</span>import org.apache.hadoop.hbase.client.DoNotRetryRegionException;<a name="line.42"></a> +<span class="sourceLineNo">043</span>import org.apache.hadoop.hbase.client.RegionInfo;<a name="line.43"></a> +<span class="sourceLineNo">044</span>import org.apache.hadoop.hbase.client.RegionInfoBuilder;<a name="line.44"></a> +<span class="sourceLineNo">045</span>import org.apache.hadoop.hbase.client.Result;<a name="line.45"></a> +<span class="sourceLineNo">046</span>import org.apache.hadoop.hbase.client.TableState;<a name="line.46"></a> +<span class="sourceLineNo">047</span>import org.apache.hadoop.hbase.exceptions.UnexpectedStateException;<a name="line.47"></a> +<span class="sourceLineNo">048</span>import org.apache.hadoop.hbase.favored.FavoredNodesManager;<a name="line.48"></a> +<span class="sourceLineNo">049</span>import org.apache.hadoop.hbase.favored.FavoredNodesPromoter;<a name="line.49"></a> +<span class="sourceLineNo">050</span>import org.apache.hadoop.hbase.master.LoadBalancer;<a name="line.50"></a> +<span class="sourceLineNo">051</span>import org.apache.hadoop.hbase.master.MasterServices;<a name="line.51"></a> +<span class="sourceLineNo">052</span>import org.apache.hadoop.hbase.master.MetricsAssignmentManager;<a name="line.52"></a> +<span class="sourceLineNo">053</span>import org.apache.hadoop.hbase.master.RegionPlan;<a name="line.53"></a> +<span class="sourceLineNo">054</span>import org.apache.hadoop.hbase.master.RegionState;<a name="line.54"></a> +<span class="sourceLineNo">055</span>import org.apache.hadoop.hbase.master.RegionState.State;<a name="line.55"></a> +<span class="sourceLineNo">056</span>import org.apache.hadoop.hbase.master.ServerListener;<a name="line.56"></a> +<span class="sourceLineNo">057</span>import org.apache.hadoop.hbase.master.TableStateManager;<a name="line.57"></a> +<span class="sourceLineNo">058</span>import org.apache.hadoop.hbase.master.balancer.FavoredStochasticBalancer;<a name="line.58"></a> +<span class="sourceLineNo">059</span>import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;<a name="line.59"></a> +<span class="sourceLineNo">060</span>import org.apache.hadoop.hbase.master.procedure.MasterProcedureScheduler;<a name="line.60"></a> +<span class="sourceLineNo">061</span>import org.apache.hadoop.hbase.master.procedure.ProcedureSyncWait;<a name="line.61"></a> +<span class="sourceLineNo">062</span>import org.apache.hadoop.hbase.master.procedure.ServerCrashProcedure;<a name="line.62"></a> +<span class="sourceLineNo">063</span>import org.apache.hadoop.hbase.procedure2.Procedure;<a name="line.63"></a> +<span class="sourceLineNo">064</span>import org.apache.hadoop.hbase.procedure2.ProcedureEvent;<a name="line.64"></a> +<span class="sourceLineNo">065</span>import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;<a name="line.65"></a> +<span class="sourceLineNo">066</span>import org.apache.hadoop.hbase.procedure2.ProcedureInMemoryChore;<a name="line.66"></a> +<span class="sourceLineNo">067</span>import org.apache.hadoop.hbase.procedure2.util.StringUtils;<a name="line.67"></a> +<span class="sourceLineNo">068</span>import org.apache.hadoop.hbase.regionserver.SequenceId;<a name="line.68"></a> +<span class="sourceLineNo">069</span>import org.apache.hadoop.hbase.util.Bytes;<a name="line.69"></a> +<span class="sourceLineNo">070</span>import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;<a name="line.70"></a> +<span class="sourceLineNo">071</span>import org.apache.hadoop.hbase.util.HasThread;<a name="line.71"></a> +<span class="sourceLineNo">072</span>import org.apache.hadoop.hbase.util.Pair;<a name="line.72"></a> +<span class="sourceLineNo">073</span>import org.apache.hadoop.hbase.util.Threads;<a name="line.73"></a> +<span class="sourceLineNo">074</span>import org.apache.hadoop.hbase.util.VersionInfo;<a name="line.74"></a> +<span class="sourceLineNo">075</span>import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;<a name="line.75"></a> +<span class="sourceLineNo">076</span>import org.apache.hadoop.hbase.zookeeper.ZKWatcher;<a name="line.76"></a> +<span class="sourceLineNo">077</span>import org.apache.yetus.audience.InterfaceAudience;<a name="line.77"></a> +<span class="sourceLineNo">078</span>import org.apache.zookeeper.KeeperException;<a name="line.78"></a> +<span class="sourceLineNo">079</span>import org.slf4j.Logger;<a name="line.79"></a> +<span class="sourceLineNo">080</span>import org.slf4j.LoggerFactory;<a name="line.80"></a> +<span class="sourceLineNo">081</span><a name="line.81"></a> +<span class="sourceLineNo">082</span>import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting;<a name="line.82"></a> +<span class="sourceLineNo">083</span><a name="line.83"></a> +<span class="sourceLineNo">084</span>import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;<a name="line.84"></a> +<span class="sourceLineNo">085</span>import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionStateTransition;<a name="line.85"></a> +<span class="sourceLineNo">086</span>import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionStateTransition.TransitionCode;<a name="line.86"></a> +<span class="sourceLineNo">087</span>import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.ReportRegionStateTransitionRequest;<a name="line.87"></a> +<span class="sourceLineNo">088</span>import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.ReportRegionStateTransitionResponse;<a name="line.88"></a> +<span class="sourceLineNo">089</span><a name="line.89"></a> +<span class="sourceLineNo">090</span>/**<a name="line.90"></a> +<span class="sourceLineNo">091</span> * The AssignmentManager is the coordinator for region assign/unassign operations.<a name="line.91"></a> +<span class="sourceLineNo">092</span> * <ul><a name="line.92"></a> +<span class="sourceLineNo">093</span> * <li>In-memory states of regions and servers are stored in {@link RegionStates}.</li><a name="line.93"></a> +<span class="sourceLineNo">094</span> * <li>hbase:meta state updates are handled by {@link RegionStateStore}.</li><a name="line.94"></a> +<span class="sourceLineNo">095</span> * </ul><a name="line.95"></a> +<span class="sourceLineNo">096</span> * Regions are created by CreateTable, Split, Merge.<a name="line.96"></a> +<span class="sourceLineNo">097</span> * Regions are deleted by DeleteTable, Split, Merge.<a name="line.97"></a> +<span class="sourceLineNo">098</span> * Assigns are triggered by CreateTable, EnableTable, Split, Merge, ServerCrash.<a name="line.98"></a> +<span class="sourceLineNo">099</span> * Unassigns are triggered by DisableTable, Split, Merge<a name="line.99"></a> +<span class="sourceLineNo">100</span> */<a name="line.100"></a> +<span class="sourceLineNo">101</span>@InterfaceAudience.Private<a name="line.101"></a> +<span class="sourceLineNo">102</span>public class AssignmentManager implements ServerListener {<a name="line.102"></a> +<span class="sourceLineNo">103</span> private static final Logger LOG = LoggerFactory.getLogger(AssignmentManager.class);<a name="line.103"></a> +<span class="sourceLineNo">104</span><a name="line.104"></a> +<span class="sourceLineNo">105</span> // TODO: AMv2<a name="line.105"></a> +<span class="sourceLineNo">106</span> // - handle region migration from hbase1 to hbase2.<a name="line.106"></a> +<span class="sourceLineNo">107</span> // - handle sys table assignment first (e.g. acl, namespace)<a name="line.107"></a> +<span class="sourceLineNo">108</span> // - handle table priorities<a name="line.108"></a> +<span class="sourceLineNo">109</span> // - If ServerBusyException trying to update hbase:meta, we abort the Master<a name="line.109"></a> +<span class="sourceLineNo">110</span> // See updateRegionLocation in RegionStateStore.<a name="line.110"></a> +<span class="sourceLineNo">111</span> //<a name="line.111"></a> +<span class="sourceLineNo">112</span> // See also<a name="line.112"></a> +<span class="sourceLineNo">113</span> // https://docs.google.com/document/d/1eVKa7FHdeoJ1-9o8yZcOTAQbv0u0bblBlCCzVSIn69g/edit#heading=h.ystjyrkbtoq5<a name="line.113"></a> +<span class="sourceLineNo">114</span> // for other TODOs.<a name="line.114"></a> +<span class="sourceLineNo">115</span><a name="line.115"></a> +<span class="sourceLineNo">116</span> public static final String BOOTSTRAP_THREAD_POOL_SIZE_CONF_KEY =<a name="line.116"></a> +<span class="sourceLineNo">117</span> "hbase.assignment.bootstrap.thread.pool.size";<a name="line.117"></a> +<span class="sourceLineNo">118</span><a name="line.118"></a> +<span class="sourceLineNo">119</span> public static final String ASSIGN_DISPATCH_WAIT_MSEC_CONF_KEY =<a name="line.119"></a> +<span class="sourceLineNo">120</span> "hbase.assignment.dispatch.wait.msec";<a name="line.120"></a> +<span class="sourceLineNo">121</span> private static final int DEFAULT_ASSIGN_DISPATCH_WAIT_MSEC = 150;<a name="line.121"></a> +<span class="sourceLineNo">122</span><a name="line.122"></a> +<span class="sourceLineNo">123</span> public static final String ASSIGN_DISPATCH_WAITQ_MAX_CONF_KEY =<a name="line.123"></a> +<span class="sourceLineNo">124</span> "hbase.assignment.dispatch.wait.queue.max.size";<a name="line.124"></a> +<span class="sourceLineNo">125</span> private static final int DEFAULT_ASSIGN_DISPATCH_WAITQ_MAX = 100;<a name="line.125"></a> +<span class="sourceLineNo">126</span><a name="line.126"></a> +<span class="sourceLineNo">127</span> public static final String RIT_CHORE_INTERVAL_MSEC_CONF_KEY =<a name="line.127"></a> +<span class="sourceLineNo">128</span> "hbase.assignment.rit.chore.interval.msec";<a name="line.128"></a> +<span class="sourceLineNo">129</span> private static final int DEFAULT_RIT_CHORE_INTERVAL_MSEC = 60 * 1000;<a name="line.129"></a> +<span class="sourceLineNo">130</span><a name="line.130"></a> +<span class="sourceLineNo">131</span> public static final String ASSIGN_MAX_ATTEMPTS =<a name="line.131"></a> +<span class="sourceLineNo">132</span> "hbase.assignment.maximum.attempts";<a name="line.132"></a> +<span class="sourceLineNo">133</span> private static final int DEFAULT_ASSIGN_MAX_ATTEMPTS = Integer.MAX_VALUE;<a name="line.133"></a> +<span class="sourceLineNo">134</span><a name="line.134"></a> +<span class="sourceLineNo">135</span> /** Region in Transition metrics threshold time */<a name="line.135"></a> +<span class="sourceLineNo">136</span> public static final String METRICS_RIT_STUCK_WARNING_THRESHOLD =<a name="line.136"></a> +<span class="sourceLineNo">137</span> "hbase.metrics.rit.stuck.warning.threshold";<a name="line.137"></a> +<span class="sourceLineNo">138</span> private static final int DEFAULT_RIT_STUCK_WARNING_THRESHOLD = 60 * 1000;<a name="line.138"></a> +<span class="sourceLineNo">139</span><a name="line.139"></a> +<span class="sourceLineNo">140</span> private final ProcedureEvent<?> metaAssignEvent = new ProcedureEvent<>("meta assign");<a name="line.140"></a> +<span class="sourceLineNo">141</span> private final ProcedureEvent<?> metaLoadEvent = new ProcedureEvent<>("meta load");<a name="line.141"></a> +<span class="sourceLineNo">142</span><a name="line.142"></a> +<span class="sourceLineNo">143</span> private final MetricsAssignmentManager metrics;<a name="line.143"></a> +<span class="sourceLineNo">144</span> private final RegionInTransitionChore ritChore;<a name="line.144"></a> +<span class="sourceLineNo">145</span> private final MasterServices master;<a name="line.145"></a> +<span class="sourceLineNo">146</span><a name="line.146"></a> +<span class="sourceLineNo">147</span> private final AtomicBoolean running = new AtomicBoolean(false);<a name="line.147"></a> +<span class="sourceLineNo">148</span> private final RegionStates regionStates = new RegionStates();<a name="line.148"></a> +<span class="sourceLineNo">149</span> private final RegionStateStore regionStateStore;<a name="line.149"></a> +<span class="sourceLineNo">150</span><a name="line.150"></a> +<span class="sourceLineNo">151</span> private final boolean shouldAssignRegionsWithFavoredNodes;<a name="line.151"></a> +<span class="sourceLineNo">152</span> private final int assignDispatchWaitQueueMaxSize;<a name="line.152"></a> +<span class="sourceLineNo">153</span> private final int assignDispatchWaitMillis;<a name="line.153"></a> +<span class="sourceLineNo">154</span> private final int assignMaxAttempts;<a name="line.154"></a> +<span class="sourceLineNo">155</span><a name="line.155"></a> +<span class="sourceLineNo">156</span> private final Object checkIfShouldMoveSystemRegionLock = new Object();<a name="line.156"></a> +<span class="sourceLineNo">157</span><a name="line.157"></a> +<span class="sourceLineNo">158</span> private Thread assignThread;<a name="line.158"></a> +<span class="sourceLineNo">159</span><a name="line.159"></a> +<span class="sourceLineNo">160</span> public AssignmentManager(final MasterServices master) {<a name="line.160"></a> +<span class="sourceLineNo">161</span> this(master, new RegionStateStore(master));<a name="line.161"></a> +<span class="sourceLineNo">162</span> }<a name="line.162"></a> +<span class="sourceLineNo">163</span><a name="line.163"></a> +<span class="sourceLineNo">164</span> @VisibleForTesting<a name="line.164"></a> +<span class="sourceLineNo">165</span> AssignmentManager(final MasterServices master, final RegionStateStore stateStore) {<a name="line.165"></a> <span class="sourceLineNo">166</span> this.master = master;<a name="line.166"></a> <span class="sourceLineNo">167</span> this.regionStateStore = stateStore;<a name="line.167"></a> <span class="sourceLineNo">168</span> this.metrics = new MetricsAssignmentManager();<a name="line.168"></a> @@ -987,941 +987,895 @@ <span class="sourceLineNo">979</span> // RS Status update (report online regions) helpers<a name="line.979"></a> <span class="sourceLineNo">980</span> // ============================================================================================<a name="line.980"></a> <span class="sourceLineNo">981</span> /**<a name="line.981"></a> -<span class="sourceLineNo">982</span> * the master will call this method when the RS send the regionServerReport().<a name="line.982"></a> -<span class="sourceLineNo">983</span> * the report will contains the "online regions".<a name="line.983"></a> -<span class="sourceLineNo">984</span> * this method will check the the online regions against the in-memory state of the AM,<a name="line.984"></a> -<span class="sourceLineNo">985</span> * if there is a mismatch we will try to fence out the RS with the assumption<a name="line.985"></a> -<span class="sourceLineNo">986</span> * that something went wrong on the RS side.<a name="line.986"></a> -<span class="sourceLineNo">987</span> */<a name="line.987"></a> -<span class="sourceLineNo">988</span> public void reportOnlineRegions(final ServerName serverName, final Set<byte[]> regionNames)<a name="line.988"></a> -<span class="sourceLineNo">989</span> throws YouAreDeadException {<a name="line.989"></a> -<span class="sourceLineNo">990</span> if (!isRunning()) return;<a name="line.990"></a> -<span class="sourceLineNo">991</span> if (LOG.isTraceEnabled()) {<a name="line.991"></a> -<span class="sourceLineNo">992</span> LOG.trace("ReportOnlineRegions " + serverName + " regionCount=" + regionNames.size() +<a name="line.992"></a> -<span class="sourceLineNo">993</span> ", metaLoaded=" + isMetaLoaded() + " " +<a name="line.993"></a> -<span class="sourceLineNo">994</span> regionNames.stream().map(element -> Bytes.toStringBinary(element)).<a name="line.994"></a> -<span class="sourceLineNo">995</span> collect(Collectors.toList()));<a name="line.995"></a> -<span class="sourceLineNo">996</span> }<a name="line.996"></a> -<span class="sourceLineNo">997</span><a name="line.997"></a> -<span class="sourceLineNo">998</span> final ServerStateNode serverNode = regionStates.getOrCreateServer(serverName);<a name="line.998"></a> -<span class="sourceLineNo">999</span><a name="line.999"></a> -<span class="sourceLineNo">1000</span> synchronized (serverNode) {<a name="line.1000"></a> -<span class="sourceLineNo">1001</span> if (!serverNode.isInState(ServerState.ONLINE)) {<a name="line.1001"></a> -<span class="sourceLineNo">1002</span> LOG.warn("Got a report from a server result in state " + serverNode.getState());<a name="line.1002"></a> -<span class="sourceLineNo">1003</span> return;<a name="line.1003"></a> -<span class="sourceLineNo">1004</span> }<a name="line.1004"></a> -<span class="sourceLineNo">1005</span> }<a name="line.1005"></a> -<span class="sourceLineNo">1006</span><a name="line.1006"></a> -<span class="sourceLineNo">1007</span> if (regionNames.isEmpty()) {<a name="line.1007"></a> -<span class="sourceLineNo">1008</span> // nothing to do if we don't have regions<a name="line.1008"></a> -<span class="sourceLineNo">1009</span> LOG.trace("no online region found on " + serverName);<a name="line.1009"></a> -<span class="sourceLineNo">1010</span> } else if (!isMetaLoaded()) {<a name="line.1010"></a> -<span class="sourceLineNo">1011</span> // if we are still on startup, discard the report unless is from someone holding meta<a name="line.1011"></a> -<span class="sourceLineNo">1012</span> checkOnlineRegionsReportForMeta(serverNode, regionNames);<a name="line.1012"></a> -<span class="sourceLineNo">1013</span> } else {<a name="line.1013"></a> -<span class="sourceLineNo">1014</span> // The Heartbeat updates us of what regions are only. check and verify the state.<a name="line.1014"></a> -<span class="sourceLineNo">1015</span> checkOnlineRegionsReport(serverNode, regionNames);<a name="line.1015"></a> -<span class="sourceLineNo">1016</span> }<a name="line.1016"></a> -<span class="sourceLineNo">1017</span><a name="line.1017"></a> -<span class="sourceLineNo">1018</span> // wake report event<a name="line.1018"></a> -<span class="sourceLineNo">1019</span> wakeServerReportEvent(serverNode);<a name="line.1019"></a> -<span class="sourceLineNo">1020</span> }<a name="line.1020"></a> -<span class="sourceLineNo">1021</span><a name="line.1021"></a> -<span class="sourceLineNo">1022</span> void checkOnlineRegionsReportForMeta(ServerStateNode serverNode, Set<byte[]> regionNames) {<a name="line.1022"></a> -<span class="sourceLineNo">1023</span> try {<a name="line.1023"></a> -<span class="sourceLineNo">1024</span> for (byte[] regionName : regionNames) {<a name="line.1024"></a> -<span class="sourceLineNo">1025</span> final RegionInfo hri = getMetaRegionFromName(regionName);<a name="line.1025"></a> -<span class="sourceLineNo">1026</span> if (hri == null) {<a name="line.1026"></a> -<span class="sourceLineNo">1027</span> if (LOG.isTraceEnabled()) {<a name="line.1027"></a> -<span class="sourceLineNo">1028</span> LOG.trace("Skip online report for region=" + Bytes.toStringBinary(regionName) +<a name="line.1028"></a> -<span class="sourceLineNo">1029</span> " while meta is loading");<a name="line.1029"></a> -<span class="sourceLineNo">1030</span> }<a name="line.1030"></a> -<span class="sourceLineNo">1031</span> continue;<a name="line.1031"></a> -<span class="sourceLineNo">1032</span> }<a name="line.1032"></a> -<span class="sourceLineNo">1033</span><a name="line.1033"></a> -<span class="sourceLineNo">1034</span> RegionStateNode regionNode = regionStates.getOrCreateRegionStateNode(hri);<a name="line.1034"></a> -<span class="sourceLineNo">1035</span> LOG.info("META REPORTED: " + regionNode);<a name="line.1035"></a> -<span class="sourceLineNo">1036</span> regionNode.lock();<a name="line.1036"></a> -<span class="sourceLineNo">1037</span> try {<a name="line.1037"></a> -<span class="sourceLineNo">1038</span> if (!reportTransition(regionNode, serverNode, TransitionCode.OPENED, 0)) {<a name="line.1038"></a> -<span class="sourceLineNo">1039</span> LOG.warn("META REPORTED but no procedure found (complete?); set location=" +<a name="line.1039"></a> -<span class="sourceLineNo">1040</span> serverNode.getServerName());<a name="line.1040"></a> -<span class="sourceLineNo">1041</span> regionNode.setRegionLocation(serverNode.getServerName());<a name="line.1041"></a> -<span class="sourceLineNo">1042</span> } else if (LOG.isTraceEnabled()) {<a name="line.1042"></a> -<span class="sourceLineNo">1043</span> LOG.trace("META REPORTED: " + regionNode);<a name="line.1043"></a> -<span class="sourceLineNo">1044</span> }<a name="line.1044"></a> -<span class="sourceLineNo">1045</span> } finally {<a name="line.1045"></a> -<span class="sourceLineNo">1046</span> regionNode.unlock();<a name="line.1046"></a> -<span class="sourceLineNo">1047</span> }<a name="line.1047"></a> -<span class="sourceLineNo">1048</span> }<a name="line.1048"></a> -<span class="sourceLineNo">1049</span> } catch (IOException e) {<a name="line.1049"></a> -<span class="sourceLineNo">1050</span> ServerName serverName = serverNode.getServerName();<a name="line.1050"></a> -<span class="sourceLineNo">1051</span> LOG.warn("KILLING " + serverName + ": " + e.getMessage());<a name="line.1051"></a> -<span class="sourceLineNo">1052</span> killRegionServer(serverNode);<a name="line.1052"></a> -<span class="sourceLineNo">1053</span> }<a name="line.1053"></a> -<span class="sourceLineNo">1054</span> }<a name="line.1054"></a> -<span class="sourceLineNo">1055</span><a name="line.1055"></a> -<span class="sourceLineNo">1056</span> void checkOnlineRegionsReport(final ServerStateNode serverNode, final Set<byte[]> regionNames) {<a name="line.1056"></a> -<span class="sourceLineNo">1057</span> final ServerName serverName = serverNode.getServerName();<a name="line.1057"></a> -<span class="sourceLineNo">1058</span> try {<a name="line.1058"></a> -<span class="sourceLineNo">1059</span> for (byte[] regionName: regionNames) {<a name="line.1059"></a> -<span class="sourceLineNo">1060</span> if (!isRunning()) {<a name="line.1060"></a> -<span class="sourceLineNo">1061</span> return;<a name="line.1061"></a> -<span class="sourceLineNo">1062</span> }<a name="line.1062"></a> -<span class="sourceLineNo">1063</span> final RegionStateNode regionNode = regionStates.getRegionStateNodeFromName(regionName);<a name="line.1063"></a> -<span class="sourceLineNo">1064</span> if (regionNode == null) {<a name="line.1064"></a> -<span class="sourceLineNo">1065</span> throw new UnexpectedStateException("Not online: " + Bytes.toStringBinary(regionName));<a name="line.1065"></a> -<span class="sourceLineNo">1066</span> }<a name="line.1066"></a> -<span class="sourceLineNo">1067</span> regionNode.lock();<a name="line.1067"></a> -<span class="sourceLineNo">1068</span> try {<a name="line.1068"></a> -<span class="sourceLineNo">1069</span> if (regionNode.isInState(State.OPENING, State.OPEN)) {<a name="line.1069"></a> -<span class="sourceLineNo">1070</span> if (!regionNode.getRegionLocation().equals(serverName)) {<a name="line.1070"></a> -<span class="sourceLineNo">1071</span> throw new UnexpectedStateException(regionNode.toString() +<a name="line.1071"></a> -<span class="sourceLineNo">1072</span> " reported OPEN on server=" + serverName +<a name="line.1072"></a> -<span class="sourceLineNo">1073</span> " but state has otherwise.");<a name="line.1073"></a> -<span class="sourceLineNo">1074</span> } else if (regionNode.isInState(State.OPENING)) {<a name="line.1074"></a> -<span class="sourceLineNo">1075</span> try {<a name="line.1075"></a> -<span class="sourceLineNo">1076</span> if (!reportTransition(regionNode, serverNode, TransitionCode.OPENED, 0)) {<a name="line.1076"></a> -<span class="sourceLineNo">1077</span> LOG.warn(regionNode.toString() + " reported OPEN on server=" + serverName +<a name="line.1077"></a> -<span class="sourceLineNo">1078</span> " but state has otherwise AND NO procedure is running");<a name="line.1078"></a> -<span class="sourceLineNo">1079</span> }<a name="line.1079"></a> -<span class="sourceLineNo">1080</span> } catch (UnexpectedStateException e) {<a name="line.1080"></a> -<span class="sourceLineNo">1081</span> LOG.warn(regionNode.toString() + " reported unexpteced OPEN: " + e.getMessage(), e);<a name="line.1081"></a> -<span class="sourceLineNo">1082</span> }<a name="line.1082"></a> -<span class="sourceLineNo">1083</span> }<a name="line.1083"></a> -<span class="sourceLineNo">1084</span> } else if (!regionNode.isInState(State.CLOSING, State.SPLITTING)) {<a name="line.1084"></a> -<span class="sourceLineNo">1085</span> long diff = regionNode.getLastUpdate() - EnvironmentEdgeManager.currentTime();<a name="line.1085"></a> -<span class="sourceLineNo">1086</span> if (diff > 1000/*One Second... make configurable if an issue*/) {<a name="line.1086"></a> -<span class="sourceLineNo">1087</span> // So, we can get report that a region is CLOSED or SPLIT because a heartbeat<a name="line.1087"></a> -<span class="sourceLineNo">1088</span> // came in at about same time as a region transition. Make sure there is some<a name="line.1088"></a> -<span class="sourceLineNo">1089</span> // elapsed time between killing remote server.<a name="line.1089"></a> -<span class="sourceLineNo">1090</span> throw new UnexpectedStateException(regionNode.toString() +<a name="line.1090"></a> -<span class="sourceLineNo">1091</span> " reported an unexpected OPEN; time since last update=" + diff);<a name="line.1091"></a> -<span class="sourceLineNo">1092</span> }<a name="line.1092"></a> -<span class="sourceLineNo">1093</span> }<a name="line.1093"></a> -<span class="sourceLineNo">1094</span> } finally {<a name="line.1094"></a> -<span class="sourceLineNo">1095</span> regionNode.unlock();<a name="line.1095"></a> -<span class="sourceLineNo">1096</span> }<a name="line.1096"></a> -<span class="sourceLineNo">1097</span> }<a name="line.1097"></a> -<span class="sourceLineNo">1098</span> } catch (IOException e) {<a name="line.1098"></a> -<span class="sourceLineNo">1099</span> //See HBASE-21421, we can count on reportRegionStateTransition calls<a name="line.1099"></a> -<span class="sourceLineNo">1100</span> //We only log a warming here. It could be a network lag.<a name="line.1100"></a> -<span class="sourceLineNo">1101</span> LOG.warn("Failed to checkOnlineRegionsReport, maybe due to network lag, "<a name="line.1101"></a> -<span class="sourceLineNo">1102</span> + "if this message continues, be careful of double assign", e);<a name="line.1102"></a> -<span class="sourceLineNo">1103</span> }<a name="line.1103"></a> +<span class="sourceLineNo">982</span> * The master will call this method when the RS send the regionServerReport(). The report will<a name="line.982"></a> +<span class="sourceLineNo">983</span> * contains the "online regions". This method will check the the online regions against the<a name="line.983"></a> +<span class="sourceLineNo">984</span> * in-memory state of the AM, and we will log a warn message if there is a mismatch. This is<a name="line.984"></a> +<span class="sourceLineNo">985</span> * because that there is no fencing between the reportRegionStateTransition method and<a name="line.985"></a> +<span class="sourceLineNo">986</span> * regionServerReport method, so there could be race and introduce inconsistency here, but<a name="line.986"></a> +<span class="sourceLineNo">987</span> * actually there is no problem.<a name="line.987"></a> +<span class="sourceLineNo">988</span> * <p/><a name="line.988"></a> +<span class="sourceLineNo">989</span> * Please see HBASE-21421 and HBASE-21463 for more details.<a name="line.989"></a> +<span class="sourceLineNo">990</span> */<a name="line.990"></a> +<span class="sourceLineNo">991</span> public void reportOnlineRegions(ServerName serverName, Set<byte[]> regionNames) {<a name="line.991"></a> +<span class="sourceLineNo">992</span> if (!isRunning()) {<a name="line.992"></a> +<span class="sourceLineNo">993</span> return;<a name="line.993"></a> +<span class="sourceLineNo">994</span> }<a name="line.994"></a> +<span class="sourceLineNo">995</span> if (LOG.isTraceEnabled()) {<a name="line.995"></a> +<span class="sourceLineNo">996</span> LOG.trace("ReportOnlineRegions {} regionCount={}, metaLoaded={} {}", serverName,<a name="line.996"></a> +<span class="sourceLineNo">997</span> regionNames.size(), isMetaLoaded(),<a name="line.997"></a> +<span class="sourceLineNo">998</span> regionNames.stream().map(Bytes::toStringBinary).collect(Collectors.toList()));<a name="line.998"></a> +<span class="sourceLineNo">999</span> }<a name="line.999"></a> +<span class="sourceLineNo">1000</span><a name="line.1000"></a> +<span class="sourceLineNo">1001</span> ServerStateNode serverNode = regionStates.getOrCreateServer(serverName);<a name="line.1001"></a> +<span class="sourceLineNo">1002</span><a name="line.1002"></a> +<span class="sourceLineNo">1003</span> synchronized (serverNode) {<a name="line.1003"></a> +<span class="sourceLineNo">1004</span> if (!serverNode.isInState(ServerState.ONLINE)) {<a name="line.1004"></a> +<span class="sourceLineNo">1005</span> LOG.warn("Got a report from a server result in state " + serverNode.getState());<a name="line.1005"></a> +<span class="sourceLineNo">1006</span> return;<a name="line.1006"></a> +<span class="sourceLineNo">1007</span> }<a name="line.1007"></a> +<span class="sourceLineNo">1008</span> }<a name="line.1008"></a> +<span class="sourceLineNo">1009</span> if (regionNames.isEmpty()) {<a name="line.1009"></a> +<span class="sourceLineNo">1010</span> // nothing to do if we don't have regions<a name="line.1010"></a> +<span class="sourceLineNo">1011</span> LOG.trace("no online region found on {}", serverName);<a name="line.1011"></a> +<span class="sourceLineNo">1012</span> return;<a name="line.1012"></a> +<span class="sourceLineNo">1013</span> }<a name="line.1013"></a> +<span class="sourceLineNo">1014</span> if (!isMetaLoaded()) {<a name="line.1014"></a> +<span class="sourceLineNo">1015</span> // we are still on startup, skip checking<a name="line.1015"></a> +<span class="sourceLineNo">1016</span> return;<a name="line.1016"></a> +<span class="sourceLineNo">1017</span> }<a name="line.1017"></a> +<span class="sourceLineNo">1018</span> // The Heartbeat tells us of what regions are on the region serve, check the state.<a name="line.1018"></a> +<span class="sourceLineNo">1019</span> checkOnlineRegionsReport(serverNode, regionNames);<a name="line.1019"></a> +<span class="sourceLineNo">1020</span><a name="line.1020"></a> +<span class="sourceLineNo">1021</span> // wake report event<a name="line.1021"></a> +<span class="sourceLineNo">1022</span> wakeServerReportEvent(serverNode);<a name="line.1022"></a> +<span class="sourceLineNo">1023</span> }<a name="line.1023"></a> +<span class="sourceLineNo">1024</span><a name="line.1024"></a> +<span class="sourceLineNo">1025</span> // just check and output possible inconsistency, without actually doing anything<a name="line.1025"></a> +<span class="sourceLineNo">1026</span> private void checkOnlineRegionsReport(ServerStateNode serverNode, Set<byte[]> regionNames) {<a name="line.1026"></a> +<span class="sourceLineNo">1027</span> ServerName serverName = serverNode.getServerName();<a name="line.1027"></a> +<span class="sourceLineNo">1028</span> for (byte[] regionName : regionNames) {<a name="line.1028"></a> +<span class="sourceLineNo">1029</span> if (!isRunning()) {<a name="line.1029"></a> +<span class="sourceLineNo">1030</span> return;<a name="line.1030"></a> +<span class="sourceLineNo">1031</span> }<a name="line.1031"></a> +<span class="sourceLineNo">1032</span> RegionStateNode regionNode = regionStates.getRegionStateNodeFromName(regionName);<a name="line.1032"></a> +<span class="sourceLineNo">1033</span> if (regionNode == null) {<a name="line.1033"></a> +<span class="sourceLineNo">1034</span> LOG.warn("No region state node for {}, it should already be on {}",<a name="line.1034"></a> +<span class="sourceLineNo">1035</span> Bytes.toStringBinary(regionName), serverName);<a name="line.1035"></a> +<span class="sourceLineNo">1036</span> continue;<a name="line.1036"></a> +<span class="sourceLineNo">1037</span> }<a name="line.1037"></a> +<span class="sourceLineNo">1038</span> regionNode.lock();<a name="line.1038"></a> +<span class="sourceLineNo">1039</span> try {<a name="line.1039"></a> +<span class="sourceLineNo">1040</span> long diff = EnvironmentEdgeManager.currentTime() - regionNode.getLastUpdate();<a name="line.1040"></a> +<span class="sourceLineNo">1041</span> if (regionNode.isInState(State.OPENING, State.OPEN)) {<a name="line.1041"></a> +<span class="sourceLineNo">1042</span> // This is possible as a region server has just closed a region but the region server<a name="line.1042"></a> +<span class="sourceLineNo">1043</span> // report is generated before the closing, but arrive after the closing. Make sure there<a name="line.1043"></a> +<span class="sourceLineNo">1044</span> // is some elapsed time so less false alarms.<a name="line.1044"></a> +<span class="sourceLineNo">1045</span> if (!regionNode.getRegionLocation().equals(serverName) && diff > 1000) {<a name="line.1045"></a> +<span class="sourceLineNo">1046</span> LOG.warn("{} reported OPEN on server={} but state has otherwise", regionNode,<a name="line.1046"></a> +<span class="sourceLineNo">1047</span> serverName);<a name="line.1047"></a> +<span class="sourceLineNo">1048</span> }<a name="line.1048"></a> +<span class="sourceLineNo">1049</span> } else if (!regionNode.isInState(State.CLOSING, State.SPLITTING)) {<a name="line.1049"></a> +<span class="sourceLineNo">1050</span> // So, we can get report that a region is CLOSED or SPLIT because a heartbeat<a name="line.1050"></a> +<span class="sourceLineNo">1051</span> // came in at about same time as a region transition. Make sure there is some<a name="line.1051"></a> +<span class="sourceLineNo">1052</span> // elapsed time so less false alarms.<a name="line.1052"></a> +<span class="sourceLineNo">1053</span> if (diff > 1000) {<a name="line.1053"></a> +<span class="sourceLineNo">1054</span> LOG.warn("{} reported an unexpected OPEN on {}; time since last update={}ms",<a name="line.1054"></a> +<span class="sourceLineNo">1055</span> regionNode, serverName, diff);<a name="line.1055"></a> +<span class="sourceLineNo">1056</span> }<a name="line.1056"></a> +<span class="sourceLineNo">1057</span> }<a name="line.1057"></a> +<span class="sourceLineNo">1058</span> } finally {<a name="line.1058"></a> +<span class="sourceLineNo">1059</span> regionNode.unlock();<a name="line.1059"></a> +<span class="sourceLineNo">1060</span> }<a name="line.1060"></a> +<span class="sourceLineNo">1061</span> }<a name="line.1061"></a> +<span class="sourceLineNo">1062</span> }<a name="line.1062"></a> +<span class="sourceLineNo">1063</span><a name="line.1063"></a> +<span class="sourceLineNo">1064</span> protected boolean waitServerReportEvent(ServerName serverName, Procedure<?> proc) {<a name="line.1064"></a> +<span class="sourceLineNo">1065</span> final ServerStateNode serverNode = regionStates.getOrCreateServer(serverName);<a name="line.1065"></a> +<span class="sourceLineNo">1066</span> if (serverNode == null) {<a name="line.1066"></a> +<span class="sourceLineNo">1067</span> LOG.warn("serverName=null; {}", proc);<a name="line.1067"></a> +<span class="sourceLineNo">1068</span> }<a name="line.1068"></a> +<span class="sourceLineNo">1069</span> return serverNode.getReportEvent().suspendIfNotReady(proc);<a name="line.1069"></a> +<span class="sourceLineNo">1070</span> }<a name="line.1070"></a> +<span class="sourceLineNo">1071</span><a name="line.1071"></a> +<span class="sourceLineNo">1072</span> protected void wakeServerReportEvent(final ServerStateNode serverNode) {<a name="line.1072"></a> +<span class="sourceLineNo">1073</span> serverNode.getReportEvent().wake(getProcedureScheduler());<a name="line.1073"></a> +<span class="sourceLineNo">1074</span> }<a name="line.1074"></a> +<span class="sourceLineNo">1075</span><a name="line.1075"></a> +<span class="sourceLineNo">1076</span> // ============================================================================================<a name="line.1076"></a> +<span class="sourceLineNo">1077</span> // RIT chore<a name="line.1077"></a> +<span class="sourceLineNo">1078</span> // ============================================================================================<a name="line.1078"></a> +<span class="sourceLineNo">1079</span> private static class RegionInTransitionChore extends ProcedureInMemoryChore<MasterProcedureEnv> {<a name="line.1079"></a> +<span class="sourceLineNo">1080</span> public RegionInTransitionChore(final int timeoutMsec) {<a name="line.1080"></a> +<span class="sourceLineNo">1081</span> super(timeoutMsec);<a name="line.1081"></a> +<span class="sourceLineNo">1082</span> }<a name="line.1082"></a> +<span class="sourceLineNo">1083</span><a name="line.1083"></a> +<span class="sourceLineNo">1084</span> @Override<a name="line.1084"></a> +<span class="sourceLineNo">1085</span> protected void periodicExecute(final MasterProcedureEnv env) {<a name="line.1085"></a> +<span class="sourceLineNo">1086</span> final AssignmentManager am = env.getAssignmentManager();<a name="line.1086"></a> +<span class="sourceLineNo">1087</span><a name="line.1087"></a> +<span class="sourceLineNo">1088</span> final RegionInTransitionStat ritStat = am.computeRegionInTransitionStat();<a name="line.1088"></a> +<span class="sourceLineNo">1089</span> if (ritStat.hasRegionsOverThreshold()) {<a name="line.1089"></a> +<span class="sourceLineNo">1090</span> for (RegionState hri: ritStat.getRegionOverThreshold()) {<a name="line.1090"></a> +<span class="sourceLineNo">1091</span> am.handleRegionOverStuckWarningThreshold(hri.getRegion());<a name="line.1091"></a> +<span class="sourceLineNo">1092</span> }<a name="line.1092"></a> +<span class="sourceLineNo">1093</span> }<a name="line.1093"></a> +<span class="sourceLineNo">1094</span><a name="line.1094"></a> +<span class="sourceLineNo">1095</span> // update metrics<a name="line.1095"></a> +<span class="sourceLineNo">1096</span> am.updateRegionsInTransitionMetrics(ritStat);<a name="line.1096"></a> +<span class="sourceLineNo">1097</span> }<a name="line.1097"></a> +<span class="sourceLineNo">1098</span> }<a name="line.1098"></a> +<span class="sourceLineNo">1099</span><a name="line.1099"></a> +<span class="sourceLineNo">1100</span> public RegionInTransitionStat computeRegionInTransitionStat() {<a name="line.1100"></a> +<span class="sourceLineNo">1101</span> final RegionInTransitionStat rit = new RegionInTransitionStat(getConfiguration());<a name="line.1101"></a> +<span class="sourceLineNo">1102</span> rit.update(this);<a name="line.1102"></a> +<span class="sourceLineNo">1103</span> return rit;<a name="line.1103"></a> <span class="sourceLineNo">1104</span> }<a name="line.1104"></a> <span class="sourceLineNo">1105</span><a name="line.1105"></a> -<span class="sourceLineNo">1106</span> protected boolean waitServerReportEvent(ServerName serverName, Procedure<?> proc) {<a name="line.1106"></a> -<span class="sourceLineNo">1107</span> final ServerStateNode serverNode = regionStates.getOrCreateServer(serverName);<a name="line.1107"></a> -<span class="sourceLineNo">1108</span> if (serverNode == null) {<a name="line.1108"></a> -<span class="sourceLineNo">1109</span> LOG.warn("serverName=null; {}", proc);<a name="line.1109"></a> -<span class="sourceLineNo">1110</span> }<a name="line.1110"></a> -<span class="sourceLineNo">1111</span> return serverNode.getReportEvent().suspendIfNotReady(proc);<a name="line.1111"></a> -<span class="sourceLineNo">1112</span> }<a name="line.1112"></a> -<span class="sourceLineNo">1113</span><a name="line.1113"></a> -<span class="sourceLineNo">1114</span> protected void wakeServerReportEvent(final ServerStateNode serverNode) {<a name="line.1114"></a> -<span class="sourceLineNo">1115</span> serverNode.getReportEvent().wake(getProcedureScheduler());<a name="line.1115"></a> -<span class="sourceLineNo">1116</span> }<a name="line.1116"></a> -<span class="sourceLineNo">1117</span><a name="line.1117"></a> -<span class="sourceLineNo">1118</span> // ============================================================================================<a name="line.1118"></a> -<span class="sourceLineNo">1119</span> // RIT chore<a name="line.1119"></a> -<span class="sourceLineNo">1120</span> // ============================================================================================<a name="line.1120"></a> -<span class="sourceLineNo">1121</span> private static class RegionInTransitionChore extends ProcedureInMemoryChore<MasterProcedureEnv> {<a name="line.1121"></a> -<span class="sourceLineNo">1122</span> public RegionInTransitionChore(final int timeoutMsec) {<a name="line.1122"></a> -<span class="sourceLineNo">1123</span> super(timeoutMsec);<a name="line.1123"></a> -<span class="sourceLineNo">1124</span> }<a name="line.1124"></a> -<span class="sourceLineNo">1125</span><a name="line.1125"></a> -<span class="sourceLineNo">1126</span> @Override<a name="line.1126"></a> -<span class="sourceLineNo">1127</span> protected void periodicExecute(final MasterProcedureEnv env) {<a name="line.1127"></a> -<span class="sourceLineNo">1128</span> final AssignmentManager am = env.getAssignmentManager();<a name="line.1128"></a> -<span class="sourceLineNo">1129</span><a name="line.1129"></a> -<span class="sourceLineNo">1130</span> final RegionInTransitionStat ritStat = am.computeRegionInTransitionStat();<a name="line.1130"></a> -<span class="sourceLineNo">1131</span> if (ritStat.hasRegionsOverThreshold()) {<a name="line.1131"></a> -<span class="sourceLineNo">1132</span> for (RegionState hri: ritStat.getRegionOverThreshold()) {<a name="line.1132"></a> -<span class="sourceLineNo">1133</span> am.handleRegionOverStuckWarningThreshold(hri.getRegion());<a name="line.1133"></a> -<span class="sourceLineNo">1134</span> }<a name="line.1134"></a> -<span class="sourceLineNo">1135</span> }<a name="line.1135"></a> +<span class="sourceLineNo">1106</span> public static class RegionInTransitionStat {<a name="line.1106"></a> +<span class="sourceLineNo">1107</span> private final int ritThreshold;<a name="line.1107"></a> +<span class="sourceLineNo">1108</span><a name="line.1108"></a> +<span class="sourceLineNo">1109</span> private HashMap<String, RegionState> ritsOverThreshold = null;<a name="line.1109"></a> +<span class="sourceLineNo">1110</span> private long statTimestamp;<a name="line.1110"></a> +<span class="sourceLineNo">1111</span> private long oldestRITTime = 0;<a name="line.1111"></a> +<span class="sourceLineNo">1112</span> private int totalRITsTwiceThreshold = 0;<a name="line.1112"></a> +<span class="sourceLineNo">1113</span> private int totalRITs = 0;<a name="line.1113"></a> +<span class="sourceLineNo">1114</span><a name="line.1114"></a> +<span class="sourceLineNo">1115</span> @VisibleForTesting<a name="line.1115"></a> +<span class="sourceLineNo">1116</span> public RegionInTransitionStat(final Configuration conf) {<a name="line.1116"></a> +<span class="sourceLineNo">1117</span> this.ritThreshold =<a name="line.1117"></a> +<span class="sourceLineNo">1118</span> conf.getInt(METRICS_RIT_STUCK_WARNING_THRESHOLD, DEFAULT_RIT_STUCK_WARNING_THRESHOLD);<a name="line.1118"></a> +<span class="sourceLineNo">1119</span> }<a name="line.1119"></a> +<span class="sourceLineNo">1120</span><a name="line.1120"></a> +<span class="sourceLineNo">1121</span> public int getRITThreshold() {<a name="line.1121"></a> +<span class="sourceLineNo">1122</span> return ritThreshold;<a name="line.1122"></a> +<span class="sourceLineNo">1123</span> }<a name="line.1123"></a> +<span class="sourceLineNo">1124</span><a name="line.1124"></a> +<span class="sourceLineNo">1125</span> public long getTimestamp() {<a name="line.1125"></a> +<span class="sourceLineNo">1126</span> return statTimestamp;<a name="line.1126"></a> +<span class="sourceLineNo">1127</span> }<a name="line.1127"></a> +<span class="sourceLineNo">1128</span><a name="line.1128"></a> +<span class="sourceLineNo">1129</span> public int getTotalRITs() {<a name="line.1129"></a> +<span class="sourceLineNo">1130</span> return totalRITs;<a name="line.1130"></a> +<span class="sourceLineNo">1131</span> }<a name="line.1131"></a> +<span class="sourceLineNo">1132</span><a name="line.1132"></a> +<span class="sourceLineNo">1133</span> public long getOldestRITTime() {<a name="line.1133"></a> +<span class="sourceLineNo">1134</span> return oldestRITTime;<a name="line.1134"></a> +<span class="sourceLineNo">1135</span> }<a name="line.1135"></a> <span class="sourceLineNo">1136</span><a name="line.1136"></a> -<span class="sourceLineNo">1137</span> // update metrics<a name="line.1137"></a> -<span class="sourceLineNo">1138</span> am.updateRegionsInTransitionMetrics(ritStat);<a name="line.1138"></a> -<span class="sourceLineNo">1139</span> }<a name="line.1139"></a> -<span class="sourceLineNo">1140</span> }<a name="line.1140"></a> +<span class="sourceLineNo">1137</span> public int getTotalRITsOverThreshold() {<a name="line.1137"></a> +<span class="sourceLineNo">1138</span> Map<String, RegionState> m = this.ritsOverThreshold;<a name="line.1138"></a> +<span class="sourceLineNo">1139</span> return m != null ? m.size() : 0;<a name="line.1139"></a> +<span class="sourceLineNo">1140</span> }<a name="line.1140"></a> <span class="sourceLineNo">1141</span><a name="line.1141"></a> -<span class="sourceLineNo">1142</span> public RegionInTransitionStat computeRegionInTransitionStat() {<a name="line.1142"></a> -<span class="sourceLineNo">1143</span> final RegionInTransitionStat rit = new RegionInTransitionStat(getConfiguration());<a name="line.1143"></a> -<span class="sourceLineNo">1144</span> rit.update(this);<a name="line.1144"></a> -<span class="sourceLineNo">1145</span> return rit;<a name="line.1145"></a> -<span class="sourceLineNo">1146</span> }<a name="line.1146"></a> -<span class="sourceLineNo">1147</span><a name="line.1147"></a> -<span class="sourceLineNo">1148</span> public static class RegionInTransitionStat {<a name="line.1148"></a> -<span class="sourceLineNo">1149</span> private final int ritThreshold;<a name="line.1149"></a> +<span class="sourceLineNo">1142</span> public boolean hasRegionsTwiceOverThreshold() {<a name="line.1142"></a> +<span class="sourceLineNo">1143</span> return totalRITsTwiceThreshold > 0;<a name="line.1143"></a> +<span class="sourceLineNo">1144</span> }<a name="line.1144"></a> +<span class="sourceLineNo">1145</span><a name="line.1145"></a> +<span class="sourceLineNo">1146</span> public boolean hasRegionsOverThreshold() {<a name="line.1146"></a> +<span class="sourceLineNo">1147</span> Map<String, RegionState> m = this.ritsOverThreshold;<a name="line.1147"></a> +<span class="sourceLineNo">1148</span> return m != null && !m.isEmpty();<a name="line.1148"></a> +<span class="sourceLineNo">1149</span> }<a name="line.1149"></a> <span class="sourceLineNo">1150</span><a name="line.1150"></a> -<span class="sourceLineNo">1151</span> private HashMap<String, RegionState> ritsOverThreshold = null;<a name="line.1151"></a> -<span class="sourceLineNo">1152</span> private long statTimestamp;<a name="line.1152"></a> -<span class="sourceLineNo">1153</span> private long oldestRITTime = 0;<a name="line.1153"></a> -<span class="sourceLineNo">1154</span> private int totalRITsTwiceThreshold = 0;<a name="line.1154"></a> -<span class="sourceLineNo">1155</span> private int totalRITs = 0;<a name="line.1155"></a> -<span class="sourceLineNo">1156</span><a name="line.1156"></a> -<span class="sourceLineNo">1157</span> @VisibleForTesting<a name="line.1157"></a> -<span class="sourceLineNo">1158</span> public RegionInTransitionStat(final Configuration conf) {<a name="line.1158"></a> -<span class="sourceLineNo">1159</span> this.ritThreshold =<a name="line.1159"></a> -<span class="sourceLineNo">1160</span> conf.getInt(METRICS_RIT_STUCK_WARNING_THRESHOLD, DEFAULT_RIT_STUCK_WARNING_THRESHOLD);<a name="line.1160"></a> -<span class="sourceLineNo">1161</span> }<a name="line.1161"></a> -<span class="sourceLineNo">1162</span><a name="line.1162"></a> -<span class="sourceLineNo">1163</span> public int getRITThreshold() {<a name="line.1163"></a> -<span class="sourceLineNo">1164</span> return ritThreshold;<a name="line.1164"></a> -<span class="sourceLineNo">1165</span> }<a name="line.1165"></a> -<span class="sourceLineNo">1166</span><a name="line.1166"></a> -<span class="sourceLineNo">1167</span> public long getTimestamp() {<a name="line.1167"></a> -<span class="sourceLineNo">1168</span> return statTimestamp;<a name="line.1168"></a> -<span class="sourceLineNo">1169</span> }<a name="line.1169"></a> -<span class="sourceLineNo">1170</span><a name="line.1170"></a> -<span class="sourceLineNo">1171</span> public int getTotalRITs() {<a name="line.1171"></a> -<span class="sourceLineNo">1172</span> return totalRITs;<a name="line.1172"></a> -<span class="sourceLineNo">1173</span> }<a name="line.1173"></a> -<span class="sourceLineNo">1174</span><a name="line.1174"></a> -<span class="sourceLineNo">1175</span> public long getOldestRITTime() {<a name="line.1175"></a> -<span class="sourceLineNo">1176</span> return oldestRITTime;<a name="line.1176"></a> -<span class="sourceLineNo">1177</span> }<a name="line.1177"></a> -<span class="sourceLineNo">1178</span><a name="line.1178"></a> -<span class="sourceLineNo">1179</span> public int getTotalRITsOverThreshold() {<a name="line.1179"></a> -<span class="sourceLineNo">1180</span> Map<String, RegionState> m = this.ritsOverThreshold;<a name="line.1180"></a> -<span class="sourceLineNo">1181</span> return m != null ? m.size() : 0;<a name="line.1181"></a> -<span class="sourceLineNo">1182</span> }<a name="line.1182"></a> -<span class="sourceLineNo">1183</span><a name="line.1183"></a> -<span class="sourceLineNo">1184</span> public boolean hasRegionsTwiceOverThreshold() {<a name="line.1184"></a> -<span class="sourceLineNo">1185</span> return totalRITsTwiceThreshold > 0;<a name="line.1185"></a> -<span class="sourceLineNo">1186</span> }<a name="line.1186"></a> -<span class="sourceLineNo">1187</span><a name="line.1187"></a> -<span class="sourceLineNo">1188</span> public boolean hasRegionsOverThreshold() {<a name="line.1188"></a> -<span class="sourceLineNo">1189</span> Map<String, RegionState> m = this.ritsOverThreshold;<a name="line.1189"></a> -<span class="sourceLineNo">1190</span> return m != null && !m.isEmpty();<a name="line.1190"></a> +<span class="sourceLineNo">1151</span> public Collection<RegionState> getRegionOverThreshold() {<a name="line.1151"></a> +<span class="sourceLineNo">1152</span> Map<String, RegionState> m = this.ritsOverThreshold;<a name="line.1152"></a> +<span class="sourceLineNo">1153</span> return m != null? m.values(): Collections.emptySet();<a name="line.1153"></a> +<span class="sourceLineNo">1154</span> }<a name="line.1154"></a> +<span class="sourceLineNo">1155</span><a name="line.1155"></a> +<span class="sourceLineNo">1156</span> public boolean isRegionOverThreshold(final RegionInfo regionInfo) {<a name="line.1156"></a> +<span class="sourceLineNo">1157</span> Map<String, RegionState> m = this.ritsOverThreshold;<a name="line.1157"></a> +<span class="sourceLineNo">1158</span> return m != null && m.containsKey(regionInfo.getEncodedName());<a name="line.1158"></a> +<span class="sourceLineNo">1159</span> }<a name="line.1159"></a> +<span class="sourceLineNo">1160</span><a name="line.1160"></a> +<span class="sourceLineNo">1161</span> public boolean isRegionTwiceOverThreshold(final RegionInfo regionInfo) {<a name="line.1161"></a> +<span class="sourceLineNo">1162</span> Map<String, RegionState> m = this.ritsOverThreshold;<a name="line.1162"></a> +<span class="sourceLineNo">1163</span> if (m == null) return false;<a name="line.1163"></a> +<span class="sourceLineNo">1164</span> final RegionState state = m.get(regionInfo.getEncodedName());<a name="line.1164"></a> +<span class="sourceLineNo">1165</span> if (state == null) return false;<a name="line.1165"></a> +<span class="sourceLineNo">1166</span> return (statTimestamp - state.getStamp()) > (ritThreshold * 2);<a name="line.1166"></a> +<span class="sourceLineNo">1167</span> }<a name="line.1167"></a> +<span class="sourceLineNo">1168</span><a name="line.1168"></a> +<span class="sourceLineNo">1169</span> protected void update(final AssignmentManager am) {<a name="line.1169"></a> +<span class="sourceLineNo">1170</span> final RegionStates regionStates = am.getRegionStates();<a name="line.1170"></a> +<span class="sourceLineNo">1171</span> this.statTimestamp = EnvironmentEdgeManager.currentTime();<a name="line.1171"></a> +<span class="sourceLineNo">1172</span> update(regionStates.getRegionsStateInTransition(), statTimestamp);<a name="line.1172"></a> +<span class="sourceLineNo">1173</span> update(regionStates.getRegionFailedOpen(), statTimestamp);<a name="line.1173"></a> +<span class="sourceLineNo">1174</span> }<a name="line.1174"></a> +<span class="sourceLineNo">1175</span><a name="line.1175"></a> +<span class="sourceLineNo">1176</span> private void update(final Collection<RegionState> regions, final long currentTime) {<a name="line.1176"></a> +<span class="sourceLineNo">1177</span> for (RegionState state: regions) {<a name="line.1177"></a> +<span class="sourceLineNo">1178</span> totalRITs++;<a name="line.1178"></a> +<span class="sourceLineNo">1179</span> final long ritTime = currentTime - state.getStamp();<a name="line.1179"></a> +<span class="sourceLineNo">1180</span> if (ritTime > ritThreshold) {<a name="line.1180"></a> +<span class="sourceLineNo">1181</span> if (ritsOverThreshold == null) {<a name="line.1181"></a> +<span class="sourceLineNo">1182</span> ritsOverThreshold = new HashMap<String, RegionState>();<a name="line.1182"></a> +<span class="sourceLineNo">1183</span> }<a name="line.1183"></a> +<span class="sourceLineNo">1184</span> ritsOverThreshold.put(state.getRegion().getEncodedName(), state);<a name="line.1184"></a> +<span class="sourceLineNo">1185</span> totalRITsTwiceThreshold += (ritTime > (ritThreshold * 2)) ? 1 : 0;<a name="line.1185"></a> +<span class="sourceLineNo">1186</span> }<a name="line.1186"></a> +<span class="sourceLineNo">1187</span> if (oldestRITTime < ritTime) {<a name="line.1187"></a> +<span class="sourceLineNo">1188</span> oldestRITTime = ritTime;<a name="line.1188"></a> +<span class="sourceLineNo">1189</span> }<a name="line.1189"></a> +<span class="sourceLineNo">1190</span> }<a name="line.1190"></a> <span class="sourceLineNo">1191</span> }<a name="line.1191"></a> -<span class="sourceLineNo">1192</span><a name="line.1192"></a> -<span class="sourceLineNo">1193</span> public Collection<RegionState> getRegionOverThreshold() {<a name="line.1193"></a> -<span class="sourceLineNo">1194</span> Map<String, RegionState> m = this.ritsOverThreshold;<a name="line.1194"></a> -<span class="sourceLineNo">1195</span> return m != null? m.values(): Collections.emptySet();<a name="line.1195"></a> -<span class="sourceLineNo">1196</span> }<a name="line.1196"></a> -<span class="sourceLineNo">1197</span><a name="line.1197"></a> -<span class="sourceLineNo">1198</span> public boolean isRegionOverThreshold(final RegionInfo regionInfo) {<a name="line.1198"></a> -<span class="sourceLineNo">1199</span> Map<String, RegionState> m = this.ritsOverThreshold;<a name="line.1199"></a> -<span class="sourceLineNo">1200</span> return m != null && m.containsKey(regionInfo.getEncodedName());<a name="line.1200"></a> -<span class="sourceLineNo">1201</span> }<a name="line.1201"></a> -<span class="sourceLineNo">1202</span><a name="line.1202"></a> -<span class="sourceLineNo">1203</span> public boolean isRegionTwiceOverThreshold(final RegionInfo regionInfo) {<a name="line.1203"></a> -<span class="sourceLineNo">1204</span> Map<String, RegionState> m = this.ritsOverThreshold;<a name="line.1204"></a> -<span class="sourceLineNo">1205</span> if (m == null) return false;<a name="line.1205"></a> -<span class="sourceLineNo">1206</span> final RegionState state = m.get(regionInfo.getEncodedName());<a name="line.1206"></a> -<span class="sourceLineNo">1207</span> if (state == null) return false;<a name="line.1207"></a> -<span class="sourceLineNo">1208</span> return (statTimestamp - state.getStamp()) > (ritThreshold * 2);<a name="line.1208"></a> -<span class="sourceLineNo">1209</span> }<a name="line.1209"></a> -<span class="sourceLineNo">1210</span><a name="line.1210"></a> -<span class="sourceLineNo">1211</span> protected void update(final AssignmentManager am) {<a name="line.1211"></a> -<span class="sourceLineNo">1212</span> final RegionStates regionStates = am.getRegionStates();<a name="line.1212"></a> -<span class="sourceLineNo">1213</span> this.statTimestamp = EnvironmentEdgeManager.currentTime();<a name="line.1213"></a> -<span class="sourceLineNo">1214</span> update(regionStates.getRegionsStateInTransition(), statTimestamp);<a name="line.1214"></a> -<span class="sourceLineNo">1215</span> update(regionStates.getRegionFailedOpen(), statTimestamp);<a name="line.1215"></a> -<span class="sourceLineNo">1216</span> }<a name="line.1216"></a> +<span class="sourceLineNo">1192</span> }<a name="line.1192"></a> +<span class="sourceLineNo">1193</span><a name="line.1193"></a> +<span class="sourceLineNo">1194</span> private void updateRegionsInTransitionMetrics(final RegionInTransitionStat ritStat) {<a name="line.1194"></a> +<span class="sourceLineNo">1195</span> metrics.updateRITOldestAge(ritStat.getOldestRITTime());<a name="line.1195"></a> +<span class="sourceLineNo">1196</span> metrics.updateRITCount(ritStat.getTotalRITs());<a name="line.1196"></a> +<span class="sourceLineNo">1197</span> metrics.updateRITCountOverThreshold(ritStat.getTotalRITsOverThreshold());<a name="line.1197"></a> +<span class="sourceLineNo">1198</span> }<a name="line.1198"></a> +<span class="sourceLineNo">1199</span><a name="line.1199"></a> +<span class="sourceLineNo">1200</span> private void handleRegionOverStuckWarningThreshold(final RegionInfo regionInfo) {<a name="line.1200"></a> +<span class="sourceLineNo">1201</span> final RegionStateNode regionNode = regionStates.getRegionStateNode(regionInfo);<a name="line.1201"></a> +<span class="sourceLineNo">1202</span> //if (regionNode.isStuck()) {<a name="line.1202"></a> +<span class="sourceLineNo">1203</span> LOG.warn("STUCK Region-In-Transition {}", regionNode);<a name="line.1203"></a> +<span class="sourceLineNo">1204</span> }<a name="line.1204"></a> +<span class="sourceLineNo">1205</span><a name="line.1205"></a> +<span class="sourceLineNo">1206</span> // ============================================================================================<a name="line.1206"></a> +<span class="sourceLineNo">1207</span> // TODO: Master load/bootstrap<a name="line.1207"></a> +<span class="sourceLineNo">1208</span> // ============================================================================================<a name="line.1208"></a> +<span class="sourceLineNo">1209</span> public void joinCluster() throws IOException {<a name="line.1209"></a> +<span class="sourceLineNo">1210</span> long startTime = System.nanoTime();<a name="line.1210"></a> +<span class="sourceLineNo">1211</span> LOG.debug("Joining cluster...");<a name="line.1211"></a> +<span class="sourceLineNo">1212</span><a name="line.1212"></a> +<span class="sourceLineNo">1213</span> // Scan hbase:meta to build list of existing regions, servers, and assignment.<a name="line.1213"></a> +<span class="sourceLineNo">1214</span> // hbase:meta is online now or will be. Inside loadMeta, we keep trying. Can't make progress<a name="line.1214"></a> +<span class="sourceLineNo">1215</span> // w/o meta.<a name="line.1215"></a> +<span class="sourceLineNo">1216</span> loadMeta();<a name="line.1216"></a> <span class="sourceLineNo">1217</span><a name="line.1217"></a> -<span class="sourceLineNo">1218</span> private void update(final Collection<RegionState> regions, final long currentTime) {<a name="line.1218"></a> -<span class="sourceLineNo">1219</span> for (RegionState state: regions) {<a name="line.1219"></a> -<span class="sourceLineNo">1220</span> totalRITs++;<a name="line.1220"></a> -<span class="sourceLineNo">1221</span> final long ritTime = currentTime - state.getStamp();<a name="line.1221"></a> -<span class="sourceLineNo">1222</span> if (ritTime > ritThreshold) {<a name="line.1222"></a> -<span class="sourceLineNo">1223</span> if (ritsOverThreshold == null) {<a name="line.1223"></a> -<span class="sourceLineNo">1224</span> ritsOverThreshold = new HashMap<String, RegionState>();<a name="line.1224"></a> -<span class="sourceLineNo">1225</span> }<a name="line.1225"></a> -<span class="sourceLineNo">1226</span> ritsOverThreshold.put(state.getRegion().getEncodedName(), state);<a name="line.1226"></a> -<span class="sourceLineNo">1227</span> totalRITsTwiceThreshold += (ritTime > (ritThreshold * 2)) ? 1 : 0;<a name="line.1227"></a> -<span class="sourceLineNo">1228</span> }<a name="line.1228"></a> -<span class="sourceLineNo">1229</span> if (oldestRITTime < ritTime) {<a name="line.1229"></a> -<span class="sourceLineNo">1230</span> oldestRITTime = ritTime;<a name="line.1230"></a> -<span class="sourceLineNo">1231</span> }<a name="line.1231"></a> -<span class="sourceLineNo">1232</span> }<a name="line.1232"></a> -<span class="sourceLineNo">1233</span> }<a name="line.1233"></a> -<span class="sourceLineNo">1234</span> }<a name="line.1234"></a> -<span class="sourceLineNo">1235</span><a name="line.1235"></a> -<span class="sourceLineNo">1236</span> private void updateRegionsInTransitionMetrics(final RegionInTransitionStat ritStat) {<a name="line.1236"></a> -<span class="sourceLineNo">1237</span> metrics.updateRITOldestAge(ritStat.getOldestRITTime());<a name="line.1237"></a> -<span class="sourceLineNo">1238</span> metrics.updateRITCount(ritStat.getTotalRITs());<a name="line.1238"></a> -<span class="sourceLineNo">1239</span> metrics.updateRITCountOverThreshold(ritStat.getTotalRITsOverThreshold());<a name="line.1239"></a> -<span class="sourceLineNo">1240</span> }<a name="line.1240"></a> -<span class="sourceLineNo">1241</span><a name="line.1241"></a> -<span class="sourceLineNo">1242</span> private void handleRegionOverStuckWarningThreshold(final RegionInfo regionInfo) {<a name="line.1242"></a> -<span class="sourceLineNo">1243</span> final RegionStateNode regionNode = regionStates.getRegionStateNode(regionInfo);<a name="line.1243"></a> -<span class="sourceLineNo">1244</span> //if (regionNode.isStuck()) {<a name="line.1244"></a> -<span class="sourceLineNo">1245</span> LOG.warn("STUCK Region-In-Transition {}", regionNode);<a name="line.1245"></a> -<span class="sourceLineNo">1246</span> }<a name="line.1246"></a> -<span class="sourceLineNo">1247</span><a name="line.1247"></a> -<span class="sourceLineNo">1248</span> // ============================================================================================<a name="line.1248"></a> -<span class="sourceLineNo">1249</span> // TODO: Master load/bootstrap<a name="line.1249"></a> -<span class="sourceLineNo">1250</span> // ============================================================================================<a name="line.1250"></a> -<span class="sourceLineNo">1251</span> public void joinCluster() throws IOException {<a name="line.1251"></a> -<span class="sourceLineNo">1252</span> long startTime = System.nanoTime();<a name="line.1252"></a> -<span class="sourceLineNo">1253</span> LOG.debug("Joining cluster...");<a name="line.1253"></a> -<span class="sourceLineNo">1254</span><a name="line.1254"></a> -<span class="sourceLineNo">1255</span> // Scan hbase:meta to build list of existing regions, servers, and assignment.<a name="line.1255"></a> -<span class="sourceLineNo">1256</span> // hbase:meta is online now or will be. Inside loadMeta, we keep trying. Can't make progress<a name="line.1256"></a> -<span class="sourceLineNo">1257</span> // w/o meta.<a name="line.1257"></a> -<span class="sourceLineNo">1258</span> loadMeta();<a name="line.1258"></a> -<span class="sourceLineNo">1259</span><a name="line.1259"></a> -<span class="sourceLineNo">1260</span> while (master.getServerManager().countOfRegionServers() < 1) {<a name="line.1260"></a> -<span class="sourceLineNo">1261</span> LOG.info("Waiting for RegionServers to join; current count={}",<a name="line.1261"></a> -<span class="sourceLineNo">1262</span> master.getServerManager().countOfRegionServers());<a name="line.1262"></a> -<span class="sourceLineNo">1263</span> Threads.sleep(250);<a name="line.1263"></a> -<span class="sourceLineNo">1264</span> }<a name="line.1264"></a> -<span class="sourceLineNo">1265</span> LOG.info("Number of RegionServers={}", master.getServerManager().countOfRegionServers());<a name="line.1265"></a> -<span class="sourceLineNo">1266</span><a name="line.1266"></a> -<span class="sourceLineNo">1267</span> // Start the RIT chore<a name="line.1267"></a> -<span class="sourceLineNo">1268</span> master.getMasterProcedureExecutor().addChore(this.ritChore);<a name="line.1268"></a> -<span class="sourceLineNo">1269</span><a name="line.1269"></a> -<span class="sourceLineNo">1270</span> long costMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);<a name="line.1270"></a> -<span class="sourceLineNo">1271</span> LOG.info("Joined the cluster in {}", StringUtils.humanTimeDiff(costMs));<a name="line.1271"></a> -<span class="sourceLineNo">1272</span> }<a name="line.1272"></a> -<span class="sourceLineNo">1273</span><a name="line.1273"></a> -<span class="sourceLineNo">1274</span> /**<a name="line.1274"></a> -<span class="sourceLineNo">1275</span> * Create assign procedure for offline regions.<a name="line.1275"></a> -<span class="sourceLineNo">1276</span> * Just follow the old processofflineServersWithOnlineRegions method. Since now we do not need to<a name="line.1276"></a> -<span class="sourceLineNo">1277</span> * deal with dead server any more, we only deal with the regions in OFFLINE state in this method.<a name="line.1277"></a> -<span class="sourceLineNo">1278</span> * And this is a bit strange, that for new regions, we will add it in CLOSED state instead of<a name="line.1278"></a> -<span class="sourceLineNo">1279</span> * OFFLINE state, and usually there will be a procedure to track them. The<a name="line.1279"></a> -<span class="sourceLineNo">1280</span> * processofflineServersWithOnlineRegions is a legacy from long ago, as things are going really<a name="line.1280"></a> -<span class="sourceLineNo">1281</span> * different now, maybe we do not need this method any more. Need to revisit later.<a name="line.1281"></a> -<span class="sourceLineNo">1282</span> */<a name="line.1282"></a> -<span class="sourceLineNo">1283</span> // Public so can be run by the Master as part of the startup. Needs hbase:meta to be online.<a name="line.1283"></a> -<span class="sourceLineNo">1284</span> // Needs to be done after the table state manager has been started.<a name="line.1284"></a> -<span class="sourceLineNo">1285</span> public void processOfflineRegions() {<a name="line.1285"></a> -<span class="sourceLineNo">1286</span> List<RegionInfo> offlineRegions = regionStates.getRegionStates().stream()<a name="line.1286"></a> -<span class="sourceLineNo">1287</span> .filter(RegionState::isOffline).filter(s -> isTableEnabled(s.getRegion().getTable()))<a name="line.1287"></a> -<span class="sourceLineNo">1288</span> .map(RegionState::getRegion).collect(Collectors.toList());<a name="line.1288"></a> -<span class="sourceLineNo">1289</span> if (!offlineRegions.isEmpty()) {<a name="line.1289"></a> -<span class="sourceLineNo">1290</span> master.getMasterProcedureExecutor().submitProcedures(<a name="line.1290"></a> -<span class="sourceLineNo">1291</span> master.getAssignmentManager().createRoundRobinAssignProcedures(offlineRegions));<a name="line.1291"></a> -<span class="sourceLineNo">1292</span> }<a name="line.1292"></a> -<span class="sourceLineNo">1293</span> }<a name="line.1293"></a> -<span class="sourceLineNo">1294</span><a name="line.1294"></a> -<span class="sourceLineNo">1295</span> private void loadMeta() throws IOException {<a name="line.1295"></a> -<span class="sourceLineNo">1296</span> // TODO: use a thread pool<a name="line.1296"></a> -<span class="sourceLineNo">1297</span> regionStateStore.visitMeta(new RegionStateStore.RegionStateVisitor() {<a name="line.1297"></a> -<span class="sourceLineNo">1298</span> @Override<a name="line.1298"></a> -<span class="sourceLineNo">1299</span> public void visitRegionState(Result result, final RegionInfo regionInfo, final State state,<a name="line.1299"></a> -<span class="sourceLineNo">1300</span> final ServerName regionLocation, final ServerName lastHost, final long openSeqNum) {<a name="line.1300"></a> -<span class="sourceLineNo">1301</span> if (state == null && regionLocation == null && lastHost == null &&<a name="line.1301"></a> -<span class="sourceLineNo">1302</span> openSeqNum == SequenceId.NO_SEQUENCE_ID) {<a name="line.1302"></a> -<span class="sourceLineNo">1303</span> // This is a row with nothing in it.<a name="line.1303"></a> -<span class="sourceLineNo">1304</span> LOG.warn("Skipping empty row={}", result);<a name="line.1304"></a> -<span class="sourceLineNo">1305</span> return;<a name="line.1305"></a> -<span class="sourceLineNo">1306</span> }<a name="line.1306"></a> -<span class="sourceLineNo">1307</span> State localState = state;<a name="line.1307"></a> -<span class="sourceLineNo">1308</span> if (localState == null) {<a name="line.1308"></a> -<span class="sourceLineNo">1309</span> // No region state column data in hbase:meta table! Are I doing a rolling upgrade from<a name="line.1309"></a> -<span class="sourceLineNo">1310</span> // hbase1 to hbase2? Am I restoring a SNAPSHOT or otherwise adding a region to hbase:meta?<a name="line.1310"></a> -<span class="sourceLineNo">1311</span> // In any of these cases, state is empty. For now, presume OFFLINE but there are probably<a name="line.1311"></a> -<span class="sourceLineNo">1312</span> // cases where we need to probe more to be sure this correct; TODO informed by experience.<a name="line.1312"></a> -<span class="sourceLineNo">1313</span> LOG.info(regionInfo.getEncodedName() + " regionState=null; presuming " + State.OFFLINE);<a name="line.1313"></a> -<span class="sourceLineNo">1314</span><a name="line.1314"></a> -<span class="sourceLineNo">1315</span> localState = State.OFFLINE;<a name="line.1315"></a> -<span class="sourceLineNo">1316</span> }<a name="line.1316"></a> -<span class="sourceLineNo">1317</span> RegionStateNode regionNode = regionStates.getOrCreateRegionStateNode(regionInfo);<a name="line.1317"></a> -<span class="sourceLineNo">1318</span> // Do not need to lock on regionNode, as we can make sure that before we finish loading<a name="line.1318"></a> -<span class="sourceLineNo">1319</span> // meta, all the related procedures can not be executed. The only exception is formeta<a name="line.1319"></a> -<span class="sourceLineNo">1320</span> // region related operations, but here we do not load the informations for meta region.<a name="line.1320"></a> -<span class="sourceLineNo">1321</span> regionNode.setState(localState);<a name="line.1321"></a> -<span class="sourceLineNo">1322</span> regionNode.setLastHost(lastHost);<a name="line.1322"></a> -<span class="sourceLineNo">1323</span> regionNode.setRegionLocation(regionLocation);<a name="line.1323"></a> -<span class="sourceLineNo">1324</span> regionNode.setOpenSeqNum(openSeqNum);<a name="line.1324"></a> -<span class="sourceLineNo">1325</span><a name="line.1325"></a> -<span class="sourceLineNo">1326</span> if (localState == State.OPEN) {<a name="line.1326"></a> -<span class="sourceLineNo">1327</span> assert regionLocation != null : "found null region location for " + regionNode;<a name="line.1327"></a> -<span class="sourceLineNo">1328</span> regionStates.addRegionToServer(regionNode);<a name="line.1328"></a> -<span class="sourceLineNo">1329</spa
<TRUNCATED>