http://git-wip-us.apache.org/repos/asf/hbase-site/blob/9808d50e/devapidocs/src-html/org/apache/hadoop/hbase/master/replication/ModifyPeerProcedure.html
----------------------------------------------------------------------
diff --git 
a/devapidocs/src-html/org/apache/hadoop/hbase/master/replication/ModifyPeerProcedure.html
 
b/devapidocs/src-html/org/apache/hadoop/hbase/master/replication/ModifyPeerProcedure.html
index 6e1231c..edb4a3d 100644
--- 
a/devapidocs/src-html/org/apache/hadoop/hbase/master/replication/ModifyPeerProcedure.html
+++ 
b/devapidocs/src-html/org/apache/hadoop/hbase/master/replication/ModifyPeerProcedure.html
@@ -26,315 +26,339 @@
 <span class="sourceLineNo">018</span>package 
org.apache.hadoop.hbase.master.replication;<a name="line.18"></a>
 <span class="sourceLineNo">019</span><a name="line.19"></a>
 <span class="sourceLineNo">020</span>import java.io.IOException;<a 
name="line.20"></a>
-<span class="sourceLineNo">021</span>import java.util.HashMap;<a 
name="line.21"></a>
-<span class="sourceLineNo">022</span>import java.util.Map;<a 
name="line.22"></a>
-<span class="sourceLineNo">023</span>import 
org.apache.hadoop.hbase.MetaTableAccessor;<a name="line.23"></a>
-<span class="sourceLineNo">024</span>import 
org.apache.hadoop.hbase.TableName;<a name="line.24"></a>
-<span class="sourceLineNo">025</span>import 
org.apache.hadoop.hbase.client.Connection;<a name="line.25"></a>
-<span class="sourceLineNo">026</span>import 
org.apache.hadoop.hbase.client.RegionInfo;<a name="line.26"></a>
+<span class="sourceLineNo">021</span>import java.io.InterruptedIOException;<a 
name="line.21"></a>
+<span class="sourceLineNo">022</span>import java.util.HashMap;<a 
name="line.22"></a>
+<span class="sourceLineNo">023</span>import java.util.Map;<a 
name="line.23"></a>
+<span class="sourceLineNo">024</span>import 
org.apache.hadoop.hbase.MetaTableAccessor;<a name="line.24"></a>
+<span class="sourceLineNo">025</span>import 
org.apache.hadoop.hbase.TableName;<a name="line.25"></a>
+<span class="sourceLineNo">026</span>import 
org.apache.hadoop.hbase.client.Connection;<a name="line.26"></a>
 <span class="sourceLineNo">027</span>import 
org.apache.hadoop.hbase.client.TableDescriptor;<a name="line.27"></a>
-<span class="sourceLineNo">028</span>import 
org.apache.hadoop.hbase.master.MasterFileSystem;<a name="line.28"></a>
+<span class="sourceLineNo">028</span>import 
org.apache.hadoop.hbase.client.TableState;<a name="line.28"></a>
 <span class="sourceLineNo">029</span>import 
org.apache.hadoop.hbase.master.TableStateManager;<a name="line.29"></a>
 <span class="sourceLineNo">030</span>import 
org.apache.hadoop.hbase.master.TableStateManager.TableStateNotFoundException;<a 
name="line.30"></a>
-<span class="sourceLineNo">031</span>import 
org.apache.hadoop.hbase.master.assignment.RegionStates;<a name="line.31"></a>
-<span class="sourceLineNo">032</span>import 
org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;<a 
name="line.32"></a>
-<span class="sourceLineNo">033</span>import 
org.apache.hadoop.hbase.master.procedure.ProcedurePrepareLatch;<a 
name="line.33"></a>
-<span class="sourceLineNo">034</span>import 
org.apache.hadoop.hbase.procedure2.ProcedureSuspendedException;<a 
name="line.34"></a>
-<span class="sourceLineNo">035</span>import 
org.apache.hadoop.hbase.procedure2.ProcedureYieldException;<a 
name="line.35"></a>
-<span class="sourceLineNo">036</span>import 
org.apache.hadoop.hbase.replication.ReplicationException;<a name="line.36"></a>
-<span class="sourceLineNo">037</span>import 
org.apache.hadoop.hbase.replication.ReplicationPeerConfig;<a name="line.37"></a>
-<span class="sourceLineNo">038</span>import 
org.apache.hadoop.hbase.replication.ReplicationQueueStorage;<a 
name="line.38"></a>
-<span class="sourceLineNo">039</span>import 
org.apache.hadoop.hbase.replication.ReplicationUtils;<a name="line.39"></a>
-<span class="sourceLineNo">040</span>import 
org.apache.hadoop.hbase.util.Pair;<a name="line.40"></a>
-<span class="sourceLineNo">041</span>import 
org.apache.hadoop.hbase.wal.WALSplitter;<a name="line.41"></a>
-<span class="sourceLineNo">042</span>import 
org.apache.yetus.audience.InterfaceAudience;<a name="line.42"></a>
-<span class="sourceLineNo">043</span>import org.slf4j.Logger;<a 
name="line.43"></a>
-<span class="sourceLineNo">044</span>import org.slf4j.LoggerFactory;<a 
name="line.44"></a>
+<span class="sourceLineNo">031</span>import 
org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;<a 
name="line.31"></a>
+<span class="sourceLineNo">032</span>import 
org.apache.hadoop.hbase.master.procedure.ProcedurePrepareLatch;<a 
name="line.32"></a>
+<span class="sourceLineNo">033</span>import 
org.apache.hadoop.hbase.procedure2.ProcedureSuspendedException;<a 
name="line.33"></a>
+<span class="sourceLineNo">034</span>import 
org.apache.hadoop.hbase.procedure2.ProcedureYieldException;<a 
name="line.34"></a>
+<span class="sourceLineNo">035</span>import 
org.apache.hadoop.hbase.replication.ReplicationException;<a name="line.35"></a>
+<span class="sourceLineNo">036</span>import 
org.apache.hadoop.hbase.replication.ReplicationPeerConfig;<a name="line.36"></a>
+<span class="sourceLineNo">037</span>import 
org.apache.hadoop.hbase.replication.ReplicationQueueStorage;<a 
name="line.37"></a>
+<span class="sourceLineNo">038</span>import 
org.apache.hadoop.hbase.replication.ReplicationUtils;<a name="line.38"></a>
+<span class="sourceLineNo">039</span>import 
org.apache.hadoop.hbase.util.Pair;<a name="line.39"></a>
+<span class="sourceLineNo">040</span>import 
org.apache.yetus.audience.InterfaceAudience;<a name="line.40"></a>
+<span class="sourceLineNo">041</span>import org.slf4j.Logger;<a 
name="line.41"></a>
+<span class="sourceLineNo">042</span>import org.slf4j.LoggerFactory;<a 
name="line.42"></a>
+<span class="sourceLineNo">043</span><a name="line.43"></a>
+<span class="sourceLineNo">044</span>import 
org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.PeerModificationState;<a
 name="line.44"></a>
 <span class="sourceLineNo">045</span><a name="line.45"></a>
-<span class="sourceLineNo">046</span>import 
org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.PeerModificationState;<a
 name="line.46"></a>
-<span class="sourceLineNo">047</span><a name="line.47"></a>
-<span class="sourceLineNo">048</span>/**<a name="line.48"></a>
-<span class="sourceLineNo">049</span> * The base class for all replication 
peer related procedure except sync replication state<a name="line.49"></a>
-<span class="sourceLineNo">050</span> * transition.<a name="line.50"></a>
-<span class="sourceLineNo">051</span> */<a name="line.51"></a>
-<span class="sourceLineNo">052</span>@InterfaceAudience.Private<a 
name="line.52"></a>
-<span class="sourceLineNo">053</span>public abstract class ModifyPeerProcedure 
extends AbstractPeerProcedure&lt;PeerModificationState&gt; {<a 
name="line.53"></a>
+<span class="sourceLineNo">046</span>/**<a name="line.46"></a>
+<span class="sourceLineNo">047</span> * The base class for all replication 
peer related procedure except sync replication state<a name="line.47"></a>
+<span class="sourceLineNo">048</span> * transition.<a name="line.48"></a>
+<span class="sourceLineNo">049</span> */<a name="line.49"></a>
+<span class="sourceLineNo">050</span>@InterfaceAudience.Private<a 
name="line.50"></a>
+<span class="sourceLineNo">051</span>public abstract class ModifyPeerProcedure 
extends AbstractPeerProcedure&lt;PeerModificationState&gt; {<a 
name="line.51"></a>
+<span class="sourceLineNo">052</span><a name="line.52"></a>
+<span class="sourceLineNo">053</span>  private static final Logger LOG = 
LoggerFactory.getLogger(ModifyPeerProcedure.class);<a name="line.53"></a>
 <span class="sourceLineNo">054</span><a name="line.54"></a>
-<span class="sourceLineNo">055</span>  private static final Logger LOG = 
LoggerFactory.getLogger(ModifyPeerProcedure.class);<a name="line.55"></a>
+<span class="sourceLineNo">055</span>  protected static final int 
UPDATE_LAST_SEQ_ID_BATCH_SIZE = 1000;<a name="line.55"></a>
 <span class="sourceLineNo">056</span><a name="line.56"></a>
-<span class="sourceLineNo">057</span>  protected static final int 
UPDATE_LAST_SEQ_ID_BATCH_SIZE = 1000;<a name="line.57"></a>
-<span class="sourceLineNo">058</span><a name="line.58"></a>
-<span class="sourceLineNo">059</span>  protected ModifyPeerProcedure() {<a 
name="line.59"></a>
-<span class="sourceLineNo">060</span>  }<a name="line.60"></a>
-<span class="sourceLineNo">061</span><a name="line.61"></a>
-<span class="sourceLineNo">062</span>  protected ModifyPeerProcedure(String 
peerId) {<a name="line.62"></a>
-<span class="sourceLineNo">063</span>    super(peerId);<a name="line.63"></a>
-<span class="sourceLineNo">064</span>  }<a name="line.64"></a>
-<span class="sourceLineNo">065</span><a name="line.65"></a>
-<span class="sourceLineNo">066</span>  /**<a name="line.66"></a>
-<span class="sourceLineNo">067</span>   * Called before we start the actual 
processing. The implementation should call the pre CP hook,<a 
name="line.67"></a>
-<span class="sourceLineNo">068</span>   * and also the pre-check for the peer 
modification.<a name="line.68"></a>
-<span class="sourceLineNo">069</span>   * &lt;p&gt;<a name="line.69"></a>
-<span class="sourceLineNo">070</span>   * If an IOException is thrown then we 
will give up and mark the procedure as failed directly. If<a name="line.70"></a>
-<span class="sourceLineNo">071</span>   * all checks passes then the procedure 
can not be rolled back any more.<a name="line.71"></a>
-<span class="sourceLineNo">072</span>   */<a name="line.72"></a>
-<span class="sourceLineNo">073</span>  protected abstract void 
prePeerModification(MasterProcedureEnv env)<a name="line.73"></a>
-<span class="sourceLineNo">074</span>      throws IOException, 
ReplicationException;<a name="line.74"></a>
-<span class="sourceLineNo">075</span><a name="line.75"></a>
-<span class="sourceLineNo">076</span>  protected abstract void 
updatePeerStorage(MasterProcedureEnv env) throws ReplicationException;<a 
name="line.76"></a>
-<span class="sourceLineNo">077</span><a name="line.77"></a>
-<span class="sourceLineNo">078</span>  /**<a name="line.78"></a>
-<span class="sourceLineNo">079</span>   * Called before we finish the 
procedure. The implementation can do some logging work, and also<a 
name="line.79"></a>
-<span class="sourceLineNo">080</span>   * call the coprocessor hook if any.<a 
name="line.80"></a>
-<span class="sourceLineNo">081</span>   * &lt;p&gt;<a name="line.81"></a>
-<span class="sourceLineNo">082</span>   * Notice that, since we have already 
done the actual work, throwing {@code IOException} here will<a 
name="line.82"></a>
-<span class="sourceLineNo">083</span>   * not fail this procedure, we will 
just ignore it and finish the procedure as suceeded. If<a name="line.83"></a>
-<span class="sourceLineNo">084</span>   * {@code ReplicationException} is 
thrown we will retry since this usually means we fails to<a name="line.84"></a>
-<span class="sourceLineNo">085</span>   * update the peer storage.<a 
name="line.85"></a>
-<span class="sourceLineNo">086</span>   */<a name="line.86"></a>
-<span class="sourceLineNo">087</span>  protected abstract void 
postPeerModification(MasterProcedureEnv env)<a name="line.87"></a>
-<span class="sourceLineNo">088</span>      throws IOException, 
ReplicationException;<a name="line.88"></a>
-<span class="sourceLineNo">089</span><a name="line.89"></a>
-<span class="sourceLineNo">090</span>  private void releaseLatch() {<a 
name="line.90"></a>
-<span class="sourceLineNo">091</span>    
ProcedurePrepareLatch.releaseLatch(latch, this);<a name="line.91"></a>
-<span class="sourceLineNo">092</span>  }<a name="line.92"></a>
-<span class="sourceLineNo">093</span><a name="line.93"></a>
-<span class="sourceLineNo">094</span>  /**<a name="line.94"></a>
-<span class="sourceLineNo">095</span>   * Implementation class can override 
this method. By default we will jump to<a name="line.95"></a>
-<span class="sourceLineNo">096</span>   * POST_PEER_MODIFICATION and finish 
the procedure.<a name="line.96"></a>
-<span class="sourceLineNo">097</span>   */<a name="line.97"></a>
-<span class="sourceLineNo">098</span>  protected PeerModificationState 
nextStateAfterRefresh() {<a name="line.98"></a>
-<span class="sourceLineNo">099</span>    return 
PeerModificationState.POST_PEER_MODIFICATION;<a name="line.99"></a>
-<span class="sourceLineNo">100</span>  }<a name="line.100"></a>
-<span class="sourceLineNo">101</span><a name="line.101"></a>
-<span class="sourceLineNo">102</span>  /**<a name="line.102"></a>
-<span class="sourceLineNo">103</span>   * The implementation class should 
override this method if the procedure may enter the serial<a 
name="line.103"></a>
-<span class="sourceLineNo">104</span>   * related states.<a 
name="line.104"></a>
-<span class="sourceLineNo">105</span>   */<a name="line.105"></a>
-<span class="sourceLineNo">106</span>  protected boolean 
enablePeerBeforeFinish() {<a name="line.106"></a>
-<span class="sourceLineNo">107</span>    throw new 
UnsupportedOperationException();<a name="line.107"></a>
-<span class="sourceLineNo">108</span>  }<a name="line.108"></a>
-<span class="sourceLineNo">109</span><a name="line.109"></a>
-<span class="sourceLineNo">110</span>  private void 
refreshPeer(MasterProcedureEnv env, PeerOperationType type) {<a 
name="line.110"></a>
-<span class="sourceLineNo">111</span>    
addChildProcedure(env.getMasterServices().getServerManager().getOnlineServersList().stream()<a
 name="line.111"></a>
-<span class="sourceLineNo">112</span>      .map(sn -&gt; new 
RefreshPeerProcedure(peerId, type, sn))<a name="line.112"></a>
-<span class="sourceLineNo">113</span>      
.toArray(RefreshPeerProcedure[]::new));<a name="line.113"></a>
-<span class="sourceLineNo">114</span>  }<a name="line.114"></a>
-<span class="sourceLineNo">115</span><a name="line.115"></a>
-<span class="sourceLineNo">116</span>  protected ReplicationPeerConfig 
getOldPeerConfig() {<a name="line.116"></a>
-<span class="sourceLineNo">117</span>    return null;<a name="line.117"></a>
-<span class="sourceLineNo">118</span>  }<a name="line.118"></a>
-<span class="sourceLineNo">119</span><a name="line.119"></a>
-<span class="sourceLineNo">120</span>  protected ReplicationPeerConfig 
getNewPeerConfig() {<a name="line.120"></a>
-<span class="sourceLineNo">121</span>    throw new 
UnsupportedOperationException();<a name="line.121"></a>
-<span class="sourceLineNo">122</span>  }<a name="line.122"></a>
-<span class="sourceLineNo">123</span><a name="line.123"></a>
-<span class="sourceLineNo">124</span>  protected void 
updateLastPushedSequenceIdForSerialPeer(MasterProcedureEnv env)<a 
name="line.124"></a>
-<span class="sourceLineNo">125</span>      throws IOException, 
ReplicationException {<a name="line.125"></a>
-<span class="sourceLineNo">126</span>    throw new 
UnsupportedOperationException();<a name="line.126"></a>
-<span class="sourceLineNo">127</span>  }<a name="line.127"></a>
-<span class="sourceLineNo">128</span><a name="line.128"></a>
-<span class="sourceLineNo">129</span>  private void 
reopenRegions(MasterProcedureEnv env) throws IOException {<a 
name="line.129"></a>
-<span class="sourceLineNo">130</span>    ReplicationPeerConfig peerConfig = 
getNewPeerConfig();<a name="line.130"></a>
-<span class="sourceLineNo">131</span>    ReplicationPeerConfig oldPeerConfig = 
getOldPeerConfig();<a name="line.131"></a>
-<span class="sourceLineNo">132</span>    TableStateManager tsm = 
env.getMasterServices().getTableStateManager();<a name="line.132"></a>
-<span class="sourceLineNo">133</span>    for (TableDescriptor td : 
env.getMasterServices().getTableDescriptors().getAll().values()) {<a 
name="line.133"></a>
-<span class="sourceLineNo">134</span>      if 
(!td.hasGlobalReplicationScope()) {<a name="line.134"></a>
-<span class="sourceLineNo">135</span>        continue;<a name="line.135"></a>
-<span class="sourceLineNo">136</span>      }<a name="line.136"></a>
-<span class="sourceLineNo">137</span>      TableName tn = td.getTableName();<a 
name="line.137"></a>
-<span class="sourceLineNo">138</span>      if 
(!ReplicationUtils.contains(peerConfig, tn)) {<a name="line.138"></a>
-<span class="sourceLineNo">139</span>        continue;<a name="line.139"></a>
-<span class="sourceLineNo">140</span>      }<a name="line.140"></a>
-<span class="sourceLineNo">141</span>      if (oldPeerConfig != null 
&amp;&amp; oldPeerConfig.isSerial() &amp;&amp;<a name="line.141"></a>
-<span class="sourceLineNo">142</span>        
ReplicationUtils.contains(oldPeerConfig, tn)) {<a name="line.142"></a>
-<span class="sourceLineNo">143</span>        continue;<a name="line.143"></a>
-<span class="sourceLineNo">144</span>      }<a name="line.144"></a>
-<span class="sourceLineNo">145</span>      try {<a name="line.145"></a>
-<span class="sourceLineNo">146</span>        if 
(!tsm.getTableState(tn).isEnabled()) {<a name="line.146"></a>
-<span class="sourceLineNo">147</span>          continue;<a name="line.147"></a>
-<span class="sourceLineNo">148</span>        }<a name="line.148"></a>
-<span class="sourceLineNo">149</span>      } catch 
(TableStateNotFoundException e) {<a name="line.149"></a>
-<span class="sourceLineNo">150</span>        continue;<a name="line.150"></a>
-<span class="sourceLineNo">151</span>      }<a name="line.151"></a>
-<span class="sourceLineNo">152</span>      
addChildProcedure(env.getAssignmentManager().createReopenProcedures(<a 
name="line.152"></a>
-<span class="sourceLineNo">153</span>        
env.getAssignmentManager().getRegionStates().getRegionsOfTable(tn)));<a 
name="line.153"></a>
-<span class="sourceLineNo">154</span>    }<a name="line.154"></a>
-<span class="sourceLineNo">155</span>  }<a name="line.155"></a>
-<span class="sourceLineNo">156</span><a name="line.156"></a>
-<span class="sourceLineNo">157</span>  private void addToMap(Map&lt;String, 
Long&gt; lastSeqIds, String encodedRegionName, long barrier,<a 
name="line.157"></a>
-<span class="sourceLineNo">158</span>      ReplicationQueueStorage 
queueStorage) throws ReplicationException {<a name="line.158"></a>
-<span class="sourceLineNo">159</span>    if (barrier &gt;= 0) {<a 
name="line.159"></a>
-<span class="sourceLineNo">160</span>      lastSeqIds.put(encodedRegionName, 
barrier);<a name="line.160"></a>
-<span class="sourceLineNo">161</span>      if (lastSeqIds.size() &gt;= 
UPDATE_LAST_SEQ_ID_BATCH_SIZE) {<a name="line.161"></a>
-<span class="sourceLineNo">162</span>        
queueStorage.setLastSequenceIds(peerId, lastSeqIds);<a name="line.162"></a>
-<span class="sourceLineNo">163</span>        lastSeqIds.clear();<a 
name="line.163"></a>
-<span class="sourceLineNo">164</span>      }<a name="line.164"></a>
-<span class="sourceLineNo">165</span>    }<a name="line.165"></a>
-<span class="sourceLineNo">166</span>  }<a name="line.166"></a>
-<span class="sourceLineNo">167</span><a name="line.167"></a>
-<span class="sourceLineNo">168</span>  protected final void 
setLastPushedSequenceId(MasterProcedureEnv env,<a name="line.168"></a>
-<span class="sourceLineNo">169</span>      ReplicationPeerConfig peerConfig) 
throws IOException, ReplicationException {<a name="line.169"></a>
-<span class="sourceLineNo">170</span>    Map&lt;String, Long&gt; lastSeqIds = 
new HashMap&lt;String, Long&gt;();<a name="line.170"></a>
-<span class="sourceLineNo">171</span>    for (TableDescriptor td : 
env.getMasterServices().getTableDescriptors().getAll().values()) {<a 
name="line.171"></a>
-<span class="sourceLineNo">172</span>      if 
(!td.hasGlobalReplicationScope()) {<a name="line.172"></a>
-<span class="sourceLineNo">173</span>        continue;<a name="line.173"></a>
-<span class="sourceLineNo">174</span>      }<a name="line.174"></a>
-<span class="sourceLineNo">175</span>      TableName tn = td.getTableName();<a 
name="line.175"></a>
-<span class="sourceLineNo">176</span>      if 
(!ReplicationUtils.contains(peerConfig, tn)) {<a name="line.176"></a>
-<span class="sourceLineNo">177</span>        continue;<a name="line.177"></a>
-<span class="sourceLineNo">178</span>      }<a name="line.178"></a>
-<span class="sourceLineNo">179</span>      
setLastPushedSequenceIdForTable(env, tn, lastSeqIds);<a name="line.179"></a>
-<span class="sourceLineNo">180</span>    }<a name="line.180"></a>
-<span class="sourceLineNo">181</span>    if (!lastSeqIds.isEmpty()) {<a 
name="line.181"></a>
-<span class="sourceLineNo">182</span>      
env.getReplicationPeerManager().getQueueStorage().setLastSequenceIds(peerId, 
lastSeqIds);<a name="line.182"></a>
-<span class="sourceLineNo">183</span>    }<a name="line.183"></a>
-<span class="sourceLineNo">184</span>  }<a name="line.184"></a>
-<span class="sourceLineNo">185</span><a name="line.185"></a>
-<span class="sourceLineNo">186</span>  // Will put the 
encodedRegionName-&gt;lastPushedSeqId pair into the map passed in, if the map 
is<a name="line.186"></a>
-<span class="sourceLineNo">187</span>  // large enough we will call 
queueStorage.setLastSequenceIds and clear the map. So the caller<a 
name="line.187"></a>
-<span class="sourceLineNo">188</span>  // should not forget to check whether 
the map is empty at last, if not you should call<a name="line.188"></a>
-<span class="sourceLineNo">189</span>  // queueStorage.setLastSequenceIds to 
write out the remaining entries in the map.<a name="line.189"></a>
-<span class="sourceLineNo">190</span>  protected final void 
setLastPushedSequenceIdForTable(MasterProcedureEnv env, TableName tableName,<a 
name="line.190"></a>
-<span class="sourceLineNo">191</span>      Map&lt;String, Long&gt; lastSeqIds) 
throws IOException, ReplicationException {<a name="line.191"></a>
-<span class="sourceLineNo">192</span>    TableStateManager tsm = 
env.getMasterServices().getTableStateManager();<a name="line.192"></a>
-<span class="sourceLineNo">193</span>    ReplicationQueueStorage queueStorage 
= env.getReplicationPeerManager().getQueueStorage();<a name="line.193"></a>
-<span class="sourceLineNo">194</span>    Connection conn = 
env.getMasterServices().getConnection();<a name="line.194"></a>
-<span class="sourceLineNo">195</span>    RegionStates regionStates = 
env.getAssignmentManager().getRegionStates();<a name="line.195"></a>
-<span class="sourceLineNo">196</span>    MasterFileSystem mfs = 
env.getMasterServices().getMasterFileSystem();<a name="line.196"></a>
-<span class="sourceLineNo">197</span>    boolean isTableEnabled;<a 
name="line.197"></a>
-<span class="sourceLineNo">198</span>    try {<a name="line.198"></a>
-<span class="sourceLineNo">199</span>      isTableEnabled = 
tsm.getTableState(tableName).isEnabled();<a name="line.199"></a>
-<span class="sourceLineNo">200</span>    } catch (TableStateNotFoundException 
e) {<a name="line.200"></a>
-<span class="sourceLineNo">201</span>      return;<a name="line.201"></a>
-<span class="sourceLineNo">202</span>    }<a name="line.202"></a>
-<span class="sourceLineNo">203</span>    if (isTableEnabled) {<a 
name="line.203"></a>
-<span class="sourceLineNo">204</span>      for (Pair&lt;String, Long&gt; 
name2Barrier : MetaTableAccessor<a name="line.204"></a>
-<span class="sourceLineNo">205</span>        
.getTableEncodedRegionNameAndLastBarrier(conn, tableName)) {<a 
name="line.205"></a>
-<span class="sourceLineNo">206</span>        addToMap(lastSeqIds, 
name2Barrier.getFirst(), name2Barrier.getSecond().longValue() - 1,<a 
name="line.206"></a>
-<span class="sourceLineNo">207</span>          queueStorage);<a 
name="line.207"></a>
-<span class="sourceLineNo">208</span>      }<a name="line.208"></a>
-<span class="sourceLineNo">209</span>    } else {<a name="line.209"></a>
-<span class="sourceLineNo">210</span>      for (RegionInfo region : 
regionStates.getRegionsOfTable(tableName, true)) {<a name="line.210"></a>
-<span class="sourceLineNo">211</span>        long maxSequenceId =<a 
name="line.211"></a>
-<span class="sourceLineNo">212</span>          
WALSplitter.getMaxRegionSequenceId(mfs.getFileSystem(), 
mfs.getRegionDir(region));<a name="line.212"></a>
-<span class="sourceLineNo">213</span>        addToMap(lastSeqIds, 
region.getEncodedName(), maxSequenceId, queueStorage);<a name="line.213"></a>
-<span class="sourceLineNo">214</span>      }<a name="line.214"></a>
-<span class="sourceLineNo">215</span>    }<a name="line.215"></a>
-<span class="sourceLineNo">216</span>  }<a name="line.216"></a>
-<span class="sourceLineNo">217</span><a name="line.217"></a>
-<span class="sourceLineNo">218</span>  @Override<a name="line.218"></a>
-<span class="sourceLineNo">219</span>  protected Flow 
executeFromState(MasterProcedureEnv env, PeerModificationState state)<a 
name="line.219"></a>
-<span class="sourceLineNo">220</span>      throws ProcedureSuspendedException, 
ProcedureYieldException, InterruptedException {<a name="line.220"></a>
-<span class="sourceLineNo">221</span>    switch (state) {<a 
name="line.221"></a>
-<span class="sourceLineNo">222</span>      case PRE_PEER_MODIFICATION:<a 
name="line.222"></a>
-<span class="sourceLineNo">223</span>        try {<a name="line.223"></a>
-<span class="sourceLineNo">224</span>          prePeerModification(env);<a 
name="line.224"></a>
-<span class="sourceLineNo">225</span>        } catch (IOException e) {<a 
name="line.225"></a>
-<span class="sourceLineNo">226</span>          LOG.warn("{} failed to call pre 
CP hook or the pre check is failed for peer {}, " +<a name="line.226"></a>
-<span class="sourceLineNo">227</span>            "mark the procedure as 
failure and give up", getClass().getName(), peerId, e);<a name="line.227"></a>
-<span class="sourceLineNo">228</span>          setFailure("master-" + 
getPeerOperationType().name().toLowerCase() + "-peer", e);<a 
name="line.228"></a>
-<span class="sourceLineNo">229</span>          releaseLatch();<a 
name="line.229"></a>
-<span class="sourceLineNo">230</span>          return Flow.NO_MORE_STATE;<a 
name="line.230"></a>
-<span class="sourceLineNo">231</span>        } catch (ReplicationException e) 
{<a name="line.231"></a>
-<span class="sourceLineNo">232</span>          LOG.warn("{} failed to call 
prePeerModification for peer {}, retry", getClass().getName(),<a 
name="line.232"></a>
-<span class="sourceLineNo">233</span>            peerId, e);<a 
name="line.233"></a>
-<span class="sourceLineNo">234</span>          throw new 
ProcedureYieldException();<a name="line.234"></a>
-<span class="sourceLineNo">235</span>        }<a name="line.235"></a>
-<span class="sourceLineNo">236</span>        
setNextState(PeerModificationState.UPDATE_PEER_STORAGE);<a name="line.236"></a>
-<span class="sourceLineNo">237</span>        return Flow.HAS_MORE_STATE;<a 
name="line.237"></a>
-<span class="sourceLineNo">238</span>      case UPDATE_PEER_STORAGE:<a 
name="line.238"></a>
-<span class="sourceLineNo">239</span>        try {<a name="line.239"></a>
-<span class="sourceLineNo">240</span>          updatePeerStorage(env);<a 
name="line.240"></a>
-<span class="sourceLineNo">241</span>        } catch (ReplicationException e) 
{<a name="line.241"></a>
-<span class="sourceLineNo">242</span>          LOG.warn("{} update peer 
storage for peer {} failed, retry", getClass().getName(), peerId,<a 
name="line.242"></a>
-<span class="sourceLineNo">243</span>            e);<a name="line.243"></a>
-<span class="sourceLineNo">244</span>          throw new 
ProcedureYieldException();<a name="line.244"></a>
-<span class="sourceLineNo">245</span>        }<a name="line.245"></a>
-<span class="sourceLineNo">246</span>        
setNextState(PeerModificationState.REFRESH_PEER_ON_RS);<a name="line.246"></a>
-<span class="sourceLineNo">247</span>        return Flow.HAS_MORE_STATE;<a 
name="line.247"></a>
-<span class="sourceLineNo">248</span>      case REFRESH_PEER_ON_RS:<a 
name="line.248"></a>
-<span class="sourceLineNo">249</span>        refreshPeer(env, 
getPeerOperationType());<a name="line.249"></a>
-<span class="sourceLineNo">250</span>        
setNextState(nextStateAfterRefresh());<a name="line.250"></a>
-<span class="sourceLineNo">251</span>        return Flow.HAS_MORE_STATE;<a 
name="line.251"></a>
-<span class="sourceLineNo">252</span>      case SERIAL_PEER_REOPEN_REGIONS:<a 
name="line.252"></a>
-<span class="sourceLineNo">253</span>        try {<a name="line.253"></a>
-<span class="sourceLineNo">254</span>          reopenRegions(env);<a 
name="line.254"></a>
-<span class="sourceLineNo">255</span>        } catch (Exception e) {<a 
name="line.255"></a>
-<span class="sourceLineNo">256</span>          LOG.warn("{} reopen regions for 
peer {} failed, retry", getClass().getName(), peerId, e);<a name="line.256"></a>
-<span class="sourceLineNo">257</span>          throw new 
ProcedureYieldException();<a name="line.257"></a>
-<span class="sourceLineNo">258</span>        }<a name="line.258"></a>
-<span class="sourceLineNo">259</span>        
setNextState(PeerModificationState.SERIAL_PEER_UPDATE_LAST_PUSHED_SEQ_ID);<a 
name="line.259"></a>
-<span class="sourceLineNo">260</span>        return Flow.HAS_MORE_STATE;<a 
name="line.260"></a>
-<span class="sourceLineNo">261</span>      case 
SERIAL_PEER_UPDATE_LAST_PUSHED_SEQ_ID:<a name="line.261"></a>
-<span class="sourceLineNo">262</span>        try {<a name="line.262"></a>
-<span class="sourceLineNo">263</span>          
updateLastPushedSequenceIdForSerialPeer(env);<a name="line.263"></a>
-<span class="sourceLineNo">264</span>        } catch (Exception e) {<a 
name="line.264"></a>
-<span class="sourceLineNo">265</span>          LOG.warn("{} set last sequence 
id for peer {} failed, retry", getClass().getName(),<a name="line.265"></a>
-<span class="sourceLineNo">266</span>            peerId, e);<a 
name="line.266"></a>
-<span class="sourceLineNo">267</span>          throw new 
ProcedureYieldException();<a name="line.267"></a>
-<span class="sourceLineNo">268</span>        }<a name="line.268"></a>
-<span class="sourceLineNo">269</span>        
setNextState(enablePeerBeforeFinish() ? 
PeerModificationState.SERIAL_PEER_SET_PEER_ENABLED<a name="line.269"></a>
-<span class="sourceLineNo">270</span>          : 
PeerModificationState.POST_PEER_MODIFICATION);<a name="line.270"></a>
+<span class="sourceLineNo">057</span>  // The sleep interval when waiting 
table to be enabled or disabled.<a name="line.57"></a>
+<span class="sourceLineNo">058</span>  protected static final int 
SLEEP_INTERVAL_MS = 1000;<a name="line.58"></a>
+<span class="sourceLineNo">059</span><a name="line.59"></a>
+<span class="sourceLineNo">060</span>  protected ModifyPeerProcedure() {<a 
name="line.60"></a>
+<span class="sourceLineNo">061</span>  }<a name="line.61"></a>
+<span class="sourceLineNo">062</span><a name="line.62"></a>
+<span class="sourceLineNo">063</span>  protected ModifyPeerProcedure(String 
peerId) {<a name="line.63"></a>
+<span class="sourceLineNo">064</span>    super(peerId);<a name="line.64"></a>
+<span class="sourceLineNo">065</span>  }<a name="line.65"></a>
+<span class="sourceLineNo">066</span><a name="line.66"></a>
+<span class="sourceLineNo">067</span>  /**<a name="line.67"></a>
+<span class="sourceLineNo">068</span>   * Called before we start the actual 
processing. The implementation should call the pre CP hook,<a 
name="line.68"></a>
+<span class="sourceLineNo">069</span>   * and also the pre-check for the peer 
modification.<a name="line.69"></a>
+<span class="sourceLineNo">070</span>   * &lt;p&gt;<a name="line.70"></a>
+<span class="sourceLineNo">071</span>   * If an IOException is thrown then we 
will give up and mark the procedure as failed directly. If<a name="line.71"></a>
+<span class="sourceLineNo">072</span>   * all checks passes then the procedure 
can not be rolled back any more.<a name="line.72"></a>
+<span class="sourceLineNo">073</span>   */<a name="line.73"></a>
+<span class="sourceLineNo">074</span>  protected abstract void 
prePeerModification(MasterProcedureEnv env)<a name="line.74"></a>
+<span class="sourceLineNo">075</span>      throws IOException, 
ReplicationException;<a name="line.75"></a>
+<span class="sourceLineNo">076</span><a name="line.76"></a>
+<span class="sourceLineNo">077</span>  protected abstract void 
updatePeerStorage(MasterProcedureEnv env) throws ReplicationException;<a 
name="line.77"></a>
+<span class="sourceLineNo">078</span><a name="line.78"></a>
+<span class="sourceLineNo">079</span>  /**<a name="line.79"></a>
+<span class="sourceLineNo">080</span>   * Called before we finish the 
procedure. The implementation can do some logging work, and also<a 
name="line.80"></a>
+<span class="sourceLineNo">081</span>   * call the coprocessor hook if any.<a 
name="line.81"></a>
+<span class="sourceLineNo">082</span>   * &lt;p&gt;<a name="line.82"></a>
+<span class="sourceLineNo">083</span>   * Notice that, since we have already 
done the actual work, throwing {@code IOException} here will<a 
name="line.83"></a>
+<span class="sourceLineNo">084</span>   * not fail this procedure, we will 
just ignore it and finish the procedure as suceeded. If<a name="line.84"></a>
+<span class="sourceLineNo">085</span>   * {@code ReplicationException} is 
thrown we will retry since this usually means we fails to<a name="line.85"></a>
+<span class="sourceLineNo">086</span>   * update the peer storage.<a 
name="line.86"></a>
+<span class="sourceLineNo">087</span>   */<a name="line.87"></a>
+<span class="sourceLineNo">088</span>  protected abstract void 
postPeerModification(MasterProcedureEnv env)<a name="line.88"></a>
+<span class="sourceLineNo">089</span>      throws IOException, 
ReplicationException;<a name="line.89"></a>
+<span class="sourceLineNo">090</span><a name="line.90"></a>
+<span class="sourceLineNo">091</span>  private void releaseLatch() {<a 
name="line.91"></a>
+<span class="sourceLineNo">092</span>    
ProcedurePrepareLatch.releaseLatch(latch, this);<a name="line.92"></a>
+<span class="sourceLineNo">093</span>  }<a name="line.93"></a>
+<span class="sourceLineNo">094</span><a name="line.94"></a>
+<span class="sourceLineNo">095</span>  /**<a name="line.95"></a>
+<span class="sourceLineNo">096</span>   * Implementation class can override 
this method. By default we will jump to<a name="line.96"></a>
+<span class="sourceLineNo">097</span>   * POST_PEER_MODIFICATION and finish 
the procedure.<a name="line.97"></a>
+<span class="sourceLineNo">098</span>   */<a name="line.98"></a>
+<span class="sourceLineNo">099</span>  protected PeerModificationState 
nextStateAfterRefresh() {<a name="line.99"></a>
+<span class="sourceLineNo">100</span>    return 
PeerModificationState.POST_PEER_MODIFICATION;<a name="line.100"></a>
+<span class="sourceLineNo">101</span>  }<a name="line.101"></a>
+<span class="sourceLineNo">102</span><a name="line.102"></a>
+<span class="sourceLineNo">103</span>  /**<a name="line.103"></a>
+<span class="sourceLineNo">104</span>   * The implementation class should 
override this method if the procedure may enter the serial<a 
name="line.104"></a>
+<span class="sourceLineNo">105</span>   * related states.<a 
name="line.105"></a>
+<span class="sourceLineNo">106</span>   */<a name="line.106"></a>
+<span class="sourceLineNo">107</span>  protected boolean 
enablePeerBeforeFinish() {<a name="line.107"></a>
+<span class="sourceLineNo">108</span>    throw new 
UnsupportedOperationException();<a name="line.108"></a>
+<span class="sourceLineNo">109</span>  }<a name="line.109"></a>
+<span class="sourceLineNo">110</span><a name="line.110"></a>
+<span class="sourceLineNo">111</span>  private void 
refreshPeer(MasterProcedureEnv env, PeerOperationType type) {<a 
name="line.111"></a>
+<span class="sourceLineNo">112</span>    
addChildProcedure(env.getMasterServices().getServerManager().getOnlineServersList().stream()<a
 name="line.112"></a>
+<span class="sourceLineNo">113</span>      .map(sn -&gt; new 
RefreshPeerProcedure(peerId, type, sn))<a name="line.113"></a>
+<span class="sourceLineNo">114</span>      
.toArray(RefreshPeerProcedure[]::new));<a name="line.114"></a>
+<span class="sourceLineNo">115</span>  }<a name="line.115"></a>
+<span class="sourceLineNo">116</span><a name="line.116"></a>
+<span class="sourceLineNo">117</span>  protected ReplicationPeerConfig 
getOldPeerConfig() {<a name="line.117"></a>
+<span class="sourceLineNo">118</span>    return null;<a name="line.118"></a>
+<span class="sourceLineNo">119</span>  }<a name="line.119"></a>
+<span class="sourceLineNo">120</span><a name="line.120"></a>
+<span class="sourceLineNo">121</span>  protected ReplicationPeerConfig 
getNewPeerConfig() {<a name="line.121"></a>
+<span class="sourceLineNo">122</span>    throw new 
UnsupportedOperationException();<a name="line.122"></a>
+<span class="sourceLineNo">123</span>  }<a name="line.123"></a>
+<span class="sourceLineNo">124</span><a name="line.124"></a>
+<span class="sourceLineNo">125</span>  protected void 
updateLastPushedSequenceIdForSerialPeer(MasterProcedureEnv env)<a 
name="line.125"></a>
+<span class="sourceLineNo">126</span>      throws IOException, 
ReplicationException {<a name="line.126"></a>
+<span class="sourceLineNo">127</span>    throw new 
UnsupportedOperationException();<a name="line.127"></a>
+<span class="sourceLineNo">128</span>  }<a name="line.128"></a>
+<span class="sourceLineNo">129</span><a name="line.129"></a>
+<span class="sourceLineNo">130</span>  // If the table is in enabling state, 
we need to wait until it is enabled and then reopen all its<a 
name="line.130"></a>
+<span class="sourceLineNo">131</span>  // regions.<a name="line.131"></a>
+<span class="sourceLineNo">132</span>  private boolean 
needReopen(TableStateManager tsm, TableName tn) throws IOException {<a 
name="line.132"></a>
+<span class="sourceLineNo">133</span>    for (;;) {<a name="line.133"></a>
+<span class="sourceLineNo">134</span>      try {<a name="line.134"></a>
+<span class="sourceLineNo">135</span>        TableState state = 
tsm.getTableState(tn);<a name="line.135"></a>
+<span class="sourceLineNo">136</span>        if (state.isEnabled()) {<a 
name="line.136"></a>
+<span class="sourceLineNo">137</span>          return true;<a 
name="line.137"></a>
+<span class="sourceLineNo">138</span>        }<a name="line.138"></a>
+<span class="sourceLineNo">139</span>        if (!state.isEnabling()) {<a 
name="line.139"></a>
+<span class="sourceLineNo">140</span>          return false;<a 
name="line.140"></a>
+<span class="sourceLineNo">141</span>        }<a name="line.141"></a>
+<span class="sourceLineNo">142</span>        
Thread.sleep(SLEEP_INTERVAL_MS);<a name="line.142"></a>
+<span class="sourceLineNo">143</span>      } catch 
(TableStateNotFoundException e) {<a name="line.143"></a>
+<span class="sourceLineNo">144</span>        return false;<a 
name="line.144"></a>
+<span class="sourceLineNo">145</span>      } catch (InterruptedException e) 
{<a name="line.145"></a>
+<span class="sourceLineNo">146</span>        throw (IOException) new 
InterruptedIOException(e.getMessage()).initCause(e);<a name="line.146"></a>
+<span class="sourceLineNo">147</span>      }<a name="line.147"></a>
+<span class="sourceLineNo">148</span>    }<a name="line.148"></a>
+<span class="sourceLineNo">149</span>  }<a name="line.149"></a>
+<span class="sourceLineNo">150</span><a name="line.150"></a>
+<span class="sourceLineNo">151</span>  private void 
reopenRegions(MasterProcedureEnv env) throws IOException {<a 
name="line.151"></a>
+<span class="sourceLineNo">152</span>    ReplicationPeerConfig peerConfig = 
getNewPeerConfig();<a name="line.152"></a>
+<span class="sourceLineNo">153</span>    ReplicationPeerConfig oldPeerConfig = 
getOldPeerConfig();<a name="line.153"></a>
+<span class="sourceLineNo">154</span>    TableStateManager tsm = 
env.getMasterServices().getTableStateManager();<a name="line.154"></a>
+<span class="sourceLineNo">155</span>    for (TableDescriptor td : 
env.getMasterServices().getTableDescriptors().getAll().values()) {<a 
name="line.155"></a>
+<span class="sourceLineNo">156</span>      if 
(!td.hasGlobalReplicationScope()) {<a name="line.156"></a>
+<span class="sourceLineNo">157</span>        continue;<a name="line.157"></a>
+<span class="sourceLineNo">158</span>      }<a name="line.158"></a>
+<span class="sourceLineNo">159</span>      TableName tn = td.getTableName();<a 
name="line.159"></a>
+<span class="sourceLineNo">160</span>      if 
(!ReplicationUtils.contains(peerConfig, tn)) {<a name="line.160"></a>
+<span class="sourceLineNo">161</span>        continue;<a name="line.161"></a>
+<span class="sourceLineNo">162</span>      }<a name="line.162"></a>
+<span class="sourceLineNo">163</span>      if (oldPeerConfig != null 
&amp;&amp; oldPeerConfig.isSerial() &amp;&amp;<a name="line.163"></a>
+<span class="sourceLineNo">164</span>        
ReplicationUtils.contains(oldPeerConfig, tn)) {<a name="line.164"></a>
+<span class="sourceLineNo">165</span>        continue;<a name="line.165"></a>
+<span class="sourceLineNo">166</span>      }<a name="line.166"></a>
+<span class="sourceLineNo">167</span>      if (needReopen(tsm, tn)) {<a 
name="line.167"></a>
+<span class="sourceLineNo">168</span>        
addChildProcedure(env.getAssignmentManager().createReopenProcedures(<a 
name="line.168"></a>
+<span class="sourceLineNo">169</span>          
env.getAssignmentManager().getRegionStates().getRegionsOfTable(tn)));<a 
name="line.169"></a>
+<span class="sourceLineNo">170</span>      }<a name="line.170"></a>
+<span class="sourceLineNo">171</span>    }<a name="line.171"></a>
+<span class="sourceLineNo">172</span>  }<a name="line.172"></a>
+<span class="sourceLineNo">173</span><a name="line.173"></a>
+<span class="sourceLineNo">174</span>  private void addToMap(Map&lt;String, 
Long&gt; lastSeqIds, String encodedRegionName, long barrier,<a 
name="line.174"></a>
+<span class="sourceLineNo">175</span>      ReplicationQueueStorage 
queueStorage) throws ReplicationException {<a name="line.175"></a>
+<span class="sourceLineNo">176</span>    if (barrier &gt;= 0) {<a 
name="line.176"></a>
+<span class="sourceLineNo">177</span>      lastSeqIds.put(encodedRegionName, 
barrier);<a name="line.177"></a>
+<span class="sourceLineNo">178</span>      if (lastSeqIds.size() &gt;= 
UPDATE_LAST_SEQ_ID_BATCH_SIZE) {<a name="line.178"></a>
+<span class="sourceLineNo">179</span>        
queueStorage.setLastSequenceIds(peerId, lastSeqIds);<a name="line.179"></a>
+<span class="sourceLineNo">180</span>        lastSeqIds.clear();<a 
name="line.180"></a>
+<span class="sourceLineNo">181</span>      }<a name="line.181"></a>
+<span class="sourceLineNo">182</span>    }<a name="line.182"></a>
+<span class="sourceLineNo">183</span>  }<a name="line.183"></a>
+<span class="sourceLineNo">184</span><a name="line.184"></a>
+<span class="sourceLineNo">185</span>  protected final void 
setLastPushedSequenceId(MasterProcedureEnv env,<a name="line.185"></a>
+<span class="sourceLineNo">186</span>      ReplicationPeerConfig peerConfig) 
throws IOException, ReplicationException {<a name="line.186"></a>
+<span class="sourceLineNo">187</span>    Map&lt;String, Long&gt; lastSeqIds = 
new HashMap&lt;String, Long&gt;();<a name="line.187"></a>
+<span class="sourceLineNo">188</span>    for (TableDescriptor td : 
env.getMasterServices().getTableDescriptors().getAll().values()) {<a 
name="line.188"></a>
+<span class="sourceLineNo">189</span>      if 
(!td.hasGlobalReplicationScope()) {<a name="line.189"></a>
+<span class="sourceLineNo">190</span>        continue;<a name="line.190"></a>
+<span class="sourceLineNo">191</span>      }<a name="line.191"></a>
+<span class="sourceLineNo">192</span>      TableName tn = td.getTableName();<a 
name="line.192"></a>
+<span class="sourceLineNo">193</span>      if 
(!ReplicationUtils.contains(peerConfig, tn)) {<a name="line.193"></a>
+<span class="sourceLineNo">194</span>        continue;<a name="line.194"></a>
+<span class="sourceLineNo">195</span>      }<a name="line.195"></a>
+<span class="sourceLineNo">196</span>      
setLastPushedSequenceIdForTable(env, tn, lastSeqIds);<a name="line.196"></a>
+<span class="sourceLineNo">197</span>    }<a name="line.197"></a>
+<span class="sourceLineNo">198</span>    if (!lastSeqIds.isEmpty()) {<a 
name="line.198"></a>
+<span class="sourceLineNo">199</span>      
env.getReplicationPeerManager().getQueueStorage().setLastSequenceIds(peerId, 
lastSeqIds);<a name="line.199"></a>
+<span class="sourceLineNo">200</span>    }<a name="line.200"></a>
+<span class="sourceLineNo">201</span>  }<a name="line.201"></a>
+<span class="sourceLineNo">202</span><a name="line.202"></a>
+<span class="sourceLineNo">203</span>  // If the table is currently disabling, 
then we need to wait until it is disabled.We will write<a name="line.203"></a>
+<span class="sourceLineNo">204</span>  // replication barrier for a disabled 
table. And return whether we need to update the last pushed<a 
name="line.204"></a>
+<span class="sourceLineNo">205</span>  // sequence id, if the table has been 
deleted already, i.e, we hit TableStateNotFoundException,<a name="line.205"></a>
+<span class="sourceLineNo">206</span>  // then we do not need to update last 
pushed sequence id for this table.<a name="line.206"></a>
+<span class="sourceLineNo">207</span>  private boolean 
needSetLastPushedSequenceId(TableStateManager tsm, TableName tn)<a 
name="line.207"></a>
+<span class="sourceLineNo">208</span>      throws IOException {<a 
name="line.208"></a>
+<span class="sourceLineNo">209</span>    for (;;) {<a name="line.209"></a>
+<span class="sourceLineNo">210</span>      try {<a name="line.210"></a>
+<span class="sourceLineNo">211</span>        if 
(!tsm.getTableState(tn).isDisabling()) {<a name="line.211"></a>
+<span class="sourceLineNo">212</span>          return true;<a 
name="line.212"></a>
+<span class="sourceLineNo">213</span>        }<a name="line.213"></a>
+<span class="sourceLineNo">214</span>        
Thread.sleep(SLEEP_INTERVAL_MS);<a name="line.214"></a>
+<span class="sourceLineNo">215</span>      } catch 
(TableStateNotFoundException e) {<a name="line.215"></a>
+<span class="sourceLineNo">216</span>        return false;<a 
name="line.216"></a>
+<span class="sourceLineNo">217</span>      } catch (InterruptedException e) 
{<a name="line.217"></a>
+<span class="sourceLineNo">218</span>        throw (IOException) new 
InterruptedIOException(e.getMessage()).initCause(e);<a name="line.218"></a>
+<span class="sourceLineNo">219</span>      }<a name="line.219"></a>
+<span class="sourceLineNo">220</span>    }<a name="line.220"></a>
+<span class="sourceLineNo">221</span>  }<a name="line.221"></a>
+<span class="sourceLineNo">222</span><a name="line.222"></a>
+<span class="sourceLineNo">223</span>  // Will put the 
encodedRegionName-&gt;lastPushedSeqId pair into the map passed in, if the map 
is<a name="line.223"></a>
+<span class="sourceLineNo">224</span>  // large enough we will call 
queueStorage.setLastSequenceIds and clear the map. So the caller<a 
name="line.224"></a>
+<span class="sourceLineNo">225</span>  // should not forget to check whether 
the map is empty at last, if not you should call<a name="line.225"></a>
+<span class="sourceLineNo">226</span>  // queueStorage.setLastSequenceIds to 
write out the remaining entries in the map.<a name="line.226"></a>
+<span class="sourceLineNo">227</span>  protected final void 
setLastPushedSequenceIdForTable(MasterProcedureEnv env, TableName tableName,<a 
name="line.227"></a>
+<span class="sourceLineNo">228</span>      Map&lt;String, Long&gt; lastSeqIds) 
throws IOException, ReplicationException {<a name="line.228"></a>
+<span class="sourceLineNo">229</span>    TableStateManager tsm = 
env.getMasterServices().getTableStateManager();<a name="line.229"></a>
+<span class="sourceLineNo">230</span>    ReplicationQueueStorage queueStorage 
= env.getReplicationPeerManager().getQueueStorage();<a name="line.230"></a>
+<span class="sourceLineNo">231</span>    Connection conn = 
env.getMasterServices().getConnection();<a name="line.231"></a>
+<span class="sourceLineNo">232</span>    if (!needSetLastPushedSequenceId(tsm, 
tableName)) {<a name="line.232"></a>
+<span class="sourceLineNo">233</span>      return;<a name="line.233"></a>
+<span class="sourceLineNo">234</span>    }<a name="line.234"></a>
+<span class="sourceLineNo">235</span>    for (Pair&lt;String, Long&gt; 
name2Barrier : MetaTableAccessor<a name="line.235"></a>
+<span class="sourceLineNo">236</span>      
.getTableEncodedRegionNameAndLastBarrier(conn, tableName)) {<a 
name="line.236"></a>
+<span class="sourceLineNo">237</span>      addToMap(lastSeqIds, 
name2Barrier.getFirst(), name2Barrier.getSecond().longValue() - 1,<a 
name="line.237"></a>
+<span class="sourceLineNo">238</span>        queueStorage);<a 
name="line.238"></a>
+<span class="sourceLineNo">239</span>    }<a name="line.239"></a>
+<span class="sourceLineNo">240</span>  }<a name="line.240"></a>
+<span class="sourceLineNo">241</span><a name="line.241"></a>
+<span class="sourceLineNo">242</span>  @Override<a name="line.242"></a>
+<span class="sourceLineNo">243</span>  protected Flow 
executeFromState(MasterProcedureEnv env, PeerModificationState state)<a 
name="line.243"></a>
+<span class="sourceLineNo">244</span>      throws ProcedureSuspendedException, 
ProcedureYieldException, InterruptedException {<a name="line.244"></a>
+<span class="sourceLineNo">245</span>    switch (state) {<a 
name="line.245"></a>
+<span class="sourceLineNo">246</span>      case PRE_PEER_MODIFICATION:<a 
name="line.246"></a>
+<span class="sourceLineNo">247</span>        try {<a name="line.247"></a>
+<span class="sourceLineNo">248</span>          prePeerModification(env);<a 
name="line.248"></a>
+<span class="sourceLineNo">249</span>        } catch (IOException e) {<a 
name="line.249"></a>
+<span class="sourceLineNo">250</span>          LOG.warn("{} failed to call pre 
CP hook or the pre check is failed for peer {}, " +<a name="line.250"></a>
+<span class="sourceLineNo">251</span>            "mark the procedure as 
failure and give up", getClass().getName(), peerId, e);<a name="line.251"></a>
+<span class="sourceLineNo">252</span>          setFailure("master-" + 
getPeerOperationType().name().toLowerCase() + "-peer", e);<a 
name="line.252"></a>
+<span class="sourceLineNo">253</span>          releaseLatch();<a 
name="line.253"></a>
+<span class="sourceLineNo">254</span>          return Flow.NO_MORE_STATE;<a 
name="line.254"></a>
+<span class="sourceLineNo">255</span>        } catch (ReplicationException e) 
{<a name="line.255"></a>
+<span class="sourceLineNo">256</span>          LOG.warn("{} failed to call 
prePeerModification for peer {}, retry", getClass().getName(),<a 
name="line.256"></a>
+<span class="sourceLineNo">257</span>            peerId, e);<a 
name="line.257"></a>
+<span class="sourceLineNo">258</span>          throw new 
ProcedureYieldException();<a name="line.258"></a>
+<span class="sourceLineNo">259</span>        }<a name="line.259"></a>
+<span class="sourceLineNo">260</span>        
setNextState(PeerModificationState.UPDATE_PEER_STORAGE);<a name="line.260"></a>
+<span class="sourceLineNo">261</span>        return Flow.HAS_MORE_STATE;<a 
name="line.261"></a>
+<span class="sourceLineNo">262</span>      case UPDATE_PEER_STORAGE:<a 
name="line.262"></a>
+<span class="sourceLineNo">263</span>        try {<a name="line.263"></a>
+<span class="sourceLineNo">264</span>          updatePeerStorage(env);<a 
name="line.264"></a>
+<span class="sourceLineNo">265</span>        } catch (ReplicationException e) 
{<a name="line.265"></a>
+<span class="sourceLineNo">266</span>          LOG.warn("{} update peer 
storage for peer {} failed, retry", getClass().getName(), peerId,<a 
name="line.266"></a>
+<span class="sourceLineNo">267</span>            e);<a name="line.267"></a>
+<span class="sourceLineNo">268</span>          throw new 
ProcedureYieldException();<a name="line.268"></a>
+<span class="sourceLineNo">269</span>        }<a name="line.269"></a>
+<span class="sourceLineNo">270</span>        
setNextState(PeerModificationState.REFRESH_PEER_ON_RS);<a name="line.270"></a>
 <span class="sourceLineNo">271</span>        return Flow.HAS_MORE_STATE;<a 
name="line.271"></a>
-<span class="sourceLineNo">272</span>      case 
SERIAL_PEER_SET_PEER_ENABLED:<a name="line.272"></a>
-<span class="sourceLineNo">273</span>        try {<a name="line.273"></a>
-<span class="sourceLineNo">274</span>          
env.getReplicationPeerManager().enablePeer(peerId);<a name="line.274"></a>
-<span class="sourceLineNo">275</span>        } catch (ReplicationException e) 
{<a name="line.275"></a>
-<span class="sourceLineNo">276</span>          LOG.warn("{} enable peer before 
finish for peer {} failed, retry", getClass().getName(),<a name="line.276"></a>
-<span class="sourceLineNo">277</span>            peerId, e);<a 
name="line.277"></a>
-<span class="sourceLineNo">278</span>          throw new 
ProcedureYieldException();<a name="line.278"></a>
-<span class="sourceLineNo">279</span>        }<a name="line.279"></a>
-<span class="sourceLineNo">280</span>        
setNextState(PeerModificationState.SERIAL_PEER_ENABLE_PEER_REFRESH_PEER_ON_RS);<a
 name="line.280"></a>
-<span class="sourceLineNo">281</span>        return Flow.HAS_MORE_STATE;<a 
name="line.281"></a>
-<span class="sourceLineNo">282</span>      case 
SERIAL_PEER_ENABLE_PEER_REFRESH_PEER_ON_RS:<a name="line.282"></a>
-<span class="sourceLineNo">283</span>        refreshPeer(env, 
PeerOperationType.ENABLE);<a name="line.283"></a>
-<span class="sourceLineNo">284</span>        
setNextState(PeerModificationState.POST_PEER_MODIFICATION);<a 
name="line.284"></a>
-<span class="sourceLineNo">285</span>        return Flow.HAS_MORE_STATE;<a 
name="line.285"></a>
-<span class="sourceLineNo">286</span>      case POST_PEER_MODIFICATION:<a 
name="line.286"></a>
-<span class="sourceLineNo">287</span>        try {<a name="line.287"></a>
-<span class="sourceLineNo">288</span>          postPeerModification(env);<a 
name="line.288"></a>
-<span class="sourceLineNo">289</span>        } catch (ReplicationException e) 
{<a name="line.289"></a>
-<span class="sourceLineNo">290</span>          LOG.warn("{} failed to call 
postPeerModification for peer {}, retry",<a name="line.290"></a>
-<span class="sourceLineNo">291</span>            getClass().getName(), peerId, 
e);<a name="line.291"></a>
-<span class="sourceLineNo">292</span>          throw new 
ProcedureYieldException();<a name="line.292"></a>
-<span class="sourceLineNo">293</span>        } catch (IOException e) {<a 
name="line.293"></a>
-<span class="sourceLineNo">294</span>          LOG.warn("{} failed to call 
post CP hook for peer {}, " +<a name="line.294"></a>
-<span class="sourceLineNo">295</span>            "ignore since the procedure 
has already done", getClass().getName(), peerId, e);<a name="line.295"></a>
-<span class="sourceLineNo">296</span>        }<a name="line.296"></a>
-<span class="sourceLineNo">297</span>        releaseLatch();<a 
name="line.297"></a>
-<span class="sourceLineNo">298</span>        return Flow.NO_MORE_STATE;<a 
name="line.298"></a>
-<span class="sourceLineNo">299</span>      default:<a name="line.299"></a>
-<span class="sourceLineNo">300</span>        throw new 
UnsupportedOperationException("unhandled state=" + state);<a 
name="line.300"></a>
-<span class="sourceLineNo">301</span>    }<a name="line.301"></a>
-<span class="sourceLineNo">302</span>  }<a name="line.302"></a>
-<span class="sourceLineNo">303</span><a name="line.303"></a>
-<span class="sourceLineNo">304</span>  @Override<a name="line.304"></a>
-<span class="sourceLineNo">305</span>  protected void 
rollbackState(MasterProcedureEnv env, PeerModificationState state)<a 
name="line.305"></a>
-<span class="sourceLineNo">306</span>      throws IOException, 
InterruptedException {<a name="line.306"></a>
-<span class="sourceLineNo">307</span>    if (state == 
PeerModificationState.PRE_PEER_MODIFICATION) {<a name="line.307"></a>
-<span class="sourceLineNo">308</span>      // actually the peer related 
operations has no rollback, but if we haven't done any<a name="line.308"></a>
-<span class="sourceLineNo">309</span>      // modifications on the peer 
storage yet, we can just return.<a name="line.309"></a>
-<span class="sourceLineNo">310</span>      return;<a name="line.310"></a>
-<span class="sourceLineNo">311</span>    }<a name="line.311"></a>
-<span class="sourceLineNo">312</span>    throw new 
UnsupportedOperationException();<a name="line.312"></a>
-<span class="sourceLineNo">313</span>  }<a name="line.313"></a>
-<span class="sourceLineNo">314</span><a name="line.314"></a>
-<span class="sourceLineNo">315</span>  @Override<a name="line.315"></a>
-<span class="sourceLineNo">316</span>  protected PeerModificationState 
getState(int stateId) {<a name="line.316"></a>
-<span class="sourceLineNo">317</span>    return 
PeerModificationState.forNumber(stateId);<a name="line.317"></a>
-<span class="sourceLineNo">318</span>  }<a name="line.318"></a>
-<span class="sourceLineNo">319</span><a name="line.319"></a>
-<span class="sourceLineNo">320</span>  @Override<a name="line.320"></a>
-<span class="sourceLineNo">321</span>  protected int 
getStateId(PeerModificationState state) {<a name="line.321"></a>
-<span class="sourceLineNo">322</span>    return state.getNumber();<a 
name="line.322"></a>
-<span class="sourceLineNo">323</span>  }<a name="line.323"></a>
-<span class="sourceLineNo">324</span><a name="line.324"></a>
-<span class="sourceLineNo">325</span>  @Override<a name="line.325"></a>
-<span class="sourceLineNo">326</span>  protected PeerModificationState 
getInitialState() {<a name="line.326"></a>
-<span class="sourceLineNo">327</span>    return 
PeerModificationState.PRE_PEER_MODIFICATION;<a name="line.327"></a>
-<span class="sourceLineNo">328</span>  }<a name="line.328"></a>
-<span class="sourceLineNo">329</span>}<a name="line.329"></a>
+<span class="sourceLineNo">272</span>      case REFRESH_PEER_ON_RS:<a 
name="line.272"></a>
+<span class="sourceLineNo">273</span>        refreshPeer(env, 
getPeerOperationType());<a name="line.273"></a>
+<span class="sourceLineNo">274</span>        
setNextState(nextStateAfterRefresh());<a name="line.274"></a>
+<span class="sourceLineNo">275</span>        return Flow.HAS_MORE_STATE;<a 
name="line.275"></a>
+<span class="sourceLineNo">276</span>      case SERIAL_PEER_REOPEN_REGIONS:<a 
name="line.276"></a>
+<span class="sourceLineNo">277</span>        try {<a name="line.277"></a>
+<span class="sourceLineNo">278</span>          reopenRegions(env);<a 
name="line.278"></a>
+<span class="sourceLineNo">279</span>        } catch (Exception e) {<a 
name="line.279"></a>
+<span class="sourceLineNo">280</span>          LOG.warn("{} reopen regions for 
peer {} failed, retry", getClass().getName(), peerId, e);<a name="line.280"></a>
+<span class="sourceLineNo">281</span>          throw new 
ProcedureYieldException();<a name="line.281"></a>
+<span class="sourceLineNo">282</span>        }<a name="line.282"></a>
+<span class="sourceLineNo">283</span>        
setNextState(PeerModificationState.SERIAL_PEER_UPDATE_LAST_PUSHED_SEQ_ID);<a 
name="line.283"></a>
+<span class="sourceLineNo">284</span>        return Flow.HAS_MORE_STATE;<a 
name="line.284"></a>
+<span class="sourceLineNo">285</span>      case 
SERIAL_PEER_UPDATE_LAST_PUSHED_SEQ_ID:<a name="line.285"></a>
+<span class="sourceLineNo">286</span>        try {<a name="line.286"></a>
+<span class="sourceLineNo">287</span>          
updateLastPushedSequenceIdForSerialPeer(env);<a name="line.287"></a>
+<span class="sourceLineNo">288</span>        } catch (Exception e) {<a 
name="line.288"></a>
+<span class="sourceLineNo">289</span>          LOG.warn("{} set last sequence 
id for peer {} failed, retry", getClass().getName(),<a name="line.289"></a>
+<span class="sourceLineNo">290</span>            peerId, e);<a 
name="line.290"></a>
+<span class="sourceLineNo">291</span>          throw new 
ProcedureYieldException();<a name="line.291"></a>
+<span class="sourceLineNo">292</span>        }<a name="line.292"></a>
+<span class="sourceLineNo">293</span>        
setNextState(enablePeerBeforeFinish() ? 
PeerModificationState.SERIAL_PEER_SET_PEER_ENABLED<a name="line.293"></a>
+<span class="sourceLineNo">294</span>          : 
PeerModificationState.POST_PEER_MODIFICATION);<a name="line.294"></a>
+<span class="sourceLineNo">295</span>        return Flow.HAS_MORE_STATE;<a 
name="line.295"></a>
+<span class="sourceLineNo">296</span>      case 
SERIAL_PEER_SET_PEER_ENABLED:<a name="line.296"></a>
+<span class="sourceLineNo">297</span>        try {<a name="line.297"></a>
+<span class="sourceLineNo">298</span>          
env.getReplicationPeerManager().enablePeer(peerId);<a name="line.298"></a>
+<span class="sourceLineNo">299</span>        } catch (ReplicationException e) 
{<a name="line.299"></a>
+<span class="sourceLineNo">300</span>          LOG.warn("{} enable peer before 
finish for peer {} failed, retry", getClass().getName(),<a name="line.300"></a>
+<span class="sourceLineNo">301</span>            peerId, e);<a 
name="line.301"></a>
+<span class="sourceLineNo">302</span>          throw new 
ProcedureYieldException();<a name="line.302"></a>
+<span class="sourceLineNo">303</span>        }<a name="line.303"></a>
+<span class="sourceLineNo">304</span>        
setNextState(PeerModificationState.SERIAL_PEER_ENABLE_PEER_REFRESH_PEER_ON_RS);<a
 name="line.304"></a>
+<span class="sourceLineNo">305</span>        return Flow.HAS_MORE_STATE;<a 
name="line.305"></a>
+<span class="sourceLineNo">306</span>      case 
SERIAL_PEER_ENABLE_PEER_REFRESH_PEER_ON_RS:<a name="line.306"></a>
+<span class="sourceLineNo">307</span>        refreshPeer(env, 
PeerOperationType.ENABLE);<a name="line.307"></a>
+<span class="sourceLineNo">308</span>        
setNextState(PeerModificationState.POST_PEER_MODIFICATION);<a 
name="line.308"></a>
+<span class="sourceLineNo">309</span>        return Flow.HAS_MORE_STATE;<a 
name="line.309"></a>
+<span class="sourceLineNo">310</span>      case POST_PEER_MODIFICATION:<a 
name="line.310"></a>
+<span class="sourceLineNo">311</span>        try {<a name="line.311"></a>
+<span class="sourceLineNo">312</span>          postPeerModification(env);<a 
name="line.312"></a>
+<span class="sourceLineNo">313</span>        } catch (ReplicationException e) 
{<a name="line.313"></a>
+<span class="sourceLineNo">314</span>          LOG.warn("{} failed to call 
postPeerModification for peer {}, retry",<a name="line.314"></a>
+<span class="sourceLineNo">315</span>            getClass().getName(), peerId, 
e);<a name="line.315"></a>
+<span class="sourceLineNo">316</span>          throw new 
ProcedureYieldException();<a name="line.316"></a>
+<span class="sourceLineNo">317</span>        } catch (IOException e) {<a 
name="line.317"></a>
+<span class="sourceLineNo">318</span>          LOG.warn("{} failed to call 
post CP hook for peer {}, " +<a name="line.318"></a>
+<span class="sourceLineNo">319</span>            "ignore since the procedure 
has already done", getClass().getName(), peerId, e);<a name="line.319"></a>
+<span class="sourceLineNo">320</span>        }<a name="line.320"></a>
+<span class="sourceLineNo">321</span>        releaseLatch();<a 
name="line.321"></a>
+<span class="sourceLineNo">322</span>        return Flow.NO_MORE_STATE;<a 
name="line.322"></a>
+<span class="sourceLineNo">323</span>      default:<a name="line.323"></a>
+<span class="sourceLineNo">324</span>        throw new 
UnsupportedOperationException("unhandled state=" + state);<a 
name="line.324"></a>
+<span class="sourceLineNo">325</span>    }<a name="line.325"></a>
+<span class="sourceLineNo">326</span>  }<a name="line.326"></a>
+<span class="sourceLineNo">327</span><a name="line.327"></a>
+<span class="sourceLineNo">328</span>  @Override<a name="line.328"></a>
+<span class="sourceLineNo">329</span>  protected void 
rollbackState(MasterProcedureEnv env, PeerModificationState state)<a 
name="line.329"></a>
+<span class="sourceLineNo">330</span>      throws IOException, 
InterruptedException {<a name="line.330"></a>
+<span class="sourceLineNo">331</span>    if (state == 
PeerModificationState.PRE_PEER_MODIFICATION) {<a name="line.331"></a>
+<span class="sourceLineNo">332</span>      // actually the peer related 
operations has no rollback, but if we haven't done any<a name="line.332"></a>
+<span class="sourceLineNo">333</span>      // modifications on the peer 
storage yet, we can just return.<a name="line.333"></a>
+<span class="sourceLineNo">334</span>      return;<a name="line.334"></a>
+<span class="sourceLineNo">335</span>    }<a name="line.335"></a>
+<span class="sourceLineNo">336</span>    throw new 
UnsupportedOperationException();<a name="line.336"></a>
+<span class="sourceLineNo">337</span>  }<a name="line.337"></a>
+<span class="sourceLineNo">338</span><a name="line.338"></a>
+<span class="sourceLineNo">339</span>  @Override<a name="line.339"></a>
+<span class="sourceLineNo">340</span>  protected PeerModificationState 
getState(int stateId) {<a name="line.340"></a>
+<span class="sourceLineNo">341</span>    return 
PeerModificationState.forNumber(stateId);<a name="line.341"></a>
+<span class="sourceLineNo">342</span>  }<a name="line.342"></a>
+<span class="sourceLineNo">343</span><a name="line.343"></a>
+<span class="sourceLineNo">344</span>  @Override<a name="line.344"></a>
+<span class="sourceLineNo">345</span>  protected int 
getStateId(PeerModificationState state) {<a name="line.345"></a>
+<span class="sourceLineNo">346</span>    return state.getNumber();<a 
name="line.346"></a>
+<span class="sourceLineNo">347</span>  }<a name="line.347"></a>
+<span class="sourceLineNo">348</span><a name="line.348"></a>
+<span class="sourceLineNo">349</span>  @Override<a name="line.349"></a>
+<span class="sourceLineNo">350</span>  protected PeerModificationState 
getInitialState() {<a name="line.350"></a>
+<span class="sourceLineNo">351</span>    return 
PeerModificationState.PRE_PEER_MODIFICATION;<a name="line.351"></a>
+<span class="sourceLineNo">352</span>  }<a name="line.352"></a>
+<span class="sourceLineNo">353</span>}<a name="line.353"></a>
 
 
 

Reply via email to