hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [17/40] hbase-site git commit: Published site at 5fd16f38533591615aa9afa48bb89bcbd8313caf.
Date Sat, 09 Jun 2018 14:49:32 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/4f0b7674/devapidocs/src-html/org/apache/hadoop/hbase/master/assignment/AssignmentManager.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/master/assignment/AssignmentManager.html b/devapidocs/src-html/org/apache/hadoop/hbase/master/assignment/AssignmentManager.html
index 7927e94..7356e7a 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/master/assignment/AssignmentManager.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/master/assignment/AssignmentManager.html
@@ -921,7 +921,7 @@
 <span class="sourceLineNo">913</span>    master.getMasterProcedureExecutor().submitProcedure(createSplitProcedure(parent, splitKey));<a name="line.913"></a>
 <span class="sourceLineNo">914</span><a name="line.914"></a>
 <span class="sourceLineNo">915</span>    // If the RS is &lt; 2.0 throw an exception to abort the operation, we are handling the split<a name="line.915"></a>
-<span class="sourceLineNo">916</span>    if (regionStates.getOrCreateServer(serverName).getVersionNumber() &lt; 0x0200000) {<a name="line.916"></a>
+<span class="sourceLineNo">916</span>    if (master.getServerManager().getServerVersion(serverName) &lt; 0x0200000) {<a name="line.916"></a>
 <span class="sourceLineNo">917</span>      throw new UnsupportedOperationException(String.format(<a name="line.917"></a>
 <span class="sourceLineNo">918</span>        "Split handled by the master: parent=%s hriA=%s hriB=%s", parent.getShortNameToLog(), hriA, hriB));<a name="line.918"></a>
 <span class="sourceLineNo">919</span>    }<a name="line.919"></a>
@@ -944,7 +944,7 @@
 <span class="sourceLineNo">936</span>    master.getMasterProcedureExecutor().submitProcedure(createMergeProcedure(hriA, hriB));<a name="line.936"></a>
 <span class="sourceLineNo">937</span><a name="line.937"></a>
 <span class="sourceLineNo">938</span>    // If the RS is &lt; 2.0 throw an exception to abort the operation, we are handling the merge<a name="line.938"></a>
-<span class="sourceLineNo">939</span>    if (regionStates.getOrCreateServer(serverName).getVersionNumber() &lt; 0x0200000) {<a name="line.939"></a>
+<span class="sourceLineNo">939</span>    if (master.getServerManager().getServerVersion(serverName) &lt; 0x0200000) {<a name="line.939"></a>
 <span class="sourceLineNo">940</span>      throw new UnsupportedOperationException(String.format(<a name="line.940"></a>
 <span class="sourceLineNo">941</span>        "Merge not handled yet: regionState=%s merged=%s hriA=%s hriB=%s", state, merged, hriA,<a name="line.941"></a>
 <span class="sourceLineNo">942</span>          hriB));<a name="line.942"></a>
@@ -956,13 +956,13 @@
 <span class="sourceLineNo">948</span>  // ============================================================================================<a name="line.948"></a>
 <span class="sourceLineNo">949</span>  /**<a name="line.949"></a>
 <span class="sourceLineNo">950</span>   * the master will call this method when the RS send the regionServerReport().<a name="line.950"></a>
-<span class="sourceLineNo">951</span>   * the report will contains the "hbase version" and the "online regions".<a name="line.951"></a>
+<span class="sourceLineNo">951</span>   * the report will contains the "online regions".<a name="line.951"></a>
 <span class="sourceLineNo">952</span>   * this method will check the the online regions against the in-memory state of the AM,<a name="line.952"></a>
 <span class="sourceLineNo">953</span>   * if there is a mismatch we will try to fence out the RS with the assumption<a name="line.953"></a>
 <span class="sourceLineNo">954</span>   * that something went wrong on the RS side.<a name="line.954"></a>
 <span class="sourceLineNo">955</span>   */<a name="line.955"></a>
-<span class="sourceLineNo">956</span>  public void reportOnlineRegions(final ServerName serverName,<a name="line.956"></a>
-<span class="sourceLineNo">957</span>      final int versionNumber, final Set&lt;byte[]&gt; regionNames) throws YouAreDeadException {<a name="line.957"></a>
+<span class="sourceLineNo">956</span>  public void reportOnlineRegions(final ServerName serverName, final Set&lt;byte[]&gt; regionNames)<a name="line.956"></a>
+<span class="sourceLineNo">957</span>      throws YouAreDeadException {<a name="line.957"></a>
 <span class="sourceLineNo">958</span>    if (!isRunning()) return;<a name="line.958"></a>
 <span class="sourceLineNo">959</span>    if (LOG.isTraceEnabled()) {<a name="line.959"></a>
 <span class="sourceLineNo">960</span>      LOG.trace("ReportOnlineRegions " + serverName + " regionCount=" + regionNames.size() +<a name="line.960"></a>
@@ -973,1021 +973,1014 @@
 <span class="sourceLineNo">965</span><a name="line.965"></a>
 <span class="sourceLineNo">966</span>    final ServerStateNode serverNode = regionStates.getOrCreateServer(serverName);<a name="line.966"></a>
 <span class="sourceLineNo">967</span><a name="line.967"></a>
-<span class="sourceLineNo">968</span>    // update the server version number. This will be used for live upgrades.<a name="line.968"></a>
-<span class="sourceLineNo">969</span>    synchronized (serverNode) {<a name="line.969"></a>
-<span class="sourceLineNo">970</span>      serverNode.setVersionNumber(versionNumber);<a name="line.970"></a>
-<span class="sourceLineNo">971</span>      if (serverNode.isInState(ServerState.SPLITTING, ServerState.OFFLINE)) {<a name="line.971"></a>
-<span class="sourceLineNo">972</span>        LOG.warn("Got a report from a server result in state " + serverNode.getState());<a name="line.972"></a>
-<span class="sourceLineNo">973</span>        return;<a name="line.973"></a>
-<span class="sourceLineNo">974</span>      }<a name="line.974"></a>
-<span class="sourceLineNo">975</span>    }<a name="line.975"></a>
-<span class="sourceLineNo">976</span><a name="line.976"></a>
-<span class="sourceLineNo">977</span>    if (regionNames.isEmpty()) {<a name="line.977"></a>
-<span class="sourceLineNo">978</span>      // nothing to do if we don't have regions<a name="line.978"></a>
-<span class="sourceLineNo">979</span>      LOG.trace("no online region found on " + serverName);<a name="line.979"></a>
-<span class="sourceLineNo">980</span>    } else if (!isMetaLoaded()) {<a name="line.980"></a>
-<span class="sourceLineNo">981</span>      // if we are still on startup, discard the report unless is from someone holding meta<a name="line.981"></a>
-<span class="sourceLineNo">982</span>      checkOnlineRegionsReportForMeta(serverNode, regionNames);<a name="line.982"></a>
-<span class="sourceLineNo">983</span>    } else {<a name="line.983"></a>
-<span class="sourceLineNo">984</span>      // The Heartbeat updates us of what regions are only. check and verify the state.<a name="line.984"></a>
-<span class="sourceLineNo">985</span>      checkOnlineRegionsReport(serverNode, regionNames);<a name="line.985"></a>
-<span class="sourceLineNo">986</span>    }<a name="line.986"></a>
-<span class="sourceLineNo">987</span><a name="line.987"></a>
-<span class="sourceLineNo">988</span>    // wake report event<a name="line.988"></a>
-<span class="sourceLineNo">989</span>    wakeServerReportEvent(serverNode);<a name="line.989"></a>
-<span class="sourceLineNo">990</span>  }<a name="line.990"></a>
-<span class="sourceLineNo">991</span><a name="line.991"></a>
-<span class="sourceLineNo">992</span>  void checkOnlineRegionsReportForMeta(final ServerStateNode serverNode,<a name="line.992"></a>
-<span class="sourceLineNo">993</span>      final Set&lt;byte[]&gt; regionNames) {<a name="line.993"></a>
-<span class="sourceLineNo">994</span>    try {<a name="line.994"></a>
-<span class="sourceLineNo">995</span>      for (byte[] regionName: regionNames) {<a name="line.995"></a>
-<span class="sourceLineNo">996</span>        final RegionInfo hri = getMetaRegionFromName(regionName);<a name="line.996"></a>
-<span class="sourceLineNo">997</span>        if (hri == null) {<a name="line.997"></a>
-<span class="sourceLineNo">998</span>          if (LOG.isTraceEnabled()) {<a name="line.998"></a>
-<span class="sourceLineNo">999</span>            LOG.trace("Skip online report for region=" + Bytes.toStringBinary(regionName) +<a name="line.999"></a>
-<span class="sourceLineNo">1000</span>              " while meta is loading");<a name="line.1000"></a>
-<span class="sourceLineNo">1001</span>          }<a name="line.1001"></a>
-<span class="sourceLineNo">1002</span>          continue;<a name="line.1002"></a>
-<span class="sourceLineNo">1003</span>        }<a name="line.1003"></a>
-<span class="sourceLineNo">1004</span><a name="line.1004"></a>
-<span class="sourceLineNo">1005</span>        final RegionStateNode regionNode = regionStates.getOrCreateRegionStateNode(hri);<a name="line.1005"></a>
-<span class="sourceLineNo">1006</span>        LOG.info("META REPORTED: " + regionNode);<a name="line.1006"></a>
-<span class="sourceLineNo">1007</span>        if (!reportTransition(regionNode, serverNode, TransitionCode.OPENED, 0)) {<a name="line.1007"></a>
-<span class="sourceLineNo">1008</span>          LOG.warn("META REPORTED but no procedure found (complete?); set location=" +<a name="line.1008"></a>
-<span class="sourceLineNo">1009</span>              serverNode.getServerName());<a name="line.1009"></a>
-<span class="sourceLineNo">1010</span>          regionNode.setRegionLocation(serverNode.getServerName());<a name="line.1010"></a>
-<span class="sourceLineNo">1011</span>        } else if (LOG.isTraceEnabled()) {<a name="line.1011"></a>
-<span class="sourceLineNo">1012</span>          LOG.trace("META REPORTED: " + regionNode);<a name="line.1012"></a>
-<span class="sourceLineNo">1013</span>        }<a name="line.1013"></a>
-<span class="sourceLineNo">1014</span>      }<a name="line.1014"></a>
-<span class="sourceLineNo">1015</span>    } catch (UnexpectedStateException e) {<a name="line.1015"></a>
-<span class="sourceLineNo">1016</span>      final ServerName serverName = serverNode.getServerName();<a name="line.1016"></a>
-<span class="sourceLineNo">1017</span>      LOG.warn("KILLING " + serverName + ": " + e.getMessage());<a name="line.1017"></a>
-<span class="sourceLineNo">1018</span>      killRegionServer(serverNode);<a name="line.1018"></a>
-<span class="sourceLineNo">1019</span>    }<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 checkOnlineRegionsReport(final ServerStateNode serverNode, final Set&lt;byte[]&gt; regionNames)<a name="line.1022"></a>
-<span class="sourceLineNo">1023</span>      throws YouAreDeadException {<a name="line.1023"></a>
-<span class="sourceLineNo">1024</span>    final ServerName serverName = serverNode.getServerName();<a name="line.1024"></a>
-<span class="sourceLineNo">1025</span>    try {<a name="line.1025"></a>
-<span class="sourceLineNo">1026</span>      for (byte[] regionName: regionNames) {<a name="line.1026"></a>
-<span class="sourceLineNo">1027</span>        if (!isRunning()) return;<a name="line.1027"></a>
-<span class="sourceLineNo">1028</span>        final RegionStateNode regionNode = regionStates.getRegionStateNodeFromName(regionName);<a name="line.1028"></a>
-<span class="sourceLineNo">1029</span>        if (regionNode == null) {<a name="line.1029"></a>
-<span class="sourceLineNo">1030</span>          throw new UnexpectedStateException("Not online: " + Bytes.toStringBinary(regionName));<a name="line.1030"></a>
-<span class="sourceLineNo">1031</span>        }<a name="line.1031"></a>
-<span class="sourceLineNo">1032</span>        synchronized (regionNode) {<a name="line.1032"></a>
-<span class="sourceLineNo">1033</span>          if (regionNode.isInState(State.OPENING, State.OPEN)) {<a name="line.1033"></a>
-<span class="sourceLineNo">1034</span>            if (!regionNode.getRegionLocation().equals(serverName)) {<a name="line.1034"></a>
-<span class="sourceLineNo">1035</span>              throw new UnexpectedStateException(regionNode.toString() +<a name="line.1035"></a>
-<span class="sourceLineNo">1036</span>                "reported OPEN on server=" + serverName +<a name="line.1036"></a>
-<span class="sourceLineNo">1037</span>                " but state has otherwise.");<a name="line.1037"></a>
-<span class="sourceLineNo">1038</span>            } else if (regionNode.isInState(State.OPENING)) {<a name="line.1038"></a>
-<span class="sourceLineNo">1039</span>              try {<a name="line.1039"></a>
-<span class="sourceLineNo">1040</span>                if (!reportTransition(regionNode, serverNode, TransitionCode.OPENED, 0)) {<a name="line.1040"></a>
-<span class="sourceLineNo">1041</span>                  LOG.warn(regionNode.toString() + " reported OPEN on server=" + serverName +<a name="line.1041"></a>
-<span class="sourceLineNo">1042</span>                    " but state has otherwise AND NO procedure is running");<a name="line.1042"></a>
-<span class="sourceLineNo">1043</span>                }<a name="line.1043"></a>
-<span class="sourceLineNo">1044</span>              } catch (UnexpectedStateException e) {<a name="line.1044"></a>
-<span class="sourceLineNo">1045</span>                LOG.warn(regionNode.toString() + " reported unexpteced OPEN: " + e.getMessage(), e);<a name="line.1045"></a>
-<span class="sourceLineNo">1046</span>              }<a name="line.1046"></a>
-<span class="sourceLineNo">1047</span>            }<a name="line.1047"></a>
-<span class="sourceLineNo">1048</span>          } else if (!regionNode.isInState(State.CLOSING, State.SPLITTING)) {<a name="line.1048"></a>
-<span class="sourceLineNo">1049</span>            long diff = regionNode.getLastUpdate() - EnvironmentEdgeManager.currentTime();<a name="line.1049"></a>
-<span class="sourceLineNo">1050</span>            if (diff &gt; 1000/*One Second... make configurable if an issue*/) {<a name="line.1050"></a>
-<span class="sourceLineNo">1051</span>              // So, we can get report that a region is CLOSED or SPLIT because a heartbeat<a name="line.1051"></a>
-<span class="sourceLineNo">1052</span>              // came in at about same time as a region transition. Make sure there is some<a name="line.1052"></a>
-<span class="sourceLineNo">1053</span>              // elapsed time between killing remote server.<a name="line.1053"></a>
-<span class="sourceLineNo">1054</span>              throw new UnexpectedStateException(regionNode.toString() +<a name="line.1054"></a>
-<span class="sourceLineNo">1055</span>                " reported an unexpected OPEN; time since last update=" + 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>        }<a name="line.1058"></a>
-<span class="sourceLineNo">1059</span>      }<a name="line.1059"></a>
-<span class="sourceLineNo">1060</span>    } catch (UnexpectedStateException e) {<a name="line.1060"></a>
-<span class="sourceLineNo">1061</span>      LOG.warn("Killing " + serverName + ": " + e.getMessage());<a name="line.1061"></a>
-<span class="sourceLineNo">1062</span>      killRegionServer(serverNode);<a name="line.1062"></a>
-<span class="sourceLineNo">1063</span>      throw (YouAreDeadException)new YouAreDeadException(e.getMessage()).initCause(e);<a name="line.1063"></a>
-<span class="sourceLineNo">1064</span>    }<a name="line.1064"></a>
-<span class="sourceLineNo">1065</span>  }<a name="line.1065"></a>
-<span class="sourceLineNo">1066</span><a name="line.1066"></a>
-<span class="sourceLineNo">1067</span>  protected boolean waitServerReportEvent(final ServerName serverName, final Procedure proc) {<a name="line.1067"></a>
-<span class="sourceLineNo">1068</span>    final ServerStateNode serverNode = regionStates.getOrCreateServer(serverName);<a name="line.1068"></a>
-<span class="sourceLineNo">1069</span>    if (serverNode == null) {<a name="line.1069"></a>
-<span class="sourceLineNo">1070</span>      LOG.warn("serverName=null; {}", proc);<a name="line.1070"></a>
-<span class="sourceLineNo">1071</span>    }<a name="line.1071"></a>
-<span class="sourceLineNo">1072</span>    return serverNode.getReportEvent().suspendIfNotReady(proc);<a name="line.1072"></a>
-<span class="sourceLineNo">1073</span>  }<a name="line.1073"></a>
-<span class="sourceLineNo">1074</span><a name="line.1074"></a>
-<span class="sourceLineNo">1075</span>  protected void wakeServerReportEvent(final ServerStateNode serverNode) {<a name="line.1075"></a>
-<span class="sourceLineNo">1076</span>    serverNode.getReportEvent().wake(getProcedureScheduler());<a name="line.1076"></a>
-<span class="sourceLineNo">1077</span>  }<a name="line.1077"></a>
-<span class="sourceLineNo">1078</span><a name="line.1078"></a>
+<span class="sourceLineNo">968</span>    synchronized (serverNode) {<a name="line.968"></a>
+<span class="sourceLineNo">969</span>      if (serverNode.isInState(ServerState.SPLITTING, ServerState.OFFLINE)) {<a name="line.969"></a>
+<span class="sourceLineNo">970</span>        LOG.warn("Got a report from a server result in state " + serverNode.getState());<a name="line.970"></a>
+<span class="sourceLineNo">971</span>        return;<a name="line.971"></a>
+<span class="sourceLineNo">972</span>      }<a name="line.972"></a>
+<span class="sourceLineNo">973</span>    }<a name="line.973"></a>
+<span class="sourceLineNo">974</span><a name="line.974"></a>
+<span class="sourceLineNo">975</span>    if (regionNames.isEmpty()) {<a name="line.975"></a>
+<span class="sourceLineNo">976</span>      // nothing to do if we don't have regions<a name="line.976"></a>
+<span class="sourceLineNo">977</span>      LOG.trace("no online region found on " + serverName);<a name="line.977"></a>
+<span class="sourceLineNo">978</span>    } else if (!isMetaLoaded()) {<a name="line.978"></a>
+<span class="sourceLineNo">979</span>      // if we are still on startup, discard the report unless is from someone holding meta<a name="line.979"></a>
+<span class="sourceLineNo">980</span>      checkOnlineRegionsReportForMeta(serverNode, regionNames);<a name="line.980"></a>
+<span class="sourceLineNo">981</span>    } else {<a name="line.981"></a>
+<span class="sourceLineNo">982</span>      // The Heartbeat updates us of what regions are only. check and verify the state.<a name="line.982"></a>
+<span class="sourceLineNo">983</span>      checkOnlineRegionsReport(serverNode, regionNames);<a name="line.983"></a>
+<span class="sourceLineNo">984</span>    }<a name="line.984"></a>
+<span class="sourceLineNo">985</span><a name="line.985"></a>
+<span class="sourceLineNo">986</span>    // wake report event<a name="line.986"></a>
+<span class="sourceLineNo">987</span>    wakeServerReportEvent(serverNode);<a name="line.987"></a>
+<span class="sourceLineNo">988</span>  }<a name="line.988"></a>
+<span class="sourceLineNo">989</span><a name="line.989"></a>
+<span class="sourceLineNo">990</span>  void checkOnlineRegionsReportForMeta(final ServerStateNode serverNode,<a name="line.990"></a>
+<span class="sourceLineNo">991</span>      final Set&lt;byte[]&gt; regionNames) {<a name="line.991"></a>
+<span class="sourceLineNo">992</span>    try {<a name="line.992"></a>
+<span class="sourceLineNo">993</span>      for (byte[] regionName: regionNames) {<a name="line.993"></a>
+<span class="sourceLineNo">994</span>        final RegionInfo hri = getMetaRegionFromName(regionName);<a name="line.994"></a>
+<span class="sourceLineNo">995</span>        if (hri == null) {<a name="line.995"></a>
+<span class="sourceLineNo">996</span>          if (LOG.isTraceEnabled()) {<a name="line.996"></a>
+<span class="sourceLineNo">997</span>            LOG.trace("Skip online report for region=" + Bytes.toStringBinary(regionName) +<a name="line.997"></a>
+<span class="sourceLineNo">998</span>              " while meta is loading");<a name="line.998"></a>
+<span class="sourceLineNo">999</span>          }<a name="line.999"></a>
+<span class="sourceLineNo">1000</span>          continue;<a name="line.1000"></a>
+<span class="sourceLineNo">1001</span>        }<a name="line.1001"></a>
+<span class="sourceLineNo">1002</span><a name="line.1002"></a>
+<span class="sourceLineNo">1003</span>        final RegionStateNode regionNode = regionStates.getOrCreateRegionStateNode(hri);<a name="line.1003"></a>
+<span class="sourceLineNo">1004</span>        LOG.info("META REPORTED: " + regionNode);<a name="line.1004"></a>
+<span class="sourceLineNo">1005</span>        if (!reportTransition(regionNode, serverNode, TransitionCode.OPENED, 0)) {<a name="line.1005"></a>
+<span class="sourceLineNo">1006</span>          LOG.warn("META REPORTED but no procedure found (complete?); set location=" +<a name="line.1006"></a>
+<span class="sourceLineNo">1007</span>              serverNode.getServerName());<a name="line.1007"></a>
+<span class="sourceLineNo">1008</span>          regionNode.setRegionLocation(serverNode.getServerName());<a name="line.1008"></a>
+<span class="sourceLineNo">1009</span>        } else if (LOG.isTraceEnabled()) {<a name="line.1009"></a>
+<span class="sourceLineNo">1010</span>          LOG.trace("META REPORTED: " + regionNode);<a name="line.1010"></a>
+<span class="sourceLineNo">1011</span>        }<a name="line.1011"></a>
+<span class="sourceLineNo">1012</span>      }<a name="line.1012"></a>
+<span class="sourceLineNo">1013</span>    } catch (UnexpectedStateException e) {<a name="line.1013"></a>
+<span class="sourceLineNo">1014</span>      final ServerName serverName = serverNode.getServerName();<a name="line.1014"></a>
+<span class="sourceLineNo">1015</span>      LOG.warn("KILLING " + serverName + ": " + e.getMessage());<a name="line.1015"></a>
+<span class="sourceLineNo">1016</span>      killRegionServer(serverNode);<a name="line.1016"></a>
+<span class="sourceLineNo">1017</span>    }<a name="line.1017"></a>
+<span class="sourceLineNo">1018</span>  }<a name="line.1018"></a>
+<span class="sourceLineNo">1019</span><a name="line.1019"></a>
+<span class="sourceLineNo">1020</span>  void checkOnlineRegionsReport(final ServerStateNode serverNode, final Set&lt;byte[]&gt; regionNames)<a name="line.1020"></a>
+<span class="sourceLineNo">1021</span>      throws YouAreDeadException {<a name="line.1021"></a>
+<span class="sourceLineNo">1022</span>    final ServerName serverName = serverNode.getServerName();<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>        if (!isRunning()) return;<a name="line.1025"></a>
+<span class="sourceLineNo">1026</span>        final RegionStateNode regionNode = regionStates.getRegionStateNodeFromName(regionName);<a name="line.1026"></a>
+<span class="sourceLineNo">1027</span>        if (regionNode == null) {<a name="line.1027"></a>
+<span class="sourceLineNo">1028</span>          throw new UnexpectedStateException("Not online: " + Bytes.toStringBinary(regionName));<a name="line.1028"></a>
+<span class="sourceLineNo">1029</span>        }<a name="line.1029"></a>
+<span class="sourceLineNo">1030</span>        synchronized (regionNode) {<a name="line.1030"></a>
+<span class="sourceLineNo">1031</span>          if (regionNode.isInState(State.OPENING, State.OPEN)) {<a name="line.1031"></a>
+<span class="sourceLineNo">1032</span>            if (!regionNode.getRegionLocation().equals(serverName)) {<a name="line.1032"></a>
+<span class="sourceLineNo">1033</span>              throw new UnexpectedStateException(regionNode.toString() +<a name="line.1033"></a>
+<span class="sourceLineNo">1034</span>                "reported OPEN on server=" + serverName +<a name="line.1034"></a>
+<span class="sourceLineNo">1035</span>                " but state has otherwise.");<a name="line.1035"></a>
+<span class="sourceLineNo">1036</span>            } else if (regionNode.isInState(State.OPENING)) {<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(regionNode.toString() + " reported OPEN on server=" + serverName +<a name="line.1039"></a>
+<span class="sourceLineNo">1040</span>                    " but state has otherwise AND NO procedure is running");<a name="line.1040"></a>
+<span class="sourceLineNo">1041</span>                }<a name="line.1041"></a>
+<span class="sourceLineNo">1042</span>              } catch (UnexpectedStateException e) {<a name="line.1042"></a>
+<span class="sourceLineNo">1043</span>                LOG.warn(regionNode.toString() + " reported unexpteced OPEN: " + e.getMessage(), e);<a name="line.1043"></a>
+<span class="sourceLineNo">1044</span>              }<a name="line.1044"></a>
+<span class="sourceLineNo">1045</span>            }<a name="line.1045"></a>
+<span class="sourceLineNo">1046</span>          } else if (!regionNode.isInState(State.CLOSING, State.SPLITTING)) {<a name="line.1046"></a>
+<span class="sourceLineNo">1047</span>            long diff = regionNode.getLastUpdate() - EnvironmentEdgeManager.currentTime();<a name="line.1047"></a>
+<span class="sourceLineNo">1048</span>            if (diff &gt; 1000/*One Second... make configurable if an issue*/) {<a name="line.1048"></a>
+<span class="sourceLineNo">1049</span>              // So, we can get report that a region is CLOSED or SPLIT because a heartbeat<a name="line.1049"></a>
+<span class="sourceLineNo">1050</span>              // came in at about same time as a region transition. Make sure there is some<a name="line.1050"></a>
+<span class="sourceLineNo">1051</span>              // elapsed time between killing remote server.<a name="line.1051"></a>
+<span class="sourceLineNo">1052</span>              throw new UnexpectedStateException(regionNode.toString() +<a name="line.1052"></a>
+<span class="sourceLineNo">1053</span>                " reported an unexpected OPEN; time since last update=" + diff);<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>        }<a name="line.1056"></a>
+<span class="sourceLineNo">1057</span>      }<a name="line.1057"></a>
+<span class="sourceLineNo">1058</span>    } catch (UnexpectedStateException e) {<a name="line.1058"></a>
+<span class="sourceLineNo">1059</span>      LOG.warn("Killing " + serverName + ": " + e.getMessage());<a name="line.1059"></a>
+<span class="sourceLineNo">1060</span>      killRegionServer(serverNode);<a name="line.1060"></a>
+<span class="sourceLineNo">1061</span>      throw (YouAreDeadException)new YouAreDeadException(e.getMessage()).initCause(e);<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><a name="line.1064"></a>
+<span class="sourceLineNo">1065</span>  protected boolean waitServerReportEvent(final ServerName serverName, final Procedure proc) {<a name="line.1065"></a>
+<span class="sourceLineNo">1066</span>    final ServerStateNode serverNode = regionStates.getOrCreateServer(serverName);<a name="line.1066"></a>
+<span class="sourceLineNo">1067</span>    if (serverNode == null) {<a name="line.1067"></a>
+<span class="sourceLineNo">1068</span>      LOG.warn("serverName=null; {}", proc);<a name="line.1068"></a>
+<span class="sourceLineNo">1069</span>    }<a name="line.1069"></a>
+<span class="sourceLineNo">1070</span>    return serverNode.getReportEvent().suspendIfNotReady(proc);<a name="line.1070"></a>
+<span class="sourceLineNo">1071</span>  }<a name="line.1071"></a>
+<span class="sourceLineNo">1072</span><a name="line.1072"></a>
+<span class="sourceLineNo">1073</span>  protected void wakeServerReportEvent(final ServerStateNode serverNode) {<a name="line.1073"></a>
+<span class="sourceLineNo">1074</span>    serverNode.getReportEvent().wake(getProcedureScheduler());<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>  // ============================================================================================<a name="line.1077"></a>
+<span class="sourceLineNo">1078</span>  //  RIT chore<a name="line.1078"></a>
 <span class="sourceLineNo">1079</span>  // ============================================================================================<a name="line.1079"></a>
-<span class="sourceLineNo">1080</span>  //  RIT chore<a name="line.1080"></a>
-<span class="sourceLineNo">1081</span>  // ============================================================================================<a name="line.1081"></a>
-<span class="sourceLineNo">1082</span>  private static class RegionInTransitionChore extends ProcedureInMemoryChore&lt;MasterProcedureEnv&gt; {<a name="line.1082"></a>
-<span class="sourceLineNo">1083</span>    public RegionInTransitionChore(final int timeoutMsec) {<a name="line.1083"></a>
-<span class="sourceLineNo">1084</span>      super(timeoutMsec);<a name="line.1084"></a>
-<span class="sourceLineNo">1085</span>    }<a name="line.1085"></a>
-<span class="sourceLineNo">1086</span><a name="line.1086"></a>
-<span class="sourceLineNo">1087</span>    @Override<a name="line.1087"></a>
-<span class="sourceLineNo">1088</span>    protected void periodicExecute(final MasterProcedureEnv env) {<a name="line.1088"></a>
-<span class="sourceLineNo">1089</span>      final AssignmentManager am = env.getAssignmentManager();<a name="line.1089"></a>
-<span class="sourceLineNo">1090</span><a name="line.1090"></a>
-<span class="sourceLineNo">1091</span>      final RegionInTransitionStat ritStat = am.computeRegionInTransitionStat();<a name="line.1091"></a>
-<span class="sourceLineNo">1092</span>      if (ritStat.hasRegionsOverThreshold()) {<a name="line.1092"></a>
-<span class="sourceLineNo">1093</span>        for (RegionState hri: ritStat.getRegionOverThreshold()) {<a name="line.1093"></a>
-<span class="sourceLineNo">1094</span>          am.handleRegionOverStuckWarningThreshold(hri.getRegion());<a name="line.1094"></a>
-<span class="sourceLineNo">1095</span>        }<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>      // update metrics<a name="line.1098"></a>
-<span class="sourceLineNo">1099</span>      am.updateRegionsInTransitionMetrics(ritStat);<a name="line.1099"></a>
-<span class="sourceLineNo">1100</span>    }<a name="line.1100"></a>
-<span class="sourceLineNo">1101</span>  }<a name="line.1101"></a>
-<span class="sourceLineNo">1102</span><a name="line.1102"></a>
-<span class="sourceLineNo">1103</span>  public RegionInTransitionStat computeRegionInTransitionStat() {<a name="line.1103"></a>
-<span class="sourceLineNo">1104</span>    final RegionInTransitionStat rit = new RegionInTransitionStat(getConfiguration());<a name="line.1104"></a>
-<span class="sourceLineNo">1105</span>    rit.update(this);<a name="line.1105"></a>
-<span class="sourceLineNo">1106</span>    return rit;<a name="line.1106"></a>
-<span class="sourceLineNo">1107</span>  }<a name="line.1107"></a>
-<span class="sourceLineNo">1108</span><a name="line.1108"></a>
-<span class="sourceLineNo">1109</span>  public static class RegionInTransitionStat {<a name="line.1109"></a>
-<span class="sourceLineNo">1110</span>    private final int ritThreshold;<a name="line.1110"></a>
-<span class="sourceLineNo">1111</span><a name="line.1111"></a>
-<span class="sourceLineNo">1112</span>    private HashMap&lt;String, RegionState&gt; ritsOverThreshold = null;<a name="line.1112"></a>
-<span class="sourceLineNo">1113</span>    private long statTimestamp;<a name="line.1113"></a>
-<span class="sourceLineNo">1114</span>    private long oldestRITTime = 0;<a name="line.1114"></a>
-<span class="sourceLineNo">1115</span>    private int totalRITsTwiceThreshold = 0;<a name="line.1115"></a>
-<span class="sourceLineNo">1116</span>    private int totalRITs = 0;<a name="line.1116"></a>
-<span class="sourceLineNo">1117</span><a name="line.1117"></a>
-<span class="sourceLineNo">1118</span>    @VisibleForTesting<a name="line.1118"></a>
-<span class="sourceLineNo">1119</span>    public RegionInTransitionStat(final Configuration conf) {<a name="line.1119"></a>
-<span class="sourceLineNo">1120</span>      this.ritThreshold =<a name="line.1120"></a>
-<span class="sourceLineNo">1121</span>        conf.getInt(METRICS_RIT_STUCK_WARNING_THRESHOLD, DEFAULT_RIT_STUCK_WARNING_THRESHOLD);<a name="line.1121"></a>
-<span class="sourceLineNo">1122</span>    }<a name="line.1122"></a>
-<span class="sourceLineNo">1123</span><a name="line.1123"></a>
-<span class="sourceLineNo">1124</span>    public int getRITThreshold() {<a name="line.1124"></a>
-<span class="sourceLineNo">1125</span>      return ritThreshold;<a name="line.1125"></a>
-<span class="sourceLineNo">1126</span>    }<a name="line.1126"></a>
-<span class="sourceLineNo">1127</span><a name="line.1127"></a>
-<span class="sourceLineNo">1128</span>    public long getTimestamp() {<a name="line.1128"></a>
-<span class="sourceLineNo">1129</span>      return statTimestamp;<a name="line.1129"></a>
-<span class="sourceLineNo">1130</span>    }<a name="line.1130"></a>
-<span class="sourceLineNo">1131</span><a name="line.1131"></a>
-<span class="sourceLineNo">1132</span>    public int getTotalRITs() {<a name="line.1132"></a>
-<span class="sourceLineNo">1133</span>      return totalRITs;<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">1136</span>    public long getOldestRITTime() {<a name="line.1136"></a>
-<span class="sourceLineNo">1137</span>      return oldestRITTime;<a name="line.1137"></a>
-<span class="sourceLineNo">1138</span>    }<a name="line.1138"></a>
-<span class="sourceLineNo">1139</span><a name="line.1139"></a>
-<span class="sourceLineNo">1140</span>    public int getTotalRITsOverThreshold() {<a name="line.1140"></a>
-<span class="sourceLineNo">1141</span>      Map&lt;String, RegionState&gt; m = this.ritsOverThreshold;<a name="line.1141"></a>
-<span class="sourceLineNo">1142</span>      return m != null ? m.size() : 0;<a name="line.1142"></a>
-<span class="sourceLineNo">1143</span>    }<a name="line.1143"></a>
-<span class="sourceLineNo">1144</span><a name="line.1144"></a>
-<span class="sourceLineNo">1145</span>    public boolean hasRegionsTwiceOverThreshold() {<a name="line.1145"></a>
-<span class="sourceLineNo">1146</span>      return totalRITsTwiceThreshold &gt; 0;<a name="line.1146"></a>
-<span class="sourceLineNo">1147</span>    }<a name="line.1147"></a>
-<span class="sourceLineNo">1148</span><a name="line.1148"></a>
-<span class="sourceLineNo">1149</span>    public boolean hasRegionsOverThreshold() {<a name="line.1149"></a>
-<span class="sourceLineNo">1150</span>      Map&lt;String, RegionState&gt; m = this.ritsOverThreshold;<a name="line.1150"></a>
-<span class="sourceLineNo">1151</span>      return m != null &amp;&amp; !m.isEmpty();<a name="line.1151"></a>
-<span class="sourceLineNo">1152</span>    }<a name="line.1152"></a>
-<span class="sourceLineNo">1153</span><a name="line.1153"></a>
-<span class="sourceLineNo">1154</span>    public Collection&lt;RegionState&gt; getRegionOverThreshold() {<a name="line.1154"></a>
-<span class="sourceLineNo">1155</span>      Map&lt;String, RegionState&gt; m = this.ritsOverThreshold;<a name="line.1155"></a>
-<span class="sourceLineNo">1156</span>      return m != null? m.values(): Collections.EMPTY_SET;<a name="line.1156"></a>
-<span class="sourceLineNo">1157</span>    }<a name="line.1157"></a>
-<span class="sourceLineNo">1158</span><a name="line.1158"></a>
-<span class="sourceLineNo">1159</span>    public boolean isRegionOverThreshold(final RegionInfo regionInfo) {<a name="line.1159"></a>
-<span class="sourceLineNo">1160</span>      Map&lt;String, RegionState&gt; m = this.ritsOverThreshold;<a name="line.1160"></a>
-<span class="sourceLineNo">1161</span>      return m != null &amp;&amp; m.containsKey(regionInfo.getEncodedName());<a name="line.1161"></a>
-<span class="sourceLineNo">1162</span>    }<a name="line.1162"></a>
-<span class="sourceLineNo">1163</span><a name="line.1163"></a>
-<span class="sourceLineNo">1164</span>    public boolean isRegionTwiceOverThreshold(final RegionInfo regionInfo) {<a name="line.1164"></a>
-<span class="sourceLineNo">1165</span>      Map&lt;String, RegionState&gt; m = this.ritsOverThreshold;<a name="line.1165"></a>
-<span class="sourceLineNo">1166</span>      if (m == null) return false;<a name="line.1166"></a>
-<span class="sourceLineNo">1167</span>      final RegionState state = m.get(regionInfo.getEncodedName());<a name="line.1167"></a>
-<span class="sourceLineNo">1168</span>      if (state == null) return false;<a name="line.1168"></a>
-<span class="sourceLineNo">1169</span>      return (statTimestamp - state.getStamp()) &gt; (ritThreshold * 2);<a name="line.1169"></a>
-<span class="sourceLineNo">1170</span>    }<a name="line.1170"></a>
-<span class="sourceLineNo">1171</span><a name="line.1171"></a>
-<span class="sourceLineNo">1172</span>    protected void update(final AssignmentManager am) {<a name="line.1172"></a>
-<span class="sourceLineNo">1173</span>      final RegionStates regionStates = am.getRegionStates();<a name="line.1173"></a>
-<span class="sourceLineNo">1174</span>      this.statTimestamp = EnvironmentEdgeManager.currentTime();<a name="line.1174"></a>
-<span class="sourceLineNo">1175</span>      update(regionStates.getRegionsStateInTransition(), statTimestamp);<a name="line.1175"></a>
-<span class="sourceLineNo">1176</span>      update(regionStates.getRegionFailedOpen(), statTimestamp);<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>    private void update(final Collection&lt;RegionState&gt; regions, final long currentTime) {<a name="line.1179"></a>
-<span class="sourceLineNo">1180</span>      for (RegionState state: regions) {<a name="line.1180"></a>
-<span class="sourceLineNo">1181</span>        totalRITs++;<a name="line.1181"></a>
-<span class="sourceLineNo">1182</span>        final long ritTime = currentTime - state.getStamp();<a name="line.1182"></a>
-<span class="sourceLineNo">1183</span>        if (ritTime &gt; ritThreshold) {<a name="line.1183"></a>
-<span class="sourceLineNo">1184</span>          if (ritsOverThreshold == null) {<a name="line.1184"></a>
-<span class="sourceLineNo">1185</span>            ritsOverThreshold = new HashMap&lt;String, RegionState&gt;();<a name="line.1185"></a>
-<span class="sourceLineNo">1186</span>          }<a name="line.1186"></a>
-<span class="sourceLineNo">1187</span>          ritsOverThreshold.put(state.getRegion().getEncodedName(), state);<a name="line.1187"></a>
-<span class="sourceLineNo">1188</span>          totalRITsTwiceThreshold += (ritTime &gt; (ritThreshold * 2)) ? 1 : 0;<a name="line.1188"></a>
-<span class="sourceLineNo">1189</span>        }<a name="line.1189"></a>
-<span class="sourceLineNo">1190</span>        if (oldestRITTime &lt; ritTime) {<a name="line.1190"></a>
-<span class="sourceLineNo">1191</span>          oldestRITTime = ritTime;<a name="line.1191"></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>    }<a name="line.1194"></a>
-<span class="sourceLineNo">1195</span>  }<a name="line.1195"></a>
-<span class="sourceLineNo">1196</span><a name="line.1196"></a>
-<span class="sourceLineNo">1197</span>  private void updateRegionsInTransitionMetrics(final RegionInTransitionStat ritStat) {<a name="line.1197"></a>
-<span class="sourceLineNo">1198</span>    metrics.updateRITOldestAge(ritStat.getOldestRITTime());<a name="line.1198"></a>
-<span class="sourceLineNo">1199</span>    metrics.updateRITCount(ritStat.getTotalRITs());<a name="line.1199"></a>
-<span class="sourceLineNo">1200</span>    metrics.updateRITCountOverThreshold(ritStat.getTotalRITsOverThreshold());<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>  private void handleRegionOverStuckWarningThreshold(final RegionInfo regionInfo) {<a name="line.1203"></a>
-<span class="sourceLineNo">1204</span>    final RegionStateNode regionNode = regionStates.getRegionStateNode(regionInfo);<a name="line.1204"></a>
-<span class="sourceLineNo">1205</span>    //if (regionNode.isStuck()) {<a name="line.1205"></a>
-<span class="sourceLineNo">1206</span>    LOG.warn("STUCK Region-In-Transition {}", regionNode);<a name="line.1206"></a>
-<span class="sourceLineNo">1207</span>  }<a name="line.1207"></a>
-<span class="sourceLineNo">1208</span><a name="line.1208"></a>
+<span class="sourceLineNo">1080</span>  private static class RegionInTransitionChore extends ProcedureInMemoryChore&lt;MasterProcedureEnv&gt; {<a name="line.1080"></a>
+<span class="sourceLineNo">1081</span>    public RegionInTransitionChore(final int timeoutMsec) {<a name="line.1081"></a>
+<span class="sourceLineNo">1082</span>      super(timeoutMsec);<a name="line.1082"></a>
+<span class="sourceLineNo">1083</span>    }<a name="line.1083"></a>
+<span class="sourceLineNo">1084</span><a name="line.1084"></a>
+<span class="sourceLineNo">1085</span>    @Override<a name="line.1085"></a>
+<span class="sourceLineNo">1086</span>    protected void periodicExecute(final MasterProcedureEnv env) {<a name="line.1086"></a>
+<span class="sourceLineNo">1087</span>      final AssignmentManager am = env.getAssignmentManager();<a name="line.1087"></a>
+<span class="sourceLineNo">1088</span><a name="line.1088"></a>
+<span class="sourceLineNo">1089</span>      final RegionInTransitionStat ritStat = am.computeRegionInTransitionStat();<a name="line.1089"></a>
+<span class="sourceLineNo">1090</span>      if (ritStat.hasRegionsOverThreshold()) {<a name="line.1090"></a>
+<span class="sourceLineNo">1091</span>        for (RegionState hri: ritStat.getRegionOverThreshold()) {<a name="line.1091"></a>
+<span class="sourceLineNo">1092</span>          am.handleRegionOverStuckWarningThreshold(hri.getRegion());<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><a name="line.1095"></a>
+<span class="sourceLineNo">1096</span>      // update metrics<a name="line.1096"></a>
+<span class="sourceLineNo">1097</span>      am.updateRegionsInTransitionMetrics(ritStat);<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><a name="line.1100"></a>
+<span class="sourceLineNo">1101</span>  public RegionInTransitionStat computeRegionInTransitionStat() {<a name="line.1101"></a>
+<span class="sourceLineNo">1102</span>    final RegionInTransitionStat rit = new RegionInTransitionStat(getConfiguration());<a name="line.1102"></a>
+<span class="sourceLineNo">1103</span>    rit.update(this);<a name="line.1103"></a>
+<span class="sourceLineNo">1104</span>    return rit;<a name="line.1104"></a>
+<span class="sourceLineNo">1105</span>  }<a name="line.1105"></a>
+<span class="sourceLineNo">1106</span><a name="line.1106"></a>
+<span class="sourceLineNo">1107</span>  public static class RegionInTransitionStat {<a name="line.1107"></a>
+<span class="sourceLineNo">1108</span>    private final int ritThreshold;<a name="line.1108"></a>
+<span class="sourceLineNo">1109</span><a name="line.1109"></a>
+<span class="sourceLineNo">1110</span>    private HashMap&lt;String, RegionState&gt; ritsOverThreshold = null;<a name="line.1110"></a>
+<span class="sourceLineNo">1111</span>    private long statTimestamp;<a name="line.1111"></a>
+<span class="sourceLineNo">1112</span>    private long oldestRITTime = 0;<a name="line.1112"></a>
+<span class="sourceLineNo">1113</span>    private int totalRITsTwiceThreshold = 0;<a name="line.1113"></a>
+<span class="sourceLineNo">1114</span>    private int totalRITs = 0;<a name="line.1114"></a>
+<span class="sourceLineNo">1115</span><a name="line.1115"></a>
+<span class="sourceLineNo">1116</span>    @VisibleForTesting<a name="line.1116"></a>
+<span class="sourceLineNo">1117</span>    public RegionInTransitionStat(final Configuration conf) {<a name="line.1117"></a>
+<span class="sourceLineNo">1118</span>      this.ritThreshold =<a name="line.1118"></a>
+<span class="sourceLineNo">1119</span>        conf.getInt(METRICS_RIT_STUCK_WARNING_THRESHOLD, DEFAULT_RIT_STUCK_WARNING_THRESHOLD);<a name="line.1119"></a>
+<span class="sourceLineNo">1120</span>    }<a name="line.1120"></a>
+<span class="sourceLineNo">1121</span><a name="line.1121"></a>
+<span class="sourceLineNo">1122</span>    public int getRITThreshold() {<a name="line.1122"></a>
+<span class="sourceLineNo">1123</span>      return ritThreshold;<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>    public long getTimestamp() {<a name="line.1126"></a>
+<span class="sourceLineNo">1127</span>      return statTimestamp;<a name="line.1127"></a>
+<span class="sourceLineNo">1128</span>    }<a name="line.1128"></a>
+<span class="sourceLineNo">1129</span><a name="line.1129"></a>
+<span class="sourceLineNo">1130</span>    public int getTotalRITs() {<a name="line.1130"></a>
+<span class="sourceLineNo">1131</span>      return totalRITs;<a name="line.1131"></a>
+<span class="sourceLineNo">1132</span>    }<a name="line.1132"></a>
+<span class="sourceLineNo">1133</span><a name="line.1133"></a>
+<span class="sourceLineNo">1134</span>    public long getOldestRITTime() {<a name="line.1134"></a>
+<span class="sourceLineNo">1135</span>      return oldestRITTime;<a name="line.1135"></a>
+<span class="sourceLineNo">1136</span>    }<a name="line.1136"></a>
+<span class="sourceLineNo">1137</span><a name="line.1137"></a>
+<span class="sourceLineNo">1138</span>    public int getTotalRITsOverThreshold() {<a name="line.1138"></a>
+<span class="sourceLineNo">1139</span>      Map&lt;String, RegionState&gt; m = this.ritsOverThreshold;<a name="line.1139"></a>
+<span class="sourceLineNo">1140</span>      return m != null ? m.size() : 0;<a name="line.1140"></a>
+<span class="sourceLineNo">1141</span>    }<a name="line.1141"></a>
+<span class="sourceLineNo">1142</span><a name="line.1142"></a>
+<span class="sourceLineNo">1143</span>    public boolean hasRegionsTwiceOverThreshold() {<a name="line.1143"></a>
+<span class="sourceLineNo">1144</span>      return totalRITsTwiceThreshold &gt; 0;<a name="line.1144"></a>
+<span class="sourceLineNo">1145</span>    }<a name="line.1145"></a>
+<span class="sourceLineNo">1146</span><a name="line.1146"></a>
+<span class="sourceLineNo">1147</span>    public boolean hasRegionsOverThreshold() {<a name="line.1147"></a>
+<span class="sourceLineNo">1148</span>      Map&lt;String, RegionState&gt; m = this.ritsOverThreshold;<a name="line.1148"></a>
+<span class="sourceLineNo">1149</span>      return m != null &amp;&amp; !m.isEmpty();<a name="line.1149"></a>
+<span class="sourceLineNo">1150</span>    }<a name="line.1150"></a>
+<span class="sourceLineNo">1151</span><a name="line.1151"></a>
+<span class="sourceLineNo">1152</span>    public Collection&lt;RegionState&gt; getRegionOverThreshold() {<a name="line.1152"></a>
+<span class="sourceLineNo">1153</span>      Map&lt;String, RegionState&gt; m = this.ritsOverThreshold;<a name="line.1153"></a>
+<span class="sourceLineNo">1154</span>      return m != null? m.values(): Collections.EMPTY_SET;<a name="line.1154"></a>
+<span class="sourceLineNo">1155</span>    }<a name="line.1155"></a>
+<span class="sourceLineNo">1156</span><a name="line.1156"></a>
+<span class="sourceLineNo">1157</span>    public boolean isRegionOverThreshold(final RegionInfo regionInfo) {<a name="line.1157"></a>
+<span class="sourceLineNo">1158</span>      Map&lt;String, RegionState&gt; m = this.ritsOverThreshold;<a name="line.1158"></a>
+<span class="sourceLineNo">1159</span>      return m != null &amp;&amp; m.containsKey(regionInfo.getEncodedName());<a name="line.1159"></a>
+<span class="sourceLineNo">1160</span>    }<a name="line.1160"></a>
+<span class="sourceLineNo">1161</span><a name="line.1161"></a>
+<span class="sourceLineNo">1162</span>    public boolean isRegionTwiceOverThreshold(final RegionInfo regionInfo) {<a name="line.1162"></a>
+<span class="sourceLineNo">1163</span>      Map&lt;String, RegionState&gt; m = this.ritsOverThreshold;<a name="line.1163"></a>
+<span class="sourceLineNo">1164</span>      if (m == null) return false;<a name="line.1164"></a>
+<span class="sourceLineNo">1165</span>      final RegionState state = m.get(regionInfo.getEncodedName());<a name="line.1165"></a>
+<span class="sourceLineNo">1166</span>      if (state == null) return false;<a name="line.1166"></a>
+<span class="sourceLineNo">1167</span>      return (statTimestamp - state.getStamp()) &gt; (ritThreshold * 2);<a name="line.1167"></a>
+<span class="sourceLineNo">1168</span>    }<a name="line.1168"></a>
+<span class="sourceLineNo">1169</span><a name="line.1169"></a>
+<span class="sourceLineNo">1170</span>    protected void update(final AssignmentManager am) {<a name="line.1170"></a>
+<span class="sourceLineNo">1171</span>      final RegionStates regionStates = am.getRegionStates();<a name="line.1171"></a>
+<span class="sourceLineNo">1172</span>      this.statTimestamp = EnvironmentEdgeManager.currentTime();<a name="line.1172"></a>
+<span class="sourceLineNo">1173</span>      update(regionStates.getRegionsStateInTransition(), statTimestamp);<a name="line.1173"></a>
+<span class="sourceLineNo">1174</span>      update(regionStates.getRegionFailedOpen(), statTimestamp);<a name="line.1174"></a>
+<span class="sourceLineNo">1175</span>    }<a name="line.1175"></a>
+<span class="sourceLineNo">1176</span><a name="line.1176"></a>
+<span class="sourceLineNo">1177</span>    private void update(final Collection&lt;RegionState&gt; regions, final long currentTime) {<a name="line.1177"></a>
+<span class="sourceLineNo">1178</span>      for (RegionState state: regions) {<a name="line.1178"></a>
+<span class="sourceLineNo">1179</span>        totalRITs++;<a name="line.1179"></a>
+<span class="sourceLineNo">1180</span>        final long ritTime = currentTime - state.getStamp();<a name="line.1180"></a>
+<span class="sourceLineNo">1181</span>        if (ritTime &gt; ritThreshold) {<a name="line.1181"></a>
+<span class="sourceLineNo">1182</span>          if (ritsOverThreshold == null) {<a name="line.1182"></a>
+<span class="sourceLineNo">1183</span>            ritsOverThreshold = new HashMap&lt;String, RegionState&gt;();<a name="line.1183"></a>
+<span class="sourceLineNo">1184</span>          }<a name="line.1184"></a>
+<span class="sourceLineNo">1185</span>          ritsOverThreshold.put(state.getRegion().getEncodedName(), state);<a name="line.1185"></a>
+<span class="sourceLineNo">1186</span>          totalRITsTwiceThreshold += (ritTime &gt; (ritThreshold * 2)) ? 1 : 0;<a name="line.1186"></a>
+<span class="sourceLineNo">1187</span>        }<a name="line.1187"></a>
+<span class="sourceLineNo">1188</span>        if (oldestRITTime &lt; ritTime) {<a name="line.1188"></a>
+<span class="sourceLineNo">1189</span>          oldestRITTime = ritTime;<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>  }<a name="line.1193"></a>
+<span class="sourceLineNo">1194</span><a name="line.1194"></a>
+<span class="sourceLineNo">1195</span>  private void updateRegionsInTransitionMetrics(final RegionInTransitionStat ritStat) {<a name="line.1195"></a>
+<span class="sourceLineNo">1196</span>    metrics.updateRITOldestAge(ritStat.getOldestRITTime());<a name="line.1196"></a>
+<span class="sourceLineNo">1197</span>    metrics.updateRITCount(ritStat.getTotalRITs());<a name="line.1197"></a>
+<span class="sourceLineNo">1198</span>    metrics.updateRITCountOverThreshold(ritStat.getTotalRITsOverThreshold());<a name="line.1198"></a>
+<span class="sourceLineNo">1199</span>  }<a name="line.1199"></a>
+<span class="sourceLineNo">1200</span><a name="line.1200"></a>
+<span class="sourceLineNo">1201</span>  private void handleRegionOverStuckWarningThreshold(final RegionInfo regionInfo) {<a name="line.1201"></a>
+<span class="sourceLineNo">1202</span>    final RegionStateNode regionNode = regionStates.getRegionStateNode(regionInfo);<a name="line.1202"></a>
+<span class="sourceLineNo">1203</span>    //if (regionNode.isStuck()) {<a name="line.1203"></a>
+<span class="sourceLineNo">1204</span>    LOG.warn("STUCK Region-In-Transition {}", regionNode);<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>  // ============================================================================================<a name="line.1207"></a>
+<span class="sourceLineNo">1208</span>  //  TODO: Master load/bootstrap<a name="line.1208"></a>
 <span class="sourceLineNo">1209</span>  // ============================================================================================<a name="line.1209"></a>
-<span class="sourceLineNo">1210</span>  //  TODO: Master load/bootstrap<a name="line.1210"></a>
-<span class="sourceLineNo">1211</span>  // ============================================================================================<a name="line.1211"></a>
-<span class="sourceLineNo">1212</span>  public void joinCluster() throws IOException {<a name="line.1212"></a>
-<span class="sourceLineNo">1213</span>    final long startTime = System.currentTimeMillis();<a name="line.1213"></a>
-<span class="sourceLineNo">1214</span>    LOG.debug("Joining cluster...");<a name="line.1214"></a>
-<span class="sourceLineNo">1215</span><a name="line.1215"></a>
-<span class="sourceLineNo">1216</span>    // Scan hbase:meta to build list of existing regions, servers, and assignment<a name="line.1216"></a>
-<span class="sourceLineNo">1217</span>    // hbase:meta is online when we get to here and TableStateManager has been started.<a name="line.1217"></a>
-<span class="sourceLineNo">1218</span>    loadMeta();<a name="line.1218"></a>
-<span class="sourceLineNo">1219</span><a name="line.1219"></a>
-<span class="sourceLineNo">1220</span>    for (int i = 0; master.getServerManager().countOfRegionServers() &lt; 1; ++i) {<a name="line.1220"></a>
-<span class="sourceLineNo">1221</span>      LOG.info("Waiting for RegionServers to join; current count=" +<a name="line.1221"></a>
-<span class="sourceLineNo">1222</span>          master.getServerManager().countOfRegionServers());<a name="line.1222"></a>
-<span class="sourceLineNo">1223</span>      Threads.sleep(250);<a name="line.1223"></a>
-<span class="sourceLineNo">1224</span>    }<a name="line.1224"></a>
-<span class="sourceLineNo">1225</span>    LOG.info("Number of RegionServers=" + master.getServerManager().countOfRegionServers());<a name="line.1225"></a>
+<span class="sourceLineNo">1210</span>  public void joinCluster() throws IOException {<a name="line.1210"></a>
+<span class="sourceLineNo">1211</span>    final long startTime = System.currentTimeMillis();<a name="line.1211"></a>
+<span class="sourceLineNo">1212</span>    LOG.debug("Joining cluster...");<a name="line.1212"></a>
+<span class="sourceLineNo">1213</span><a name="line.1213"></a>
+<span class="sourceLineNo">1214</span>    // Scan hbase:meta to build list of existing regions, servers, and assignment<a name="line.1214"></a>
+<span class="sourceLineNo">1215</span>    // hbase:meta is online when we get to here and TableStateManager has been started.<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>    for (int i = 0; master.getServerManager().countOfRegionServers() &lt; 1; ++i) {<a name="line.1218"></a>
+<span class="sourceLineNo">1219</span>      LOG.info("Waiting for RegionServers to join; current count=" +<a name="line.1219"></a>
+<span class="sourceLineNo">1220</span>          master.getServerManager().countOfRegionServers());<a name="line.1220"></a>
+<span class="sourceLineNo">1221</span>      Threads.sleep(250);<a name="line.1221"></a>
+<span class="sourceLineNo">1222</span>    }<a name="line.1222"></a>
+<span class="sourceLineNo">1223</span>    LOG.info("Number of RegionServers=" + master.getServerManager().countOfRegionServers());<a name="line.1223"></a>
+<span class="sourceLineNo">1224</span><a name="line.1224"></a>
+<span class="sourceLineNo">1225</span>    boolean failover = processofflineServersWithOnlineRegions();<a name="line.1225"></a>
 <span class="sourceLineNo">1226</span><a name="line.1226"></a>
-<span class="sourceLineNo">1227</span>    boolean failover = processofflineServersWithOnlineRegions();<a name="line.1227"></a>
-<span class="sourceLineNo">1228</span><a name="line.1228"></a>
-<span class="sourceLineNo">1229</span>    // Start the RIT chore<a name="line.1229"></a>
-<span class="sourceLineNo">1230</span>    master.getMasterProcedureExecutor().addChore(this.ritChore);<a name="line.1230"></a>
-<span class="sourceLineNo">1231</span><a name="line.1231"></a>
-<span class="sourceLineNo">1232</span>    LOG.info(String.format("Joined the cluster in %s, failover=%s",<a name="line.1232"></a>
-<span class="sourceLineNo">1233</span>      StringUtils.humanTimeDiff(System.currentTimeMillis() - startTime), failover));<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 loadMeta() throws IOException {<a name="line.1236"></a>
-<span class="sourceLineNo">1237</span>    // TODO: use a thread pool<a name="line.1237"></a>
-<span class="sourceLineNo">1238</span>    regionStateStore.visitMeta(new RegionStateStore.RegionStateVisitor() {<a name="line.1238"></a>
-<span class="sourceLineNo">1239</span>      @Override<a name="line.1239"></a>
-<span class="sourceLineNo">1240</span>      public void visitRegionState(Result result, final RegionInfo regionInfo, final State state,<a name="line.1240"></a>
-<span class="sourceLineNo">1241</span>          final ServerName regionLocation, final ServerName lastHost, final long openSeqNum) {<a name="line.1241"></a>
-<span class="sourceLineNo">1242</span>        if (state == null &amp;&amp; regionLocation == null &amp;&amp; lastHost == null &amp;&amp;<a name="line.1242"></a>
-<span class="sourceLineNo">1243</span>            openSeqNum == SequenceId.NO_SEQUENCE_ID) {<a name="line.1243"></a>
-<span class="sourceLineNo">1244</span>          // This is a row with nothing in it.<a name="line.1244"></a>
-<span class="sourceLineNo">1245</span>          LOG.warn("Skipping empty row={}", result);<a name="line.1245"></a>
-<span class="sourceLineNo">1246</span>          return;<a name="line.1246"></a>
-<span class="sourceLineNo">1247</span>        }<a name="line.1247"></a>
-<span class="sourceLineNo">1248</span>        State localState = state;<a name="line.1248"></a>
-<span class="sourceLineNo">1249</span>        if (localState == null) {<a name="line.1249"></a>
-<span class="sourceLineNo">1250</span>          // No region state column data in hbase:meta table! Are I doing a rolling upgrade from<a name="line.1250"></a>
-<span class="sourceLineNo">1251</span>          // hbase1 to hbase2? Am I restoring a SNAPSHOT or otherwise adding a region to hbase:meta?<a name="line.1251"></a>
-<span class="sourceLineNo">1252</span>          // In any of these cases, state is empty. For now, presume OFFLINE but there are probably<a name="line.1252"></a>
-<span class="sourceLineNo">1253</span>          // cases where we need to probe more to be sure this correct; TODO informed by experience.<a name="line.1253"></a>
-<span class="sourceLineNo">1254</span>          LOG.info(regionInfo.getEncodedName() + " regionState=null; presuming " + State.OFFLINE);<a name="line.1254"></a>
-<span class="sourceLineNo">1255</span><a name="line.1255"></a>
-<span class="sourceLineNo">1256</span>          localState = State.OFFLINE;<a name="line.1256"></a>
-<span class="sourceLineNo">1257</span>        }<a name="line.1257"></a>
-<span class="sourceLineNo">1258</span>        final RegionStateNode regionNode = regionStates.getOrCreateRegionStateNode(regionInfo);<a name="line.1258"></a>
-<span class="sourceLineNo">1259</span>        synchronized (regionNode) {<a name="line.1259"></a>
-<span class="sourceLineNo">1260</span>          if (!regionNode.isInTransition()) {<a name="line.1260"></a>
-<span class="sourceLineNo">1261</span>            regionNode.setState(localState);<a name="line.1261"></a>
-<span class="sourceLineNo">1262</span>            regionNode.setLastHost(lastHost);<a name="line.1262"></a>
-<span class="sourceLineNo">1263</span>            regionNode.setRegionLocation(regionLocation);<a name="line.1263"></a>
-<span class="sourceLineNo">1264</span>            regionNode.setOpenSeqNum(openSeqNum);<a name="line.1264"></a>
-<span class="sourceLineNo">1265</span><a name="line.1265"></a>
-<span class="sourceLineNo">1266</span>            if (localState == State.OPEN) {<a name="line.1266"></a>
-<span class="sourceLineNo">1267</span>              assert regionLocation != null : "found null region location for " + regionNode;<a name="line.1267"></a>
-<span class="sourceLineNo">1268</span>              regionStates.addRegionToServer(regionNode);<a name="line.1268"></a>
-<span class="sourceLineNo">1269</span>            } else if (localState == State.OFFLINE || regionInfo.isOffline()) {<a name="line.1269"></a>
-<span class="sourceLineNo">1270</span>              regionStates.addToOfflineRegions(regionNode);<a name="line.1270"></a>
-<span class="sourceLineNo">1271</span>            } else if (localState == State.CLOSED &amp;&amp; getTableStateManager().<a name="line.1271"></a>
-<span class="sourceLineNo">1272</span>                isTableState(regionNode.getTable(), TableState.State.DISABLED,<a name="line.1272"></a>
-<span class="sourceLineNo">1273</span>                TableState.State.DISABLING)) {<a name="line.1273"></a>
-<span class="sourceLineNo">1274</span>              // The region is CLOSED and the table is DISABLED/ DISABLING, there is nothing to<a name="line.1274"></a>
-<span class="sourceLineNo">1275</span>              // schedule; the region is inert.<a name="line.1275"></a>
-<span class="sourceLineNo">1276</span>            } else {<a name="line.1276"></a>
-<span class="sourceLineNo">1277</span>              // These regions should have a procedure in replay<a name="line.1277"></a>
-<span class="sourceLineNo">1278</span>              regionStates.addRegionInTransition(regionNode, null);<a name="line.1278"></a>
-<span class="sourceLineNo">1279</span>            }<a name="line.1279"></a>
-<span class="sourceLineNo">1280</span>          }<a name="line.1280"></a>
-<span class="sourceLineNo">1281</span>        }<a name="line.1281"></a>
-<span class="sourceLineNo">1282</span>      }<a name="line.1282"></a>
-<span class="sourceLineNo">1283</span>    });<a name="line.1283"></a>
-<span class="sourceLineNo">1284</span><a name="line.1284"></a>
-<span class="sourceLineNo">1285</span>    // every assignment is blocked until meta is loaded.<a name="line.1285"></a>
-<span class="sourceLineNo">1286</span>    wakeMetaLoadedEvent();<a name="line.1286"></a>
-<span class="sourceLineNo">1287</span>  }<a name="line.1287"></a>
-<span class="sourceLineNo">1288</span><a name="line.1288"></a>
-<span class="sourceLineNo">1289</span>  /**<a name="line.1289"></a>
-<span class="sourceLineNo">1290</span>   * Look at what is in meta and the list of servers that have checked in and make reconciliation.<a name="line.1290"></a>
-<span class="sourceLineNo">1291</span>   * We cannot tell definitively the difference between a clean shutdown and a cluster that has<a name="line.1291"></a>
-<span class="sourceLineNo">1292</span>   * been crashed down. At this stage of a Master startup, they look the same: they have the<a name="line.1292"></a>
-<span class="sourceLineNo">1293</span>   * same state in hbase:meta. We could do detective work probing ZK and the FS for old WALs to<a name="line.1293"></a>
-<span class="sourceLineNo">1294</span>   * split but SCP does this already so just let it do its job.<a name="line.1294"></a>
-<span class="sourceLineNo">1295</span>   * &lt;p&gt;&gt;The profiles of clean shutdown and cluster crash-down are the same because on clean<a name="line.1295"></a>
-<span class="sourceLineNo">1296</span>   * shutdown currently, we do not update hbase:meta with region close state (In AMv2, region<a name="line.1296"></a>
-<span class="sourceLineNo">1297</span>   * state is kept in hbse:meta). Usually the master runs all region transitions as of AMv2 but on<a name="line.1297"></a>
-<span class="sourceLineNo">1298</span>   * cluster controlled shutdown, the RegionServers close all their regions only reporting the<a name="line.1298"></a>
-<span class="sourceLineNo">1299</span>   * final change to the Master. Currently this report is ignored. Later we could take it and<a name="line.1299"></a>
-<span class="sourceLineNo">1300</span>   * update as many regions as we can before hbase:meta goes down or have the master run the<a name="line.1300"></a>
-<span class="sourceLineNo">1301</span>   * close of all regions out on the cluster but we may never be able to achieve the proper state on<a name="line.1301"></a>
-<span class="sourceLineNo">1302</span>   * all regions (at least not w/o lots of painful manipulations and waiting) so clean shutdown<a name="line.1302"></a>
-<span class="sourceLineNo">1303</span>   * might not be possible especially on big clusters.... And clean shutdown will take time. Given<a name="line.1303"></a>
-<span class="sourceLineNo">1304</span>   * this current state of affairs, we just run ServerCrashProcedure in both cases. It will always<a name="line.1304"></a>
-<span class="sourceLineNo">1305</span>   * do the right thing.<a name="line.1305"></a>
-<span class="sourceLineNo">1306</span>   * @return True if for sure this is a failover where a Master is starting up into an already<a name="line.1306"></a>
-<span class="sourceLineNo">1307</span>   * running cluster.<a name="line.1307"></a>
-<span class="sourceLineNo">1308</span>   */<a name="line.1308"></a>
-<span class="sourceLineNo">1309</span>  // The assumption here is that if RSs are crashing while we are executing this<a name="line.1309"></a>
-<span class="sourceLineNo">1310</span>  // they will be handled by the SSH that are put in the ServerManager deadservers "queue".<a name="line.1310"></a>
-<span class="sourceLineNo">1311</span>  private boolean processofflineServersWithOnlineRegions() {<a name="line.1311"></a>
-<span class="sourceLineNo">1312</span>    boolean deadServers = !master.getServerManager().getDeadServers().isEmpty();<a name="line.1312"></a>
-<span class="sourceLineNo">1313</span>    final Set&lt;ServerName&gt; offlineServersWithOnlineRegions = new HashSet&lt;&gt;();<a name="line.1313"></a>
-<span class="sourceLineNo">1314</span>    int size = regionStates.getRegionStateNodes().size();<a name="line.1314"></a>
-<span class="sourceLineNo">1315</span>    final List&lt;RegionInfo&gt; offlineRegionsToAssign = new ArrayList&lt;&gt;(size);<a name="line.1315"></a>
-<span class="sourceLineNo">1316</span>    // If deadservers then its a failover, else, we are not sure yet.<a name="line.1316"></a>
-<span class="sourceLineNo">1317</span>    boolean failover = deadServers;<a name="line.1317"></a>
-<span class="sourceLineNo">1318</span>    for (RegionStateNode regionNode: regionStates.getRegionStateNodes()) {<a name="line.1318"></a>
-<span class="sourceLineNo">1319</span>      // Region State can be OPEN even if we did controlled cluster shutdown; Master does not close<a name="line.1319"></a>
-<span class="sourceLineNo">1320</span>      // the regions in this case. The RegionServer does the close so hbase:meta is state in<a name="line.1320"></a>
-<span class="sourceLineNo">1321</span>      // hbase:meta is not updated -- Master does all updates -- and is left with OPEN as region<a name="line.1321"></a>
-<span class="sourceLineNo">1322</span>      // state in meta. How to tell difference between ordered shutdown and crashed-down cluster<a name="line.1322"></a>
-<span class="sourceLineNo">1323</span>      // then? We can't. Not currently. Perhaps if we updated hbase:meta with CLOSED on ordered<a name="line.1323"></a>
-<span class="sourceLineNo">1324</span>      // shutdown. This would slow shutdown though and not all edits would make it in anyways.<a name="line.1324"></a>
-<span class="sourceLineNo">1325</span>      // TODO: Examine.<a name="line.1325"></a>
-<span class="sourceLineNo">1326</span>      // Because we can't be sure it an ordered shutdown, we run ServerCrashProcedure always.<a name="line.1326"></a>
-<span class="sourceLineNo">1327</span>      // ServerCrashProcedure will try to retain old deploy when it goes to assign.<a name="line.1327"></a>
-<span class="sourceLineNo">1328</span>      if (regionNode.getState() == State.OPEN) {<a name="line.1328"></a>
-<span class="sourceLineNo">1329</span>        final ServerName serverName = regionNode.getRegionLocation();<a name="line.1329"></a>
-<span class="sourceLineNo">1330</span>        if (!master.getServerManager().isServerOnline(serverName)) {<a name="line.1330"></a>
-<span class="sourceLineNo">1331</span>          offlineServersWithOnlineRegions.add(serverName);<a name="line.1331"></a>
-<span class="sourceLineNo">1332</span>        } else {<a name="line.1332"></a>
-<span class="sourceLineNo">1333</span>          // Server is online. This a failover. Master is starting into already-running cluster.<a name="line.1333"></a>
-<span class="sourceLineNo">1334</span>          failover = true;<a name="line.1334"></a>
-<span class="sourceLineNo">1335</span>        }<a name="line.1335"></a>
-<span class="sourceLineNo">1336</span>      } else if (regionNode.getState() == State.OFFLINE) {<a name="line.1336"></a>
-<span class="sourceLineNo">1337</span>        if (isTableEnabled(regionNode.getTable())) {<a name="line.1337"></a>
-<span class="sourceLineNo">1338</span>          offlineRegionsToAssign.add(regionNode.getRegionInfo());<a name="line.1338"></a>
-<span class="sourceLineNo">1339</span>        }<a name="line.1339"></a>
-<span class="sourceLineNo">1340</span>      }<a name="line.1340"></a>
-<span class="sourceLineNo">1341</span>    }<a name="line.1341"></a>
-<span class="sourceLineNo">1342</span>    // Kill servers with online regions just-in-case. Runs ServerCrashProcedure.<a name="line.1342"></a>
-<span class="sourceLineNo">1343</span>    for (ServerName serverName: offlineServersWithOnlineRegions) {<a name="line.1343"></a>
-<span class="sourceLineNo">1344</span>      if (!master.getServerManager().isServerOnline(serverName)) {<a name="line.1344"></a>
-<span class="sourceLineNo">1345</span>        LOG.info("KILL RegionServer=" + serverName + " hosting regions but not online.");<a name="line.1345"></a>
-<span class="sourceLineNo">1346</span>        killRegionServer(serverName);<a name="line.1346"></a>
-<span class="sourceLineNo">1347</span>      }<a name="line.1347"></a>
-<span class="sourceLineNo">1348</span>    }<a name="line.1348"></a>
-<span class="sourceLineNo">1349</span>    setFailoverCleanupDone(true);<a name="line.1349"></a>
-<span class="sourceLineNo">1350</span><a name="line.1350"></a>
-<span class="sourceLineNo">1351</span>    // Assign offline regions. Uses round-robin.<a name="line.1351"></a>
-<span class="sourceLineNo">1352</span>    if (offlineRegionsToAssign.size() &gt; 0) {<a name="line.1352"></a>
-<span class="sourceLineNo">1353</span>      master.getMasterProcedureExecutor().submitProcedures(master.getAssignmentManager().<a name="line.1353"></a>
-<span class="sourceLineNo">1354</span>          createRoundRobinAssignProcedures(offlineRegionsToAssign));<a name="line.1354"></a>
-<span class="sourceLineNo">1355</span>    }<a name="line.1355"></a>
-<span class="sourceLineNo">1356</span><a name="line.1356"></a>
-<span class="sourceLineNo">1357</span>    return failover;<a name="line.1357"></a>
-<span class="sourceLineNo">1358</span>  }<a name="line.1358"></a>
-<span class="sourceLineNo">1359</span><a name="line.1359"></a>
-<span class="sourceLineNo">1360</span>  /**<a name="line.1360"></a>
-<span class="sourceLineNo">1361</span>   * Used by ServerCrashProcedure to make sure AssignmentManager has completed<a name="line.1361"></a>
-<span class="sourceLineNo">1362</span>   * the failover cleanup before re-assigning regions of dead servers. So that<a name="line.1362"></a>
-<span class="sourceLineNo">1363</span>   * when re-assignment happens, AssignmentManager has proper region states.<a name="line.1363"></a>
-<span class="sourceLineNo">1364</span>   */<a name="line.1364"></a>
-<span class="sourceLineNo">1365</span>  public boolean isFailoverCleanupDone() {<a name="line.1365"></a>
-<span class="sourceLineNo">1366</span>    return failoverCleanupDone.isReady();<a name="line.1366"></a>
-<span class="sourceLineNo">1367</span>  }<a name="line.1367"></a>
-<span class="sourceLineNo">1368</span><a name="line.1368"></a>
-<span class="sourceLineNo">1369</span>  /**<a name="line.1369"></a>
-<span class="sourceLineNo">1370</span>   * Used by ServerCrashProcedure tests verify the ability to suspend the<a name="line.1370"></a>
-<span class="sourceLineNo">1371</span>   * execution of the ServerCrashProcedure.<a name="line.1371"></a>
-<span class="sourceLineNo">1372</span>   */<a name="line.1372"></a>
-<span class="sourceLineNo">1373</span>  @VisibleForTesting<a name="line.1373"></a>
-<span class="sourceLineNo">1374</span>  public void setFailoverCleanupDone(final boolean b) {<a name="line.1374"></a>
-<span class="sourceLineNo">1375</span>    master.getMasterProcedureExecutor().getEnvironment()<a name="line.1375"></a>
-<span class="sourceLineNo">1376</span>      .setEventReady(failoverCleanupDone, b);<a name="line.1376"></a>
-<span class="sourceLineNo">1377</span>  }<a name="line.1377"></a>
-<span class="sourceLineNo">1378</span><a name="line.1378"></a>
-<span class="sourceLineNo">1379</span>  public ProcedureEvent getFailoverCleanupEvent() {<a name="line.1379"></a>
-<span class="sourceLineNo">1380</span>    return failoverCleanupDone;<a name="line.1380"></a>
-<span class="sourceLineNo">1381</span>  }<a name="line.1381"></a>
-<span class="sourceLineNo">1382</span><a name="line.1382"></a>
-<span class="sourceLineNo">1383</span>  /**<a name="line.1383"></a>
-<span class="sourceLineNo">1384</span>   * Used to check if the failover cleanup is done.<a name="line.1384"></a>
-<span class="sourceLineNo">1385</span>   * if not we throw PleaseHoldException since we are rebuilding the RegionStates<a name="line.1385"></a>
-<span class="sourceLineNo">1386</span>   * @param hri region to check if it is already rebuild<a name="line.1386"></a>
-<span class="sourceLineNo">1387</span>   * @throws PleaseHoldException if the failover cleanup is not completed<a name="line.1387"></a>
-<span class="sourceLineNo">1388</span>   */<a name="line.1388"></a>
-<span class="sourceLineNo">1389</span>  private void checkFailoverCleanupCompleted(final RegionInfo hri) throws PleaseHoldException {<a name="line.1389"></a>
-<span class="sourceLineNo">1390</span>    if (!isRunning()) {<a name="line.1390"></a>
-<span class="sourceLineNo">1391</span>      throw new PleaseHoldException("AssignmentManager not running");<a name="line.1391"></a>
-<span class="sourceLineNo">1392</span>    }<a name="line.1392"></a>
-<span class="sourceLineNo">1393</span><a name="line.1393"></a>
-<span class="sourceLineNo">1394</span>    // TODO: can we avoid throwing an exception if hri is already loaded?<a name="line.1394"></a>
-<span class="sourceLineNo">1395</span>    //       at the moment we bypass only meta<a name="line.1395"></a>
-<span class="sourceLineNo">1396</span>    boolean meta = isMetaRegion(hri);<a name="line.1396"></a>
-<span class="sourceLineNo">1397</span>    boolean cleanup = isFailoverCleanupDone();<a name="line.1397"></a>
-<span class="sourceLineNo">1398</span>    if (!isMetaRegion(hri) &amp;&amp; !isFailoverCleanupDone()) {<a name="line.1398"></a>
-<span class="sourceLineNo">1399</span>      String msg = "Master not fully online; hbase:meta=" + meta + ", failoverCleanup=" + cleanup;<a name="line.1399"></a>
-<span class="sourceLineNo">1400</span>      throw new PleaseHoldException(msg);<a name="line.1400"></a>
-<span class="sourceLineNo">1401</span>    }<a name="line.1401"></a>
-<span class="sourceLineNo">1402</span>  }<a name="line.1402"></a>
-<span class="sourceLineNo">1403</span><a name="line.1403"></a>
+<span class="sourceLineNo">1227</span>    // Start the RIT chore<a name="line.1227"></a>
+<span class="sourceLineNo">1228</span>    master.getMasterProcedureExecutor().addChore(this.ritChore);<a name="line.1228"></a>
+<span class="sourceLineNo">1229</span><a name="line.1229"></a>
+<span class="sourceLineNo">1230</span>    LOG.info(String.format("Joined the cluster in %s, failover=%s",<a name="line.1230"></a>
+<span class="sourceLineNo">1231</span>      StringUtils.humanTimeDiff(System.currentTimeMillis() - startTime), failover));<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>  private void loadMeta() throws IOException {<a name="line.1234"></a>
+<span class="sourceLineNo">1235</span>    // TODO: use a thread pool<a name="line.1235"></a>
+<span class="sourceLineNo">1236</span>    regionStateStore.visitMeta(new RegionStateStore.RegionStateVisitor() {<a name="line.1236"></a>
+<span class="sourceLineNo">1237</span>      @Override<a name="line.1237"></a>
+<span class="sourceLineNo">1238</span>      public void visitRegionState(Result result, final RegionInfo regionInfo, final State state,<a name="line.1238"></a>
+<span class="sourceLineNo">1239</span>          final ServerName regionLocation, final ServerName lastHost, final long openSeqNum) {<a name="line.1239"></a>
+<span class="sourceLineNo">1240</span>        if (state == null &amp;&amp; regionLocation == null &amp;&amp; lastHost == null &amp;&amp;<a name="line.1240"></a>
+<span class="sourceLineNo">1241</span>            openSeqNum == SequenceId.NO_SEQUENCE_ID) {<a name="line.1241"></a>
+<span class="sourceLineNo">1242</span>          // This is a row with nothing in it.<a name="line.1242"></a>
+<span class="sourceLineNo">1243</span>          LOG.warn("Skipping empty row={}", result);<a name="line.1243"></a>
+<span class="sourceLineNo">1244</span>          return;<a name="line.1244"></a>
+<span class="sourceLineNo">1245</span>        }<a name="line.1245"></a>
+<span class="sourceLineNo">1246</span>        State localState = state;<a name="line.1246"></a>
+<span class="sourceLineNo">1247</span>        if (localState == null) {<a name="line.1247"></a>
+<span class="sourceLineNo">1248</span>          // No region state column data in hbase:meta table! Are I doing a rolling upgrade from<a name="line.1248"></a>
+<span class="sourceLineNo">1249</span>          // hbase1 to hbase2? Am I restoring a SNAPSHOT or otherwise adding a region to hbase:meta?<a name="line.1249"></a>
+<span class="sourceLineNo">1250</span>          // In any of these cases, state is empty. For now, presume OFFLINE but there are probably<a name="line.1250"></a>
+<span class="sourceLineNo">1251</span>          // cases where we need to probe more to be sure this correct; TODO informed by experience.<a name="line.1251"></a>
+<span class="sourceLineNo">1252</span>          LOG.info(regionInfo.getEncodedName() + " regionState=null; presuming " + State.OFFLINE);<a name="line.1252"></a>
+<span class="sourceLineNo">1253</span><a name="line.1253"></a>
+<span class="sourceLineNo">1254</span>          localState = State.OFFLINE;<a name="line.1254"></a>
+<span class="sourceLineNo">1255</span>        }<a name="line.1255"></a>
+<span class="sourceLineNo">1256</span>        final RegionStateNode regionNode = regionStates.getOrCreateRegionStateNode(regionInfo);<a name="line.1256"></a>
+<span class="sourceLineNo">1257</span>        synchronized (regionNode) {<a name="line.1257"></a>
+<span class="sourceLineNo">1258</span>          if (!regionNode.isInTransition()) {<a name="line.1258"></a>
+<span class="sourceLineNo">1259</span>            regionNode.setState(localState);<a name="line.1259"></a>
+<span class="sourceLineNo">1260</span>            regionNode.setLastHost(lastHost);<a name="line.1260"></a>
+<span class="sourceLineNo">1261</span>            regionNode.setRegionLocation(regionLocation);<a name="line.1261"></a>
+<span class="sourceLineNo">1262</span>            regionNode.setOpenSeqNum(openSeqNum);<a name="line.1262"></a>
+<span class="sourceLineNo">1263</span><a name="line.1263"></a>
+<span class="sourceLineNo">1264</span>            if (localState == State.OPEN) {<a name="line.1264"></a>
+<span class="sourceLineNo">1265</span>              assert regionLocation != null : "found null region location for " + regionNode;<a name="line.1265"></a>
+<span class="sourceLineNo">1266</span>              regionStates.addRegionToServer(regionNode);<a name="line.1266"></a>
+<span class="sourceLineNo">1267</span>            } else if (localState == State.OFFLINE || regionInfo.isOffline()) {<a name="line.1267"></a>
+<span class="sourceLineNo">1268</span>              regionStates.addToOfflineRegions(regionNode);<a name="line.1268"></a>
+<span class="sourceLineNo">1269</span>            } else if (localState == State.CLOSED &amp;&amp; getTableStateManager().<a name="line.1269"></a>
+<span class="sourceLineNo">1270</span>                isTableState(regionNode.getTable(), TableState.State.DISABLED,<a name="line.1270"></a>
+<span class="sourceLineNo">1271</span>                TableState.State.DISABLING)) {<a name="line.1271"></a>
+<span class="sourceLineNo">1272</span>              // The region is CLOSED and the table is DISABLED/ DISABLING, there is nothing to<a name="line.1272"></a>
+<span class="sourceLineNo">1273</span>              // schedule; the region is inert.<a name="line.1273"></a>
+<span class="sourceLineNo">1274</span>            } else {<a name="line.1274"></a>
+<span class="sourceLineNo">1275</span>              // These regions should have a procedure in replay<a name="line.1275"></a>
+<span class="sourceLineNo">1276</span>              regionStates.addRegionInTransition(regionNode, null);<a name="line.1276"></a>
+<span class="sourceLineNo">1277</span>            }<a name="line.1277"></a>
+<span class="sourceLineNo">1278</span>          }<a name="line.1278"></a>
+<span class="sourceLineNo">1279</span>        }<a name="line.1279"></a>
+<span class="sourceLineNo">1280</span>      }<a name="line.1280"></a>
+<span class="sourceLineNo">1281</span>    });<a name="line.1281"></a>
+<span class="sourceLineNo">1282</span><a name="line.1282"></a>
+<span class="sourceLineNo">1283</span>    // every assignment is blocked until meta is loaded.<a name="line.1283"></a>
+<span class="sourceLineNo">1284</span>    wakeMetaLoadedEvent();<a name="line.1284"></a>
+<span class="sourceLineNo">1285</span>  }<a name="line.1285"></a>
+<span class="sourceLineNo">1286</span><a name="line.1286"></a>
+<span class="sourceLineNo">1287</span>  /**<a name="line.1287"></a>
+<span class="sourceLineNo">1288</span>   * Look at what is in meta and the list of servers that have checked in and make reconciliation.<a name="line.1288"></a>
+<span class="sourceLineNo">1289</span>   * We cannot tell definitively the difference between a clean shutdown and a cluster that has<a name="line.1289"></a>
+<span class="sourceLineNo">1290</span>   * been crashed down. At this stage of a Master startup, they look the same: they have the<a name="line.1290"></a>
+<span class="sourceLineNo">1291</span>   * same state in hbase:meta. We could do detective work probing ZK and the FS for old WALs to<a name="line.1291"></a>
+<span class="sourceLineNo">1292</span>   * split but SCP does this already so just let it do its job.<a name="line.1292"></a>
+<span class="sourceLineNo">1293</span>   * &lt;p&gt;&gt;The profiles of clean shutdown and cluster crash-down are the same because on clean<a name="line.1293"></a>
+<span class="sourceLineNo">1294</span>   * shutdown currently, we do not update hbase:meta with region close state (In AMv2, region<a name="line.1294"></a>
+<span class="sourceLineNo">1295</span>   * state is kept in hbse:meta). Usually the master runs all region transitions as of AMv2 but on<a name="line.1295"></a>
+<span class="sourceLineNo">1296</span>   * cluster controlled shutdown, the RegionServers close all their regions only reporting the<a name="line.1296"></a>
+<span class="sourceLineNo">1297</span>   * final change to the Master. Currently this report is ignored. Later we could take it and<a name="line.1297"></a>
+<span class="sourceLineNo">1298</span>   * update as many regions as we can before hbase:meta goes down or have the master run the<a name="line.1298"></a>
+<span class="sourceLineNo">1299</span>   * close of all regions out on the cluster but we may never be able to achieve the proper state on<a name="line.1299"></a>
+<span class="sourceLineNo">1300</span>   * all regions (at least not w/o lots of painful manipulations and waiting) so clean shutdown<a name="line.1300"></a>
+<span class="sourceLineNo">1301</span>   * might not be possible especially on big clusters.... And clean shutdown will take time. Given<a name="line.1301"></a>
+<span class="sourceLineNo">1302</span>   * this current state of affairs, we just run ServerCrashProcedure in both cases. It will always<a name="line.1302"></a>
+<span class="sourceLineNo">1303</span>   * do the right thing.<a name="line.1303"></a>
+<span class="sourceLineNo">1304</span>   * @return True if for sure this is a failover where a Master is starting up into an already<a name="line.1304"></a>
+<span class="sourceLineNo">1305</span>   * running cluster.<a name="line.1305"></a>
+<span class="sourceLineNo">1306</span>   */<a name="line.1306"></a>
+<span class="sourceLineNo">1307</span>  // The assumption here is that if RSs are crashing while we are executing this<a name="line.1307"></a>
+<span class="sourceLineNo">1308</span>  // they will be handled by the SSH that are put in the ServerManager deadservers "queue".<a name="line.1308"></a>
+<span class="sourceLineNo">1309</span>  private boolean processofflineServersWithOnlineRegions() {<a name="line.1309"></a>
+<span class="sourceLineNo">1310</span>    boolean deadServers = !master.getServerManager().getDeadServers().isEmpty();<a name="line.1310"></a>
+<span class="sourceLineNo">1311</span>    final Set&lt;ServerName&gt; offlineServersWithOnlineRegions = new HashSet&lt;&gt;();<a name="line.1311"></a>
+<span class="sourceLineNo">1312</span>    int size = regionStates.getRegionStateNodes().size();<a name="line.1312"></a>
+<span class="sourceLineNo">1313</span>    final List&lt;RegionInfo&gt; offlineRegionsToAssign = new ArrayList&lt;&gt;(size);<a name="line.1313"></a>
+<span class="sourceLineNo">1314</span>    // If deadservers then its a failover, else, we are not sure yet.<a name="line.1314"></a>
+<span class="sourceLineNo">1315</span>    boolean failover = deadServers;<a name="line.1315"></a>
+<span class="sourceLineNo">1316</span>    for (RegionStateNode regionNode: regionStates.getRegionStateNodes()) {<a name="line.1316"></a>
+<span class="sourceLineNo">1317</span>      // Region State can be OPEN even if we did controlled cluster shutdown; Master does not close<a name="line.1317"></a>
+<span class="sourceLineNo">1318</span>      // the regions in this case. The RegionServer does the close so hbase:meta is state in<a name="line.1318"></a>
+<span class="sourceLineNo">1319</span>      // hbase:meta is not updated -- Master does all updates -- a

<TRUNCATED>

Mime
View raw message