hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject [40/51] [partial] hbase-site git commit: Published site at 2f5767376f42c0416e025df412e3d5944a1b2a67.
Date Wed, 03 Feb 2016 17:26:13 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/6a13df3e/devapidocs/src-html/org/apache/hadoop/hbase/master/CatalogJanitor.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/master/CatalogJanitor.html b/devapidocs/src-html/org/apache/hadoop/hbase/master/CatalogJanitor.html
index 0129065..f72db18 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/master/CatalogJanitor.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/master/CatalogJanitor.html
@@ -222,227 +222,228 @@
 <span class="sourceLineNo">214</span>  int scan() throws IOException {<a name="line.214"></a>
 <span class="sourceLineNo">215</span>    try {<a name="line.215"></a>
 <span class="sourceLineNo">216</span>      if (!alreadyRunning.compareAndSet(false, true)) {<a name="line.216"></a>
-<span class="sourceLineNo">217</span>        return 0;<a name="line.217"></a>
-<span class="sourceLineNo">218</span>      }<a name="line.218"></a>
-<span class="sourceLineNo">219</span>      Triple&lt;Integer, Map&lt;HRegionInfo, Result&gt;, Map&lt;HRegionInfo, Result&gt;&gt; scanTriple =<a name="line.219"></a>
-<span class="sourceLineNo">220</span>        getMergedRegionsAndSplitParents();<a name="line.220"></a>
-<span class="sourceLineNo">221</span>      int count = scanTriple.getFirst();<a name="line.221"></a>
-<span class="sourceLineNo">222</span>      /**<a name="line.222"></a>
-<span class="sourceLineNo">223</span>       * clean merge regions first<a name="line.223"></a>
-<span class="sourceLineNo">224</span>       */<a name="line.224"></a>
-<span class="sourceLineNo">225</span>      int mergeCleaned = 0;<a name="line.225"></a>
-<span class="sourceLineNo">226</span>      Map&lt;HRegionInfo, Result&gt; mergedRegions = scanTriple.getSecond();<a name="line.226"></a>
-<span class="sourceLineNo">227</span>      for (Map.Entry&lt;HRegionInfo, Result&gt; e : mergedRegions.entrySet()) {<a name="line.227"></a>
-<span class="sourceLineNo">228</span>        PairOfSameType&lt;HRegionInfo&gt; p = MetaTableAccessor.getMergeRegions(e.getValue());<a name="line.228"></a>
-<span class="sourceLineNo">229</span>        HRegionInfo regionA = p.getFirst();<a name="line.229"></a>
-<span class="sourceLineNo">230</span>        HRegionInfo regionB = p.getSecond();<a name="line.230"></a>
-<span class="sourceLineNo">231</span>        if (regionA == null || regionB == null) {<a name="line.231"></a>
-<span class="sourceLineNo">232</span>          LOG.warn("Unexpected references regionA="<a name="line.232"></a>
-<span class="sourceLineNo">233</span>              + (regionA == null ? "null" : regionA.getRegionNameAsString())<a name="line.233"></a>
-<span class="sourceLineNo">234</span>              + ",regionB="<a name="line.234"></a>
-<span class="sourceLineNo">235</span>              + (regionB == null ? "null" : regionB.getRegionNameAsString())<a name="line.235"></a>
-<span class="sourceLineNo">236</span>              + " in merged region " + e.getKey().getRegionNameAsString());<a name="line.236"></a>
-<span class="sourceLineNo">237</span>        } else {<a name="line.237"></a>
-<span class="sourceLineNo">238</span>          if (cleanMergeRegion(e.getKey(), regionA, regionB)) {<a name="line.238"></a>
-<span class="sourceLineNo">239</span>            mergeCleaned++;<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>      }<a name="line.242"></a>
-<span class="sourceLineNo">243</span>      /**<a name="line.243"></a>
-<span class="sourceLineNo">244</span>       * clean split parents<a name="line.244"></a>
-<span class="sourceLineNo">245</span>       */<a name="line.245"></a>
-<span class="sourceLineNo">246</span>      Map&lt;HRegionInfo, Result&gt; splitParents = scanTriple.getThird();<a name="line.246"></a>
-<span class="sourceLineNo">247</span><a name="line.247"></a>
-<span class="sourceLineNo">248</span>      // Now work on our list of found parents. See if any we can clean up.<a name="line.248"></a>
-<span class="sourceLineNo">249</span>      int splitCleaned = 0;<a name="line.249"></a>
-<span class="sourceLineNo">250</span>      // regions whose parents are still around<a name="line.250"></a>
-<span class="sourceLineNo">251</span>      HashSet&lt;String&gt; parentNotCleaned = new HashSet&lt;String&gt;();<a name="line.251"></a>
-<span class="sourceLineNo">252</span>      for (Map.Entry&lt;HRegionInfo, Result&gt; e : splitParents.entrySet()) {<a name="line.252"></a>
-<span class="sourceLineNo">253</span>        if (!parentNotCleaned.contains(e.getKey().getEncodedName()) &amp;&amp;<a name="line.253"></a>
-<span class="sourceLineNo">254</span>            cleanParent(e.getKey(), e.getValue())) {<a name="line.254"></a>
-<span class="sourceLineNo">255</span>          splitCleaned++;<a name="line.255"></a>
-<span class="sourceLineNo">256</span>        } else {<a name="line.256"></a>
-<span class="sourceLineNo">257</span>          // We could not clean the parent, so it's daughters should not be<a name="line.257"></a>
-<span class="sourceLineNo">258</span>          // cleaned either (HBASE-6160)<a name="line.258"></a>
-<span class="sourceLineNo">259</span>          PairOfSameType&lt;HRegionInfo&gt; daughters =<a name="line.259"></a>
-<span class="sourceLineNo">260</span>              MetaTableAccessor.getDaughterRegions(e.getValue());<a name="line.260"></a>
-<span class="sourceLineNo">261</span>          parentNotCleaned.add(daughters.getFirst().getEncodedName());<a name="line.261"></a>
-<span class="sourceLineNo">262</span>          parentNotCleaned.add(daughters.getSecond().getEncodedName());<a name="line.262"></a>
-<span class="sourceLineNo">263</span>        }<a name="line.263"></a>
-<span class="sourceLineNo">264</span>      }<a name="line.264"></a>
-<span class="sourceLineNo">265</span>      if ((mergeCleaned + splitCleaned) != 0) {<a name="line.265"></a>
-<span class="sourceLineNo">266</span>        LOG.info("Scanned " + count + " catalog row(s), gc'd " + mergeCleaned<a name="line.266"></a>
-<span class="sourceLineNo">267</span>            + " unreferenced merged region(s) and " + splitCleaned<a name="line.267"></a>
-<span class="sourceLineNo">268</span>            + " unreferenced parent region(s)");<a name="line.268"></a>
-<span class="sourceLineNo">269</span>      } else if (LOG.isTraceEnabled()) {<a name="line.269"></a>
-<span class="sourceLineNo">270</span>        LOG.trace("Scanned " + count + " catalog row(s), gc'd " + mergeCleaned<a name="line.270"></a>
-<span class="sourceLineNo">271</span>            + " unreferenced merged region(s) and " + splitCleaned<a name="line.271"></a>
-<span class="sourceLineNo">272</span>            + " unreferenced parent region(s)");<a name="line.272"></a>
-<span class="sourceLineNo">273</span>      }<a name="line.273"></a>
-<span class="sourceLineNo">274</span>      return mergeCleaned + splitCleaned;<a name="line.274"></a>
-<span class="sourceLineNo">275</span>    } finally {<a name="line.275"></a>
-<span class="sourceLineNo">276</span>      alreadyRunning.set(false);<a name="line.276"></a>
-<span class="sourceLineNo">277</span>    }<a name="line.277"></a>
-<span class="sourceLineNo">278</span>  }<a name="line.278"></a>
-<span class="sourceLineNo">279</span><a name="line.279"></a>
-<span class="sourceLineNo">280</span>  /**<a name="line.280"></a>
-<span class="sourceLineNo">281</span>   * Compare HRegionInfos in a way that has split parents sort BEFORE their<a name="line.281"></a>
-<span class="sourceLineNo">282</span>   * daughters.<a name="line.282"></a>
-<span class="sourceLineNo">283</span>   */<a name="line.283"></a>
-<span class="sourceLineNo">284</span>  static class SplitParentFirstComparator implements Comparator&lt;HRegionInfo&gt; {<a name="line.284"></a>
-<span class="sourceLineNo">285</span>    Comparator&lt;byte[]&gt; rowEndKeyComparator = new Bytes.RowEndKeyComparator();<a name="line.285"></a>
-<span class="sourceLineNo">286</span>    @Override<a name="line.286"></a>
-<span class="sourceLineNo">287</span>    public int compare(HRegionInfo left, HRegionInfo right) {<a name="line.287"></a>
-<span class="sourceLineNo">288</span>      // This comparator differs from the one HRegionInfo in that it sorts<a name="line.288"></a>
-<span class="sourceLineNo">289</span>      // parent before daughters.<a name="line.289"></a>
-<span class="sourceLineNo">290</span>      if (left == null) return -1;<a name="line.290"></a>
-<span class="sourceLineNo">291</span>      if (right == null) return 1;<a name="line.291"></a>
-<span class="sourceLineNo">292</span>      // Same table name.<a name="line.292"></a>
-<span class="sourceLineNo">293</span>      int result = left.getTable().compareTo(right.getTable());<a name="line.293"></a>
-<span class="sourceLineNo">294</span>      if (result != 0) return result;<a name="line.294"></a>
-<span class="sourceLineNo">295</span>      // Compare start keys.<a name="line.295"></a>
-<span class="sourceLineNo">296</span>      result = Bytes.compareTo(left.getStartKey(), right.getStartKey());<a name="line.296"></a>
-<span class="sourceLineNo">297</span>      if (result != 0) return result;<a name="line.297"></a>
-<span class="sourceLineNo">298</span>      // Compare end keys, but flip the operands so parent comes first<a name="line.298"></a>
-<span class="sourceLineNo">299</span>      result = rowEndKeyComparator.compare(right.getEndKey(), left.getEndKey());<a name="line.299"></a>
-<span class="sourceLineNo">300</span><a name="line.300"></a>
-<span class="sourceLineNo">301</span>      return result;<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><a name="line.304"></a>
-<span class="sourceLineNo">305</span>  /**<a name="line.305"></a>
-<span class="sourceLineNo">306</span>   * If daughters no longer hold reference to the parents, delete the parent.<a name="line.306"></a>
-<span class="sourceLineNo">307</span>   * @param parent HRegionInfo of split offlined parent<a name="line.307"></a>
-<span class="sourceLineNo">308</span>   * @param rowContent Content of &lt;code&gt;parent&lt;/code&gt; row in<a name="line.308"></a>
-<span class="sourceLineNo">309</span>   * &lt;code&gt;metaRegionName&lt;/code&gt;<a name="line.309"></a>
-<span class="sourceLineNo">310</span>   * @return True if we removed &lt;code&gt;parent&lt;/code&gt; from meta table and from<a name="line.310"></a>
-<span class="sourceLineNo">311</span>   * the filesystem.<a name="line.311"></a>
-<span class="sourceLineNo">312</span>   * @throws IOException<a name="line.312"></a>
-<span class="sourceLineNo">313</span>   */<a name="line.313"></a>
-<span class="sourceLineNo">314</span>  boolean cleanParent(final HRegionInfo parent, Result rowContent)<a name="line.314"></a>
-<span class="sourceLineNo">315</span>  throws IOException {<a name="line.315"></a>
-<span class="sourceLineNo">316</span>    boolean result = false;<a name="line.316"></a>
-<span class="sourceLineNo">317</span>    // Check whether it is a merged region and not clean reference<a name="line.317"></a>
-<span class="sourceLineNo">318</span>    // No necessary to check MERGEB_QUALIFIER because these two qualifiers will<a name="line.318"></a>
-<span class="sourceLineNo">319</span>    // be inserted/deleted together<a name="line.319"></a>
-<span class="sourceLineNo">320</span>    if (rowContent.getValue(HConstants.CATALOG_FAMILY,<a name="line.320"></a>
-<span class="sourceLineNo">321</span>        HConstants.MERGEA_QUALIFIER) != null) {<a name="line.321"></a>
-<span class="sourceLineNo">322</span>      // wait cleaning merge region first<a name="line.322"></a>
-<span class="sourceLineNo">323</span>      return result;<a name="line.323"></a>
-<span class="sourceLineNo">324</span>    }<a name="line.324"></a>
-<span class="sourceLineNo">325</span>    // Run checks on each daughter split.<a name="line.325"></a>
-<span class="sourceLineNo">326</span>    PairOfSameType&lt;HRegionInfo&gt; daughters = MetaTableAccessor.getDaughterRegions(rowContent);<a name="line.326"></a>
-<span class="sourceLineNo">327</span>    Pair&lt;Boolean, Boolean&gt; a = checkDaughterInFs(parent, daughters.getFirst());<a name="line.327"></a>
-<span class="sourceLineNo">328</span>    Pair&lt;Boolean, Boolean&gt; b = checkDaughterInFs(parent, daughters.getSecond());<a name="line.328"></a>
-<span class="sourceLineNo">329</span>    if (hasNoReferences(a) &amp;&amp; hasNoReferences(b)) {<a name="line.329"></a>
-<span class="sourceLineNo">330</span>      LOG.debug("Deleting region " + parent.getRegionNameAsString() +<a name="line.330"></a>
-<span class="sourceLineNo">331</span>        " because daughter splits no longer hold references");<a name="line.331"></a>
-<span class="sourceLineNo">332</span>      FileSystem fs = this.services.getMasterFileSystem().getFileSystem();<a name="line.332"></a>
-<span class="sourceLineNo">333</span>      if (LOG.isTraceEnabled()) LOG.trace("Archiving parent region: " + parent);<a name="line.333"></a>
-<span class="sourceLineNo">334</span>      HFileArchiver.archiveRegion(this.services.getConfiguration(), fs, parent);<a name="line.334"></a>
-<span class="sourceLineNo">335</span>      MetaTableAccessor.deleteRegion(this.connection, parent);<a name="line.335"></a>
-<span class="sourceLineNo">336</span>      result = true;<a name="line.336"></a>
-<span class="sourceLineNo">337</span>    }<a name="line.337"></a>
-<span class="sourceLineNo">338</span>    return result;<a name="line.338"></a>
-<span class="sourceLineNo">339</span>  }<a name="line.339"></a>
-<span class="sourceLineNo">340</span><a name="line.340"></a>
-<span class="sourceLineNo">341</span>  /**<a name="line.341"></a>
-<span class="sourceLineNo">342</span>   * @param p A pair where the first boolean says whether or not the daughter<a name="line.342"></a>
-<span class="sourceLineNo">343</span>   * region directory exists in the filesystem and then the second boolean says<a name="line.343"></a>
-<span class="sourceLineNo">344</span>   * whether the daughter has references to the parent.<a name="line.344"></a>
-<span class="sourceLineNo">345</span>   * @return True the passed &lt;code&gt;p&lt;/code&gt; signifies no references.<a name="line.345"></a>
-<span class="sourceLineNo">346</span>   */<a name="line.346"></a>
-<span class="sourceLineNo">347</span>  private boolean hasNoReferences(final Pair&lt;Boolean, Boolean&gt; p) {<a name="line.347"></a>
-<span class="sourceLineNo">348</span>    return !p.getFirst() || !p.getSecond();<a name="line.348"></a>
-<span class="sourceLineNo">349</span>  }<a name="line.349"></a>
-<span class="sourceLineNo">350</span><a name="line.350"></a>
-<span class="sourceLineNo">351</span>  /**<a name="line.351"></a>
-<span class="sourceLineNo">352</span>   * Checks if a daughter region -- either splitA or splitB -- still holds<a name="line.352"></a>
-<span class="sourceLineNo">353</span>   * references to parent.<a name="line.353"></a>
-<span class="sourceLineNo">354</span>   * @param parent Parent region<a name="line.354"></a>
-<span class="sourceLineNo">355</span>   * @param daughter Daughter region<a name="line.355"></a>
-<span class="sourceLineNo">356</span>   * @return A pair where the first boolean says whether or not the daughter<a name="line.356"></a>
-<span class="sourceLineNo">357</span>   * region directory exists in the filesystem and then the second boolean says<a name="line.357"></a>
-<span class="sourceLineNo">358</span>   * whether the daughter has references to the parent.<a name="line.358"></a>
-<span class="sourceLineNo">359</span>   * @throws IOException<a name="line.359"></a>
-<span class="sourceLineNo">360</span>   */<a name="line.360"></a>
-<span class="sourceLineNo">361</span>  Pair&lt;Boolean, Boolean&gt; checkDaughterInFs(final HRegionInfo parent, final HRegionInfo daughter)<a name="line.361"></a>
-<span class="sourceLineNo">362</span>  throws IOException {<a name="line.362"></a>
-<span class="sourceLineNo">363</span>    if (daughter == null)  {<a name="line.363"></a>
-<span class="sourceLineNo">364</span>      return new Pair&lt;Boolean, Boolean&gt;(Boolean.FALSE, Boolean.FALSE);<a name="line.364"></a>
-<span class="sourceLineNo">365</span>    }<a name="line.365"></a>
-<span class="sourceLineNo">366</span><a name="line.366"></a>
-<span class="sourceLineNo">367</span>    FileSystem fs = this.services.getMasterFileSystem().getFileSystem();<a name="line.367"></a>
-<span class="sourceLineNo">368</span>    Path rootdir = this.services.getMasterFileSystem().getRootDir();<a name="line.368"></a>
-<span class="sourceLineNo">369</span>    Path tabledir = FSUtils.getTableDir(rootdir, daughter.getTable());<a name="line.369"></a>
-<span class="sourceLineNo">370</span><a name="line.370"></a>
-<span class="sourceLineNo">371</span>    Path daughterRegionDir = new Path(tabledir, daughter.getEncodedName());<a name="line.371"></a>
-<span class="sourceLineNo">372</span><a name="line.372"></a>
-<span class="sourceLineNo">373</span>    HRegionFileSystem regionFs = null;<a name="line.373"></a>
-<span class="sourceLineNo">374</span><a name="line.374"></a>
-<span class="sourceLineNo">375</span>    try {<a name="line.375"></a>
-<span class="sourceLineNo">376</span>      if (!FSUtils.isExists(fs, daughterRegionDir)) {<a name="line.376"></a>
-<span class="sourceLineNo">377</span>        return new Pair&lt;Boolean, Boolean&gt;(Boolean.FALSE, Boolean.FALSE);<a name="line.377"></a>
-<span class="sourceLineNo">378</span>      }<a name="line.378"></a>
-<span class="sourceLineNo">379</span>    } catch (IOException ioe) {<a name="line.379"></a>
-<span class="sourceLineNo">380</span>      LOG.warn("Error trying to determine if daughter region exists, " +<a name="line.380"></a>
-<span class="sourceLineNo">381</span>               "assuming exists and has references", ioe);<a name="line.381"></a>
-<span class="sourceLineNo">382</span>      return new Pair&lt;Boolean, Boolean&gt;(Boolean.TRUE, Boolean.TRUE);<a name="line.382"></a>
-<span class="sourceLineNo">383</span>    }<a name="line.383"></a>
-<span class="sourceLineNo">384</span><a name="line.384"></a>
-<span class="sourceLineNo">385</span>    try {<a name="line.385"></a>
-<span class="sourceLineNo">386</span>      regionFs = HRegionFileSystem.openRegionFromFileSystem(<a name="line.386"></a>
-<span class="sourceLineNo">387</span>          this.services.getConfiguration(), fs, tabledir, daughter, true);<a name="line.387"></a>
-<span class="sourceLineNo">388</span>    } catch (IOException e) {<a name="line.388"></a>
-<span class="sourceLineNo">389</span>      LOG.warn("Error trying to determine referenced files from : " + daughter.getEncodedName()<a name="line.389"></a>
-<span class="sourceLineNo">390</span>          + ", to: " + parent.getEncodedName() + " assuming has references", e);<a name="line.390"></a>
-<span class="sourceLineNo">391</span>      return new Pair&lt;Boolean, Boolean&gt;(Boolean.TRUE, Boolean.TRUE);<a name="line.391"></a>
-<span class="sourceLineNo">392</span>    }<a name="line.392"></a>
-<span class="sourceLineNo">393</span><a name="line.393"></a>
-<span class="sourceLineNo">394</span>    boolean references = false;<a name="line.394"></a>
-<span class="sourceLineNo">395</span>    HTableDescriptor parentDescriptor = getTableDescriptor(parent.getTable());<a name="line.395"></a>
-<span class="sourceLineNo">396</span>    for (HColumnDescriptor family: parentDescriptor.getFamilies()) {<a name="line.396"></a>
-<span class="sourceLineNo">397</span>      if ((references = regionFs.hasReferences(family.getNameAsString()))) {<a name="line.397"></a>
-<span class="sourceLineNo">398</span>        break;<a name="line.398"></a>
-<span class="sourceLineNo">399</span>      }<a name="line.399"></a>
-<span class="sourceLineNo">400</span>    }<a name="line.400"></a>
-<span class="sourceLineNo">401</span>    return new Pair&lt;Boolean, Boolean&gt;(Boolean.TRUE, Boolean.valueOf(references));<a name="line.401"></a>
-<span class="sourceLineNo">402</span>  }<a name="line.402"></a>
-<span class="sourceLineNo">403</span><a name="line.403"></a>
-<span class="sourceLineNo">404</span>  private HTableDescriptor getTableDescriptor(final TableName tableName)<a name="line.404"></a>
-<span class="sourceLineNo">405</span>      throws FileNotFoundException, IOException {<a name="line.405"></a>
-<span class="sourceLineNo">406</span>    return this.services.getTableDescriptors().get(tableName);<a name="line.406"></a>
-<span class="sourceLineNo">407</span>  }<a name="line.407"></a>
-<span class="sourceLineNo">408</span><a name="line.408"></a>
-<span class="sourceLineNo">409</span>  /**<a name="line.409"></a>
-<span class="sourceLineNo">410</span>   * Checks if the specified region has merge qualifiers, if so, try to clean<a name="line.410"></a>
-<span class="sourceLineNo">411</span>   * them<a name="line.411"></a>
-<span class="sourceLineNo">412</span>   * @param region<a name="line.412"></a>
-<span class="sourceLineNo">413</span>   * @return true if the specified region doesn't have merge qualifier now<a name="line.413"></a>
-<span class="sourceLineNo">414</span>   * @throws IOException<a name="line.414"></a>
-<span class="sourceLineNo">415</span>   */<a name="line.415"></a>
-<span class="sourceLineNo">416</span>  public boolean cleanMergeQualifier(final HRegionInfo region)<a name="line.416"></a>
-<span class="sourceLineNo">417</span>      throws IOException {<a name="line.417"></a>
-<span class="sourceLineNo">418</span>    // Get merge regions if it is a merged region and already has merge<a name="line.418"></a>
-<span class="sourceLineNo">419</span>    // qualifier<a name="line.419"></a>
-<span class="sourceLineNo">420</span>    Pair&lt;HRegionInfo, HRegionInfo&gt; mergeRegions = MetaTableAccessor<a name="line.420"></a>
-<span class="sourceLineNo">421</span>        .getRegionsFromMergeQualifier(this.services.getConnection(),<a name="line.421"></a>
-<span class="sourceLineNo">422</span>          region.getRegionName());<a name="line.422"></a>
-<span class="sourceLineNo">423</span>    if (mergeRegions == null<a name="line.423"></a>
-<span class="sourceLineNo">424</span>        || (mergeRegions.getFirst() == null &amp;&amp; mergeRegions.getSecond() == null)) {<a name="line.424"></a>
-<span class="sourceLineNo">425</span>      // It doesn't have merge qualifier, no need to clean<a name="line.425"></a>
-<span class="sourceLineNo">426</span>      return true;<a name="line.426"></a>
-<span class="sourceLineNo">427</span>    }<a name="line.427"></a>
-<span class="sourceLineNo">428</span>    // It shouldn't happen, we must insert/delete these two qualifiers together<a name="line.428"></a>
-<span class="sourceLineNo">429</span>    if (mergeRegions.getFirst() == null || mergeRegions.getSecond() == null) {<a name="line.429"></a>
-<span class="sourceLineNo">430</span>      LOG.error("Merged region " + region.getRegionNameAsString()<a name="line.430"></a>
-<span class="sourceLineNo">431</span>          + " has only one merge qualifier in META.");<a name="line.431"></a>
-<span class="sourceLineNo">432</span>      return false;<a name="line.432"></a>
-<span class="sourceLineNo">433</span>    }<a name="line.433"></a>
-<span class="sourceLineNo">434</span>    return cleanMergeRegion(region, mergeRegions.getFirst(),<a name="line.434"></a>
-<span class="sourceLineNo">435</span>        mergeRegions.getSecond());<a name="line.435"></a>
-<span class="sourceLineNo">436</span>  }<a name="line.436"></a>
-<span class="sourceLineNo">437</span>}<a name="line.437"></a>
+<span class="sourceLineNo">217</span>        LOG.debug("CatalogJanitor already running");<a name="line.217"></a>
+<span class="sourceLineNo">218</span>        return 0;<a name="line.218"></a>
+<span class="sourceLineNo">219</span>      }<a name="line.219"></a>
+<span class="sourceLineNo">220</span>      Triple&lt;Integer, Map&lt;HRegionInfo, Result&gt;, Map&lt;HRegionInfo, Result&gt;&gt; scanTriple =<a name="line.220"></a>
+<span class="sourceLineNo">221</span>        getMergedRegionsAndSplitParents();<a name="line.221"></a>
+<span class="sourceLineNo">222</span>      int count = scanTriple.getFirst();<a name="line.222"></a>
+<span class="sourceLineNo">223</span>      /**<a name="line.223"></a>
+<span class="sourceLineNo">224</span>       * clean merge regions first<a name="line.224"></a>
+<span class="sourceLineNo">225</span>       */<a name="line.225"></a>
+<span class="sourceLineNo">226</span>      int mergeCleaned = 0;<a name="line.226"></a>
+<span class="sourceLineNo">227</span>      Map&lt;HRegionInfo, Result&gt; mergedRegions = scanTriple.getSecond();<a name="line.227"></a>
+<span class="sourceLineNo">228</span>      for (Map.Entry&lt;HRegionInfo, Result&gt; e : mergedRegions.entrySet()) {<a name="line.228"></a>
+<span class="sourceLineNo">229</span>        PairOfSameType&lt;HRegionInfo&gt; p = MetaTableAccessor.getMergeRegions(e.getValue());<a name="line.229"></a>
+<span class="sourceLineNo">230</span>        HRegionInfo regionA = p.getFirst();<a name="line.230"></a>
+<span class="sourceLineNo">231</span>        HRegionInfo regionB = p.getSecond();<a name="line.231"></a>
+<span class="sourceLineNo">232</span>        if (regionA == null || regionB == null) {<a name="line.232"></a>
+<span class="sourceLineNo">233</span>          LOG.warn("Unexpected references regionA="<a name="line.233"></a>
+<span class="sourceLineNo">234</span>              + (regionA == null ? "null" : regionA.getRegionNameAsString())<a name="line.234"></a>
+<span class="sourceLineNo">235</span>              + ",regionB="<a name="line.235"></a>
+<span class="sourceLineNo">236</span>              + (regionB == null ? "null" : regionB.getRegionNameAsString())<a name="line.236"></a>
+<span class="sourceLineNo">237</span>              + " in merged region " + e.getKey().getRegionNameAsString());<a name="line.237"></a>
+<span class="sourceLineNo">238</span>        } else {<a name="line.238"></a>
+<span class="sourceLineNo">239</span>          if (cleanMergeRegion(e.getKey(), regionA, regionB)) {<a name="line.239"></a>
+<span class="sourceLineNo">240</span>            mergeCleaned++;<a name="line.240"></a>
+<span class="sourceLineNo">241</span>          }<a name="line.241"></a>
+<span class="sourceLineNo">242</span>        }<a name="line.242"></a>
+<span class="sourceLineNo">243</span>      }<a name="line.243"></a>
+<span class="sourceLineNo">244</span>      /**<a name="line.244"></a>
+<span class="sourceLineNo">245</span>       * clean split parents<a name="line.245"></a>
+<span class="sourceLineNo">246</span>       */<a name="line.246"></a>
+<span class="sourceLineNo">247</span>      Map&lt;HRegionInfo, Result&gt; splitParents = scanTriple.getThird();<a name="line.247"></a>
+<span class="sourceLineNo">248</span><a name="line.248"></a>
+<span class="sourceLineNo">249</span>      // Now work on our list of found parents. See if any we can clean up.<a name="line.249"></a>
+<span class="sourceLineNo">250</span>      int splitCleaned = 0;<a name="line.250"></a>
+<span class="sourceLineNo">251</span>      // regions whose parents are still around<a name="line.251"></a>
+<span class="sourceLineNo">252</span>      HashSet&lt;String&gt; parentNotCleaned = new HashSet&lt;String&gt;();<a name="line.252"></a>
+<span class="sourceLineNo">253</span>      for (Map.Entry&lt;HRegionInfo, Result&gt; e : splitParents.entrySet()) {<a name="line.253"></a>
+<span class="sourceLineNo">254</span>        if (!parentNotCleaned.contains(e.getKey().getEncodedName()) &amp;&amp;<a name="line.254"></a>
+<span class="sourceLineNo">255</span>            cleanParent(e.getKey(), e.getValue())) {<a name="line.255"></a>
+<span class="sourceLineNo">256</span>          splitCleaned++;<a name="line.256"></a>
+<span class="sourceLineNo">257</span>        } else {<a name="line.257"></a>
+<span class="sourceLineNo">258</span>          // We could not clean the parent, so it's daughters should not be<a name="line.258"></a>
+<span class="sourceLineNo">259</span>          // cleaned either (HBASE-6160)<a name="line.259"></a>
+<span class="sourceLineNo">260</span>          PairOfSameType&lt;HRegionInfo&gt; daughters =<a name="line.260"></a>
+<span class="sourceLineNo">261</span>              MetaTableAccessor.getDaughterRegions(e.getValue());<a name="line.261"></a>
+<span class="sourceLineNo">262</span>          parentNotCleaned.add(daughters.getFirst().getEncodedName());<a name="line.262"></a>
+<span class="sourceLineNo">263</span>          parentNotCleaned.add(daughters.getSecond().getEncodedName());<a name="line.263"></a>
+<span class="sourceLineNo">264</span>        }<a name="line.264"></a>
+<span class="sourceLineNo">265</span>      }<a name="line.265"></a>
+<span class="sourceLineNo">266</span>      if ((mergeCleaned + splitCleaned) != 0) {<a name="line.266"></a>
+<span class="sourceLineNo">267</span>        LOG.info("Scanned " + count + " catalog row(s), gc'd " + mergeCleaned<a name="line.267"></a>
+<span class="sourceLineNo">268</span>            + " unreferenced merged region(s) and " + splitCleaned<a name="line.268"></a>
+<span class="sourceLineNo">269</span>            + " unreferenced parent region(s)");<a name="line.269"></a>
+<span class="sourceLineNo">270</span>      } else if (LOG.isTraceEnabled()) {<a name="line.270"></a>
+<span class="sourceLineNo">271</span>        LOG.trace("Scanned " + count + " catalog row(s), gc'd " + mergeCleaned<a name="line.271"></a>
+<span class="sourceLineNo">272</span>            + " unreferenced merged region(s) and " + splitCleaned<a name="line.272"></a>
+<span class="sourceLineNo">273</span>            + " unreferenced parent region(s)");<a name="line.273"></a>
+<span class="sourceLineNo">274</span>      }<a name="line.274"></a>
+<span class="sourceLineNo">275</span>      return mergeCleaned + splitCleaned;<a name="line.275"></a>
+<span class="sourceLineNo">276</span>    } finally {<a name="line.276"></a>
+<span class="sourceLineNo">277</span>      alreadyRunning.set(false);<a name="line.277"></a>
+<span class="sourceLineNo">278</span>    }<a name="line.278"></a>
+<span class="sourceLineNo">279</span>  }<a name="line.279"></a>
+<span class="sourceLineNo">280</span><a name="line.280"></a>
+<span class="sourceLineNo">281</span>  /**<a name="line.281"></a>
+<span class="sourceLineNo">282</span>   * Compare HRegionInfos in a way that has split parents sort BEFORE their<a name="line.282"></a>
+<span class="sourceLineNo">283</span>   * daughters.<a name="line.283"></a>
+<span class="sourceLineNo">284</span>   */<a name="line.284"></a>
+<span class="sourceLineNo">285</span>  static class SplitParentFirstComparator implements Comparator&lt;HRegionInfo&gt; {<a name="line.285"></a>
+<span class="sourceLineNo">286</span>    Comparator&lt;byte[]&gt; rowEndKeyComparator = new Bytes.RowEndKeyComparator();<a name="line.286"></a>
+<span class="sourceLineNo">287</span>    @Override<a name="line.287"></a>
+<span class="sourceLineNo">288</span>    public int compare(HRegionInfo left, HRegionInfo right) {<a name="line.288"></a>
+<span class="sourceLineNo">289</span>      // This comparator differs from the one HRegionInfo in that it sorts<a name="line.289"></a>
+<span class="sourceLineNo">290</span>      // parent before daughters.<a name="line.290"></a>
+<span class="sourceLineNo">291</span>      if (left == null) return -1;<a name="line.291"></a>
+<span class="sourceLineNo">292</span>      if (right == null) return 1;<a name="line.292"></a>
+<span class="sourceLineNo">293</span>      // Same table name.<a name="line.293"></a>
+<span class="sourceLineNo">294</span>      int result = left.getTable().compareTo(right.getTable());<a name="line.294"></a>
+<span class="sourceLineNo">295</span>      if (result != 0) return result;<a name="line.295"></a>
+<span class="sourceLineNo">296</span>      // Compare start keys.<a name="line.296"></a>
+<span class="sourceLineNo">297</span>      result = Bytes.compareTo(left.getStartKey(), right.getStartKey());<a name="line.297"></a>
+<span class="sourceLineNo">298</span>      if (result != 0) return result;<a name="line.298"></a>
+<span class="sourceLineNo">299</span>      // Compare end keys, but flip the operands so parent comes first<a name="line.299"></a>
+<span class="sourceLineNo">300</span>      result = rowEndKeyComparator.compare(right.getEndKey(), left.getEndKey());<a name="line.300"></a>
+<span class="sourceLineNo">301</span><a name="line.301"></a>
+<span class="sourceLineNo">302</span>      return result;<a name="line.302"></a>
+<span class="sourceLineNo">303</span>    }<a name="line.303"></a>
+<span class="sourceLineNo">304</span>  }<a name="line.304"></a>
+<span class="sourceLineNo">305</span><a name="line.305"></a>
+<span class="sourceLineNo">306</span>  /**<a name="line.306"></a>
+<span class="sourceLineNo">307</span>   * If daughters no longer hold reference to the parents, delete the parent.<a name="line.307"></a>
+<span class="sourceLineNo">308</span>   * @param parent HRegionInfo of split offlined parent<a name="line.308"></a>
+<span class="sourceLineNo">309</span>   * @param rowContent Content of &lt;code&gt;parent&lt;/code&gt; row in<a name="line.309"></a>
+<span class="sourceLineNo">310</span>   * &lt;code&gt;metaRegionName&lt;/code&gt;<a name="line.310"></a>
+<span class="sourceLineNo">311</span>   * @return True if we removed &lt;code&gt;parent&lt;/code&gt; from meta table and from<a name="line.311"></a>
+<span class="sourceLineNo">312</span>   * the filesystem.<a name="line.312"></a>
+<span class="sourceLineNo">313</span>   * @throws IOException<a name="line.313"></a>
+<span class="sourceLineNo">314</span>   */<a name="line.314"></a>
+<span class="sourceLineNo">315</span>  boolean cleanParent(final HRegionInfo parent, Result rowContent)<a name="line.315"></a>
+<span class="sourceLineNo">316</span>  throws IOException {<a name="line.316"></a>
+<span class="sourceLineNo">317</span>    boolean result = false;<a name="line.317"></a>
+<span class="sourceLineNo">318</span>    // Check whether it is a merged region and not clean reference<a name="line.318"></a>
+<span class="sourceLineNo">319</span>    // No necessary to check MERGEB_QUALIFIER because these two qualifiers will<a name="line.319"></a>
+<span class="sourceLineNo">320</span>    // be inserted/deleted together<a name="line.320"></a>
+<span class="sourceLineNo">321</span>    if (rowContent.getValue(HConstants.CATALOG_FAMILY,<a name="line.321"></a>
+<span class="sourceLineNo">322</span>        HConstants.MERGEA_QUALIFIER) != null) {<a name="line.322"></a>
+<span class="sourceLineNo">323</span>      // wait cleaning merge region first<a name="line.323"></a>
+<span class="sourceLineNo">324</span>      return result;<a name="line.324"></a>
+<span class="sourceLineNo">325</span>    }<a name="line.325"></a>
+<span class="sourceLineNo">326</span>    // Run checks on each daughter split.<a name="line.326"></a>
+<span class="sourceLineNo">327</span>    PairOfSameType&lt;HRegionInfo&gt; daughters = MetaTableAccessor.getDaughterRegions(rowContent);<a name="line.327"></a>
+<span class="sourceLineNo">328</span>    Pair&lt;Boolean, Boolean&gt; a = checkDaughterInFs(parent, daughters.getFirst());<a name="line.328"></a>
+<span class="sourceLineNo">329</span>    Pair&lt;Boolean, Boolean&gt; b = checkDaughterInFs(parent, daughters.getSecond());<a name="line.329"></a>
+<span class="sourceLineNo">330</span>    if (hasNoReferences(a) &amp;&amp; hasNoReferences(b)) {<a name="line.330"></a>
+<span class="sourceLineNo">331</span>      LOG.debug("Deleting region " + parent.getRegionNameAsString() +<a name="line.331"></a>
+<span class="sourceLineNo">332</span>        " because daughter splits no longer hold references");<a name="line.332"></a>
+<span class="sourceLineNo">333</span>      FileSystem fs = this.services.getMasterFileSystem().getFileSystem();<a name="line.333"></a>
+<span class="sourceLineNo">334</span>      if (LOG.isTraceEnabled()) LOG.trace("Archiving parent region: " + parent);<a name="line.334"></a>
+<span class="sourceLineNo">335</span>      HFileArchiver.archiveRegion(this.services.getConfiguration(), fs, parent);<a name="line.335"></a>
+<span class="sourceLineNo">336</span>      MetaTableAccessor.deleteRegion(this.connection, parent);<a name="line.336"></a>
+<span class="sourceLineNo">337</span>      result = true;<a name="line.337"></a>
+<span class="sourceLineNo">338</span>    }<a name="line.338"></a>
+<span class="sourceLineNo">339</span>    return result;<a name="line.339"></a>
+<span class="sourceLineNo">340</span>  }<a name="line.340"></a>
+<span class="sourceLineNo">341</span><a name="line.341"></a>
+<span class="sourceLineNo">342</span>  /**<a name="line.342"></a>
+<span class="sourceLineNo">343</span>   * @param p A pair where the first boolean says whether or not the daughter<a name="line.343"></a>
+<span class="sourceLineNo">344</span>   * region directory exists in the filesystem and then the second boolean says<a name="line.344"></a>
+<span class="sourceLineNo">345</span>   * whether the daughter has references to the parent.<a name="line.345"></a>
+<span class="sourceLineNo">346</span>   * @return True the passed &lt;code&gt;p&lt;/code&gt; signifies no references.<a name="line.346"></a>
+<span class="sourceLineNo">347</span>   */<a name="line.347"></a>
+<span class="sourceLineNo">348</span>  private boolean hasNoReferences(final Pair&lt;Boolean, Boolean&gt; p) {<a name="line.348"></a>
+<span class="sourceLineNo">349</span>    return !p.getFirst() || !p.getSecond();<a name="line.349"></a>
+<span class="sourceLineNo">350</span>  }<a name="line.350"></a>
+<span class="sourceLineNo">351</span><a name="line.351"></a>
+<span class="sourceLineNo">352</span>  /**<a name="line.352"></a>
+<span class="sourceLineNo">353</span>   * Checks if a daughter region -- either splitA or splitB -- still holds<a name="line.353"></a>
+<span class="sourceLineNo">354</span>   * references to parent.<a name="line.354"></a>
+<span class="sourceLineNo">355</span>   * @param parent Parent region<a name="line.355"></a>
+<span class="sourceLineNo">356</span>   * @param daughter Daughter region<a name="line.356"></a>
+<span class="sourceLineNo">357</span>   * @return A pair where the first boolean says whether or not the daughter<a name="line.357"></a>
+<span class="sourceLineNo">358</span>   * region directory exists in the filesystem and then the second boolean says<a name="line.358"></a>
+<span class="sourceLineNo">359</span>   * whether the daughter has references to the parent.<a name="line.359"></a>
+<span class="sourceLineNo">360</span>   * @throws IOException<a name="line.360"></a>
+<span class="sourceLineNo">361</span>   */<a name="line.361"></a>
+<span class="sourceLineNo">362</span>  Pair&lt;Boolean, Boolean&gt; checkDaughterInFs(final HRegionInfo parent, final HRegionInfo daughter)<a name="line.362"></a>
+<span class="sourceLineNo">363</span>  throws IOException {<a name="line.363"></a>
+<span class="sourceLineNo">364</span>    if (daughter == null)  {<a name="line.364"></a>
+<span class="sourceLineNo">365</span>      return new Pair&lt;Boolean, Boolean&gt;(Boolean.FALSE, Boolean.FALSE);<a name="line.365"></a>
+<span class="sourceLineNo">366</span>    }<a name="line.366"></a>
+<span class="sourceLineNo">367</span><a name="line.367"></a>
+<span class="sourceLineNo">368</span>    FileSystem fs = this.services.getMasterFileSystem().getFileSystem();<a name="line.368"></a>
+<span class="sourceLineNo">369</span>    Path rootdir = this.services.getMasterFileSystem().getRootDir();<a name="line.369"></a>
+<span class="sourceLineNo">370</span>    Path tabledir = FSUtils.getTableDir(rootdir, daughter.getTable());<a name="line.370"></a>
+<span class="sourceLineNo">371</span><a name="line.371"></a>
+<span class="sourceLineNo">372</span>    Path daughterRegionDir = new Path(tabledir, daughter.getEncodedName());<a name="line.372"></a>
+<span class="sourceLineNo">373</span><a name="line.373"></a>
+<span class="sourceLineNo">374</span>    HRegionFileSystem regionFs = null;<a name="line.374"></a>
+<span class="sourceLineNo">375</span><a name="line.375"></a>
+<span class="sourceLineNo">376</span>    try {<a name="line.376"></a>
+<span class="sourceLineNo">377</span>      if (!FSUtils.isExists(fs, daughterRegionDir)) {<a name="line.377"></a>
+<span class="sourceLineNo">378</span>        return new Pair&lt;Boolean, Boolean&gt;(Boolean.FALSE, Boolean.FALSE);<a name="line.378"></a>
+<span class="sourceLineNo">379</span>      }<a name="line.379"></a>
+<span class="sourceLineNo">380</span>    } catch (IOException ioe) {<a name="line.380"></a>
+<span class="sourceLineNo">381</span>      LOG.warn("Error trying to determine if daughter region exists, " +<a name="line.381"></a>
+<span class="sourceLineNo">382</span>               "assuming exists and has references", ioe);<a name="line.382"></a>
+<span class="sourceLineNo">383</span>      return new Pair&lt;Boolean, Boolean&gt;(Boolean.TRUE, Boolean.TRUE);<a name="line.383"></a>
+<span class="sourceLineNo">384</span>    }<a name="line.384"></a>
+<span class="sourceLineNo">385</span><a name="line.385"></a>
+<span class="sourceLineNo">386</span>    try {<a name="line.386"></a>
+<span class="sourceLineNo">387</span>      regionFs = HRegionFileSystem.openRegionFromFileSystem(<a name="line.387"></a>
+<span class="sourceLineNo">388</span>          this.services.getConfiguration(), fs, tabledir, daughter, true);<a name="line.388"></a>
+<span class="sourceLineNo">389</span>    } catch (IOException e) {<a name="line.389"></a>
+<span class="sourceLineNo">390</span>      LOG.warn("Error trying to determine referenced files from : " + daughter.getEncodedName()<a name="line.390"></a>
+<span class="sourceLineNo">391</span>          + ", to: " + parent.getEncodedName() + " assuming has references", e);<a name="line.391"></a>
+<span class="sourceLineNo">392</span>      return new Pair&lt;Boolean, Boolean&gt;(Boolean.TRUE, Boolean.TRUE);<a name="line.392"></a>
+<span class="sourceLineNo">393</span>    }<a name="line.393"></a>
+<span class="sourceLineNo">394</span><a name="line.394"></a>
+<span class="sourceLineNo">395</span>    boolean references = false;<a name="line.395"></a>
+<span class="sourceLineNo">396</span>    HTableDescriptor parentDescriptor = getTableDescriptor(parent.getTable());<a name="line.396"></a>
+<span class="sourceLineNo">397</span>    for (HColumnDescriptor family: parentDescriptor.getFamilies()) {<a name="line.397"></a>
+<span class="sourceLineNo">398</span>      if ((references = regionFs.hasReferences(family.getNameAsString()))) {<a name="line.398"></a>
+<span class="sourceLineNo">399</span>        break;<a name="line.399"></a>
+<span class="sourceLineNo">400</span>      }<a name="line.400"></a>
+<span class="sourceLineNo">401</span>    }<a name="line.401"></a>
+<span class="sourceLineNo">402</span>    return new Pair&lt;Boolean, Boolean&gt;(Boolean.TRUE, Boolean.valueOf(references));<a name="line.402"></a>
+<span class="sourceLineNo">403</span>  }<a name="line.403"></a>
+<span class="sourceLineNo">404</span><a name="line.404"></a>
+<span class="sourceLineNo">405</span>  private HTableDescriptor getTableDescriptor(final TableName tableName)<a name="line.405"></a>
+<span class="sourceLineNo">406</span>      throws FileNotFoundException, IOException {<a name="line.406"></a>
+<span class="sourceLineNo">407</span>    return this.services.getTableDescriptors().get(tableName);<a name="line.407"></a>
+<span class="sourceLineNo">408</span>  }<a name="line.408"></a>
+<span class="sourceLineNo">409</span><a name="line.409"></a>
+<span class="sourceLineNo">410</span>  /**<a name="line.410"></a>
+<span class="sourceLineNo">411</span>   * Checks if the specified region has merge qualifiers, if so, try to clean<a name="line.411"></a>
+<span class="sourceLineNo">412</span>   * them<a name="line.412"></a>
+<span class="sourceLineNo">413</span>   * @param region<a name="line.413"></a>
+<span class="sourceLineNo">414</span>   * @return true if the specified region doesn't have merge qualifier now<a name="line.414"></a>
+<span class="sourceLineNo">415</span>   * @throws IOException<a name="line.415"></a>
+<span class="sourceLineNo">416</span>   */<a name="line.416"></a>
+<span class="sourceLineNo">417</span>  public boolean cleanMergeQualifier(final HRegionInfo region)<a name="line.417"></a>
+<span class="sourceLineNo">418</span>      throws IOException {<a name="line.418"></a>
+<span class="sourceLineNo">419</span>    // Get merge regions if it is a merged region and already has merge<a name="line.419"></a>
+<span class="sourceLineNo">420</span>    // qualifier<a name="line.420"></a>
+<span class="sourceLineNo">421</span>    Pair&lt;HRegionInfo, HRegionInfo&gt; mergeRegions = MetaTableAccessor<a name="line.421"></a>
+<span class="sourceLineNo">422</span>        .getRegionsFromMergeQualifier(this.services.getConnection(),<a name="line.422"></a>
+<span class="sourceLineNo">423</span>          region.getRegionName());<a name="line.423"></a>
+<span class="sourceLineNo">424</span>    if (mergeRegions == null<a name="line.424"></a>
+<span class="sourceLineNo">425</span>        || (mergeRegions.getFirst() == null &amp;&amp; mergeRegions.getSecond() == null)) {<a name="line.425"></a>
+<span class="sourceLineNo">426</span>      // It doesn't have merge qualifier, no need to clean<a name="line.426"></a>
+<span class="sourceLineNo">427</span>      return true;<a name="line.427"></a>
+<span class="sourceLineNo">428</span>    }<a name="line.428"></a>
+<span class="sourceLineNo">429</span>    // It shouldn't happen, we must insert/delete these two qualifiers together<a name="line.429"></a>
+<span class="sourceLineNo">430</span>    if (mergeRegions.getFirst() == null || mergeRegions.getSecond() == null) {<a name="line.430"></a>
+<span class="sourceLineNo">431</span>      LOG.error("Merged region " + region.getRegionNameAsString()<a name="line.431"></a>
+<span class="sourceLineNo">432</span>          + " has only one merge qualifier in META.");<a name="line.432"></a>
+<span class="sourceLineNo">433</span>      return false;<a name="line.433"></a>
+<span class="sourceLineNo">434</span>    }<a name="line.434"></a>
+<span class="sourceLineNo">435</span>    return cleanMergeRegion(region, mergeRegions.getFirst(),<a name="line.435"></a>
+<span class="sourceLineNo">436</span>        mergeRegions.getSecond());<a name="line.436"></a>
+<span class="sourceLineNo">437</span>  }<a name="line.437"></a>
+<span class="sourceLineNo">438</span>}<a name="line.438"></a>
 
 
 

http://git-wip-us.apache.org/repos/asf/hbase-site/blob/6a13df3e/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.BatchOperationInProgress.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.BatchOperationInProgress.html b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.BatchOperationInProgress.html
index a0ca7d9..e2c4389 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.BatchOperationInProgress.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.BatchOperationInProgress.html
@@ -1283,7 +1283,7 @@
 <span class="sourceLineNo">1275</span><a name="line.1275"></a>
 <span class="sourceLineNo">1276</span>  @Override<a name="line.1276"></a>
 <span class="sourceLineNo">1277</span>  public long getReadPoint(IsolationLevel isolationLevel) {<a name="line.1277"></a>
-<span class="sourceLineNo">1278</span>    if (isolationLevel == IsolationLevel.READ_UNCOMMITTED) {<a name="line.1278"></a>
+<span class="sourceLineNo">1278</span>    if (isolationLevel != null &amp;&amp; isolationLevel == IsolationLevel.READ_UNCOMMITTED) {<a name="line.1278"></a>
 <span class="sourceLineNo">1279</span>      // This scan can read even uncommitted transactions<a name="line.1279"></a>
 <span class="sourceLineNo">1280</span>      return Long.MAX_VALUE;<a name="line.1280"></a>
 <span class="sourceLineNo">1281</span>    }<a name="line.1281"></a>

http://git-wip-us.apache.org/repos/asf/hbase-site/blob/6a13df3e/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.FlushResultImpl.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.FlushResultImpl.html b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.FlushResultImpl.html
index a0ca7d9..e2c4389 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.FlushResultImpl.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.FlushResultImpl.html
@@ -1283,7 +1283,7 @@
 <span class="sourceLineNo">1275</span><a name="line.1275"></a>
 <span class="sourceLineNo">1276</span>  @Override<a name="line.1276"></a>
 <span class="sourceLineNo">1277</span>  public long getReadPoint(IsolationLevel isolationLevel) {<a name="line.1277"></a>
-<span class="sourceLineNo">1278</span>    if (isolationLevel == IsolationLevel.READ_UNCOMMITTED) {<a name="line.1278"></a>
+<span class="sourceLineNo">1278</span>    if (isolationLevel != null &amp;&amp; isolationLevel == IsolationLevel.READ_UNCOMMITTED) {<a name="line.1278"></a>
 <span class="sourceLineNo">1279</span>      // This scan can read even uncommitted transactions<a name="line.1279"></a>
 <span class="sourceLineNo">1280</span>      return Long.MAX_VALUE;<a name="line.1280"></a>
 <span class="sourceLineNo">1281</span>    }<a name="line.1281"></a>

http://git-wip-us.apache.org/repos/asf/hbase-site/blob/6a13df3e/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.MutationBatch.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.MutationBatch.html b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.MutationBatch.html
index a0ca7d9..e2c4389 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.MutationBatch.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.MutationBatch.html
@@ -1283,7 +1283,7 @@
 <span class="sourceLineNo">1275</span><a name="line.1275"></a>
 <span class="sourceLineNo">1276</span>  @Override<a name="line.1276"></a>
 <span class="sourceLineNo">1277</span>  public long getReadPoint(IsolationLevel isolationLevel) {<a name="line.1277"></a>
-<span class="sourceLineNo">1278</span>    if (isolationLevel == IsolationLevel.READ_UNCOMMITTED) {<a name="line.1278"></a>
+<span class="sourceLineNo">1278</span>    if (isolationLevel != null &amp;&amp; isolationLevel == IsolationLevel.READ_UNCOMMITTED) {<a name="line.1278"></a>
 <span class="sourceLineNo">1279</span>      // This scan can read even uncommitted transactions<a name="line.1279"></a>
 <span class="sourceLineNo">1280</span>      return Long.MAX_VALUE;<a name="line.1280"></a>
 <span class="sourceLineNo">1281</span>    }<a name="line.1281"></a>

http://git-wip-us.apache.org/repos/asf/hbase-site/blob/6a13df3e/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.PrepareFlushResult.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.PrepareFlushResult.html b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.PrepareFlushResult.html
index a0ca7d9..e2c4389 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.PrepareFlushResult.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.PrepareFlushResult.html
@@ -1283,7 +1283,7 @@
 <span class="sourceLineNo">1275</span><a name="line.1275"></a>
 <span class="sourceLineNo">1276</span>  @Override<a name="line.1276"></a>
 <span class="sourceLineNo">1277</span>  public long getReadPoint(IsolationLevel isolationLevel) {<a name="line.1277"></a>
-<span class="sourceLineNo">1278</span>    if (isolationLevel == IsolationLevel.READ_UNCOMMITTED) {<a name="line.1278"></a>
+<span class="sourceLineNo">1278</span>    if (isolationLevel != null &amp;&amp; isolationLevel == IsolationLevel.READ_UNCOMMITTED) {<a name="line.1278"></a>
 <span class="sourceLineNo">1279</span>      // This scan can read even uncommitted transactions<a name="line.1279"></a>
 <span class="sourceLineNo">1280</span>      return Long.MAX_VALUE;<a name="line.1280"></a>
 <span class="sourceLineNo">1281</span>    }<a name="line.1281"></a>

http://git-wip-us.apache.org/repos/asf/hbase-site/blob/6a13df3e/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.RegionScannerImpl.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.RegionScannerImpl.html b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.RegionScannerImpl.html
index a0ca7d9..e2c4389 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.RegionScannerImpl.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.RegionScannerImpl.html
@@ -1283,7 +1283,7 @@
 <span class="sourceLineNo">1275</span><a name="line.1275"></a>
 <span class="sourceLineNo">1276</span>  @Override<a name="line.1276"></a>
 <span class="sourceLineNo">1277</span>  public long getReadPoint(IsolationLevel isolationLevel) {<a name="line.1277"></a>
-<span class="sourceLineNo">1278</span>    if (isolationLevel == IsolationLevel.READ_UNCOMMITTED) {<a name="line.1278"></a>
+<span class="sourceLineNo">1278</span>    if (isolationLevel != null &amp;&amp; isolationLevel == IsolationLevel.READ_UNCOMMITTED) {<a name="line.1278"></a>
 <span class="sourceLineNo">1279</span>      // This scan can read even uncommitted transactions<a name="line.1279"></a>
 <span class="sourceLineNo">1280</span>      return Long.MAX_VALUE;<a name="line.1280"></a>
 <span class="sourceLineNo">1281</span>    }<a name="line.1281"></a>

http://git-wip-us.apache.org/repos/asf/hbase-site/blob/6a13df3e/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.ReplayBatch.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.ReplayBatch.html b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.ReplayBatch.html
index a0ca7d9..e2c4389 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.ReplayBatch.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.ReplayBatch.html
@@ -1283,7 +1283,7 @@
 <span class="sourceLineNo">1275</span><a name="line.1275"></a>
 <span class="sourceLineNo">1276</span>  @Override<a name="line.1276"></a>
 <span class="sourceLineNo">1277</span>  public long getReadPoint(IsolationLevel isolationLevel) {<a name="line.1277"></a>
-<span class="sourceLineNo">1278</span>    if (isolationLevel == IsolationLevel.READ_UNCOMMITTED) {<a name="line.1278"></a>
+<span class="sourceLineNo">1278</span>    if (isolationLevel != null &amp;&amp; isolationLevel == IsolationLevel.READ_UNCOMMITTED) {<a name="line.1278"></a>
 <span class="sourceLineNo">1279</span>      // This scan can read even uncommitted transactions<a name="line.1279"></a>
 <span class="sourceLineNo">1280</span>      return Long.MAX_VALUE;<a name="line.1280"></a>
 <span class="sourceLineNo">1281</span>    }<a name="line.1281"></a>

http://git-wip-us.apache.org/repos/asf/hbase-site/blob/6a13df3e/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.RowLockContext.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.RowLockContext.html b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.RowLockContext.html
index a0ca7d9..e2c4389 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.RowLockContext.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.RowLockContext.html
@@ -1283,7 +1283,7 @@
 <span class="sourceLineNo">1275</span><a name="line.1275"></a>
 <span class="sourceLineNo">1276</span>  @Override<a name="line.1276"></a>
 <span class="sourceLineNo">1277</span>  public long getReadPoint(IsolationLevel isolationLevel) {<a name="line.1277"></a>
-<span class="sourceLineNo">1278</span>    if (isolationLevel == IsolationLevel.READ_UNCOMMITTED) {<a name="line.1278"></a>
+<span class="sourceLineNo">1278</span>    if (isolationLevel != null &amp;&amp; isolationLevel == IsolationLevel.READ_UNCOMMITTED) {<a name="line.1278"></a>
 <span class="sourceLineNo">1279</span>      // This scan can read even uncommitted transactions<a name="line.1279"></a>
 <span class="sourceLineNo">1280</span>      return Long.MAX_VALUE;<a name="line.1280"></a>
 <span class="sourceLineNo">1281</span>    }<a name="line.1281"></a>

http://git-wip-us.apache.org/repos/asf/hbase-site/blob/6a13df3e/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.RowLockImpl.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.RowLockImpl.html b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.RowLockImpl.html
index a0ca7d9..e2c4389 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.RowLockImpl.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.RowLockImpl.html
@@ -1283,7 +1283,7 @@
 <span class="sourceLineNo">1275</span><a name="line.1275"></a>
 <span class="sourceLineNo">1276</span>  @Override<a name="line.1276"></a>
 <span class="sourceLineNo">1277</span>  public long getReadPoint(IsolationLevel isolationLevel) {<a name="line.1277"></a>
-<span class="sourceLineNo">1278</span>    if (isolationLevel == IsolationLevel.READ_UNCOMMITTED) {<a name="line.1278"></a>
+<span class="sourceLineNo">1278</span>    if (isolationLevel != null &amp;&amp; isolationLevel == IsolationLevel.READ_UNCOMMITTED) {<a name="line.1278"></a>
 <span class="sourceLineNo">1279</span>      // This scan can read even uncommitted transactions<a name="line.1279"></a>
 <span class="sourceLineNo">1280</span>      return Long.MAX_VALUE;<a name="line.1280"></a>
 <span class="sourceLineNo">1281</span>    }<a name="line.1281"></a>

http://git-wip-us.apache.org/repos/asf/hbase-site/blob/6a13df3e/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.WriteState.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.WriteState.html b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.WriteState.html
index a0ca7d9..e2c4389 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.WriteState.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.WriteState.html
@@ -1283,7 +1283,7 @@
 <span class="sourceLineNo">1275</span><a name="line.1275"></a>
 <span class="sourceLineNo">1276</span>  @Override<a name="line.1276"></a>
 <span class="sourceLineNo">1277</span>  public long getReadPoint(IsolationLevel isolationLevel) {<a name="line.1277"></a>
-<span class="sourceLineNo">1278</span>    if (isolationLevel == IsolationLevel.READ_UNCOMMITTED) {<a name="line.1278"></a>
+<span class="sourceLineNo">1278</span>    if (isolationLevel != null &amp;&amp; isolationLevel == IsolationLevel.READ_UNCOMMITTED) {<a name="line.1278"></a>
 <span class="sourceLineNo">1279</span>      // This scan can read even uncommitted transactions<a name="line.1279"></a>
 <span class="sourceLineNo">1280</span>      return Long.MAX_VALUE;<a name="line.1280"></a>
 <span class="sourceLineNo">1281</span>    }<a name="line.1281"></a>

http://git-wip-us.apache.org/repos/asf/hbase-site/blob/6a13df3e/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.html b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.html
index a0ca7d9..e2c4389 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegion.html
@@ -1283,7 +1283,7 @@
 <span class="sourceLineNo">1275</span><a name="line.1275"></a>
 <span class="sourceLineNo">1276</span>  @Override<a name="line.1276"></a>
 <span class="sourceLineNo">1277</span>  public long getReadPoint(IsolationLevel isolationLevel) {<a name="line.1277"></a>
-<span class="sourceLineNo">1278</span>    if (isolationLevel == IsolationLevel.READ_UNCOMMITTED) {<a name="line.1278"></a>
+<span class="sourceLineNo">1278</span>    if (isolationLevel != null &amp;&amp; isolationLevel == IsolationLevel.READ_UNCOMMITTED) {<a name="line.1278"></a>
 <span class="sourceLineNo">1279</span>      // This scan can read even uncommitted transactions<a name="line.1279"></a>
 <span class="sourceLineNo">1280</span>      return Long.MAX_VALUE;<a name="line.1280"></a>
 <span class="sourceLineNo">1281</span>    }<a name="line.1281"></a>

http://git-wip-us.apache.org/repos/asf/hbase-site/blob/6a13df3e/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/MultiVersionConcurrencyControl.WriteEntry.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/MultiVersionConcurrencyControl.WriteEntry.html b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/MultiVersionConcurrencyControl.WriteEntry.html
index bd087f6..5f46b26 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/MultiVersionConcurrencyControl.WriteEntry.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/MultiVersionConcurrencyControl.WriteEntry.html
@@ -163,7 +163,7 @@
 <span class="sourceLineNo">155</span>   * changes completely) so we can clean up the outstanding transaction.<a name="line.155"></a>
 <span class="sourceLineNo">156</span>   *<a name="line.156"></a>
 <span class="sourceLineNo">157</span>   * How much is the read point advanced?<a name="line.157"></a>
-<span class="sourceLineNo">158</span>   * <a name="line.158"></a>
+<span class="sourceLineNo">158</span>   *<a name="line.158"></a>
 <span class="sourceLineNo">159</span>   * Let S be the set of all write numbers that are completed. Set the read point to the highest<a name="line.159"></a>
 <span class="sourceLineNo">160</span>   * numbered write of S.<a name="line.160"></a>
 <span class="sourceLineNo">161</span>   *<a name="line.161"></a>
@@ -174,120 +174,119 @@
 <span class="sourceLineNo">166</span>  public boolean complete(WriteEntry writeEntry) {<a name="line.166"></a>
 <span class="sourceLineNo">167</span>    synchronized (writeQueue) {<a name="line.167"></a>
 <span class="sourceLineNo">168</span>      writeEntry.markCompleted();<a name="line.168"></a>
-<span class="sourceLineNo">169</span><a name="line.169"></a>
-<span class="sourceLineNo">170</span>      long nextReadValue = NONE;<a name="line.170"></a>
-<span class="sourceLineNo">171</span>      boolean ranOnce = false;<a name="line.171"></a>
-<span class="sourceLineNo">172</span>      while (!writeQueue.isEmpty()) {<a name="line.172"></a>
-<span class="sourceLineNo">173</span>        ranOnce = true;<a name="line.173"></a>
-<span class="sourceLineNo">174</span>        WriteEntry queueFirst = writeQueue.getFirst();<a name="line.174"></a>
-<span class="sourceLineNo">175</span><a name="line.175"></a>
-<span class="sourceLineNo">176</span>        if (nextReadValue &gt; 0) {<a name="line.176"></a>
-<span class="sourceLineNo">177</span>          if (nextReadValue + 1 != queueFirst.getWriteNumber()) {<a name="line.177"></a>
-<span class="sourceLineNo">178</span>            throw new RuntimeException("Invariant in complete violated, nextReadValue="<a name="line.178"></a>
-<span class="sourceLineNo">179</span>                + nextReadValue + ", writeNumber=" + queueFirst.getWriteNumber());<a name="line.179"></a>
-<span class="sourceLineNo">180</span>          }<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>        if (queueFirst.isCompleted()) {<a name="line.183"></a>
-<span class="sourceLineNo">184</span>          nextReadValue = queueFirst.getWriteNumber();<a name="line.184"></a>
-<span class="sourceLineNo">185</span>          writeQueue.removeFirst();<a name="line.185"></a>
-<span class="sourceLineNo">186</span>        } else {<a name="line.186"></a>
-<span class="sourceLineNo">187</span>          break;<a name="line.187"></a>
-<span class="sourceLineNo">188</span>        }<a name="line.188"></a>
-<span class="sourceLineNo">189</span>      }<a name="line.189"></a>
-<span class="sourceLineNo">190</span><a name="line.190"></a>
-<span class="sourceLineNo">191</span>      if (!ranOnce) {<a name="line.191"></a>
-<span class="sourceLineNo">192</span>        throw new RuntimeException("There is no first!");<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>      if (nextReadValue &gt; 0) {<a name="line.195"></a>
-<span class="sourceLineNo">196</span>        synchronized (readWaiters) {<a name="line.196"></a>
-<span class="sourceLineNo">197</span>          readPoint.set(nextReadValue);<a name="line.197"></a>
-<span class="sourceLineNo">198</span>          readWaiters.notifyAll();<a name="line.198"></a>
-<span class="sourceLineNo">199</span>        }<a name="line.199"></a>
-<span class="sourceLineNo">200</span>      }<a name="line.200"></a>
-<span class="sourceLineNo">201</span>      return readPoint.get() &gt;= writeEntry.getWriteNumber();<a name="line.201"></a>
-<span class="sourceLineNo">202</span>    }<a name="line.202"></a>
-<span class="sourceLineNo">203</span>  }<a name="line.203"></a>
-<span class="sourceLineNo">204</span><a name="line.204"></a>
-<span class="sourceLineNo">205</span>  /**<a name="line.205"></a>
-<span class="sourceLineNo">206</span>   * Wait for the global readPoint to advance up to the passed in write entry number.<a name="line.206"></a>
-<span class="sourceLineNo">207</span>   */<a name="line.207"></a>
-<span class="sourceLineNo">208</span>  void waitForRead(WriteEntry e) {<a name="line.208"></a>
-<span class="sourceLineNo">209</span>    boolean interrupted = false;<a name="line.209"></a>
-<span class="sourceLineNo">210</span>    int count = 0;<a name="line.210"></a>
-<span class="sourceLineNo">211</span>    synchronized (readWaiters) {<a name="line.211"></a>
-<span class="sourceLineNo">212</span>      while (readPoint.get() &lt; e.getWriteNumber()) {<a name="line.212"></a>
-<span class="sourceLineNo">213</span>        if (count % 100 == 0 &amp;&amp; count &gt; 0) {<a name="line.213"></a>
-<span class="sourceLineNo">214</span>          LOG.warn("STUCK: " + this);<a name="line.214"></a>
-<span class="sourceLineNo">215</span>        }<a name="line.215"></a>
-<span class="sourceLineNo">216</span>        count++;<a name="line.216"></a>
-<span class="sourceLineNo">217</span>        try {<a name="line.217"></a>
-<span class="sourceLineNo">218</span>          readWaiters.wait(10);<a name="line.218"></a>
-<span class="sourceLineNo">219</span>        } catch (InterruptedException ie) {<a name="line.219"></a>
-<span class="sourceLineNo">220</span>          // We were interrupted... finish the loop -- i.e. cleanup --and then<a name="line.220"></a>
-<span class="sourceLineNo">221</span>          // on our way out, reset the interrupt flag.<a name="line.221"></a>
-<span class="sourceLineNo">222</span>          interrupted = true;<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>    }<a name="line.225"></a>
-<span class="sourceLineNo">226</span>    if (interrupted) {<a name="line.226"></a>
-<span class="sourceLineNo">227</span>      Thread.currentThread().interrupt();<a name="line.227"></a>
-<span class="sourceLineNo">228</span>    }<a name="line.228"></a>
-<span class="sourceLineNo">229</span>  }<a name="line.229"></a>
-<span class="sourceLineNo">230</span><a name="line.230"></a>
-<span class="sourceLineNo">231</span>  @VisibleForTesting<a name="line.231"></a>
-<span class="sourceLineNo">232</span>  public String toString() {<a name="line.232"></a>
-<span class="sourceLineNo">233</span>    return Objects.toStringHelper(this)<a name="line.233"></a>
-<span class="sourceLineNo">234</span>        .add("readPoint", readPoint)<a name="line.234"></a>
-<span class="sourceLineNo">235</span>        .add("writePoint", writePoint).toString();<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">238</span>  public long getReadPoint() {<a name="line.238"></a>
-<span class="sourceLineNo">239</span>    return readPoint.get();<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>  @VisibleForTesting<a name="line.242"></a>
-<span class="sourceLineNo">243</span>  public long getWritePoint() {<a name="line.243"></a>
-<span class="sourceLineNo">244</span>    return writePoint.get();<a name="line.244"></a>
-<span class="sourceLineNo">245</span>  }<a name="line.245"></a>
-<span class="sourceLineNo">246</span><a name="line.246"></a>
-<span class="sourceLineNo">247</span>  /**<a name="line.247"></a>
-<span class="sourceLineNo">248</span>   * Write number and whether write has completed given out at start of a write transaction.<a name="line.248"></a>
-<span class="sourceLineNo">249</span>   * Every created WriteEntry must be completed by calling mvcc#complete or #completeAndWait.<a name="line.249"></a>
-<span class="sourceLineNo">250</span>   */<a name="line.250"></a>
-<span class="sourceLineNo">251</span>  @InterfaceAudience.Private<a name="line.251"></a>
-<span class="sourceLineNo">252</span>  public static class WriteEntry {<a name="line.252"></a>
-<span class="sourceLineNo">253</span>    private final long writeNumber;<a name="line.253"></a>
-<span class="sourceLineNo">254</span>    private boolean completed = false;<a name="line.254"></a>
-<span class="sourceLineNo">255</span><a name="line.255"></a>
-<span class="sourceLineNo">256</span>    WriteEntry(long writeNumber) {<a name="line.256"></a>
-<span class="sourceLineNo">257</span>      this.writeNumber = writeNumber;<a name="line.257"></a>
-<span class="sourceLineNo">258</span>    }<a name="line.258"></a>
-<span class="sourceLineNo">259</span><a name="line.259"></a>
-<span class="sourceLineNo">260</span>    void markCompleted() {<a name="line.260"></a>
-<span class="sourceLineNo">261</span>      this.completed = true;<a name="line.261"></a>
-<span class="sourceLineNo">262</span>    }<a name="line.262"></a>
-<span class="sourceLineNo">263</span><a name="line.263"></a>
-<span class="sourceLineNo">264</span>    boolean isCompleted() {<a name="line.264"></a>
-<span class="sourceLineNo">265</span>      return this.completed;<a name="line.265"></a>
-<span class="sourceLineNo">266</span>    }<a name="line.266"></a>
-<span class="sourceLineNo">267</span><a name="line.267"></a>
-<span class="sourceLineNo">268</span>    public long getWriteNumber() {<a name="line.268"></a>
-<span class="sourceLineNo">269</span>      return this.writeNumber;<a name="line.269"></a>
-<span class="sourceLineNo">270</span>    }<a name="line.270"></a>
-<span class="sourceLineNo">271</span><a name="line.271"></a>
-<span class="sourceLineNo">272</span>    @Override<a name="line.272"></a>
-<span class="sourceLineNo">273</span>    public String toString() {<a name="line.273"></a>
-<span class="sourceLineNo">274</span>      return this.writeNumber + ", " + this.completed;<a name="line.274"></a>
-<span class="sourceLineNo">275</span>    }<a name="line.275"></a>
-<span class="sourceLineNo">276</span>  }<a name="line.276"></a>
-<span class="sourceLineNo">277</span><a name="line.277"></a>
-<span class="sourceLineNo">278</span>  public static final long FIXED_SIZE = ClassSize.align(<a name="line.278"></a>
-<span class="sourceLineNo">279</span>      ClassSize.OBJECT +<a name="line.279"></a>
-<span class="sourceLineNo">280</span>      2 * Bytes.SIZEOF_LONG +<a name="line.280"></a>
-<span class="sourceLineNo">281</span>      2 * ClassSize.REFERENCE);<a name="line.281"></a>
-<span class="sourceLineNo">282</span>}<a name="line.282"></a>
+<span class="sourceLineNo">169</span>      long nextReadValue = NONE;<a name="line.169"></a>
+<span class="sourceLineNo">170</span>      boolean ranOnce = false;<a name="line.170"></a>
+<span class="sourceLineNo">171</span>      while (!writeQueue.isEmpty()) {<a name="line.171"></a>
+<span class="sourceLineNo">172</span>        ranOnce = true;<a name="line.172"></a>
+<span class="sourceLineNo">173</span>        WriteEntry queueFirst = writeQueue.getFirst();<a name="line.173"></a>
+<span class="sourceLineNo">174</span><a name="line.174"></a>
+<span class="sourceLineNo">175</span>        if (nextReadValue &gt; 0) {<a name="line.175"></a>
+<span class="sourceLineNo">176</span>          if (nextReadValue + 1 != queueFirst.getWriteNumber()) {<a name="line.176"></a>
+<span class="sourceLineNo">177</span>            throw new RuntimeException("Invariant in complete violated, nextReadValue="<a name="line.177"></a>
+<span class="sourceLineNo">178</span>                + nextReadValue + ", writeNumber=" + queueFirst.getWriteNumber());<a name="line.178"></a>
+<span class="sourceLineNo">179</span>          }<a name="line.179"></a>
+<span class="sourceLineNo">180</span>        }<a name="line.180"></a>
+<span class="sourceLineNo">181</span><a name="line.181"></a>
+<span class="sourceLineNo">182</span>        if (queueFirst.isCompleted()) {<a name="line.182"></a>
+<span class="sourceLineNo">183</span>          nextReadValue = queueFirst.getWriteNumber();<a name="line.183"></a>
+<span class="sourceLineNo">184</span>          writeQueue.removeFirst();<a name="line.184"></a>
+<span class="sourceLineNo">185</span>        } else {<a name="line.185"></a>
+<span class="sourceLineNo">186</span>          break;<a name="line.186"></a>
+<span class="sourceLineNo">187</span>        }<a name="line.187"></a>
+<span class="sourceLineNo">188</span>      }<a name="line.188"></a>
+<span class="sourceLineNo">189</span><a name="line.189"></a>
+<span class="sourceLineNo">190</span>      if (!ranOnce) {<a name="line.190"></a>
+<span class="sourceLineNo">191</span>        throw new RuntimeException("There is no first!");<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>      if (nextReadValue &gt; 0) {<a name="line.194"></a>
+<span class="sourceLineNo">195</span>        synchronized (readWaiters) {<a name="line.195"></a>
+<span class="sourceLineNo">196</span>          readPoint.set(nextReadValue);<a name="line.196"></a>
+<span class="sourceLineNo">197</span>          readWaiters.notifyAll();<a name="line.197"></a>
+<span class="sourceLineNo">198</span>        }<a name="line.198"></a>
+<span class="sourceLineNo">199</span>      }<a name="line.199"></a>
+<span class="sourceLineNo">200</span>      return readPoint.get() &gt;= writeEntry.getWriteNumber();<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><a name="line.203"></a>
+<span class="sourceLineNo">204</span>  /**<a name="line.204"></a>
+<span class="sourceLineNo">205</span>   * Wait for the global readPoint to advance up to the passed in write entry number.<a name="line.205"></a>
+<span class="sourceLineNo">206</span>   */<a name="line.206"></a>
+<span class="sourceLineNo">207</span>  void waitForRead(WriteEntry e) {<a name="line.207"></a>
+<span class="sourceLineNo">208</span>    boolean interrupted = false;<a name="line.208"></a>
+<span class="sourceLineNo">209</span>    int count = 0;<a name="line.209"></a>
+<span class="sourceLineNo">210</span>    synchronized (readWaiters) {<a name="line.210"></a>
+<span class="sourceLineNo">211</span>      while (readPoint.get() &lt; e.getWriteNumber()) {<a name="line.211"></a>
+<span class="sourceLineNo">212</span>        if (count % 100 == 0 &amp;&amp; count &gt; 0) {<a name="line.212"></a>
+<span class="sourceLineNo">213</span>          LOG.warn("STUCK: " + this);<a name="line.213"></a>
+<span class="sourceLineNo">214</span>        }<a name="line.214"></a>
+<span class="sourceLineNo">215</span>        count++;<a name="line.215"></a>
+<span class="sourceLineNo">216</span>        try {<a name="line.216"></a>
+<span class="sourceLineNo">217</span>          readWaiters.wait(10);<a name="line.217"></a>
+<span class="sourceLineNo">218</span>        } catch (InterruptedException ie) {<a name="line.218"></a>
+<span class="sourceLineNo">219</span>          // We were interrupted... finish the loop -- i.e. cleanup --and then<a name="line.219"></a>
+<span class="sourceLineNo">220</span>          // on our way out, reset the interrupt flag.<a name="line.220"></a>
+<span class="sourceLineNo">221</span>          interrupted = true;<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>    }<a name="line.224"></a>
+<span class="sourceLineNo">225</span>    if (interrupted) {<a name="line.225"></a>
+<span class="sourceLineNo">226</span>      Thread.currentThread().interrupt();<a name="line.226"></a>
+<span class="sourceLineNo">227</span>    }<a name="line.227"></a>
+<span class="sourceLineNo">228</span>  }<a name="line.228"></a>
+<span class="sourceLineNo">229</span><a name="line.229"></a>
+<span class="sourceLineNo">230</span>  @VisibleForTesting<a name="line.230"></a>
+<span class="sourceLineNo">231</span>  public String toString() {<a name="line.231"></a>
+<span class="sourceLineNo">232</span>    return Objects.toStringHelper(this)<a name="line.232"></a>
+<span class="sourceLineNo">233</span>        .add("readPoint", readPoint)<a name="line.233"></a>
+<span class="sourceLineNo">234</span>        .add("writePoint", writePoint).toString();<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>
+<span class="sourceLineNo">237</span>  public long getReadPoint() {<a name="line.237"></a>
+<span class="sourceLineNo">238</span>    return readPoint.get();<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>  @VisibleForTesting<a name="line.241"></a>
+<span class="sourceLineNo">242</span>  public long getWritePoint() {<a name="line.242"></a>
+<span class="sourceLineNo">243</span>    return writePoint.get();<a name="line.243"></a>
+<span class="sourceLineNo">244</span>  }<a name="line.244"></a>
+<span class="sourceLineNo">245</span><a name="line.245"></a>
+<span class="sourceLineNo">246</span>  /**<a name="line.246"></a>
+<span class="sourceLineNo">247</span>   * Write number and whether write has completed given out at start of a write transaction.<a name="line.247"></a>
+<span class="sourceLineNo">248</span>   * Every created WriteEntry must be completed by calling mvcc#complete or #completeAndWait.<a name="line.248"></a>
+<span class="sourceLineNo">249</span>   */<a name="line.249"></a>
+<span class="sourceLineNo">250</span>  @InterfaceAudience.Private<a name="line.250"></a>
+<span class="sourceLineNo">251</span>  public static class WriteEntry {<a name="line.251"></a>
+<span class="sourceLineNo">252</span>    private final long writeNumber;<a name="line.252"></a>
+<span class="sourceLineNo">253</span>    private boolean completed = false;<a name="line.253"></a>
+<span class="sourceLineNo">254</span><a name="line.254"></a>
+<span class="sourceLineNo">255</span>    WriteEntry(long writeNumber) {<a name="line.255"></a>
+<span class="sourceLineNo">256</span>      this.writeNumber = writeNumber;<a name="line.256"></a>
+<span class="sourceLineNo">257</span>    }<a name="line.257"></a>
+<span class="sourceLineNo">258</span><a name="line.258"></a>
+<span class="sourceLineNo">259</span>    void markCompleted() {<a name="line.259"></a>
+<span class="sourceLineNo">260</span>      this.completed = true;<a name="line.260"></a>
+<span class="sourceLineNo">261</span>    }<a name="line.261"></a>
+<span class="sourceLineNo">262</span><a name="line.262"></a>
+<span class="sourceLineNo">263</span>    boolean isCompleted() {<a name="line.263"></a>
+<span class="sourceLineNo">264</span>      return this.completed;<a name="line.264"></a>
+<span class="sourceLineNo">265</span>    }<a name="line.265"></a>
+<span class="sourceLineNo">266</span><a name="line.266"></a>
+<span class="sourceLineNo">267</span>    public long getWriteNumber() {<a name="line.267"></a>
+<span class="sourceLineNo">268</span>      return this.writeNumber;<a name="line.268"></a>
+<span class="sourceLineNo">269</span>    }<a name="line.269"></a>
+<span class="sourceLineNo">270</span><a name="line.270"></a>
+<span class="sourceLineNo">271</span>    @Override<a name="line.271"></a>
+<span class="sourceLineNo">272</span>    public String toString() {<a name="line.272"></a>
+<span class="sourceLineNo">273</span>      return this.writeNumber + ", " + this.completed;<a name="line.273"></a>
+<span class="sourceLineNo">274</span>    }<a name="line.274"></a>
+<span class="sourceLineNo">275</span>  }<a name="line.275"></a>
+<span class="sourceLineNo">276</span><a name="line.276"></a>
+<span class="sourceLineNo">277</span>  public static final long FIXED_SIZE = ClassSize.align(<a name="line.277"></a>
+<span class="sourceLineNo">278</span>      ClassSize.OBJECT +<a name="line.278"></a>
+<span class="sourceLineNo">279</span>      2 * Bytes.SIZEOF_LONG +<a name="line.279"></a>
+<span class="sourceLineNo">280</span>      2 * ClassSize.REFERENCE);<a name="line.280"></a>
+<span class="sourceLineNo">281</span>}<a name="line.281"></a>
 
 
 


Mime
View raw message