hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject [14/51] [partial] hbase-site git commit: Published site at 2cc48e039d1f800832ac8880bbc820982e0ac8a5.
Date Mon, 01 Feb 2016 16:57:10 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/a7e5a8ce/devapidocs/src-html/org/apache/hadoop/hbase/coprocessor/example/ZooKeeperScanPolicyObserver.ZKWatcher.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/coprocessor/example/ZooKeeperScanPolicyObserver.ZKWatcher.html b/devapidocs/src-html/org/apache/hadoop/hbase/coprocessor/example/ZooKeeperScanPolicyObserver.ZKWatcher.html
index aca192f..761d6a4 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/coprocessor/example/ZooKeeperScanPolicyObserver.ZKWatcher.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/coprocessor/example/ZooKeeperScanPolicyObserver.ZKWatcher.html
@@ -41,208 +41,207 @@
 <span class="sourceLineNo">033</span>import org.apache.hadoop.hbase.coprocessor.ObserverContext;<a name="line.33"></a>
 <span class="sourceLineNo">034</span>import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;<a name="line.34"></a>
 <span class="sourceLineNo">035</span>import org.apache.hadoop.hbase.regionserver.HStore;<a name="line.35"></a>
-<span class="sourceLineNo">036</span>import org.apache.hadoop.hbase.regionserver.Store;<a name="line.36"></a>
-<span class="sourceLineNo">037</span>import org.apache.hadoop.hbase.regionserver.ScanInfo;<a name="line.37"></a>
-<span class="sourceLineNo">038</span>import org.apache.hadoop.hbase.regionserver.InternalScanner;<a name="line.38"></a>
-<span class="sourceLineNo">039</span>import org.apache.hadoop.hbase.regionserver.KeyValueScanner;<a name="line.39"></a>
-<span class="sourceLineNo">040</span>import org.apache.hadoop.hbase.regionserver.ScanType;<a name="line.40"></a>
-<span class="sourceLineNo">041</span>import org.apache.hadoop.hbase.regionserver.Store;<a name="line.41"></a>
-<span class="sourceLineNo">042</span>import org.apache.hadoop.hbase.regionserver.StoreScanner;<a name="line.42"></a>
-<span class="sourceLineNo">043</span>import org.apache.hadoop.hbase.util.Bytes;<a name="line.43"></a>
-<span class="sourceLineNo">044</span>import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;<a name="line.44"></a>
-<span class="sourceLineNo">045</span>import org.apache.zookeeper.KeeperException;<a name="line.45"></a>
-<span class="sourceLineNo">046</span>import org.apache.zookeeper.WatchedEvent;<a name="line.46"></a>
-<span class="sourceLineNo">047</span>import org.apache.zookeeper.Watcher;<a name="line.47"></a>
-<span class="sourceLineNo">048</span>import org.apache.zookeeper.ZooKeeper;<a name="line.48"></a>
-<span class="sourceLineNo">049</span><a name="line.49"></a>
-<span class="sourceLineNo">050</span>/**<a name="line.50"></a>
-<span class="sourceLineNo">051</span> * This is an example showing how a RegionObserver could configured<a name="line.51"></a>
-<span class="sourceLineNo">052</span> * via ZooKeeper in order to control a Region compaction, flush, and scan policy.<a name="line.52"></a>
-<span class="sourceLineNo">053</span> *<a name="line.53"></a>
-<span class="sourceLineNo">054</span> * This also demonstrated the use of shared <a name="line.54"></a>
-<span class="sourceLineNo">055</span> * {@link org.apache.hadoop.hbase.coprocessor.RegionObserver} state.<a name="line.55"></a>
-<span class="sourceLineNo">056</span> * See {@link RegionCoprocessorEnvironment#getSharedData()}.<a name="line.56"></a>
-<span class="sourceLineNo">057</span> *<a name="line.57"></a>
-<span class="sourceLineNo">058</span> * This would be useful for an incremental backup tool, which would indicate the last<a name="line.58"></a>
-<span class="sourceLineNo">059</span> * time of a successful backup via ZK and instruct HBase to not delete data that was<a name="line.59"></a>
-<span class="sourceLineNo">060</span> * inserted since (based on wall clock time). <a name="line.60"></a>
-<span class="sourceLineNo">061</span> *<a name="line.61"></a>
-<span class="sourceLineNo">062</span> * This implements org.apache.zookeeper.Watcher directly instead of using<a name="line.62"></a>
-<span class="sourceLineNo">063</span> * {@link org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher}, <a name="line.63"></a>
-<span class="sourceLineNo">064</span> * because RegionObservers come and go and currently<a name="line.64"></a>
-<span class="sourceLineNo">065</span> * listeners registered with ZooKeeperWatcher cannot be removed.<a name="line.65"></a>
-<span class="sourceLineNo">066</span> */<a name="line.66"></a>
-<span class="sourceLineNo">067</span>public class ZooKeeperScanPolicyObserver extends BaseRegionObserver {<a name="line.67"></a>
-<span class="sourceLineNo">068</span>  public static final String node = "/backup/example/lastbackup";<a name="line.68"></a>
-<span class="sourceLineNo">069</span>  public static final String zkkey = "ZK";<a name="line.69"></a>
-<span class="sourceLineNo">070</span>  private static final Log LOG = LogFactory.getLog(ZooKeeperScanPolicyObserver.class);<a name="line.70"></a>
-<span class="sourceLineNo">071</span><a name="line.71"></a>
-<span class="sourceLineNo">072</span>  /**<a name="line.72"></a>
-<span class="sourceLineNo">073</span>   * Internal watcher that keep "data" up to date asynchronously.<a name="line.73"></a>
-<span class="sourceLineNo">074</span>   */<a name="line.74"></a>
-<span class="sourceLineNo">075</span>  private static class ZKWatcher implements Watcher {<a name="line.75"></a>
-<span class="sourceLineNo">076</span>    private byte[] data = null;<a name="line.76"></a>
-<span class="sourceLineNo">077</span>    private ZooKeeper zk;<a name="line.77"></a>
-<span class="sourceLineNo">078</span>    private volatile boolean needSetup = true;<a name="line.78"></a>
-<span class="sourceLineNo">079</span>    private volatile long lastSetupTry = 0;<a name="line.79"></a>
-<span class="sourceLineNo">080</span><a name="line.80"></a>
-<span class="sourceLineNo">081</span>    public ZKWatcher(ZooKeeper zk) {<a name="line.81"></a>
-<span class="sourceLineNo">082</span>      this.zk = zk;<a name="line.82"></a>
-<span class="sourceLineNo">083</span>      // trigger the listening<a name="line.83"></a>
-<span class="sourceLineNo">084</span>      getData();<a name="line.84"></a>
-<span class="sourceLineNo">085</span>    }<a name="line.85"></a>
-<span class="sourceLineNo">086</span><a name="line.86"></a>
-<span class="sourceLineNo">087</span>    /**<a name="line.87"></a>
-<span class="sourceLineNo">088</span>     * Get the maintained data. In case of any ZK exceptions this will retry<a name="line.88"></a>
-<span class="sourceLineNo">089</span>     * establishing the connection (but not more than twice/minute).<a name="line.89"></a>
-<span class="sourceLineNo">090</span>     *<a name="line.90"></a>
-<span class="sourceLineNo">091</span>     * getData is on the critical path, so make sure it is fast unless there is<a name="line.91"></a>
-<span class="sourceLineNo">092</span>     * a problem (network partion, ZK ensemble down, etc)<a name="line.92"></a>
-<span class="sourceLineNo">093</span>     * Make sure at most one (unlucky) thread retries and other threads don't pile up<a name="line.93"></a>
-<span class="sourceLineNo">094</span>     * while that threads tries to recreate the connection.<a name="line.94"></a>
-<span class="sourceLineNo">095</span>     *<a name="line.95"></a>
-<span class="sourceLineNo">096</span>     * @return the last know version of the data<a name="line.96"></a>
-<span class="sourceLineNo">097</span>     */<a name="line.97"></a>
-<span class="sourceLineNo">098</span>    @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="REC_CATCH_EXCEPTION")<a name="line.98"></a>
-<span class="sourceLineNo">099</span>    public byte[] getData() {<a name="line.99"></a>
-<span class="sourceLineNo">100</span>      // try at most twice/minute<a name="line.100"></a>
-<span class="sourceLineNo">101</span>      if (needSetup &amp;&amp; EnvironmentEdgeManager.currentTime() &gt; lastSetupTry + 30000) {<a name="line.101"></a>
-<span class="sourceLineNo">102</span>        synchronized (this) {<a name="line.102"></a>
-<span class="sourceLineNo">103</span>          // make sure only one thread tries to reconnect<a name="line.103"></a>
-<span class="sourceLineNo">104</span>          if (needSetup) {<a name="line.104"></a>
-<span class="sourceLineNo">105</span>            needSetup = false;<a name="line.105"></a>
-<span class="sourceLineNo">106</span>          } else {<a name="line.106"></a>
-<span class="sourceLineNo">107</span>            return data;<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>        // do this without the lock held to avoid threads piling up on this lock,<a name="line.110"></a>
-<span class="sourceLineNo">111</span>        // as it can take a while<a name="line.111"></a>
-<span class="sourceLineNo">112</span>        try {<a name="line.112"></a>
-<span class="sourceLineNo">113</span>          LOG.debug("Connecting to ZK");<a name="line.113"></a>
-<span class="sourceLineNo">114</span>          // record this attempt<a name="line.114"></a>
-<span class="sourceLineNo">115</span>          lastSetupTry = EnvironmentEdgeManager.currentTime();<a name="line.115"></a>
-<span class="sourceLineNo">116</span>          if (zk.exists(node, false) != null) {<a name="line.116"></a>
-<span class="sourceLineNo">117</span>            data = zk.getData(node, this, null);<a name="line.117"></a>
-<span class="sourceLineNo">118</span>            LOG.debug("Read synchronously: "+(data == null ? "null" : Bytes.toLong(data)));<a name="line.118"></a>
-<span class="sourceLineNo">119</span>          } else {<a name="line.119"></a>
-<span class="sourceLineNo">120</span>            zk.exists(node, this);<a name="line.120"></a>
-<span class="sourceLineNo">121</span>          }<a name="line.121"></a>
-<span class="sourceLineNo">122</span>        } catch (Exception x) {<a name="line.122"></a>
-<span class="sourceLineNo">123</span>          // try again if this fails<a name="line.123"></a>
-<span class="sourceLineNo">124</span>          needSetup = true;<a name="line.124"></a>
-<span class="sourceLineNo">125</span>        }<a name="line.125"></a>
-<span class="sourceLineNo">126</span>      }<a name="line.126"></a>
-<span class="sourceLineNo">127</span>      return data;<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>    @Override<a name="line.130"></a>
-<span class="sourceLineNo">131</span>    public void process(WatchedEvent event) {<a name="line.131"></a>
-<span class="sourceLineNo">132</span>      switch(event.getType()) {<a name="line.132"></a>
-<span class="sourceLineNo">133</span>      case NodeDataChanged:<a name="line.133"></a>
-<span class="sourceLineNo">134</span>      case NodeCreated:<a name="line.134"></a>
-<span class="sourceLineNo">135</span>      try {<a name="line.135"></a>
-<span class="sourceLineNo">136</span>        // get data and re-watch<a name="line.136"></a>
-<span class="sourceLineNo">137</span>        data = zk.getData(node, this, null);<a name="line.137"></a>
-<span class="sourceLineNo">138</span>        LOG.debug("Read asynchronously: "+(data == null ? "null" : Bytes.toLong(data)));<a name="line.138"></a>
-<span class="sourceLineNo">139</span>      } catch (InterruptedException ix) {<a name="line.139"></a>
-<span class="sourceLineNo">140</span>      } catch (KeeperException kx) {<a name="line.140"></a>
-<span class="sourceLineNo">141</span>        needSetup = true;<a name="line.141"></a>
-<span class="sourceLineNo">142</span>      }<a name="line.142"></a>
-<span class="sourceLineNo">143</span>      break;<a name="line.143"></a>
-<span class="sourceLineNo">144</span><a name="line.144"></a>
-<span class="sourceLineNo">145</span>      case NodeDeleted:<a name="line.145"></a>
-<span class="sourceLineNo">146</span>      try {<a name="line.146"></a>
-<span class="sourceLineNo">147</span>        // just re-watch<a name="line.147"></a>
-<span class="sourceLineNo">148</span>        zk.exists(node, this);<a name="line.148"></a>
-<span class="sourceLineNo">149</span>        data = null;<a name="line.149"></a>
-<span class="sourceLineNo">150</span>      } catch (InterruptedException ix) {<a name="line.150"></a>
-<span class="sourceLineNo">151</span>      } catch (KeeperException kx) {<a name="line.151"></a>
-<span class="sourceLineNo">152</span>        needSetup = true;<a name="line.152"></a>
-<span class="sourceLineNo">153</span>      }<a name="line.153"></a>
-<span class="sourceLineNo">154</span>      break;<a name="line.154"></a>
-<span class="sourceLineNo">155</span><a name="line.155"></a>
-<span class="sourceLineNo">156</span>      default:<a name="line.156"></a>
-<span class="sourceLineNo">157</span>        // ignore<a name="line.157"></a>
-<span class="sourceLineNo">158</span>      }<a name="line.158"></a>
-<span class="sourceLineNo">159</span>    }<a name="line.159"></a>
-<span class="sourceLineNo">160</span>  }<a name="line.160"></a>
-<span class="sourceLineNo">161</span><a name="line.161"></a>
-<span class="sourceLineNo">162</span>  @Override<a name="line.162"></a>
-<span class="sourceLineNo">163</span>  public void start(CoprocessorEnvironment e) throws IOException {<a name="line.163"></a>
-<span class="sourceLineNo">164</span>    RegionCoprocessorEnvironment re = (RegionCoprocessorEnvironment) e;<a name="line.164"></a>
-<span class="sourceLineNo">165</span>    if (!re.getSharedData().containsKey(zkkey)) {<a name="line.165"></a>
-<span class="sourceLineNo">166</span>      // there is a short race here<a name="line.166"></a>
-<span class="sourceLineNo">167</span>      // in the worst case we create a watcher that will be notified once<a name="line.167"></a>
-<span class="sourceLineNo">168</span>      re.getSharedData().putIfAbsent(<a name="line.168"></a>
-<span class="sourceLineNo">169</span>          zkkey,<a name="line.169"></a>
-<span class="sourceLineNo">170</span>          new ZKWatcher(re.getRegionServerServices().getZooKeeper()<a name="line.170"></a>
-<span class="sourceLineNo">171</span>              .getRecoverableZooKeeper().getZooKeeper()));<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><a name="line.174"></a>
-<span class="sourceLineNo">175</span>  @Override<a name="line.175"></a>
-<span class="sourceLineNo">176</span>  public void stop(CoprocessorEnvironment e) throws IOException {<a name="line.176"></a>
-<span class="sourceLineNo">177</span>    // nothing to do here<a name="line.177"></a>
-<span class="sourceLineNo">178</span>  }<a name="line.178"></a>
-<span class="sourceLineNo">179</span><a name="line.179"></a>
-<span class="sourceLineNo">180</span>  protected ScanInfo getScanInfo(Store store, RegionCoprocessorEnvironment e) {<a name="line.180"></a>
-<span class="sourceLineNo">181</span>    byte[] data = ((ZKWatcher)e.getSharedData().get(zkkey)).getData();<a name="line.181"></a>
-<span class="sourceLineNo">182</span>    if (data == null) {<a name="line.182"></a>
-<span class="sourceLineNo">183</span>      return null;<a name="line.183"></a>
-<span class="sourceLineNo">184</span>    }<a name="line.184"></a>
-<span class="sourceLineNo">185</span>    ScanInfo oldSI = store.getScanInfo();<a name="line.185"></a>
-<span class="sourceLineNo">186</span>    if (oldSI.getTtl() == Long.MAX_VALUE) {<a name="line.186"></a>
-<span class="sourceLineNo">187</span>      return null;<a name="line.187"></a>
-<span class="sourceLineNo">188</span>    }<a name="line.188"></a>
-<span class="sourceLineNo">189</span>    long ttl = Math.max(EnvironmentEdgeManager.currentTime() -<a name="line.189"></a>
-<span class="sourceLineNo">190</span>        Bytes.toLong(data), oldSI.getTtl());<a name="line.190"></a>
-<span class="sourceLineNo">191</span>    return new ScanInfo(oldSI.getConfiguration(), store.getFamily(), ttl,<a name="line.191"></a>
-<span class="sourceLineNo">192</span>        oldSI.getTimeToPurgeDeletes(), oldSI.getComparator());<a name="line.192"></a>
-<span class="sourceLineNo">193</span>  }<a name="line.193"></a>
-<span class="sourceLineNo">194</span><a name="line.194"></a>
-<span class="sourceLineNo">195</span>  @Override<a name="line.195"></a>
-<span class="sourceLineNo">196</span>  public InternalScanner preFlushScannerOpen(final ObserverContext&lt;RegionCoprocessorEnvironment&gt; c,<a name="line.196"></a>
-<span class="sourceLineNo">197</span>      Store store, KeyValueScanner memstoreScanner, InternalScanner s) throws IOException {<a name="line.197"></a>
-<span class="sourceLineNo">198</span>    ScanInfo scanInfo = getScanInfo(store, c.getEnvironment());<a name="line.198"></a>
-<span class="sourceLineNo">199</span>    if (scanInfo == null) {<a name="line.199"></a>
-<span class="sourceLineNo">200</span>      // take default action<a name="line.200"></a>
-<span class="sourceLineNo">201</span>      return null;<a name="line.201"></a>
-<span class="sourceLineNo">202</span>    }<a name="line.202"></a>
-<span class="sourceLineNo">203</span>    Scan scan = new Scan();<a name="line.203"></a>
-<span class="sourceLineNo">204</span>    scan.setMaxVersions(scanInfo.getMaxVersions());<a name="line.204"></a>
-<span class="sourceLineNo">205</span>    return new StoreScanner(store, scanInfo, scan, Collections.singletonList(memstoreScanner),<a name="line.205"></a>
-<span class="sourceLineNo">206</span>        ScanType.COMPACT_RETAIN_DELETES, store.getSmallestReadPoint(), HConstants.OLDEST_TIMESTAMP);<a name="line.206"></a>
-<span class="sourceLineNo">207</span>  }<a name="line.207"></a>
-<span class="sourceLineNo">208</span><a name="line.208"></a>
-<span class="sourceLineNo">209</span>  @Override<a name="line.209"></a>
-<span class="sourceLineNo">210</span>  public InternalScanner preCompactScannerOpen(<a name="line.210"></a>
-<span class="sourceLineNo">211</span>      final ObserverContext&lt;RegionCoprocessorEnvironment&gt; c,<a name="line.211"></a>
-<span class="sourceLineNo">212</span>      Store store, List&lt;? extends KeyValueScanner&gt; scanners, ScanType scanType, long earliestPutTs,<a name="line.212"></a>
-<span class="sourceLineNo">213</span>      InternalScanner s) throws IOException {<a name="line.213"></a>
-<span class="sourceLineNo">214</span>    ScanInfo scanInfo = getScanInfo(store, c.getEnvironment());<a name="line.214"></a>
-<span class="sourceLineNo">215</span>    if (scanInfo == null) {<a name="line.215"></a>
-<span class="sourceLineNo">216</span>      // take default action<a name="line.216"></a>
-<span class="sourceLineNo">217</span>      return null;<a name="line.217"></a>
-<span class="sourceLineNo">218</span>    }<a name="line.218"></a>
-<span class="sourceLineNo">219</span>    Scan scan = new Scan();<a name="line.219"></a>
-<span class="sourceLineNo">220</span>    scan.setMaxVersions(scanInfo.getMaxVersions());<a name="line.220"></a>
-<span class="sourceLineNo">221</span>    return new StoreScanner(store, scanInfo, scan, scanners, scanType,<a name="line.221"></a>
-<span class="sourceLineNo">222</span>        store.getSmallestReadPoint(), earliestPutTs);<a name="line.222"></a>
-<span class="sourceLineNo">223</span>  }<a name="line.223"></a>
-<span class="sourceLineNo">224</span><a name="line.224"></a>
-<span class="sourceLineNo">225</span>  @Override<a name="line.225"></a>
-<span class="sourceLineNo">226</span>  public KeyValueScanner preStoreScannerOpen(final ObserverContext&lt;RegionCoprocessorEnvironment&gt; c,<a name="line.226"></a>
-<span class="sourceLineNo">227</span>      final Store store, final Scan scan, final NavigableSet&lt;byte[]&gt; targetCols,<a name="line.227"></a>
-<span class="sourceLineNo">228</span>      final KeyValueScanner s) throws IOException {<a name="line.228"></a>
-<span class="sourceLineNo">229</span>    ScanInfo scanInfo = getScanInfo(store, c.getEnvironment());<a name="line.229"></a>
-<span class="sourceLineNo">230</span>    if (scanInfo == null) {<a name="line.230"></a>
-<span class="sourceLineNo">231</span>      // take default action<a name="line.231"></a>
-<span class="sourceLineNo">232</span>      return null;<a name="line.232"></a>
-<span class="sourceLineNo">233</span>    }<a name="line.233"></a>
-<span class="sourceLineNo">234</span>    return new StoreScanner(store, scanInfo, scan, targetCols,<a name="line.234"></a>
-<span class="sourceLineNo">235</span>      ((HStore)store).getHRegion().getReadpoint(IsolationLevel.READ_COMMITTED));<a name="line.235"></a>
-<span class="sourceLineNo">236</span>  }<a name="line.236"></a>
-<span class="sourceLineNo">237</span>}<a name="line.237"></a>
+<span class="sourceLineNo">036</span>import org.apache.hadoop.hbase.regionserver.InternalScanner;<a name="line.36"></a>
+<span class="sourceLineNo">037</span>import org.apache.hadoop.hbase.regionserver.KeyValueScanner;<a name="line.37"></a>
+<span class="sourceLineNo">038</span>import org.apache.hadoop.hbase.regionserver.ScanInfo;<a name="line.38"></a>
+<span class="sourceLineNo">039</span>import org.apache.hadoop.hbase.regionserver.ScanType;<a name="line.39"></a>
+<span class="sourceLineNo">040</span>import org.apache.hadoop.hbase.regionserver.Store;<a name="line.40"></a>
+<span class="sourceLineNo">041</span>import org.apache.hadoop.hbase.regionserver.StoreScanner;<a name="line.41"></a>
+<span class="sourceLineNo">042</span>import org.apache.hadoop.hbase.util.Bytes;<a name="line.42"></a>
+<span class="sourceLineNo">043</span>import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;<a name="line.43"></a>
+<span class="sourceLineNo">044</span>import org.apache.zookeeper.KeeperException;<a name="line.44"></a>
+<span class="sourceLineNo">045</span>import org.apache.zookeeper.WatchedEvent;<a name="line.45"></a>
+<span class="sourceLineNo">046</span>import org.apache.zookeeper.Watcher;<a name="line.46"></a>
+<span class="sourceLineNo">047</span>import org.apache.zookeeper.ZooKeeper;<a name="line.47"></a>
+<span class="sourceLineNo">048</span><a name="line.48"></a>
+<span class="sourceLineNo">049</span>/**<a name="line.49"></a>
+<span class="sourceLineNo">050</span> * This is an example showing how a RegionObserver could configured<a name="line.50"></a>
+<span class="sourceLineNo">051</span> * via ZooKeeper in order to control a Region compaction, flush, and scan policy.<a name="line.51"></a>
+<span class="sourceLineNo">052</span> *<a name="line.52"></a>
+<span class="sourceLineNo">053</span> * This also demonstrated the use of shared <a name="line.53"></a>
+<span class="sourceLineNo">054</span> * {@link org.apache.hadoop.hbase.coprocessor.RegionObserver} state.<a name="line.54"></a>
+<span class="sourceLineNo">055</span> * See {@link RegionCoprocessorEnvironment#getSharedData()}.<a name="line.55"></a>
+<span class="sourceLineNo">056</span> *<a name="line.56"></a>
+<span class="sourceLineNo">057</span> * This would be useful for an incremental backup tool, which would indicate the last<a name="line.57"></a>
+<span class="sourceLineNo">058</span> * time of a successful backup via ZK and instruct HBase to not delete data that was<a name="line.58"></a>
+<span class="sourceLineNo">059</span> * inserted since (based on wall clock time). <a name="line.59"></a>
+<span class="sourceLineNo">060</span> *<a name="line.60"></a>
+<span class="sourceLineNo">061</span> * This implements org.apache.zookeeper.Watcher directly instead of using<a name="line.61"></a>
+<span class="sourceLineNo">062</span> * {@link org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher}, <a name="line.62"></a>
+<span class="sourceLineNo">063</span> * because RegionObservers come and go and currently<a name="line.63"></a>
+<span class="sourceLineNo">064</span> * listeners registered with ZooKeeperWatcher cannot be removed.<a name="line.64"></a>
+<span class="sourceLineNo">065</span> */<a name="line.65"></a>
+<span class="sourceLineNo">066</span>public class ZooKeeperScanPolicyObserver extends BaseRegionObserver {<a name="line.66"></a>
+<span class="sourceLineNo">067</span>  public static final String node = "/backup/example/lastbackup";<a name="line.67"></a>
+<span class="sourceLineNo">068</span>  public static final String zkkey = "ZK";<a name="line.68"></a>
+<span class="sourceLineNo">069</span>  private static final Log LOG = LogFactory.getLog(ZooKeeperScanPolicyObserver.class);<a name="line.69"></a>
+<span class="sourceLineNo">070</span><a name="line.70"></a>
+<span class="sourceLineNo">071</span>  /**<a name="line.71"></a>
+<span class="sourceLineNo">072</span>   * Internal watcher that keep "data" up to date asynchronously.<a name="line.72"></a>
+<span class="sourceLineNo">073</span>   */<a name="line.73"></a>
+<span class="sourceLineNo">074</span>  private static class ZKWatcher implements Watcher {<a name="line.74"></a>
+<span class="sourceLineNo">075</span>    private byte[] data = null;<a name="line.75"></a>
+<span class="sourceLineNo">076</span>    private ZooKeeper zk;<a name="line.76"></a>
+<span class="sourceLineNo">077</span>    private volatile boolean needSetup = true;<a name="line.77"></a>
+<span class="sourceLineNo">078</span>    private volatile long lastSetupTry = 0;<a name="line.78"></a>
+<span class="sourceLineNo">079</span><a name="line.79"></a>
+<span class="sourceLineNo">080</span>    public ZKWatcher(ZooKeeper zk) {<a name="line.80"></a>
+<span class="sourceLineNo">081</span>      this.zk = zk;<a name="line.81"></a>
+<span class="sourceLineNo">082</span>      // trigger the listening<a name="line.82"></a>
+<span class="sourceLineNo">083</span>      getData();<a name="line.83"></a>
+<span class="sourceLineNo">084</span>    }<a name="line.84"></a>
+<span class="sourceLineNo">085</span><a name="line.85"></a>
+<span class="sourceLineNo">086</span>    /**<a name="line.86"></a>
+<span class="sourceLineNo">087</span>     * Get the maintained data. In case of any ZK exceptions this will retry<a name="line.87"></a>
+<span class="sourceLineNo">088</span>     * establishing the connection (but not more than twice/minute).<a name="line.88"></a>
+<span class="sourceLineNo">089</span>     *<a name="line.89"></a>
+<span class="sourceLineNo">090</span>     * getData is on the critical path, so make sure it is fast unless there is<a name="line.90"></a>
+<span class="sourceLineNo">091</span>     * a problem (network partion, ZK ensemble down, etc)<a name="line.91"></a>
+<span class="sourceLineNo">092</span>     * Make sure at most one (unlucky) thread retries and other threads don't pile up<a name="line.92"></a>
+<span class="sourceLineNo">093</span>     * while that threads tries to recreate the connection.<a name="line.93"></a>
+<span class="sourceLineNo">094</span>     *<a name="line.94"></a>
+<span class="sourceLineNo">095</span>     * @return the last know version of the data<a name="line.95"></a>
+<span class="sourceLineNo">096</span>     */<a name="line.96"></a>
+<span class="sourceLineNo">097</span>    @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="REC_CATCH_EXCEPTION")<a name="line.97"></a>
+<span class="sourceLineNo">098</span>    public byte[] getData() {<a name="line.98"></a>
+<span class="sourceLineNo">099</span>      // try at most twice/minute<a name="line.99"></a>
+<span class="sourceLineNo">100</span>      if (needSetup &amp;&amp; EnvironmentEdgeManager.currentTime() &gt; lastSetupTry + 30000) {<a name="line.100"></a>
+<span class="sourceLineNo">101</span>        synchronized (this) {<a name="line.101"></a>
+<span class="sourceLineNo">102</span>          // make sure only one thread tries to reconnect<a name="line.102"></a>
+<span class="sourceLineNo">103</span>          if (needSetup) {<a name="line.103"></a>
+<span class="sourceLineNo">104</span>            needSetup = false;<a name="line.104"></a>
+<span class="sourceLineNo">105</span>          } else {<a name="line.105"></a>
+<span class="sourceLineNo">106</span>            return data;<a name="line.106"></a>
+<span class="sourceLineNo">107</span>          }<a name="line.107"></a>
+<span class="sourceLineNo">108</span>        }<a name="line.108"></a>
+<span class="sourceLineNo">109</span>        // do this without the lock held to avoid threads piling up on this lock,<a name="line.109"></a>
+<span class="sourceLineNo">110</span>        // as it can take a while<a name="line.110"></a>
+<span class="sourceLineNo">111</span>        try {<a name="line.111"></a>
+<span class="sourceLineNo">112</span>          LOG.debug("Connecting to ZK");<a name="line.112"></a>
+<span class="sourceLineNo">113</span>          // record this attempt<a name="line.113"></a>
+<span class="sourceLineNo">114</span>          lastSetupTry = EnvironmentEdgeManager.currentTime();<a name="line.114"></a>
+<span class="sourceLineNo">115</span>          if (zk.exists(node, false) != null) {<a name="line.115"></a>
+<span class="sourceLineNo">116</span>            data = zk.getData(node, this, null);<a name="line.116"></a>
+<span class="sourceLineNo">117</span>            LOG.debug("Read synchronously: "+(data == null ? "null" : Bytes.toLong(data)));<a name="line.117"></a>
+<span class="sourceLineNo">118</span>          } else {<a name="line.118"></a>
+<span class="sourceLineNo">119</span>            zk.exists(node, this);<a name="line.119"></a>
+<span class="sourceLineNo">120</span>          }<a name="line.120"></a>
+<span class="sourceLineNo">121</span>        } catch (Exception x) {<a name="line.121"></a>
+<span class="sourceLineNo">122</span>          // try again if this fails<a name="line.122"></a>
+<span class="sourceLineNo">123</span>          needSetup = true;<a name="line.123"></a>
+<span class="sourceLineNo">124</span>        }<a name="line.124"></a>
+<span class="sourceLineNo">125</span>      }<a name="line.125"></a>
+<span class="sourceLineNo">126</span>      return data;<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>    @Override<a name="line.129"></a>
+<span class="sourceLineNo">130</span>    public void process(WatchedEvent event) {<a name="line.130"></a>
+<span class="sourceLineNo">131</span>      switch(event.getType()) {<a name="line.131"></a>
+<span class="sourceLineNo">132</span>      case NodeDataChanged:<a name="line.132"></a>
+<span class="sourceLineNo">133</span>      case NodeCreated:<a name="line.133"></a>
+<span class="sourceLineNo">134</span>      try {<a name="line.134"></a>
+<span class="sourceLineNo">135</span>        // get data and re-watch<a name="line.135"></a>
+<span class="sourceLineNo">136</span>        data = zk.getData(node, this, null);<a name="line.136"></a>
+<span class="sourceLineNo">137</span>        LOG.debug("Read asynchronously: "+(data == null ? "null" : Bytes.toLong(data)));<a name="line.137"></a>
+<span class="sourceLineNo">138</span>      } catch (InterruptedException ix) {<a name="line.138"></a>
+<span class="sourceLineNo">139</span>      } catch (KeeperException kx) {<a name="line.139"></a>
+<span class="sourceLineNo">140</span>        needSetup = true;<a name="line.140"></a>
+<span class="sourceLineNo">141</span>      }<a name="line.141"></a>
+<span class="sourceLineNo">142</span>      break;<a name="line.142"></a>
+<span class="sourceLineNo">143</span><a name="line.143"></a>
+<span class="sourceLineNo">144</span>      case NodeDeleted:<a name="line.144"></a>
+<span class="sourceLineNo">145</span>      try {<a name="line.145"></a>
+<span class="sourceLineNo">146</span>        // just re-watch<a name="line.146"></a>
+<span class="sourceLineNo">147</span>        zk.exists(node, this);<a name="line.147"></a>
+<span class="sourceLineNo">148</span>        data = null;<a name="line.148"></a>
+<span class="sourceLineNo">149</span>      } catch (InterruptedException ix) {<a name="line.149"></a>
+<span class="sourceLineNo">150</span>      } catch (KeeperException kx) {<a name="line.150"></a>
+<span class="sourceLineNo">151</span>        needSetup = true;<a name="line.151"></a>
+<span class="sourceLineNo">152</span>      }<a name="line.152"></a>
+<span class="sourceLineNo">153</span>      break;<a name="line.153"></a>
+<span class="sourceLineNo">154</span><a name="line.154"></a>
+<span class="sourceLineNo">155</span>      default:<a name="line.155"></a>
+<span class="sourceLineNo">156</span>        // ignore<a name="line.156"></a>
+<span class="sourceLineNo">157</span>      }<a name="line.157"></a>
+<span class="sourceLineNo">158</span>    }<a name="line.158"></a>
+<span class="sourceLineNo">159</span>  }<a name="line.159"></a>
+<span class="sourceLineNo">160</span><a name="line.160"></a>
+<span class="sourceLineNo">161</span>  @Override<a name="line.161"></a>
+<span class="sourceLineNo">162</span>  public void start(CoprocessorEnvironment e) throws IOException {<a name="line.162"></a>
+<span class="sourceLineNo">163</span>    RegionCoprocessorEnvironment re = (RegionCoprocessorEnvironment) e;<a name="line.163"></a>
+<span class="sourceLineNo">164</span>    if (!re.getSharedData().containsKey(zkkey)) {<a name="line.164"></a>
+<span class="sourceLineNo">165</span>      // there is a short race here<a name="line.165"></a>
+<span class="sourceLineNo">166</span>      // in the worst case we create a watcher that will be notified once<a name="line.166"></a>
+<span class="sourceLineNo">167</span>      re.getSharedData().putIfAbsent(<a name="line.167"></a>
+<span class="sourceLineNo">168</span>          zkkey,<a name="line.168"></a>
+<span class="sourceLineNo">169</span>          new ZKWatcher(re.getRegionServerServices().getZooKeeper()<a name="line.169"></a>
+<span class="sourceLineNo">170</span>              .getRecoverableZooKeeper().getZooKeeper()));<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>  @Override<a name="line.174"></a>
+<span class="sourceLineNo">175</span>  public void stop(CoprocessorEnvironment e) throws IOException {<a name="line.175"></a>
+<span class="sourceLineNo">176</span>    // nothing to do here<a name="line.176"></a>
+<span class="sourceLineNo">177</span>  }<a name="line.177"></a>
+<span class="sourceLineNo">178</span><a name="line.178"></a>
+<span class="sourceLineNo">179</span>  protected ScanInfo getScanInfo(Store store, RegionCoprocessorEnvironment e) {<a name="line.179"></a>
+<span class="sourceLineNo">180</span>    byte[] data = ((ZKWatcher)e.getSharedData().get(zkkey)).getData();<a name="line.180"></a>
+<span class="sourceLineNo">181</span>    if (data == null) {<a name="line.181"></a>
+<span class="sourceLineNo">182</span>      return null;<a name="line.182"></a>
+<span class="sourceLineNo">183</span>    }<a name="line.183"></a>
+<span class="sourceLineNo">184</span>    ScanInfo oldSI = store.getScanInfo();<a name="line.184"></a>
+<span class="sourceLineNo">185</span>    if (oldSI.getTtl() == Long.MAX_VALUE) {<a name="line.185"></a>
+<span class="sourceLineNo">186</span>      return null;<a name="line.186"></a>
+<span class="sourceLineNo">187</span>    }<a name="line.187"></a>
+<span class="sourceLineNo">188</span>    long ttl = Math.max(EnvironmentEdgeManager.currentTime() -<a name="line.188"></a>
+<span class="sourceLineNo">189</span>        Bytes.toLong(data), oldSI.getTtl());<a name="line.189"></a>
+<span class="sourceLineNo">190</span>    return new ScanInfo(oldSI.getConfiguration(), store.getFamily(), ttl,<a name="line.190"></a>
+<span class="sourceLineNo">191</span>        oldSI.getTimeToPurgeDeletes(), oldSI.getComparator());<a name="line.191"></a>
+<span class="sourceLineNo">192</span>  }<a name="line.192"></a>
+<span class="sourceLineNo">193</span><a name="line.193"></a>
+<span class="sourceLineNo">194</span>  @Override<a name="line.194"></a>
+<span class="sourceLineNo">195</span>  public InternalScanner preFlushScannerOpen(final ObserverContext&lt;RegionCoprocessorEnvironment&gt; c,<a name="line.195"></a>
+<span class="sourceLineNo">196</span>      Store store, KeyValueScanner memstoreScanner, InternalScanner s) throws IOException {<a name="line.196"></a>
+<span class="sourceLineNo">197</span>    ScanInfo scanInfo = getScanInfo(store, c.getEnvironment());<a name="line.197"></a>
+<span class="sourceLineNo">198</span>    if (scanInfo == null) {<a name="line.198"></a>
+<span class="sourceLineNo">199</span>      // take default action<a name="line.199"></a>
+<span class="sourceLineNo">200</span>      return null;<a name="line.200"></a>
+<span class="sourceLineNo">201</span>    }<a name="line.201"></a>
+<span class="sourceLineNo">202</span>    Scan scan = new Scan();<a name="line.202"></a>
+<span class="sourceLineNo">203</span>    scan.setMaxVersions(scanInfo.getMaxVersions());<a name="line.203"></a>
+<span class="sourceLineNo">204</span>    return new StoreScanner(store, scanInfo, scan, Collections.singletonList(memstoreScanner),<a name="line.204"></a>
+<span class="sourceLineNo">205</span>        ScanType.COMPACT_RETAIN_DELETES, store.getSmallestReadPoint(), HConstants.OLDEST_TIMESTAMP);<a name="line.205"></a>
+<span class="sourceLineNo">206</span>  }<a name="line.206"></a>
+<span class="sourceLineNo">207</span><a name="line.207"></a>
+<span class="sourceLineNo">208</span>  @Override<a name="line.208"></a>
+<span class="sourceLineNo">209</span>  public InternalScanner preCompactScannerOpen(<a name="line.209"></a>
+<span class="sourceLineNo">210</span>      final ObserverContext&lt;RegionCoprocessorEnvironment&gt; c,<a name="line.210"></a>
+<span class="sourceLineNo">211</span>      Store store, List&lt;? extends KeyValueScanner&gt; scanners, ScanType scanType, long earliestPutTs,<a name="line.211"></a>
+<span class="sourceLineNo">212</span>      InternalScanner s) throws IOException {<a name="line.212"></a>
+<span class="sourceLineNo">213</span>    ScanInfo scanInfo = getScanInfo(store, c.getEnvironment());<a name="line.213"></a>
+<span class="sourceLineNo">214</span>    if (scanInfo == null) {<a name="line.214"></a>
+<span class="sourceLineNo">215</span>      // take default action<a name="line.215"></a>
+<span class="sourceLineNo">216</span>      return null;<a name="line.216"></a>
+<span class="sourceLineNo">217</span>    }<a name="line.217"></a>
+<span class="sourceLineNo">218</span>    Scan scan = new Scan();<a name="line.218"></a>
+<span class="sourceLineNo">219</span>    scan.setMaxVersions(scanInfo.getMaxVersions());<a name="line.219"></a>
+<span class="sourceLineNo">220</span>    return new StoreScanner(store, scanInfo, scan, scanners, scanType,<a name="line.220"></a>
+<span class="sourceLineNo">221</span>        store.getSmallestReadPoint(), earliestPutTs);<a name="line.221"></a>
+<span class="sourceLineNo">222</span>  }<a name="line.222"></a>
+<span class="sourceLineNo">223</span><a name="line.223"></a>
+<span class="sourceLineNo">224</span>  @Override<a name="line.224"></a>
+<span class="sourceLineNo">225</span>  public KeyValueScanner preStoreScannerOpen(final ObserverContext&lt;RegionCoprocessorEnvironment&gt; c,<a name="line.225"></a>
+<span class="sourceLineNo">226</span>      final Store store, final Scan scan, final NavigableSet&lt;byte[]&gt; targetCols,<a name="line.226"></a>
+<span class="sourceLineNo">227</span>      final KeyValueScanner s) throws IOException {<a name="line.227"></a>
+<span class="sourceLineNo">228</span>    ScanInfo scanInfo = getScanInfo(store, c.getEnvironment());<a name="line.228"></a>
+<span class="sourceLineNo">229</span>    if (scanInfo == null) {<a name="line.229"></a>
+<span class="sourceLineNo">230</span>      // take default action<a name="line.230"></a>
+<span class="sourceLineNo">231</span>      return null;<a name="line.231"></a>
+<span class="sourceLineNo">232</span>    }<a name="line.232"></a>
+<span class="sourceLineNo">233</span>    return new StoreScanner(store, scanInfo, scan, targetCols,<a name="line.233"></a>
+<span class="sourceLineNo">234</span>      ((HStore)store).getHRegion().getReadPoint(IsolationLevel.READ_COMMITTED));<a name="line.234"></a>
+<span class="sourceLineNo">235</span>  }<a name="line.235"></a>
+<span class="sourceLineNo">236</span>}<a name="line.236"></a>
 
 
 

http://git-wip-us.apache.org/repos/asf/hbase-site/blob/a7e5a8ce/devapidocs/src-html/org/apache/hadoop/hbase/coprocessor/example/ZooKeeperScanPolicyObserver.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/coprocessor/example/ZooKeeperScanPolicyObserver.html b/devapidocs/src-html/org/apache/hadoop/hbase/coprocessor/example/ZooKeeperScanPolicyObserver.html
index aca192f..761d6a4 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/coprocessor/example/ZooKeeperScanPolicyObserver.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/coprocessor/example/ZooKeeperScanPolicyObserver.html
@@ -41,208 +41,207 @@
 <span class="sourceLineNo">033</span>import org.apache.hadoop.hbase.coprocessor.ObserverContext;<a name="line.33"></a>
 <span class="sourceLineNo">034</span>import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;<a name="line.34"></a>
 <span class="sourceLineNo">035</span>import org.apache.hadoop.hbase.regionserver.HStore;<a name="line.35"></a>
-<span class="sourceLineNo">036</span>import org.apache.hadoop.hbase.regionserver.Store;<a name="line.36"></a>
-<span class="sourceLineNo">037</span>import org.apache.hadoop.hbase.regionserver.ScanInfo;<a name="line.37"></a>
-<span class="sourceLineNo">038</span>import org.apache.hadoop.hbase.regionserver.InternalScanner;<a name="line.38"></a>
-<span class="sourceLineNo">039</span>import org.apache.hadoop.hbase.regionserver.KeyValueScanner;<a name="line.39"></a>
-<span class="sourceLineNo">040</span>import org.apache.hadoop.hbase.regionserver.ScanType;<a name="line.40"></a>
-<span class="sourceLineNo">041</span>import org.apache.hadoop.hbase.regionserver.Store;<a name="line.41"></a>
-<span class="sourceLineNo">042</span>import org.apache.hadoop.hbase.regionserver.StoreScanner;<a name="line.42"></a>
-<span class="sourceLineNo">043</span>import org.apache.hadoop.hbase.util.Bytes;<a name="line.43"></a>
-<span class="sourceLineNo">044</span>import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;<a name="line.44"></a>
-<span class="sourceLineNo">045</span>import org.apache.zookeeper.KeeperException;<a name="line.45"></a>
-<span class="sourceLineNo">046</span>import org.apache.zookeeper.WatchedEvent;<a name="line.46"></a>
-<span class="sourceLineNo">047</span>import org.apache.zookeeper.Watcher;<a name="line.47"></a>
-<span class="sourceLineNo">048</span>import org.apache.zookeeper.ZooKeeper;<a name="line.48"></a>
-<span class="sourceLineNo">049</span><a name="line.49"></a>
-<span class="sourceLineNo">050</span>/**<a name="line.50"></a>
-<span class="sourceLineNo">051</span> * This is an example showing how a RegionObserver could configured<a name="line.51"></a>
-<span class="sourceLineNo">052</span> * via ZooKeeper in order to control a Region compaction, flush, and scan policy.<a name="line.52"></a>
-<span class="sourceLineNo">053</span> *<a name="line.53"></a>
-<span class="sourceLineNo">054</span> * This also demonstrated the use of shared <a name="line.54"></a>
-<span class="sourceLineNo">055</span> * {@link org.apache.hadoop.hbase.coprocessor.RegionObserver} state.<a name="line.55"></a>
-<span class="sourceLineNo">056</span> * See {@link RegionCoprocessorEnvironment#getSharedData()}.<a name="line.56"></a>
-<span class="sourceLineNo">057</span> *<a name="line.57"></a>
-<span class="sourceLineNo">058</span> * This would be useful for an incremental backup tool, which would indicate the last<a name="line.58"></a>
-<span class="sourceLineNo">059</span> * time of a successful backup via ZK and instruct HBase to not delete data that was<a name="line.59"></a>
-<span class="sourceLineNo">060</span> * inserted since (based on wall clock time). <a name="line.60"></a>
-<span class="sourceLineNo">061</span> *<a name="line.61"></a>
-<span class="sourceLineNo">062</span> * This implements org.apache.zookeeper.Watcher directly instead of using<a name="line.62"></a>
-<span class="sourceLineNo">063</span> * {@link org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher}, <a name="line.63"></a>
-<span class="sourceLineNo">064</span> * because RegionObservers come and go and currently<a name="line.64"></a>
-<span class="sourceLineNo">065</span> * listeners registered with ZooKeeperWatcher cannot be removed.<a name="line.65"></a>
-<span class="sourceLineNo">066</span> */<a name="line.66"></a>
-<span class="sourceLineNo">067</span>public class ZooKeeperScanPolicyObserver extends BaseRegionObserver {<a name="line.67"></a>
-<span class="sourceLineNo">068</span>  public static final String node = "/backup/example/lastbackup";<a name="line.68"></a>
-<span class="sourceLineNo">069</span>  public static final String zkkey = "ZK";<a name="line.69"></a>
-<span class="sourceLineNo">070</span>  private static final Log LOG = LogFactory.getLog(ZooKeeperScanPolicyObserver.class);<a name="line.70"></a>
-<span class="sourceLineNo">071</span><a name="line.71"></a>
-<span class="sourceLineNo">072</span>  /**<a name="line.72"></a>
-<span class="sourceLineNo">073</span>   * Internal watcher that keep "data" up to date asynchronously.<a name="line.73"></a>
-<span class="sourceLineNo">074</span>   */<a name="line.74"></a>
-<span class="sourceLineNo">075</span>  private static class ZKWatcher implements Watcher {<a name="line.75"></a>
-<span class="sourceLineNo">076</span>    private byte[] data = null;<a name="line.76"></a>
-<span class="sourceLineNo">077</span>    private ZooKeeper zk;<a name="line.77"></a>
-<span class="sourceLineNo">078</span>    private volatile boolean needSetup = true;<a name="line.78"></a>
-<span class="sourceLineNo">079</span>    private volatile long lastSetupTry = 0;<a name="line.79"></a>
-<span class="sourceLineNo">080</span><a name="line.80"></a>
-<span class="sourceLineNo">081</span>    public ZKWatcher(ZooKeeper zk) {<a name="line.81"></a>
-<span class="sourceLineNo">082</span>      this.zk = zk;<a name="line.82"></a>
-<span class="sourceLineNo">083</span>      // trigger the listening<a name="line.83"></a>
-<span class="sourceLineNo">084</span>      getData();<a name="line.84"></a>
-<span class="sourceLineNo">085</span>    }<a name="line.85"></a>
-<span class="sourceLineNo">086</span><a name="line.86"></a>
-<span class="sourceLineNo">087</span>    /**<a name="line.87"></a>
-<span class="sourceLineNo">088</span>     * Get the maintained data. In case of any ZK exceptions this will retry<a name="line.88"></a>
-<span class="sourceLineNo">089</span>     * establishing the connection (but not more than twice/minute).<a name="line.89"></a>
-<span class="sourceLineNo">090</span>     *<a name="line.90"></a>
-<span class="sourceLineNo">091</span>     * getData is on the critical path, so make sure it is fast unless there is<a name="line.91"></a>
-<span class="sourceLineNo">092</span>     * a problem (network partion, ZK ensemble down, etc)<a name="line.92"></a>
-<span class="sourceLineNo">093</span>     * Make sure at most one (unlucky) thread retries and other threads don't pile up<a name="line.93"></a>
-<span class="sourceLineNo">094</span>     * while that threads tries to recreate the connection.<a name="line.94"></a>
-<span class="sourceLineNo">095</span>     *<a name="line.95"></a>
-<span class="sourceLineNo">096</span>     * @return the last know version of the data<a name="line.96"></a>
-<span class="sourceLineNo">097</span>     */<a name="line.97"></a>
-<span class="sourceLineNo">098</span>    @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="REC_CATCH_EXCEPTION")<a name="line.98"></a>
-<span class="sourceLineNo">099</span>    public byte[] getData() {<a name="line.99"></a>
-<span class="sourceLineNo">100</span>      // try at most twice/minute<a name="line.100"></a>
-<span class="sourceLineNo">101</span>      if (needSetup &amp;&amp; EnvironmentEdgeManager.currentTime() &gt; lastSetupTry + 30000) {<a name="line.101"></a>
-<span class="sourceLineNo">102</span>        synchronized (this) {<a name="line.102"></a>
-<span class="sourceLineNo">103</span>          // make sure only one thread tries to reconnect<a name="line.103"></a>
-<span class="sourceLineNo">104</span>          if (needSetup) {<a name="line.104"></a>
-<span class="sourceLineNo">105</span>            needSetup = false;<a name="line.105"></a>
-<span class="sourceLineNo">106</span>          } else {<a name="line.106"></a>
-<span class="sourceLineNo">107</span>            return data;<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>        // do this without the lock held to avoid threads piling up on this lock,<a name="line.110"></a>
-<span class="sourceLineNo">111</span>        // as it can take a while<a name="line.111"></a>
-<span class="sourceLineNo">112</span>        try {<a name="line.112"></a>
-<span class="sourceLineNo">113</span>          LOG.debug("Connecting to ZK");<a name="line.113"></a>
-<span class="sourceLineNo">114</span>          // record this attempt<a name="line.114"></a>
-<span class="sourceLineNo">115</span>          lastSetupTry = EnvironmentEdgeManager.currentTime();<a name="line.115"></a>
-<span class="sourceLineNo">116</span>          if (zk.exists(node, false) != null) {<a name="line.116"></a>
-<span class="sourceLineNo">117</span>            data = zk.getData(node, this, null);<a name="line.117"></a>
-<span class="sourceLineNo">118</span>            LOG.debug("Read synchronously: "+(data == null ? "null" : Bytes.toLong(data)));<a name="line.118"></a>
-<span class="sourceLineNo">119</span>          } else {<a name="line.119"></a>
-<span class="sourceLineNo">120</span>            zk.exists(node, this);<a name="line.120"></a>
-<span class="sourceLineNo">121</span>          }<a name="line.121"></a>
-<span class="sourceLineNo">122</span>        } catch (Exception x) {<a name="line.122"></a>
-<span class="sourceLineNo">123</span>          // try again if this fails<a name="line.123"></a>
-<span class="sourceLineNo">124</span>          needSetup = true;<a name="line.124"></a>
-<span class="sourceLineNo">125</span>        }<a name="line.125"></a>
-<span class="sourceLineNo">126</span>      }<a name="line.126"></a>
-<span class="sourceLineNo">127</span>      return data;<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>    @Override<a name="line.130"></a>
-<span class="sourceLineNo">131</span>    public void process(WatchedEvent event) {<a name="line.131"></a>
-<span class="sourceLineNo">132</span>      switch(event.getType()) {<a name="line.132"></a>
-<span class="sourceLineNo">133</span>      case NodeDataChanged:<a name="line.133"></a>
-<span class="sourceLineNo">134</span>      case NodeCreated:<a name="line.134"></a>
-<span class="sourceLineNo">135</span>      try {<a name="line.135"></a>
-<span class="sourceLineNo">136</span>        // get data and re-watch<a name="line.136"></a>
-<span class="sourceLineNo">137</span>        data = zk.getData(node, this, null);<a name="line.137"></a>
-<span class="sourceLineNo">138</span>        LOG.debug("Read asynchronously: "+(data == null ? "null" : Bytes.toLong(data)));<a name="line.138"></a>
-<span class="sourceLineNo">139</span>      } catch (InterruptedException ix) {<a name="line.139"></a>
-<span class="sourceLineNo">140</span>      } catch (KeeperException kx) {<a name="line.140"></a>
-<span class="sourceLineNo">141</span>        needSetup = true;<a name="line.141"></a>
-<span class="sourceLineNo">142</span>      }<a name="line.142"></a>
-<span class="sourceLineNo">143</span>      break;<a name="line.143"></a>
-<span class="sourceLineNo">144</span><a name="line.144"></a>
-<span class="sourceLineNo">145</span>      case NodeDeleted:<a name="line.145"></a>
-<span class="sourceLineNo">146</span>      try {<a name="line.146"></a>
-<span class="sourceLineNo">147</span>        // just re-watch<a name="line.147"></a>
-<span class="sourceLineNo">148</span>        zk.exists(node, this);<a name="line.148"></a>
-<span class="sourceLineNo">149</span>        data = null;<a name="line.149"></a>
-<span class="sourceLineNo">150</span>      } catch (InterruptedException ix) {<a name="line.150"></a>
-<span class="sourceLineNo">151</span>      } catch (KeeperException kx) {<a name="line.151"></a>
-<span class="sourceLineNo">152</span>        needSetup = true;<a name="line.152"></a>
-<span class="sourceLineNo">153</span>      }<a name="line.153"></a>
-<span class="sourceLineNo">154</span>      break;<a name="line.154"></a>
-<span class="sourceLineNo">155</span><a name="line.155"></a>
-<span class="sourceLineNo">156</span>      default:<a name="line.156"></a>
-<span class="sourceLineNo">157</span>        // ignore<a name="line.157"></a>
-<span class="sourceLineNo">158</span>      }<a name="line.158"></a>
-<span class="sourceLineNo">159</span>    }<a name="line.159"></a>
-<span class="sourceLineNo">160</span>  }<a name="line.160"></a>
-<span class="sourceLineNo">161</span><a name="line.161"></a>
-<span class="sourceLineNo">162</span>  @Override<a name="line.162"></a>
-<span class="sourceLineNo">163</span>  public void start(CoprocessorEnvironment e) throws IOException {<a name="line.163"></a>
-<span class="sourceLineNo">164</span>    RegionCoprocessorEnvironment re = (RegionCoprocessorEnvironment) e;<a name="line.164"></a>
-<span class="sourceLineNo">165</span>    if (!re.getSharedData().containsKey(zkkey)) {<a name="line.165"></a>
-<span class="sourceLineNo">166</span>      // there is a short race here<a name="line.166"></a>
-<span class="sourceLineNo">167</span>      // in the worst case we create a watcher that will be notified once<a name="line.167"></a>
-<span class="sourceLineNo">168</span>      re.getSharedData().putIfAbsent(<a name="line.168"></a>
-<span class="sourceLineNo">169</span>          zkkey,<a name="line.169"></a>
-<span class="sourceLineNo">170</span>          new ZKWatcher(re.getRegionServerServices().getZooKeeper()<a name="line.170"></a>
-<span class="sourceLineNo">171</span>              .getRecoverableZooKeeper().getZooKeeper()));<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><a name="line.174"></a>
-<span class="sourceLineNo">175</span>  @Override<a name="line.175"></a>
-<span class="sourceLineNo">176</span>  public void stop(CoprocessorEnvironment e) throws IOException {<a name="line.176"></a>
-<span class="sourceLineNo">177</span>    // nothing to do here<a name="line.177"></a>
-<span class="sourceLineNo">178</span>  }<a name="line.178"></a>
-<span class="sourceLineNo">179</span><a name="line.179"></a>
-<span class="sourceLineNo">180</span>  protected ScanInfo getScanInfo(Store store, RegionCoprocessorEnvironment e) {<a name="line.180"></a>
-<span class="sourceLineNo">181</span>    byte[] data = ((ZKWatcher)e.getSharedData().get(zkkey)).getData();<a name="line.181"></a>
-<span class="sourceLineNo">182</span>    if (data == null) {<a name="line.182"></a>
-<span class="sourceLineNo">183</span>      return null;<a name="line.183"></a>
-<span class="sourceLineNo">184</span>    }<a name="line.184"></a>
-<span class="sourceLineNo">185</span>    ScanInfo oldSI = store.getScanInfo();<a name="line.185"></a>
-<span class="sourceLineNo">186</span>    if (oldSI.getTtl() == Long.MAX_VALUE) {<a name="line.186"></a>
-<span class="sourceLineNo">187</span>      return null;<a name="line.187"></a>
-<span class="sourceLineNo">188</span>    }<a name="line.188"></a>
-<span class="sourceLineNo">189</span>    long ttl = Math.max(EnvironmentEdgeManager.currentTime() -<a name="line.189"></a>
-<span class="sourceLineNo">190</span>        Bytes.toLong(data), oldSI.getTtl());<a name="line.190"></a>
-<span class="sourceLineNo">191</span>    return new ScanInfo(oldSI.getConfiguration(), store.getFamily(), ttl,<a name="line.191"></a>
-<span class="sourceLineNo">192</span>        oldSI.getTimeToPurgeDeletes(), oldSI.getComparator());<a name="line.192"></a>
-<span class="sourceLineNo">193</span>  }<a name="line.193"></a>
-<span class="sourceLineNo">194</span><a name="line.194"></a>
-<span class="sourceLineNo">195</span>  @Override<a name="line.195"></a>
-<span class="sourceLineNo">196</span>  public InternalScanner preFlushScannerOpen(final ObserverContext&lt;RegionCoprocessorEnvironment&gt; c,<a name="line.196"></a>
-<span class="sourceLineNo">197</span>      Store store, KeyValueScanner memstoreScanner, InternalScanner s) throws IOException {<a name="line.197"></a>
-<span class="sourceLineNo">198</span>    ScanInfo scanInfo = getScanInfo(store, c.getEnvironment());<a name="line.198"></a>
-<span class="sourceLineNo">199</span>    if (scanInfo == null) {<a name="line.199"></a>
-<span class="sourceLineNo">200</span>      // take default action<a name="line.200"></a>
-<span class="sourceLineNo">201</span>      return null;<a name="line.201"></a>
-<span class="sourceLineNo">202</span>    }<a name="line.202"></a>
-<span class="sourceLineNo">203</span>    Scan scan = new Scan();<a name="line.203"></a>
-<span class="sourceLineNo">204</span>    scan.setMaxVersions(scanInfo.getMaxVersions());<a name="line.204"></a>
-<span class="sourceLineNo">205</span>    return new StoreScanner(store, scanInfo, scan, Collections.singletonList(memstoreScanner),<a name="line.205"></a>
-<span class="sourceLineNo">206</span>        ScanType.COMPACT_RETAIN_DELETES, store.getSmallestReadPoint(), HConstants.OLDEST_TIMESTAMP);<a name="line.206"></a>
-<span class="sourceLineNo">207</span>  }<a name="line.207"></a>
-<span class="sourceLineNo">208</span><a name="line.208"></a>
-<span class="sourceLineNo">209</span>  @Override<a name="line.209"></a>
-<span class="sourceLineNo">210</span>  public InternalScanner preCompactScannerOpen(<a name="line.210"></a>
-<span class="sourceLineNo">211</span>      final ObserverContext&lt;RegionCoprocessorEnvironment&gt; c,<a name="line.211"></a>
-<span class="sourceLineNo">212</span>      Store store, List&lt;? extends KeyValueScanner&gt; scanners, ScanType scanType, long earliestPutTs,<a name="line.212"></a>
-<span class="sourceLineNo">213</span>      InternalScanner s) throws IOException {<a name="line.213"></a>
-<span class="sourceLineNo">214</span>    ScanInfo scanInfo = getScanInfo(store, c.getEnvironment());<a name="line.214"></a>
-<span class="sourceLineNo">215</span>    if (scanInfo == null) {<a name="line.215"></a>
-<span class="sourceLineNo">216</span>      // take default action<a name="line.216"></a>
-<span class="sourceLineNo">217</span>      return null;<a name="line.217"></a>
-<span class="sourceLineNo">218</span>    }<a name="line.218"></a>
-<span class="sourceLineNo">219</span>    Scan scan = new Scan();<a name="line.219"></a>
-<span class="sourceLineNo">220</span>    scan.setMaxVersions(scanInfo.getMaxVersions());<a name="line.220"></a>
-<span class="sourceLineNo">221</span>    return new StoreScanner(store, scanInfo, scan, scanners, scanType,<a name="line.221"></a>
-<span class="sourceLineNo">222</span>        store.getSmallestReadPoint(), earliestPutTs);<a name="line.222"></a>
-<span class="sourceLineNo">223</span>  }<a name="line.223"></a>
-<span class="sourceLineNo">224</span><a name="line.224"></a>
-<span class="sourceLineNo">225</span>  @Override<a name="line.225"></a>
-<span class="sourceLineNo">226</span>  public KeyValueScanner preStoreScannerOpen(final ObserverContext&lt;RegionCoprocessorEnvironment&gt; c,<a name="line.226"></a>
-<span class="sourceLineNo">227</span>      final Store store, final Scan scan, final NavigableSet&lt;byte[]&gt; targetCols,<a name="line.227"></a>
-<span class="sourceLineNo">228</span>      final KeyValueScanner s) throws IOException {<a name="line.228"></a>
-<span class="sourceLineNo">229</span>    ScanInfo scanInfo = getScanInfo(store, c.getEnvironment());<a name="line.229"></a>
-<span class="sourceLineNo">230</span>    if (scanInfo == null) {<a name="line.230"></a>
-<span class="sourceLineNo">231</span>      // take default action<a name="line.231"></a>
-<span class="sourceLineNo">232</span>      return null;<a name="line.232"></a>
-<span class="sourceLineNo">233</span>    }<a name="line.233"></a>
-<span class="sourceLineNo">234</span>    return new StoreScanner(store, scanInfo, scan, targetCols,<a name="line.234"></a>
-<span class="sourceLineNo">235</span>      ((HStore)store).getHRegion().getReadpoint(IsolationLevel.READ_COMMITTED));<a name="line.235"></a>
-<span class="sourceLineNo">236</span>  }<a name="line.236"></a>
-<span class="sourceLineNo">237</span>}<a name="line.237"></a>
+<span class="sourceLineNo">036</span>import org.apache.hadoop.hbase.regionserver.InternalScanner;<a name="line.36"></a>
+<span class="sourceLineNo">037</span>import org.apache.hadoop.hbase.regionserver.KeyValueScanner;<a name="line.37"></a>
+<span class="sourceLineNo">038</span>import org.apache.hadoop.hbase.regionserver.ScanInfo;<a name="line.38"></a>
+<span class="sourceLineNo">039</span>import org.apache.hadoop.hbase.regionserver.ScanType;<a name="line.39"></a>
+<span class="sourceLineNo">040</span>import org.apache.hadoop.hbase.regionserver.Store;<a name="line.40"></a>
+<span class="sourceLineNo">041</span>import org.apache.hadoop.hbase.regionserver.StoreScanner;<a name="line.41"></a>
+<span class="sourceLineNo">042</span>import org.apache.hadoop.hbase.util.Bytes;<a name="line.42"></a>
+<span class="sourceLineNo">043</span>import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;<a name="line.43"></a>
+<span class="sourceLineNo">044</span>import org.apache.zookeeper.KeeperException;<a name="line.44"></a>
+<span class="sourceLineNo">045</span>import org.apache.zookeeper.WatchedEvent;<a name="line.45"></a>
+<span class="sourceLineNo">046</span>import org.apache.zookeeper.Watcher;<a name="line.46"></a>
+<span class="sourceLineNo">047</span>import org.apache.zookeeper.ZooKeeper;<a name="line.47"></a>
+<span class="sourceLineNo">048</span><a name="line.48"></a>
+<span class="sourceLineNo">049</span>/**<a name="line.49"></a>
+<span class="sourceLineNo">050</span> * This is an example showing how a RegionObserver could configured<a name="line.50"></a>
+<span class="sourceLineNo">051</span> * via ZooKeeper in order to control a Region compaction, flush, and scan policy.<a name="line.51"></a>
+<span class="sourceLineNo">052</span> *<a name="line.52"></a>
+<span class="sourceLineNo">053</span> * This also demonstrated the use of shared <a name="line.53"></a>
+<span class="sourceLineNo">054</span> * {@link org.apache.hadoop.hbase.coprocessor.RegionObserver} state.<a name="line.54"></a>
+<span class="sourceLineNo">055</span> * See {@link RegionCoprocessorEnvironment#getSharedData()}.<a name="line.55"></a>
+<span class="sourceLineNo">056</span> *<a name="line.56"></a>
+<span class="sourceLineNo">057</span> * This would be useful for an incremental backup tool, which would indicate the last<a name="line.57"></a>
+<span class="sourceLineNo">058</span> * time of a successful backup via ZK and instruct HBase to not delete data that was<a name="line.58"></a>
+<span class="sourceLineNo">059</span> * inserted since (based on wall clock time). <a name="line.59"></a>
+<span class="sourceLineNo">060</span> *<a name="line.60"></a>
+<span class="sourceLineNo">061</span> * This implements org.apache.zookeeper.Watcher directly instead of using<a name="line.61"></a>
+<span class="sourceLineNo">062</span> * {@link org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher}, <a name="line.62"></a>
+<span class="sourceLineNo">063</span> * because RegionObservers come and go and currently<a name="line.63"></a>
+<span class="sourceLineNo">064</span> * listeners registered with ZooKeeperWatcher cannot be removed.<a name="line.64"></a>
+<span class="sourceLineNo">065</span> */<a name="line.65"></a>
+<span class="sourceLineNo">066</span>public class ZooKeeperScanPolicyObserver extends BaseRegionObserver {<a name="line.66"></a>
+<span class="sourceLineNo">067</span>  public static final String node = "/backup/example/lastbackup";<a name="line.67"></a>
+<span class="sourceLineNo">068</span>  public static final String zkkey = "ZK";<a name="line.68"></a>
+<span class="sourceLineNo">069</span>  private static final Log LOG = LogFactory.getLog(ZooKeeperScanPolicyObserver.class);<a name="line.69"></a>
+<span class="sourceLineNo">070</span><a name="line.70"></a>
+<span class="sourceLineNo">071</span>  /**<a name="line.71"></a>
+<span class="sourceLineNo">072</span>   * Internal watcher that keep "data" up to date asynchronously.<a name="line.72"></a>
+<span class="sourceLineNo">073</span>   */<a name="line.73"></a>
+<span class="sourceLineNo">074</span>  private static class ZKWatcher implements Watcher {<a name="line.74"></a>
+<span class="sourceLineNo">075</span>    private byte[] data = null;<a name="line.75"></a>
+<span class="sourceLineNo">076</span>    private ZooKeeper zk;<a name="line.76"></a>
+<span class="sourceLineNo">077</span>    private volatile boolean needSetup = true;<a name="line.77"></a>
+<span class="sourceLineNo">078</span>    private volatile long lastSetupTry = 0;<a name="line.78"></a>
+<span class="sourceLineNo">079</span><a name="line.79"></a>
+<span class="sourceLineNo">080</span>    public ZKWatcher(ZooKeeper zk) {<a name="line.80"></a>
+<span class="sourceLineNo">081</span>      this.zk = zk;<a name="line.81"></a>
+<span class="sourceLineNo">082</span>      // trigger the listening<a name="line.82"></a>
+<span class="sourceLineNo">083</span>      getData();<a name="line.83"></a>
+<span class="sourceLineNo">084</span>    }<a name="line.84"></a>
+<span class="sourceLineNo">085</span><a name="line.85"></a>
+<span class="sourceLineNo">086</span>    /**<a name="line.86"></a>
+<span class="sourceLineNo">087</span>     * Get the maintained data. In case of any ZK exceptions this will retry<a name="line.87"></a>
+<span class="sourceLineNo">088</span>     * establishing the connection (but not more than twice/minute).<a name="line.88"></a>
+<span class="sourceLineNo">089</span>     *<a name="line.89"></a>
+<span class="sourceLineNo">090</span>     * getData is on the critical path, so make sure it is fast unless there is<a name="line.90"></a>
+<span class="sourceLineNo">091</span>     * a problem (network partion, ZK ensemble down, etc)<a name="line.91"></a>
+<span class="sourceLineNo">092</span>     * Make sure at most one (unlucky) thread retries and other threads don't pile up<a name="line.92"></a>
+<span class="sourceLineNo">093</span>     * while that threads tries to recreate the connection.<a name="line.93"></a>
+<span class="sourceLineNo">094</span>     *<a name="line.94"></a>
+<span class="sourceLineNo">095</span>     * @return the last know version of the data<a name="line.95"></a>
+<span class="sourceLineNo">096</span>     */<a name="line.96"></a>
+<span class="sourceLineNo">097</span>    @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="REC_CATCH_EXCEPTION")<a name="line.97"></a>
+<span class="sourceLineNo">098</span>    public byte[] getData() {<a name="line.98"></a>
+<span class="sourceLineNo">099</span>      // try at most twice/minute<a name="line.99"></a>
+<span class="sourceLineNo">100</span>      if (needSetup &amp;&amp; EnvironmentEdgeManager.currentTime() &gt; lastSetupTry + 30000) {<a name="line.100"></a>
+<span class="sourceLineNo">101</span>        synchronized (this) {<a name="line.101"></a>
+<span class="sourceLineNo">102</span>          // make sure only one thread tries to reconnect<a name="line.102"></a>
+<span class="sourceLineNo">103</span>          if (needSetup) {<a name="line.103"></a>
+<span class="sourceLineNo">104</span>            needSetup = false;<a name="line.104"></a>
+<span class="sourceLineNo">105</span>          } else {<a name="line.105"></a>
+<span class="sourceLineNo">106</span>            return data;<a name="line.106"></a>
+<span class="sourceLineNo">107</span>          }<a name="line.107"></a>
+<span class="sourceLineNo">108</span>        }<a name="line.108"></a>
+<span class="sourceLineNo">109</span>        // do this without the lock held to avoid threads piling up on this lock,<a name="line.109"></a>
+<span class="sourceLineNo">110</span>        // as it can take a while<a name="line.110"></a>
+<span class="sourceLineNo">111</span>        try {<a name="line.111"></a>
+<span class="sourceLineNo">112</span>          LOG.debug("Connecting to ZK");<a name="line.112"></a>
+<span class="sourceLineNo">113</span>          // record this attempt<a name="line.113"></a>
+<span class="sourceLineNo">114</span>          lastSetupTry = EnvironmentEdgeManager.currentTime();<a name="line.114"></a>
+<span class="sourceLineNo">115</span>          if (zk.exists(node, false) != null) {<a name="line.115"></a>
+<span class="sourceLineNo">116</span>            data = zk.getData(node, this, null);<a name="line.116"></a>
+<span class="sourceLineNo">117</span>            LOG.debug("Read synchronously: "+(data == null ? "null" : Bytes.toLong(data)));<a name="line.117"></a>
+<span class="sourceLineNo">118</span>          } else {<a name="line.118"></a>
+<span class="sourceLineNo">119</span>            zk.exists(node, this);<a name="line.119"></a>
+<span class="sourceLineNo">120</span>          }<a name="line.120"></a>
+<span class="sourceLineNo">121</span>        } catch (Exception x) {<a name="line.121"></a>
+<span class="sourceLineNo">122</span>          // try again if this fails<a name="line.122"></a>
+<span class="sourceLineNo">123</span>          needSetup = true;<a name="line.123"></a>
+<span class="sourceLineNo">124</span>        }<a name="line.124"></a>
+<span class="sourceLineNo">125</span>      }<a name="line.125"></a>
+<span class="sourceLineNo">126</span>      return data;<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>    @Override<a name="line.129"></a>
+<span class="sourceLineNo">130</span>    public void process(WatchedEvent event) {<a name="line.130"></a>
+<span class="sourceLineNo">131</span>      switch(event.getType()) {<a name="line.131"></a>
+<span class="sourceLineNo">132</span>      case NodeDataChanged:<a name="line.132"></a>
+<span class="sourceLineNo">133</span>      case NodeCreated:<a name="line.133"></a>
+<span class="sourceLineNo">134</span>      try {<a name="line.134"></a>
+<span class="sourceLineNo">135</span>        // get data and re-watch<a name="line.135"></a>
+<span class="sourceLineNo">136</span>        data = zk.getData(node, this, null);<a name="line.136"></a>
+<span class="sourceLineNo">137</span>        LOG.debug("Read asynchronously: "+(data == null ? "null" : Bytes.toLong(data)));<a name="line.137"></a>
+<span class="sourceLineNo">138</span>      } catch (InterruptedException ix) {<a name="line.138"></a>
+<span class="sourceLineNo">139</span>      } catch (KeeperException kx) {<a name="line.139"></a>
+<span class="sourceLineNo">140</span>        needSetup = true;<a name="line.140"></a>
+<span class="sourceLineNo">141</span>      }<a name="line.141"></a>
+<span class="sourceLineNo">142</span>      break;<a name="line.142"></a>
+<span class="sourceLineNo">143</span><a name="line.143"></a>
+<span class="sourceLineNo">144</span>      case NodeDeleted:<a name="line.144"></a>
+<span class="sourceLineNo">145</span>      try {<a name="line.145"></a>
+<span class="sourceLineNo">146</span>        // just re-watch<a name="line.146"></a>
+<span class="sourceLineNo">147</span>        zk.exists(node, this);<a name="line.147"></a>
+<span class="sourceLineNo">148</span>        data = null;<a name="line.148"></a>
+<span class="sourceLineNo">149</span>      } catch (InterruptedException ix) {<a name="line.149"></a>
+<span class="sourceLineNo">150</span>      } catch (KeeperException kx) {<a name="line.150"></a>
+<span class="sourceLineNo">151</span>        needSetup = true;<a name="line.151"></a>
+<span class="sourceLineNo">152</span>      }<a name="line.152"></a>
+<span class="sourceLineNo">153</span>      break;<a name="line.153"></a>
+<span class="sourceLineNo">154</span><a name="line.154"></a>
+<span class="sourceLineNo">155</span>      default:<a name="line.155"></a>
+<span class="sourceLineNo">156</span>        // ignore<a name="line.156"></a>
+<span class="sourceLineNo">157</span>      }<a name="line.157"></a>
+<span class="sourceLineNo">158</span>    }<a name="line.158"></a>
+<span class="sourceLineNo">159</span>  }<a name="line.159"></a>
+<span class="sourceLineNo">160</span><a name="line.160"></a>
+<span class="sourceLineNo">161</span>  @Override<a name="line.161"></a>
+<span class="sourceLineNo">162</span>  public void start(CoprocessorEnvironment e) throws IOException {<a name="line.162"></a>
+<span class="sourceLineNo">163</span>    RegionCoprocessorEnvironment re = (RegionCoprocessorEnvironment) e;<a name="line.163"></a>
+<span class="sourceLineNo">164</span>    if (!re.getSharedData().containsKey(zkkey)) {<a name="line.164"></a>
+<span class="sourceLineNo">165</span>      // there is a short race here<a name="line.165"></a>
+<span class="sourceLineNo">166</span>      // in the worst case we create a watcher that will be notified once<a name="line.166"></a>
+<span class="sourceLineNo">167</span>      re.getSharedData().putIfAbsent(<a name="line.167"></a>
+<span class="sourceLineNo">168</span>          zkkey,<a name="line.168"></a>
+<span class="sourceLineNo">169</span>          new ZKWatcher(re.getRegionServerServices().getZooKeeper()<a name="line.169"></a>
+<span class="sourceLineNo">170</span>              .getRecoverableZooKeeper().getZooKeeper()));<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>  @Override<a name="line.174"></a>
+<span class="sourceLineNo">175</span>  public void stop(CoprocessorEnvironment e) throws IOException {<a name="line.175"></a>
+<span class="sourceLineNo">176</span>    // nothing to do here<a name="line.176"></a>
+<span class="sourceLineNo">177</span>  }<a name="line.177"></a>
+<span class="sourceLineNo">178</span><a name="line.178"></a>
+<span class="sourceLineNo">179</span>  protected ScanInfo getScanInfo(Store store, RegionCoprocessorEnvironment e) {<a name="line.179"></a>
+<span class="sourceLineNo">180</span>    byte[] data = ((ZKWatcher)e.getSharedData().get(zkkey)).getData();<a name="line.180"></a>
+<span class="sourceLineNo">181</span>    if (data == null) {<a name="line.181"></a>
+<span class="sourceLineNo">182</span>      return null;<a name="line.182"></a>
+<span class="sourceLineNo">183</span>    }<a name="line.183"></a>
+<span class="sourceLineNo">184</span>    ScanInfo oldSI = store.getScanInfo();<a name="line.184"></a>
+<span class="sourceLineNo">185</span>    if (oldSI.getTtl() == Long.MAX_VALUE) {<a name="line.185"></a>
+<span class="sourceLineNo">186</span>      return null;<a name="line.186"></a>
+<span class="sourceLineNo">187</span>    }<a name="line.187"></a>
+<span class="sourceLineNo">188</span>    long ttl = Math.max(EnvironmentEdgeManager.currentTime() -<a name="line.188"></a>
+<span class="sourceLineNo">189</span>        Bytes.toLong(data), oldSI.getTtl());<a name="line.189"></a>
+<span class="sourceLineNo">190</span>    return new ScanInfo(oldSI.getConfiguration(), store.getFamily(), ttl,<a name="line.190"></a>
+<span class="sourceLineNo">191</span>        oldSI.getTimeToPurgeDeletes(), oldSI.getComparator());<a name="line.191"></a>
+<span class="sourceLineNo">192</span>  }<a name="line.192"></a>
+<span class="sourceLineNo">193</span><a name="line.193"></a>
+<span class="sourceLineNo">194</span>  @Override<a name="line.194"></a>
+<span class="sourceLineNo">195</span>  public InternalScanner preFlushScannerOpen(final ObserverContext&lt;RegionCoprocessorEnvironment&gt; c,<a name="line.195"></a>
+<span class="sourceLineNo">196</span>      Store store, KeyValueScanner memstoreScanner, InternalScanner s) throws IOException {<a name="line.196"></a>
+<span class="sourceLineNo">197</span>    ScanInfo scanInfo = getScanInfo(store, c.getEnvironment());<a name="line.197"></a>
+<span class="sourceLineNo">198</span>    if (scanInfo == null) {<a name="line.198"></a>
+<span class="sourceLineNo">199</span>      // take default action<a name="line.199"></a>
+<span class="sourceLineNo">200</span>      return null;<a name="line.200"></a>
+<span class="sourceLineNo">201</span>    }<a name="line.201"></a>
+<span class="sourceLineNo">202</span>    Scan scan = new Scan();<a name="line.202"></a>
+<span class="sourceLineNo">203</span>    scan.setMaxVersions(scanInfo.getMaxVersions());<a name="line.203"></a>
+<span class="sourceLineNo">204</span>    return new StoreScanner(store, scanInfo, scan, Collections.singletonList(memstoreScanner),<a name="line.204"></a>
+<span class="sourceLineNo">205</span>        ScanType.COMPACT_RETAIN_DELETES, store.getSmallestReadPoint(), HConstants.OLDEST_TIMESTAMP);<a name="line.205"></a>
+<span class="sourceLineNo">206</span>  }<a name="line.206"></a>
+<span class="sourceLineNo">207</span><a name="line.207"></a>
+<span class="sourceLineNo">208</span>  @Override<a name="line.208"></a>
+<span class="sourceLineNo">209</span>  public InternalScanner preCompactScannerOpen(<a name="line.209"></a>
+<span class="sourceLineNo">210</span>      final ObserverContext&lt;RegionCoprocessorEnvironment&gt; c,<a name="line.210"></a>
+<span class="sourceLineNo">211</span>      Store store, List&lt;? extends KeyValueScanner&gt; scanners, ScanType scanType, long earliestPutTs,<a name="line.211"></a>
+<span class="sourceLineNo">212</span>      InternalScanner s) throws IOException {<a name="line.212"></a>
+<span class="sourceLineNo">213</span>    ScanInfo scanInfo = getScanInfo(store, c.getEnvironment());<a name="line.213"></a>
+<span class="sourceLineNo">214</span>    if (scanInfo == null) {<a name="line.214"></a>
+<span class="sourceLineNo">215</span>      // take default action<a name="line.215"></a>
+<span class="sourceLineNo">216</span>      return null;<a name="line.216"></a>
+<span class="sourceLineNo">217</span>    }<a name="line.217"></a>
+<span class="sourceLineNo">218</span>    Scan scan = new Scan();<a name="line.218"></a>
+<span class="sourceLineNo">219</span>    scan.setMaxVersions(scanInfo.getMaxVersions());<a name="line.219"></a>
+<span class="sourceLineNo">220</span>    return new StoreScanner(store, scanInfo, scan, scanners, scanType,<a name="line.220"></a>
+<span class="sourceLineNo">221</span>        store.getSmallestReadPoint(), earliestPutTs);<a name="line.221"></a>
+<span class="sourceLineNo">222</span>  }<a name="line.222"></a>
+<span class="sourceLineNo">223</span><a name="line.223"></a>
+<span class="sourceLineNo">224</span>  @Override<a name="line.224"></a>
+<span class="sourceLineNo">225</span>  public KeyValueScanner preStoreScannerOpen(final ObserverContext&lt;RegionCoprocessorEnvironment&gt; c,<a name="line.225"></a>
+<span class="sourceLineNo">226</span>      final Store store, final Scan scan, final NavigableSet&lt;byte[]&gt; targetCols,<a name="line.226"></a>
+<span class="sourceLineNo">227</span>      final KeyValueScanner s) throws IOException {<a name="line.227"></a>
+<span class="sourceLineNo">228</span>    ScanInfo scanInfo = getScanInfo(store, c.getEnvironment());<a name="line.228"></a>
+<span class="sourceLineNo">229</span>    if (scanInfo == null) {<a name="line.229"></a>
+<span class="sourceLineNo">230</span>      // take default action<a name="line.230"></a>
+<span class="sourceLineNo">231</span>      return null;<a name="line.231"></a>
+<span class="sourceLineNo">232</span>    }<a name="line.232"></a>
+<span class="sourceLineNo">233</span>    return new StoreScanner(store, scanInfo, scan, targetCols,<a name="line.233"></a>
+<span class="sourceLineNo">234</span>      ((HStore)store).getHRegion().getReadPoint(IsolationLevel.READ_COMMITTED));<a name="line.234"></a>
+<span class="sourceLineNo">235</span>  }<a name="line.235"></a>
+<span class="sourceLineNo">236</span>}<a name="line.236"></a>
 
 
 

http://git-wip-us.apache.org/repos/asf/hbase-site/blob/a7e5a8ce/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFileBlockIndex.BlockIndexChunk.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFileBlockIndex.BlockIndexChunk.html b/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFileBlockIndex.BlockIndexChunk.html
index 1be6fdf..35e3c5c 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFileBlockIndex.BlockIndexChunk.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFileBlockIndex.BlockIndexChunk.html
@@ -42,18 +42,18 @@
 <span class="sourceLineNo">034</span>import org.apache.commons.logging.LogFactory;<a name="line.34"></a>
 <span class="sourceLineNo">035</span>import org.apache.hadoop.conf.Configuration;<a name="line.35"></a>
 <span class="sourceLineNo">036</span>import org.apache.hadoop.fs.FSDataOutputStream;<a name="line.36"></a>
-<span class="sourceLineNo">037</span>import org.apache.hadoop.hbase.Cell;<a name="line.37"></a>
-<span class="sourceLineNo">038</span>import org.apache.hadoop.hbase.CellComparator;<a name="line.38"></a>
-<span class="sourceLineNo">039</span>import org.apache.hadoop.hbase.CellUtil;<a name="line.39"></a>
-<span class="sourceLineNo">040</span>import org.apache.hadoop.hbase.HConstants;<a name="line.40"></a>
+<span class="sourceLineNo">037</span>import org.apache.hadoop.hbase.ByteBufferedKeyOnlyKeyValue;<a name="line.37"></a>
+<span class="sourceLineNo">038</span>import org.apache.hadoop.hbase.Cell;<a name="line.38"></a>
+<span class="sourceLineNo">039</span>import org.apache.hadoop.hbase.CellComparator;<a name="line.39"></a>
+<span class="sourceLineNo">040</span>import org.apache.hadoop.hbase.CellUtil;<a name="line.40"></a>
 <span class="sourceLineNo">041</span>import org.apache.hadoop.hbase.KeyValue;<a name="line.41"></a>
 <span class="sourceLineNo">042</span>import org.apache.hadoop.hbase.KeyValue.KeyOnlyKeyValue;<a name="line.42"></a>
-<span class="sourceLineNo">043</span>import org.apache.hadoop.hbase.ByteBufferedKeyOnlyKeyValue;<a name="line.43"></a>
-<span class="sourceLineNo">044</span>import org.apache.hadoop.hbase.classification.InterfaceAudience;<a name="line.44"></a>
-<span class="sourceLineNo">045</span>import org.apache.hadoop.hbase.io.HeapSize;<a name="line.45"></a>
-<span class="sourceLineNo">046</span>import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;<a name="line.46"></a>
-<span class="sourceLineNo">047</span>import org.apache.hadoop.hbase.io.hfile.HFile.CachingBlockReader;<a name="line.47"></a>
-<span class="sourceLineNo">048</span>import org.apache.hadoop.hbase.nio.ByteBuff;<a name="line.48"></a>
+<span class="sourceLineNo">043</span>import org.apache.hadoop.hbase.classification.InterfaceAudience;<a name="line.43"></a>
+<span class="sourceLineNo">044</span>import org.apache.hadoop.hbase.io.HeapSize;<a name="line.44"></a>
+<span class="sourceLineNo">045</span>import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;<a name="line.45"></a>
+<span class="sourceLineNo">046</span>import org.apache.hadoop.hbase.io.hfile.HFile.CachingBlockReader;<a name="line.46"></a>
+<span class="sourceLineNo">047</span>import org.apache.hadoop.hbase.nio.ByteBuff;<a name="line.47"></a>
+<span class="sourceLineNo">048</span>import org.apache.hadoop.hbase.regionserver.KeyValueScanner;<a name="line.48"></a>
 <span class="sourceLineNo">049</span>import org.apache.hadoop.hbase.util.Bytes;<a name="line.49"></a>
 <span class="sourceLineNo">050</span>import org.apache.hadoop.hbase.util.ClassSize;<a name="line.50"></a>
 <span class="sourceLineNo">051</span>import org.apache.hadoop.hbase.util.ObjectIntPair;<a name="line.51"></a>
@@ -297,7 +297,7 @@
 <span class="sourceLineNo">289</span>      if (rootLevelIndex &lt; blockKeys.length - 1) {<a name="line.289"></a>
 <span class="sourceLineNo">290</span>        nextIndexedKey = blockKeys[rootLevelIndex + 1];<a name="line.290"></a>
 <span class="sourceLineNo">291</span>      } else {<a name="line.291"></a>
-<span class="sourceLineNo">292</span>        nextIndexedKey = HConstants.NO_NEXT_INDEXED_KEY;<a name="line.292"></a>
+<span class="sourceLineNo">292</span>        nextIndexedKey = KeyValueScanner.NO_NEXT_INDEXED_KEY;<a name="line.292"></a>
 <span class="sourceLineNo">293</span>      }<a name="line.293"></a>
 <span class="sourceLineNo">294</span><a name="line.294"></a>
 <span class="sourceLineNo">295</span>      int lookupLevel = 1; // How many levels deep we are in our lookup.<a name="line.295"></a>


Mime
View raw message