hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [23/40] hbase-site git commit: Published site at 82d554e3783372cc6b05489452c815b57c06f6cd.
Date Fri, 23 Jun 2017 15:01:31 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/e9db7c5d/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/StripeStoreFileManager.KeyBeforeConcatenatedLists.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/StripeStoreFileManager.KeyBeforeConcatenatedLists.html b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/StripeStoreFileManager.KeyBeforeConcatenatedLists.html
index b09e20b..3c088c8 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/StripeStoreFileManager.KeyBeforeConcatenatedLists.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/StripeStoreFileManager.KeyBeforeConcatenatedLists.html
@@ -155,937 +155,942 @@
 <span class="sourceLineNo">147</span>  }<a name="line.147"></a>
 <span class="sourceLineNo">148</span><a name="line.148"></a>
 <span class="sourceLineNo">149</span>  @Override<a name="line.149"></a>
-<span class="sourceLineNo">150</span>  public void insertNewFiles(Collection&lt;StoreFile&gt; sfs) throws IOException {<a name="line.150"></a>
-<span class="sourceLineNo">151</span>    CompactionOrFlushMergeCopy cmc = new CompactionOrFlushMergeCopy(true);<a name="line.151"></a>
-<span class="sourceLineNo">152</span>    // Passing null does not cause NPE??<a name="line.152"></a>
-<span class="sourceLineNo">153</span>    cmc.mergeResults(null, sfs);<a name="line.153"></a>
-<span class="sourceLineNo">154</span>    debugDumpState("Added new files");<a name="line.154"></a>
-<span class="sourceLineNo">155</span>  }<a name="line.155"></a>
-<span class="sourceLineNo">156</span><a name="line.156"></a>
-<span class="sourceLineNo">157</span>  @Override<a name="line.157"></a>
-<span class="sourceLineNo">158</span>  public ImmutableCollection&lt;StoreFile&gt; clearFiles() {<a name="line.158"></a>
-<span class="sourceLineNo">159</span>    ImmutableCollection&lt;StoreFile&gt; result = state.allFilesCached;<a name="line.159"></a>
-<span class="sourceLineNo">160</span>    this.state = new State();<a name="line.160"></a>
-<span class="sourceLineNo">161</span>    this.fileStarts.clear();<a name="line.161"></a>
-<span class="sourceLineNo">162</span>    this.fileEnds.clear();<a name="line.162"></a>
-<span class="sourceLineNo">163</span>    return result;<a name="line.163"></a>
-<span class="sourceLineNo">164</span>  }<a name="line.164"></a>
-<span class="sourceLineNo">165</span><a name="line.165"></a>
-<span class="sourceLineNo">166</span>  @Override<a name="line.166"></a>
-<span class="sourceLineNo">167</span>  public ImmutableCollection&lt;StoreFile&gt; clearCompactedFiles() {<a name="line.167"></a>
-<span class="sourceLineNo">168</span>    ImmutableCollection&lt;StoreFile&gt; result = state.allCompactedFilesCached;<a name="line.168"></a>
-<span class="sourceLineNo">169</span>    this.state = new State();<a name="line.169"></a>
-<span class="sourceLineNo">170</span>    return result;<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>  @Override<a name="line.173"></a>
-<span class="sourceLineNo">174</span>  public int getStorefileCount() {<a name="line.174"></a>
-<span class="sourceLineNo">175</span>    return state.allFilesCached.size();<a name="line.175"></a>
+<span class="sourceLineNo">150</span>  public int getCompactedFilesCount() {<a name="line.150"></a>
+<span class="sourceLineNo">151</span>    return state.allCompactedFilesCached.size();<a name="line.151"></a>
+<span class="sourceLineNo">152</span>  }<a name="line.152"></a>
+<span class="sourceLineNo">153</span><a name="line.153"></a>
+<span class="sourceLineNo">154</span>  @Override<a name="line.154"></a>
+<span class="sourceLineNo">155</span>  public void insertNewFiles(Collection&lt;StoreFile&gt; sfs) throws IOException {<a name="line.155"></a>
+<span class="sourceLineNo">156</span>    CompactionOrFlushMergeCopy cmc = new CompactionOrFlushMergeCopy(true);<a name="line.156"></a>
+<span class="sourceLineNo">157</span>    // Passing null does not cause NPE??<a name="line.157"></a>
+<span class="sourceLineNo">158</span>    cmc.mergeResults(null, sfs);<a name="line.158"></a>
+<span class="sourceLineNo">159</span>    debugDumpState("Added new files");<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 ImmutableCollection&lt;StoreFile&gt; clearFiles() {<a name="line.163"></a>
+<span class="sourceLineNo">164</span>    ImmutableCollection&lt;StoreFile&gt; result = state.allFilesCached;<a name="line.164"></a>
+<span class="sourceLineNo">165</span>    this.state = new State();<a name="line.165"></a>
+<span class="sourceLineNo">166</span>    this.fileStarts.clear();<a name="line.166"></a>
+<span class="sourceLineNo">167</span>    this.fileEnds.clear();<a name="line.167"></a>
+<span class="sourceLineNo">168</span>    return result;<a name="line.168"></a>
+<span class="sourceLineNo">169</span>  }<a name="line.169"></a>
+<span class="sourceLineNo">170</span><a name="line.170"></a>
+<span class="sourceLineNo">171</span>  @Override<a name="line.171"></a>
+<span class="sourceLineNo">172</span>  public ImmutableCollection&lt;StoreFile&gt; clearCompactedFiles() {<a name="line.172"></a>
+<span class="sourceLineNo">173</span>    ImmutableCollection&lt;StoreFile&gt; result = state.allCompactedFilesCached;<a name="line.173"></a>
+<span class="sourceLineNo">174</span>    this.state = new State();<a name="line.174"></a>
+<span class="sourceLineNo">175</span>    return result;<a name="line.175"></a>
 <span class="sourceLineNo">176</span>  }<a name="line.176"></a>
 <span class="sourceLineNo">177</span><a name="line.177"></a>
-<span class="sourceLineNo">178</span>  /** See {@link StoreFileManager#getCandidateFilesForRowKeyBefore(KeyValue)}<a name="line.178"></a>
-<span class="sourceLineNo">179</span>   * for details on this methods. */<a name="line.179"></a>
-<span class="sourceLineNo">180</span>  @Override<a name="line.180"></a>
-<span class="sourceLineNo">181</span>  public Iterator&lt;StoreFile&gt; getCandidateFilesForRowKeyBefore(final KeyValue targetKey) {<a name="line.181"></a>
-<span class="sourceLineNo">182</span>    KeyBeforeConcatenatedLists result = new KeyBeforeConcatenatedLists();<a name="line.182"></a>
-<span class="sourceLineNo">183</span>    // Order matters for this call.<a name="line.183"></a>
-<span class="sourceLineNo">184</span>    result.addSublist(state.level0Files);<a name="line.184"></a>
-<span class="sourceLineNo">185</span>    if (!state.stripeFiles.isEmpty()) {<a name="line.185"></a>
-<span class="sourceLineNo">186</span>      int lastStripeIndex = findStripeForRow(CellUtil.cloneRow(targetKey), false);<a name="line.186"></a>
-<span class="sourceLineNo">187</span>      for (int stripeIndex = lastStripeIndex; stripeIndex &gt;= 0; --stripeIndex) {<a name="line.187"></a>
-<span class="sourceLineNo">188</span>        result.addSublist(state.stripeFiles.get(stripeIndex));<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>    return result.iterator();<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>  /** See {@link StoreFileManager#getCandidateFilesForRowKeyBefore(KeyValue)} and<a name="line.194"></a>
-<span class="sourceLineNo">195</span>   * {@link StoreFileManager#updateCandidateFilesForRowKeyBefore(Iterator, KeyValue, Cell)}<a name="line.195"></a>
-<span class="sourceLineNo">196</span>   * for details on this methods. */<a name="line.196"></a>
-<span class="sourceLineNo">197</span>  @Override<a name="line.197"></a>
-<span class="sourceLineNo">198</span>  public Iterator&lt;StoreFile&gt; updateCandidateFilesForRowKeyBefore(<a name="line.198"></a>
-<span class="sourceLineNo">199</span>      Iterator&lt;StoreFile&gt; candidateFiles, final KeyValue targetKey, final Cell candidate) {<a name="line.199"></a>
-<span class="sourceLineNo">200</span>    KeyBeforeConcatenatedLists.Iterator original =<a name="line.200"></a>
-<span class="sourceLineNo">201</span>        (KeyBeforeConcatenatedLists.Iterator)candidateFiles;<a name="line.201"></a>
-<span class="sourceLineNo">202</span>    assert original != null;<a name="line.202"></a>
-<span class="sourceLineNo">203</span>    ArrayList&lt;List&lt;StoreFile&gt;&gt; components = original.getComponents();<a name="line.203"></a>
-<span class="sourceLineNo">204</span>    for (int firstIrrelevant = 0; firstIrrelevant &lt; components.size(); ++firstIrrelevant) {<a name="line.204"></a>
-<span class="sourceLineNo">205</span>      StoreFile sf = components.get(firstIrrelevant).get(0);<a name="line.205"></a>
-<span class="sourceLineNo">206</span>      byte[] endKey = endOf(sf);<a name="line.206"></a>
-<span class="sourceLineNo">207</span>      // Entries are ordered as such: L0, then stripes in reverse order. We never remove<a name="line.207"></a>
-<span class="sourceLineNo">208</span>      // level 0; we remove the stripe, and all subsequent ones, as soon as we find the<a name="line.208"></a>
-<span class="sourceLineNo">209</span>      // first one that cannot possibly have better candidates.<a name="line.209"></a>
-<span class="sourceLineNo">210</span>      if (!isInvalid(endKey) &amp;&amp; !isOpen(endKey)<a name="line.210"></a>
-<span class="sourceLineNo">211</span>          &amp;&amp; (nonOpenRowCompare(targetKey, endKey) &gt;= 0)) {<a name="line.211"></a>
-<span class="sourceLineNo">212</span>        original.removeComponents(firstIrrelevant);<a name="line.212"></a>
-<span class="sourceLineNo">213</span>        break;<a name="line.213"></a>
-<span class="sourceLineNo">214</span>      }<a name="line.214"></a>
-<span class="sourceLineNo">215</span>    }<a name="line.215"></a>
-<span class="sourceLineNo">216</span>    return original;<a name="line.216"></a>
-<span class="sourceLineNo">217</span>  }<a name="line.217"></a>
-<span class="sourceLineNo">218</span><a name="line.218"></a>
-<span class="sourceLineNo">219</span>  private byte[] getSplitPoint(Collection&lt;StoreFile&gt; sfs) throws IOException {<a name="line.219"></a>
-<span class="sourceLineNo">220</span>    Optional&lt;StoreFile&gt; largestFile = StoreUtils.getLargestFile(sfs);<a name="line.220"></a>
-<span class="sourceLineNo">221</span>    return largestFile.isPresent()<a name="line.221"></a>
-<span class="sourceLineNo">222</span>        ? StoreUtils.getFileSplitPoint(largestFile.get(), cellComparator).orElse(null) : null;<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>   * Override of getSplitPoint that determines the split point as the boundary between two<a name="line.226"></a>
-<span class="sourceLineNo">227</span>   * stripes, unless it causes significant imbalance between split sides' sizes. In that<a name="line.227"></a>
-<span class="sourceLineNo">228</span>   * case, the split boundary will be chosen from the middle of one of the stripes to<a name="line.228"></a>
-<span class="sourceLineNo">229</span>   * minimize imbalance.<a name="line.229"></a>
-<span class="sourceLineNo">230</span>   * @return The split point, or null if no split is possible.<a name="line.230"></a>
-<span class="sourceLineNo">231</span>   */<a name="line.231"></a>
-<span class="sourceLineNo">232</span>  @Override<a name="line.232"></a>
-<span class="sourceLineNo">233</span>  public byte[] getSplitPoint() throws IOException {<a name="line.233"></a>
-<span class="sourceLineNo">234</span>    if (this.getStorefileCount() == 0) return null;<a name="line.234"></a>
-<span class="sourceLineNo">235</span>    if (state.stripeFiles.size() &lt;= 1) {<a name="line.235"></a>
-<span class="sourceLineNo">236</span>      return getSplitPointFromAllFiles();<a name="line.236"></a>
-<span class="sourceLineNo">237</span>    }<a name="line.237"></a>
-<span class="sourceLineNo">238</span>    int leftIndex = -1, rightIndex = state.stripeFiles.size();<a name="line.238"></a>
-<span class="sourceLineNo">239</span>    long leftSize = 0, rightSize = 0;<a name="line.239"></a>
-<span class="sourceLineNo">240</span>    long lastLeftSize = 0, lastRightSize = 0;<a name="line.240"></a>
-<span class="sourceLineNo">241</span>    while (rightIndex - 1 != leftIndex) {<a name="line.241"></a>
-<span class="sourceLineNo">242</span>      if (leftSize &gt;= rightSize) {<a name="line.242"></a>
-<span class="sourceLineNo">243</span>        --rightIndex;<a name="line.243"></a>
-<span class="sourceLineNo">244</span>        lastRightSize = getStripeFilesSize(rightIndex);<a name="line.244"></a>
-<span class="sourceLineNo">245</span>        rightSize += lastRightSize;<a name="line.245"></a>
-<span class="sourceLineNo">246</span>      } else {<a name="line.246"></a>
-<span class="sourceLineNo">247</span>        ++leftIndex;<a name="line.247"></a>
-<span class="sourceLineNo">248</span>        lastLeftSize = getStripeFilesSize(leftIndex);<a name="line.248"></a>
-<span class="sourceLineNo">249</span>        leftSize += lastLeftSize;<a name="line.249"></a>
-<span class="sourceLineNo">250</span>      }<a name="line.250"></a>
-<span class="sourceLineNo">251</span>    }<a name="line.251"></a>
-<span class="sourceLineNo">252</span>    if (leftSize == 0 || rightSize == 0) {<a name="line.252"></a>
-<span class="sourceLineNo">253</span>      String errMsg = String.format("Cannot split on a boundary - left index %d size %d, "<a name="line.253"></a>
-<span class="sourceLineNo">254</span>          + "right index %d size %d", leftIndex, leftSize, rightIndex, rightSize);<a name="line.254"></a>
-<span class="sourceLineNo">255</span>      debugDumpState(errMsg);<a name="line.255"></a>
-<span class="sourceLineNo">256</span>      LOG.warn(errMsg);<a name="line.256"></a>
-<span class="sourceLineNo">257</span>      return getSplitPointFromAllFiles();<a name="line.257"></a>
-<span class="sourceLineNo">258</span>    }<a name="line.258"></a>
-<span class="sourceLineNo">259</span>    double ratio = (double)rightSize / leftSize;<a name="line.259"></a>
-<span class="sourceLineNo">260</span>    if (ratio &lt; 1) {<a name="line.260"></a>
-<span class="sourceLineNo">261</span>      ratio = 1 / ratio;<a name="line.261"></a>
-<span class="sourceLineNo">262</span>    }<a name="line.262"></a>
-<span class="sourceLineNo">263</span>    if (config.getMaxSplitImbalance() &gt; ratio) return state.stripeEndRows[leftIndex];<a name="line.263"></a>
-<span class="sourceLineNo">264</span><a name="line.264"></a>
-<span class="sourceLineNo">265</span>    // If the difference between the sides is too large, we could get the proportional key on<a name="line.265"></a>
-<span class="sourceLineNo">266</span>    // the a stripe to equalize the difference, but there's no proportional key method at the<a name="line.266"></a>
-<span class="sourceLineNo">267</span>    // moment, and it's not extremely important.<a name="line.267"></a>
-<span class="sourceLineNo">268</span>    // See if we can achieve better ratio if we split the bigger side in half.<a name="line.268"></a>
-<span class="sourceLineNo">269</span>    boolean isRightLarger = rightSize &gt;= leftSize;<a name="line.269"></a>
-<span class="sourceLineNo">270</span>    double newRatio = isRightLarger<a name="line.270"></a>
-<span class="sourceLineNo">271</span>        ? getMidStripeSplitRatio(leftSize, rightSize, lastRightSize)<a name="line.271"></a>
-<span class="sourceLineNo">272</span>        : getMidStripeSplitRatio(rightSize, leftSize, lastLeftSize);<a name="line.272"></a>
-<span class="sourceLineNo">273</span>    if (newRatio &lt; 1) {<a name="line.273"></a>
-<span class="sourceLineNo">274</span>      newRatio = 1 / newRatio;<a name="line.274"></a>
-<span class="sourceLineNo">275</span>    }<a name="line.275"></a>
-<span class="sourceLineNo">276</span>    if (newRatio &gt;= ratio)  return state.stripeEndRows[leftIndex];<a name="line.276"></a>
-<span class="sourceLineNo">277</span>    LOG.debug("Splitting the stripe - ratio w/o split " + ratio + ", ratio with split "<a name="line.277"></a>
-<span class="sourceLineNo">278</span>        + newRatio + " configured ratio " + config.getMaxSplitImbalance());<a name="line.278"></a>
-<span class="sourceLineNo">279</span>    // Ok, we may get better ratio, get it.<a name="line.279"></a>
-<span class="sourceLineNo">280</span>    return getSplitPoint(state.stripeFiles.get(isRightLarger ? rightIndex : leftIndex));<a name="line.280"></a>
-<span class="sourceLineNo">281</span>  }<a name="line.281"></a>
-<span class="sourceLineNo">282</span><a name="line.282"></a>
-<span class="sourceLineNo">283</span>  private byte[] getSplitPointFromAllFiles() throws IOException {<a name="line.283"></a>
-<span class="sourceLineNo">284</span>    ConcatenatedLists&lt;StoreFile&gt; sfs = new ConcatenatedLists&lt;&gt;();<a name="line.284"></a>
-<span class="sourceLineNo">285</span>    sfs.addSublist(state.level0Files);<a name="line.285"></a>
-<span class="sourceLineNo">286</span>    sfs.addAllSublists(state.stripeFiles);<a name="line.286"></a>
-<span class="sourceLineNo">287</span>    return getSplitPoint(sfs);<a name="line.287"></a>
-<span class="sourceLineNo">288</span>  }<a name="line.288"></a>
-<span class="sourceLineNo">289</span><a name="line.289"></a>
-<span class="sourceLineNo">290</span>  private double getMidStripeSplitRatio(long smallerSize, long largerSize, long lastLargerSize) {<a name="line.290"></a>
-<span class="sourceLineNo">291</span>    return (double)(largerSize - lastLargerSize / 2f) / (smallerSize + lastLargerSize / 2f);<a name="line.291"></a>
-<span class="sourceLineNo">292</span>  }<a name="line.292"></a>
-<span class="sourceLineNo">293</span><a name="line.293"></a>
-<span class="sourceLineNo">294</span>  @Override<a name="line.294"></a>
-<span class="sourceLineNo">295</span>  public Collection&lt;StoreFile&gt; getFilesForScan(byte[] startRow, boolean includeStartRow,<a name="line.295"></a>
-<span class="sourceLineNo">296</span>      byte[] stopRow, boolean includeStopRow) {<a name="line.296"></a>
-<span class="sourceLineNo">297</span>    if (state.stripeFiles.isEmpty()) {<a name="line.297"></a>
-<span class="sourceLineNo">298</span>      return state.level0Files; // There's just L0.<a name="line.298"></a>
-<span class="sourceLineNo">299</span>    }<a name="line.299"></a>
-<span class="sourceLineNo">300</span><a name="line.300"></a>
-<span class="sourceLineNo">301</span>    int firstStripe = findStripeForRow(startRow, true);<a name="line.301"></a>
-<span class="sourceLineNo">302</span>    int lastStripe = findStripeForRow(stopRow, false);<a name="line.302"></a>
-<span class="sourceLineNo">303</span>    assert firstStripe &lt;= lastStripe;<a name="line.303"></a>
-<span class="sourceLineNo">304</span>    if (firstStripe == lastStripe &amp;&amp; state.level0Files.isEmpty()) {<a name="line.304"></a>
-<span class="sourceLineNo">305</span>      return state.stripeFiles.get(firstStripe); // There's just one stripe we need.<a name="line.305"></a>
-<span class="sourceLineNo">306</span>    }<a name="line.306"></a>
-<span class="sourceLineNo">307</span>    if (firstStripe == 0 &amp;&amp; lastStripe == (state.stripeFiles.size() - 1)) {<a name="line.307"></a>
-<span class="sourceLineNo">308</span>      return state.allFilesCached; // We need to read all files.<a name="line.308"></a>
-<span class="sourceLineNo">309</span>    }<a name="line.309"></a>
-<span class="sourceLineNo">310</span><a name="line.310"></a>
-<span class="sourceLineNo">311</span>    ConcatenatedLists&lt;StoreFile&gt; result = new ConcatenatedLists&lt;&gt;();<a name="line.311"></a>
-<span class="sourceLineNo">312</span>    result.addAllSublists(state.stripeFiles.subList(firstStripe, lastStripe + 1));<a name="line.312"></a>
-<span class="sourceLineNo">313</span>    result.addSublist(state.level0Files);<a name="line.313"></a>
-<span class="sourceLineNo">314</span>    return result;<a name="line.314"></a>
-<span class="sourceLineNo">315</span>  }<a name="line.315"></a>
-<span class="sourceLineNo">316</span><a name="line.316"></a>
-<span class="sourceLineNo">317</span>  @Override<a name="line.317"></a>
-<span class="sourceLineNo">318</span>  public void addCompactionResults(<a name="line.318"></a>
-<span class="sourceLineNo">319</span>    Collection&lt;StoreFile&gt; compactedFiles, Collection&lt;StoreFile&gt; results) throws IOException {<a name="line.319"></a>
-<span class="sourceLineNo">320</span>    // See class comment for the assumptions we make here.<a name="line.320"></a>
-<span class="sourceLineNo">321</span>    LOG.debug("Attempting to merge compaction results: " + compactedFiles.size()<a name="line.321"></a>
-<span class="sourceLineNo">322</span>        + " files replaced by " + results.size());<a name="line.322"></a>
-<span class="sourceLineNo">323</span>    // In order to be able to fail in the middle of the operation, we'll operate on lazy<a name="line.323"></a>
-<span class="sourceLineNo">324</span>    // copies and apply the result at the end.<a name="line.324"></a>
-<span class="sourceLineNo">325</span>    CompactionOrFlushMergeCopy cmc = new CompactionOrFlushMergeCopy(false);<a name="line.325"></a>
-<span class="sourceLineNo">326</span>    cmc.mergeResults(compactedFiles, results);<a name="line.326"></a>
-<span class="sourceLineNo">327</span>    markCompactedAway(compactedFiles);<a name="line.327"></a>
-<span class="sourceLineNo">328</span>    debugDumpState("Merged compaction results");<a name="line.328"></a>
-<span class="sourceLineNo">329</span>  }<a name="line.329"></a>
-<span class="sourceLineNo">330</span><a name="line.330"></a>
-<span class="sourceLineNo">331</span>  // Mark the files as compactedAway once the storefiles and compactedfiles list is finalised<a name="line.331"></a>
-<span class="sourceLineNo">332</span>  // Let a background thread close the actual reader on these compacted files and also<a name="line.332"></a>
-<span class="sourceLineNo">333</span>  // ensure to evict the blocks from block cache so that they are no longer in<a name="line.333"></a>
-<span class="sourceLineNo">334</span>  // cache<a name="line.334"></a>
-<span class="sourceLineNo">335</span>  private void markCompactedAway(Collection&lt;StoreFile&gt; compactedFiles) {<a name="line.335"></a>
-<span class="sourceLineNo">336</span>    for (StoreFile file : compactedFiles) {<a name="line.336"></a>
-<span class="sourceLineNo">337</span>      file.markCompactedAway();<a name="line.337"></a>
-<span class="sourceLineNo">338</span>    }<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>  @Override<a name="line.341"></a>
-<span class="sourceLineNo">342</span>  public void removeCompactedFiles(Collection&lt;StoreFile&gt; compactedFiles) throws IOException {<a name="line.342"></a>
-<span class="sourceLineNo">343</span>    // See class comment for the assumptions we make here.<a name="line.343"></a>
-<span class="sourceLineNo">344</span>    LOG.debug("Attempting to delete compaction results: " + compactedFiles.size());<a name="line.344"></a>
-<span class="sourceLineNo">345</span>    // In order to be able to fail in the middle of the operation, we'll operate on lazy<a name="line.345"></a>
-<span class="sourceLineNo">346</span>    // copies and apply the result at the end.<a name="line.346"></a>
-<span class="sourceLineNo">347</span>    CompactionOrFlushMergeCopy cmc = new CompactionOrFlushMergeCopy(false);<a name="line.347"></a>
-<span class="sourceLineNo">348</span>    cmc.deleteResults(compactedFiles);<a name="line.348"></a>
-<span class="sourceLineNo">349</span>    debugDumpState("Deleted compaction results");<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>  @Override<a name="line.352"></a>
-<span class="sourceLineNo">353</span>  public int getStoreCompactionPriority() {<a name="line.353"></a>
-<span class="sourceLineNo">354</span>    // If there's only L0, do what the default store does.<a name="line.354"></a>
-<span class="sourceLineNo">355</span>    // If we are in critical priority, do the same - we don't want to trump all stores all<a name="line.355"></a>
-<span class="sourceLineNo">356</span>    // the time due to how many files we have.<a name="line.356"></a>
-<span class="sourceLineNo">357</span>    int fc = getStorefileCount();<a name="line.357"></a>
-<span class="sourceLineNo">358</span>    if (state.stripeFiles.isEmpty() || (this.blockingFileCount &lt;= fc)) {<a name="line.358"></a>
-<span class="sourceLineNo">359</span>      return this.blockingFileCount - fc;<a name="line.359"></a>
-<span class="sourceLineNo">360</span>    }<a name="line.360"></a>
-<span class="sourceLineNo">361</span>    // If we are in good shape, we don't want to be trumped by all other stores due to how<a name="line.361"></a>
-<span class="sourceLineNo">362</span>    // many files we have, so do an approximate mapping to normal priority range; L0 counts<a name="line.362"></a>
-<span class="sourceLineNo">363</span>    // for all stripes.<a name="line.363"></a>
-<span class="sourceLineNo">364</span>    int l0 = state.level0Files.size(), sc = state.stripeFiles.size();<a name="line.364"></a>
-<span class="sourceLineNo">365</span>    int priority = (int)Math.ceil(((double)(this.blockingFileCount - fc + l0) / sc) - l0);<a name="line.365"></a>
-<span class="sourceLineNo">366</span>    return (priority &lt;= HStore.PRIORITY_USER) ? (HStore.PRIORITY_USER + 1) : priority;<a name="line.366"></a>
-<span class="sourceLineNo">367</span>  }<a name="line.367"></a>
-<span class="sourceLineNo">368</span><a name="line.368"></a>
-<span class="sourceLineNo">369</span>  /**<a name="line.369"></a>
-<span class="sourceLineNo">370</span>   * Gets the total size of all files in the stripe.<a name="line.370"></a>
-<span class="sourceLineNo">371</span>   * @param stripeIndex Stripe index.<a name="line.371"></a>
-<span class="sourceLineNo">372</span>   * @return Size.<a name="line.372"></a>
-<span class="sourceLineNo">373</span>   */<a name="line.373"></a>
-<span class="sourceLineNo">374</span>  private long getStripeFilesSize(int stripeIndex) {<a name="line.374"></a>
-<span class="sourceLineNo">375</span>    long result = 0;<a name="line.375"></a>
-<span class="sourceLineNo">376</span>    for (StoreFile sf : state.stripeFiles.get(stripeIndex)) {<a name="line.376"></a>
-<span class="sourceLineNo">377</span>      result += sf.getReader().length();<a name="line.377"></a>
-<span class="sourceLineNo">378</span>    }<a name="line.378"></a>
-<span class="sourceLineNo">379</span>    return result;<a name="line.379"></a>
-<span class="sourceLineNo">380</span>  }<a name="line.380"></a>
-<span class="sourceLineNo">381</span><a name="line.381"></a>
-<span class="sourceLineNo">382</span>  /**<a name="line.382"></a>
-<span class="sourceLineNo">383</span>   * Loads initial store files that were picked up from some physical location pertaining to<a name="line.383"></a>
-<span class="sourceLineNo">384</span>   * this store (presumably). Unlike adding files after compaction, assumes empty initial<a name="line.384"></a>
-<span class="sourceLineNo">385</span>   * sets, and is forgiving with regard to stripe constraints - at worst, many/all files will<a name="line.385"></a>
-<span class="sourceLineNo">386</span>   * go to level 0.<a name="line.386"></a>
-<span class="sourceLineNo">387</span>   * @param storeFiles Store files to add.<a name="line.387"></a>
-<span class="sourceLineNo">388</span>   */<a name="line.388"></a>
-<span class="sourceLineNo">389</span>  private void loadUnclassifiedStoreFiles(List&lt;StoreFile&gt; storeFiles) {<a name="line.389"></a>
-<span class="sourceLineNo">390</span>    LOG.debug("Attempting to load " + storeFiles.size() + " store files.");<a name="line.390"></a>
-<span class="sourceLineNo">391</span>    TreeMap&lt;byte[], ArrayList&lt;StoreFile&gt;&gt; candidateStripes = new TreeMap&lt;&gt;(MAP_COMPARATOR);<a name="line.391"></a>
-<span class="sourceLineNo">392</span>    ArrayList&lt;StoreFile&gt; level0Files = new ArrayList&lt;&gt;();<a name="line.392"></a>
-<span class="sourceLineNo">393</span>    // Separate the files into tentative stripes; then validate. Currently, we rely on metadata.<a name="line.393"></a>
-<span class="sourceLineNo">394</span>    // If needed, we could dynamically determine the stripes in future.<a name="line.394"></a>
-<span class="sourceLineNo">395</span>    for (StoreFile sf : storeFiles) {<a name="line.395"></a>
-<span class="sourceLineNo">396</span>      byte[] startRow = startOf(sf), endRow = endOf(sf);<a name="line.396"></a>
-<span class="sourceLineNo">397</span>      // Validate the range and put the files into place.<a name="line.397"></a>
-<span class="sourceLineNo">398</span>      if (isInvalid(startRow) || isInvalid(endRow)) {<a name="line.398"></a>
-<span class="sourceLineNo">399</span>        insertFileIntoStripe(level0Files, sf); // No metadata - goes to L0.<a name="line.399"></a>
-<span class="sourceLineNo">400</span>        ensureLevel0Metadata(sf);<a name="line.400"></a>
-<span class="sourceLineNo">401</span>      } else if (!isOpen(startRow) &amp;&amp; !isOpen(endRow) &amp;&amp;<a name="line.401"></a>
-<span class="sourceLineNo">402</span>          nonOpenRowCompare(startRow, endRow) &gt;= 0) {<a name="line.402"></a>
-<span class="sourceLineNo">403</span>        LOG.error("Unexpected metadata - start row [" + Bytes.toString(startRow) + "], end row ["<a name="line.403"></a>
-<span class="sourceLineNo">404</span>          + Bytes.toString(endRow) + "] in file [" + sf.getPath() + "], pushing to L0");<a name="line.404"></a>
-<span class="sourceLineNo">405</span>        insertFileIntoStripe(level0Files, sf); // Bad metadata - goes to L0 also.<a name="line.405"></a>
-<span class="sourceLineNo">406</span>        ensureLevel0Metadata(sf);<a name="line.406"></a>
-<span class="sourceLineNo">407</span>      } else {<a name="line.407"></a>
-<span class="sourceLineNo">408</span>        ArrayList&lt;StoreFile&gt; stripe = candidateStripes.get(endRow);<a name="line.408"></a>
-<span class="sourceLineNo">409</span>        if (stripe == null) {<a name="line.409"></a>
-<span class="sourceLineNo">410</span>          stripe = new ArrayList&lt;&gt;();<a name="line.410"></a>
-<span class="sourceLineNo">411</span>          candidateStripes.put(endRow, stripe);<a name="line.411"></a>
-<span class="sourceLineNo">412</span>        }<a name="line.412"></a>
-<span class="sourceLineNo">413</span>        insertFileIntoStripe(stripe, sf);<a name="line.413"></a>
-<span class="sourceLineNo">414</span>      }<a name="line.414"></a>
-<span class="sourceLineNo">415</span>    }<a name="line.415"></a>
-<span class="sourceLineNo">416</span>    // Possible improvement - for variable-count stripes, if all the files are in L0, we can<a name="line.416"></a>
-<span class="sourceLineNo">417</span>    // instead create single, open-ended stripe with all files.<a name="line.417"></a>
-<span class="sourceLineNo">418</span><a name="line.418"></a>
-<span class="sourceLineNo">419</span>    boolean hasOverlaps = false;<a name="line.419"></a>
-<span class="sourceLineNo">420</span>    byte[] expectedStartRow = null; // first stripe can start wherever<a name="line.420"></a>
-<span class="sourceLineNo">421</span>    Iterator&lt;Map.Entry&lt;byte[], ArrayList&lt;StoreFile&gt;&gt;&gt; entryIter =<a name="line.421"></a>
-<span class="sourceLineNo">422</span>        candidateStripes.entrySet().iterator();<a name="line.422"></a>
-<span class="sourceLineNo">423</span>    while (entryIter.hasNext()) {<a name="line.423"></a>
-<span class="sourceLineNo">424</span>      Map.Entry&lt;byte[], ArrayList&lt;StoreFile&gt;&gt; entry = entryIter.next();<a name="line.424"></a>
-<span class="sourceLineNo">425</span>      ArrayList&lt;StoreFile&gt; files = entry.getValue();<a name="line.425"></a>
-<span class="sourceLineNo">426</span>      // Validate the file start rows, and remove the bad ones to level 0.<a name="line.426"></a>
-<span class="sourceLineNo">427</span>      for (int i = 0; i &lt; files.size(); ++i) {<a name="line.427"></a>
-<span class="sourceLineNo">428</span>        StoreFile sf = files.get(i);<a name="line.428"></a>
-<span class="sourceLineNo">429</span>        byte[] startRow = startOf(sf);<a name="line.429"></a>
-<span class="sourceLineNo">430</span>        if (expectedStartRow == null) {<a name="line.430"></a>
-<span class="sourceLineNo">431</span>          expectedStartRow = startRow; // ensure that first stripe is still consistent<a name="line.431"></a>
-<span class="sourceLineNo">432</span>        } else if (!rowEquals(expectedStartRow, startRow)) {<a name="line.432"></a>
-<span class="sourceLineNo">433</span>          hasOverlaps = true;<a name="line.433"></a>
-<span class="sourceLineNo">434</span>          LOG.warn("Store file doesn't fit into the tentative stripes - expected to start at ["<a name="line.434"></a>
-<span class="sourceLineNo">435</span>              + Bytes.toString(expectedStartRow) + "], but starts at [" + Bytes.toString(startRow)<a name="line.435"></a>
-<span class="sourceLineNo">436</span>              + "], to L0 it goes");<a name="line.436"></a>
-<span class="sourceLineNo">437</span>          StoreFile badSf = files.remove(i);<a name="line.437"></a>
-<span class="sourceLineNo">438</span>          insertFileIntoStripe(level0Files, badSf);<a name="line.438"></a>
-<span class="sourceLineNo">439</span>          ensureLevel0Metadata(badSf);<a name="line.439"></a>
-<span class="sourceLineNo">440</span>          --i;<a name="line.440"></a>
-<span class="sourceLineNo">441</span>        }<a name="line.441"></a>
-<span class="sourceLineNo">442</span>      }<a name="line.442"></a>
-<span class="sourceLineNo">443</span>      // Check if any files from the candidate stripe are valid. If so, add a stripe.<a name="line.443"></a>
-<span class="sourceLineNo">444</span>      byte[] endRow = entry.getKey();<a name="line.444"></a>
-<span class="sourceLineNo">445</span>      if (!files.isEmpty()) {<a name="line.445"></a>
-<span class="sourceLineNo">446</span>        expectedStartRow = endRow; // Next stripe must start exactly at that key.<a name="line.446"></a>
-<span class="sourceLineNo">447</span>      } else {<a name="line.447"></a>
-<span class="sourceLineNo">448</span>        entryIter.remove();<a name="line.448"></a>
-<span class="sourceLineNo">449</span>      }<a name="line.449"></a>
-<span class="sourceLineNo">450</span>    }<a name="line.450"></a>
-<span class="sourceLineNo">451</span><a name="line.451"></a>
-<span class="sourceLineNo">452</span>    // In the end, there must be open ends on two sides. If not, and there were no errors i.e.<a name="line.452"></a>
-<span class="sourceLineNo">453</span>    // files are consistent, they might be coming from a split. We will treat the boundaries<a name="line.453"></a>
-<span class="sourceLineNo">454</span>    // as open keys anyway, and log the message.<a name="line.454"></a>
-<span class="sourceLineNo">455</span>    // If there were errors, we'll play it safe and dump everything into L0.<a name="line.455"></a>
-<span class="sourceLineNo">456</span>    if (!candidateStripes.isEmpty()) {<a name="line.456"></a>
-<span class="sourceLineNo">457</span>      StoreFile firstFile = candidateStripes.firstEntry().getValue().get(0);<a name="line.457"></a>
-<span class="sourceLineNo">458</span>      boolean isOpen = isOpen(startOf(firstFile)) &amp;&amp; isOpen(candidateStripes.lastKey());<a name="line.458"></a>
-<span class="sourceLineNo">459</span>      if (!isOpen) {<a name="line.459"></a>
-<span class="sourceLineNo">460</span>        LOG.warn("The range of the loaded files does not cover full key space: from ["<a name="line.460"></a>
-<span class="sourceLineNo">461</span>            + Bytes.toString(startOf(firstFile)) + "], to ["<a name="line.461"></a>
-<span class="sourceLineNo">462</span>            + Bytes.toString(candidateStripes.lastKey()) + "]");<a name="line.462"></a>
-<span class="sourceLineNo">463</span>        if (!hasOverlaps) {<a name="line.463"></a>
-<span class="sourceLineNo">464</span>          ensureEdgeStripeMetadata(candidateStripes.firstEntry().getValue(), true);<a name="line.464"></a>
-<span class="sourceLineNo">465</span>          ensureEdgeStripeMetadata(candidateStripes.lastEntry().getValue(), false);<a name="line.465"></a>
-<span class="sourceLineNo">466</span>        } else {<a name="line.466"></a>
-<span class="sourceLineNo">467</span>          LOG.warn("Inconsistent files, everything goes to L0.");<a name="line.467"></a>
-<span class="sourceLineNo">468</span>          for (ArrayList&lt;StoreFile&gt; files : candidateStripes.values()) {<a name="line.468"></a>
-<span class="sourceLineNo">469</span>            for (StoreFile sf : files) {<a name="line.469"></a>
-<span class="sourceLineNo">470</span>              insertFileIntoStripe(level0Files, sf);<a name="line.470"></a>
-<span class="sourceLineNo">471</span>              ensureLevel0Metadata(sf);<a name="line.471"></a>
-<span class="sourceLineNo">472</span>            }<a name="line.472"></a>
-<span class="sourceLineNo">473</span>          }<a name="line.473"></a>
-<span class="sourceLineNo">474</span>          candidateStripes.clear();<a name="line.474"></a>
-<span class="sourceLineNo">475</span>        }<a name="line.475"></a>
-<span class="sourceLineNo">476</span>      }<a name="line.476"></a>
-<span class="sourceLineNo">477</span>    }<a name="line.477"></a>
-<span class="sourceLineNo">478</span><a name="line.478"></a>
-<span class="sourceLineNo">479</span>    // Copy the results into the fields.<a name="line.479"></a>
-<span class="sourceLineNo">480</span>    State state = new State();<a name="line.480"></a>
-<span class="sourceLineNo">481</span>    state.level0Files = ImmutableList.copyOf(level0Files);<a name="line.481"></a>
-<span class="sourceLineNo">482</span>    state.stripeFiles = new ArrayList&lt;&gt;(candidateStripes.size());<a name="line.482"></a>
-<span class="sourceLineNo">483</span>    state.stripeEndRows = new byte[Math.max(0, candidateStripes.size() - 1)][];<a name="line.483"></a>
-<span class="sourceLineNo">484</span>    ArrayList&lt;StoreFile&gt; newAllFiles = new ArrayList&lt;&gt;(level0Files);<a name="line.484"></a>
-<span class="sourceLineNo">485</span>    int i = candidateStripes.size() - 1;<a name="line.485"></a>
-<span class="sourceLineNo">486</span>    for (Map.Entry&lt;byte[], ArrayList&lt;StoreFile&gt;&gt; entry : candidateStripes.entrySet()) {<a name="line.486"></a>
-<span class="sourceLineNo">487</span>      state.stripeFiles.add(ImmutableList.copyOf(entry.getValue()));<a name="line.487"></a>
-<span class="sourceLineNo">488</span>      newAllFiles.addAll(entry.getValue());<a name="line.488"></a>
-<span class="sourceLineNo">489</span>      if (i &gt; 0) {<a name="line.489"></a>
-<span class="sourceLineNo">490</span>        state.stripeEndRows[state.stripeFiles.size() - 1] = entry.getKey();<a name="line.490"></a>
-<span class="sourceLineNo">491</span>      }<a name="line.491"></a>
-<span class="sourceLineNo">492</span>      --i;<a name="line.492"></a>
-<span class="sourceLineNo">493</span>    }<a name="line.493"></a>
-<span class="sourceLineNo">494</span>    state.allFilesCached = ImmutableList.copyOf(newAllFiles);<a name="line.494"></a>
-<span class="sourceLineNo">495</span>    this.state = state;<a name="line.495"></a>
-<span class="sourceLineNo">496</span>    debugDumpState("Files loaded");<a name="line.496"></a>
-<span class="sourceLineNo">497</span>  }<a name="line.497"></a>
-<span class="sourceLineNo">498</span><a name="line.498"></a>
-<span class="sourceLineNo">499</span>  private void ensureEdgeStripeMetadata(ArrayList&lt;StoreFile&gt; stripe, boolean isFirst) {<a name="line.499"></a>
-<span class="sourceLineNo">500</span>    HashMap&lt;StoreFile, byte[]&gt; targetMap = isFirst ? fileStarts : fileEnds;<a name="line.500"></a>
-<span class="sourceLineNo">501</span>    for (StoreFile sf : stripe) {<a name="line.501"></a>
-<span class="sourceLineNo">502</span>      targetMap.put(sf, OPEN_KEY);<a name="line.502"></a>
-<span class="sourceLineNo">503</span>    }<a name="line.503"></a>
-<span class="sourceLineNo">504</span>  }<a name="line.504"></a>
-<span class="sourceLineNo">505</span><a name="line.505"></a>
-<span class="sourceLineNo">506</span>  private void ensureLevel0Metadata(StoreFile sf) {<a name="line.506"></a>
-<span class="sourceLineNo">507</span>    if (!isInvalid(startOf(sf))) this.fileStarts.put(sf, INVALID_KEY_IN_MAP);<a name="line.507"></a>
-<span class="sourceLineNo">508</span>    if (!isInvalid(endOf(sf))) this.fileEnds.put(sf, INVALID_KEY_IN_MAP);<a name="line.508"></a>
+<span class="sourceLineNo">178</span>  @Override<a name="line.178"></a>
+<span class="sourceLineNo">179</span>  public int getStorefileCount() {<a name="line.179"></a>
+<span class="sourceLineNo">180</span>    return state.allFilesCached.size();<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>  /** See {@link StoreFileManager#getCandidateFilesForRowKeyBefore(KeyValue)}<a name="line.183"></a>
+<span class="sourceLineNo">184</span>   * for details on this methods. */<a name="line.184"></a>
+<span class="sourceLineNo">185</span>  @Override<a name="line.185"></a>
+<span class="sourceLineNo">186</span>  public Iterator&lt;StoreFile&gt; getCandidateFilesForRowKeyBefore(final KeyValue targetKey) {<a name="line.186"></a>
+<span class="sourceLineNo">187</span>    KeyBeforeConcatenatedLists result = new KeyBeforeConcatenatedLists();<a name="line.187"></a>
+<span class="sourceLineNo">188</span>    // Order matters for this call.<a name="line.188"></a>
+<span class="sourceLineNo">189</span>    result.addSublist(state.level0Files);<a name="line.189"></a>
+<span class="sourceLineNo">190</span>    if (!state.stripeFiles.isEmpty()) {<a name="line.190"></a>
+<span class="sourceLineNo">191</span>      int lastStripeIndex = findStripeForRow(CellUtil.cloneRow(targetKey), false);<a name="line.191"></a>
+<span class="sourceLineNo">192</span>      for (int stripeIndex = lastStripeIndex; stripeIndex &gt;= 0; --stripeIndex) {<a name="line.192"></a>
+<span class="sourceLineNo">193</span>        result.addSublist(state.stripeFiles.get(stripeIndex));<a name="line.193"></a>
+<span class="sourceLineNo">194</span>      }<a name="line.194"></a>
+<span class="sourceLineNo">195</span>    }<a name="line.195"></a>
+<span class="sourceLineNo">196</span>    return result.iterator();<a name="line.196"></a>
+<span class="sourceLineNo">197</span>  }<a name="line.197"></a>
+<span class="sourceLineNo">198</span><a name="line.198"></a>
+<span class="sourceLineNo">199</span>  /** See {@link StoreFileManager#getCandidateFilesForRowKeyBefore(KeyValue)} and<a name="line.199"></a>
+<span class="sourceLineNo">200</span>   * {@link StoreFileManager#updateCandidateFilesForRowKeyBefore(Iterator, KeyValue, Cell)}<a name="line.200"></a>
+<span class="sourceLineNo">201</span>   * for details on this methods. */<a name="line.201"></a>
+<span class="sourceLineNo">202</span>  @Override<a name="line.202"></a>
+<span class="sourceLineNo">203</span>  public Iterator&lt;StoreFile&gt; updateCandidateFilesForRowKeyBefore(<a name="line.203"></a>
+<span class="sourceLineNo">204</span>      Iterator&lt;StoreFile&gt; candidateFiles, final KeyValue targetKey, final Cell candidate) {<a name="line.204"></a>
+<span class="sourceLineNo">205</span>    KeyBeforeConcatenatedLists.Iterator original =<a name="line.205"></a>
+<span class="sourceLineNo">206</span>        (KeyBeforeConcatenatedLists.Iterator)candidateFiles;<a name="line.206"></a>
+<span class="sourceLineNo">207</span>    assert original != null;<a name="line.207"></a>
+<span class="sourceLineNo">208</span>    ArrayList&lt;List&lt;StoreFile&gt;&gt; components = original.getComponents();<a name="line.208"></a>
+<span class="sourceLineNo">209</span>    for (int firstIrrelevant = 0; firstIrrelevant &lt; components.size(); ++firstIrrelevant) {<a name="line.209"></a>
+<span class="sourceLineNo">210</span>      StoreFile sf = components.get(firstIrrelevant).get(0);<a name="line.210"></a>
+<span class="sourceLineNo">211</span>      byte[] endKey = endOf(sf);<a name="line.211"></a>
+<span class="sourceLineNo">212</span>      // Entries are ordered as such: L0, then stripes in reverse order. We never remove<a name="line.212"></a>
+<span class="sourceLineNo">213</span>      // level 0; we remove the stripe, and all subsequent ones, as soon as we find the<a name="line.213"></a>
+<span class="sourceLineNo">214</span>      // first one that cannot possibly have better candidates.<a name="line.214"></a>
+<span class="sourceLineNo">215</span>      if (!isInvalid(endKey) &amp;&amp; !isOpen(endKey)<a name="line.215"></a>
+<span class="sourceLineNo">216</span>          &amp;&amp; (nonOpenRowCompare(targetKey, endKey) &gt;= 0)) {<a name="line.216"></a>
+<span class="sourceLineNo">217</span>        original.removeComponents(firstIrrelevant);<a name="line.217"></a>
+<span class="sourceLineNo">218</span>        break;<a name="line.218"></a>
+<span class="sourceLineNo">219</span>      }<a name="line.219"></a>
+<span class="sourceLineNo">220</span>    }<a name="line.220"></a>
+<span class="sourceLineNo">221</span>    return original;<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>  private byte[] getSplitPoint(Collection&lt;StoreFile&gt; sfs) throws IOException {<a name="line.224"></a>
+<span class="sourceLineNo">225</span>    Optional&lt;StoreFile&gt; largestFile = StoreUtils.getLargestFile(sfs);<a name="line.225"></a>
+<span class="sourceLineNo">226</span>    return largestFile.isPresent()<a name="line.226"></a>
+<span class="sourceLineNo">227</span>        ? StoreUtils.getFileSplitPoint(largestFile.get(), cellComparator).orElse(null) : null;<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>   * Override of getSplitPoint that determines the split point as the boundary between two<a name="line.231"></a>
+<span class="sourceLineNo">232</span>   * stripes, unless it causes significant imbalance between split sides' sizes. In that<a name="line.232"></a>
+<span class="sourceLineNo">233</span>   * case, the split boundary will be chosen from the middle of one of the stripes to<a name="line.233"></a>
+<span class="sourceLineNo">234</span>   * minimize imbalance.<a name="line.234"></a>
+<span class="sourceLineNo">235</span>   * @return The split point, or null if no split is possible.<a name="line.235"></a>
+<span class="sourceLineNo">236</span>   */<a name="line.236"></a>
+<span class="sourceLineNo">237</span>  @Override<a name="line.237"></a>
+<span class="sourceLineNo">238</span>  public byte[] getSplitPoint() throws IOException {<a name="line.238"></a>
+<span class="sourceLineNo">239</span>    if (this.getStorefileCount() == 0) return null;<a name="line.239"></a>
+<span class="sourceLineNo">240</span>    if (state.stripeFiles.size() &lt;= 1) {<a name="line.240"></a>
+<span class="sourceLineNo">241</span>      return getSplitPointFromAllFiles();<a name="line.241"></a>
+<span class="sourceLineNo">242</span>    }<a name="line.242"></a>
+<span class="sourceLineNo">243</span>    int leftIndex = -1, rightIndex = state.stripeFiles.size();<a name="line.243"></a>
+<span class="sourceLineNo">244</span>    long leftSize = 0, rightSize = 0;<a name="line.244"></a>
+<span class="sourceLineNo">245</span>    long lastLeftSize = 0, lastRightSize = 0;<a name="line.245"></a>
+<span class="sourceLineNo">246</span>    while (rightIndex - 1 != leftIndex) {<a name="line.246"></a>
+<span class="sourceLineNo">247</span>      if (leftSize &gt;= rightSize) {<a name="line.247"></a>
+<span class="sourceLineNo">248</span>        --rightIndex;<a name="line.248"></a>
+<span class="sourceLineNo">249</span>        lastRightSize = getStripeFilesSize(rightIndex);<a name="line.249"></a>
+<span class="sourceLineNo">250</span>        rightSize += lastRightSize;<a name="line.250"></a>
+<span class="sourceLineNo">251</span>      } else {<a name="line.251"></a>
+<span class="sourceLineNo">252</span>        ++leftIndex;<a name="line.252"></a>
+<span class="sourceLineNo">253</span>        lastLeftSize = getStripeFilesSize(leftIndex);<a name="line.253"></a>
+<span class="sourceLineNo">254</span>        leftSize += lastLeftSize;<a name="line.254"></a>
+<span class="sourceLineNo">255</span>      }<a name="line.255"></a>
+<span class="sourceLineNo">256</span>    }<a name="line.256"></a>
+<span class="sourceLineNo">257</span>    if (leftSize == 0 || rightSize == 0) {<a name="line.257"></a>
+<span class="sourceLineNo">258</span>      String errMsg = String.format("Cannot split on a boundary - left index %d size %d, "<a name="line.258"></a>
+<span class="sourceLineNo">259</span>          + "right index %d size %d", leftIndex, leftSize, rightIndex, rightSize);<a name="line.259"></a>
+<span class="sourceLineNo">260</span>      debugDumpState(errMsg);<a name="line.260"></a>
+<span class="sourceLineNo">261</span>      LOG.warn(errMsg);<a name="line.261"></a>
+<span class="sourceLineNo">262</span>      return getSplitPointFromAllFiles();<a name="line.262"></a>
+<span class="sourceLineNo">263</span>    }<a name="line.263"></a>
+<span class="sourceLineNo">264</span>    double ratio = (double)rightSize / leftSize;<a name="line.264"></a>
+<span class="sourceLineNo">265</span>    if (ratio &lt; 1) {<a name="line.265"></a>
+<span class="sourceLineNo">266</span>      ratio = 1 / ratio;<a name="line.266"></a>
+<span class="sourceLineNo">267</span>    }<a name="line.267"></a>
+<span class="sourceLineNo">268</span>    if (config.getMaxSplitImbalance() &gt; ratio) return state.stripeEndRows[leftIndex];<a name="line.268"></a>
+<span class="sourceLineNo">269</span><a name="line.269"></a>
+<span class="sourceLineNo">270</span>    // If the difference between the sides is too large, we could get the proportional key on<a name="line.270"></a>
+<span class="sourceLineNo">271</span>    // the a stripe to equalize the difference, but there's no proportional key method at the<a name="line.271"></a>
+<span class="sourceLineNo">272</span>    // moment, and it's not extremely important.<a name="line.272"></a>
+<span class="sourceLineNo">273</span>    // See if we can achieve better ratio if we split the bigger side in half.<a name="line.273"></a>
+<span class="sourceLineNo">274</span>    boolean isRightLarger = rightSize &gt;= leftSize;<a name="line.274"></a>
+<span class="sourceLineNo">275</span>    double newRatio = isRightLarger<a name="line.275"></a>
+<span class="sourceLineNo">276</span>        ? getMidStripeSplitRatio(leftSize, rightSize, lastRightSize)<a name="line.276"></a>
+<span class="sourceLineNo">277</span>        : getMidStripeSplitRatio(rightSize, leftSize, lastLeftSize);<a name="line.277"></a>
+<span class="sourceLineNo">278</span>    if (newRatio &lt; 1) {<a name="line.278"></a>
+<span class="sourceLineNo">279</span>      newRatio = 1 / newRatio;<a name="line.279"></a>
+<span class="sourceLineNo">280</span>    }<a name="line.280"></a>
+<span class="sourceLineNo">281</span>    if (newRatio &gt;= ratio)  return state.stripeEndRows[leftIndex];<a name="line.281"></a>
+<span class="sourceLineNo">282</span>    LOG.debug("Splitting the stripe - ratio w/o split " + ratio + ", ratio with split "<a name="line.282"></a>
+<span class="sourceLineNo">283</span>        + newRatio + " configured ratio " + config.getMaxSplitImbalance());<a name="line.283"></a>
+<span class="sourceLineNo">284</span>    // Ok, we may get better ratio, get it.<a name="line.284"></a>
+<span class="sourceLineNo">285</span>    return getSplitPoint(state.stripeFiles.get(isRightLarger ? rightIndex : leftIndex));<a name="line.285"></a>
+<span class="sourceLineNo">286</span>  }<a name="line.286"></a>
+<span class="sourceLineNo">287</span><a name="line.287"></a>
+<span class="sourceLineNo">288</span>  private byte[] getSplitPointFromAllFiles() throws IOException {<a name="line.288"></a>
+<span class="sourceLineNo">289</span>    ConcatenatedLists&lt;StoreFile&gt; sfs = new ConcatenatedLists&lt;&gt;();<a name="line.289"></a>
+<span class="sourceLineNo">290</span>    sfs.addSublist(state.level0Files);<a name="line.290"></a>
+<span class="sourceLineNo">291</span>    sfs.addAllSublists(state.stripeFiles);<a name="line.291"></a>
+<span class="sourceLineNo">292</span>    return getSplitPoint(sfs);<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>  private double getMidStripeSplitRatio(long smallerSize, long largerSize, long lastLargerSize) {<a name="line.295"></a>
+<span class="sourceLineNo">296</span>    return (double)(largerSize - lastLargerSize / 2f) / (smallerSize + lastLargerSize / 2f);<a name="line.296"></a>
+<span class="sourceLineNo">297</span>  }<a name="line.297"></a>
+<span class="sourceLineNo">298</span><a name="line.298"></a>
+<span class="sourceLineNo">299</span>  @Override<a name="line.299"></a>
+<span class="sourceLineNo">300</span>  public Collection&lt;StoreFile&gt; getFilesForScan(byte[] startRow, boolean includeStartRow,<a name="line.300"></a>
+<span class="sourceLineNo">301</span>      byte[] stopRow, boolean includeStopRow) {<a name="line.301"></a>
+<span class="sourceLineNo">302</span>    if (state.stripeFiles.isEmpty()) {<a name="line.302"></a>
+<span class="sourceLineNo">303</span>      return state.level0Files; // There's just L0.<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>    int firstStripe = findStripeForRow(startRow, true);<a name="line.306"></a>
+<span class="sourceLineNo">307</span>    int lastStripe = findStripeForRow(stopRow, false);<a name="line.307"></a>
+<span class="sourceLineNo">308</span>    assert firstStripe &lt;= lastStripe;<a name="line.308"></a>
+<span class="sourceLineNo">309</span>    if (firstStripe == lastStripe &amp;&amp; state.level0Files.isEmpty()) {<a name="line.309"></a>
+<span class="sourceLineNo">310</span>      return state.stripeFiles.get(firstStripe); // There's just one stripe we need.<a name="line.310"></a>
+<span class="sourceLineNo">311</span>    }<a name="line.311"></a>
+<span class="sourceLineNo">312</span>    if (firstStripe == 0 &amp;&amp; lastStripe == (state.stripeFiles.size() - 1)) {<a name="line.312"></a>
+<span class="sourceLineNo">313</span>      return state.allFilesCached; // We need to read all files.<a name="line.313"></a>
+<span class="sourceLineNo">314</span>    }<a name="line.314"></a>
+<span class="sourceLineNo">315</span><a name="line.315"></a>
+<span class="sourceLineNo">316</span>    ConcatenatedLists&lt;StoreFile&gt; result = new ConcatenatedLists&lt;&gt;();<a name="line.316"></a>
+<span class="sourceLineNo">317</span>    result.addAllSublists(state.stripeFiles.subList(firstStripe, lastStripe + 1));<a name="line.317"></a>
+<span class="sourceLineNo">318</span>    result.addSublist(state.level0Files);<a name="line.318"></a>
+<span class="sourceLineNo">319</span>    return result;<a name="line.319"></a>
+<span class="sourceLineNo">320</span>  }<a name="line.320"></a>
+<span class="sourceLineNo">321</span><a name="line.321"></a>
+<span class="sourceLineNo">322</span>  @Override<a name="line.322"></a>
+<span class="sourceLineNo">323</span>  public void addCompactionResults(<a name="line.323"></a>
+<span class="sourceLineNo">324</span>    Collection&lt;StoreFile&gt; compactedFiles, Collection&lt;StoreFile&gt; results) throws IOException {<a name="line.324"></a>
+<span class="sourceLineNo">325</span>    // See class comment for the assumptions we make here.<a name="line.325"></a>
+<span class="sourceLineNo">326</span>    LOG.debug("Attempting to merge compaction results: " + compactedFiles.size()<a name="line.326"></a>
+<span class="sourceLineNo">327</span>        + " files replaced by " + results.size());<a name="line.327"></a>
+<span class="sourceLineNo">328</span>    // In order to be able to fail in the middle of the operation, we'll operate on lazy<a name="line.328"></a>
+<span class="sourceLineNo">329</span>    // copies and apply the result at the end.<a name="line.329"></a>
+<span class="sourceLineNo">330</span>    CompactionOrFlushMergeCopy cmc = new CompactionOrFlushMergeCopy(false);<a name="line.330"></a>
+<span class="sourceLineNo">331</span>    cmc.mergeResults(compactedFiles, results);<a name="line.331"></a>
+<span class="sourceLineNo">332</span>    markCompactedAway(compactedFiles);<a name="line.332"></a>
+<span class="sourceLineNo">333</span>    debugDumpState("Merged compaction results");<a name="line.333"></a>
+<span class="sourceLineNo">334</span>  }<a name="line.334"></a>
+<span class="sourceLineNo">335</span><a name="line.335"></a>
+<span class="sourceLineNo">336</span>  // Mark the files as compactedAway once the storefiles and compactedfiles list is finalised<a name="line.336"></a>
+<span class="sourceLineNo">337</span>  // Let a background thread close the actual reader on these compacted files and also<a name="line.337"></a>
+<span class="sourceLineNo">338</span>  // ensure to evict the blocks from block cache so that they are no longer in<a name="line.338"></a>
+<span class="sourceLineNo">339</span>  // cache<a name="line.339"></a>
+<span class="sourceLineNo">340</span>  private void markCompactedAway(Collection&lt;StoreFile&gt; compactedFiles) {<a name="line.340"></a>
+<span class="sourceLineNo">341</span>    for (StoreFile file : compactedFiles) {<a name="line.341"></a>
+<span class="sourceLineNo">342</span>      file.markCompactedAway();<a name="line.342"></a>
+<span class="sourceLineNo">343</span>    }<a name="line.343"></a>
+<span class="sourceLineNo">344</span>  }<a name="line.344"></a>
+<span class="sourceLineNo">345</span><a name="line.345"></a>
+<span class="sourceLineNo">346</span>  @Override<a name="line.346"></a>
+<span class="sourceLineNo">347</span>  public void removeCompactedFiles(Collection&lt;StoreFile&gt; compactedFiles) throws IOException {<a name="line.347"></a>
+<span class="sourceLineNo">348</span>    // See class comment for the assumptions we make here.<a name="line.348"></a>
+<span class="sourceLineNo">349</span>    LOG.debug("Attempting to delete compaction results: " + compactedFiles.size());<a name="line.349"></a>
+<span class="sourceLineNo">350</span>    // In order to be able to fail in the middle of the operation, we'll operate on lazy<a name="line.350"></a>
+<span class="sourceLineNo">351</span>    // copies and apply the result at the end.<a name="line.351"></a>
+<span class="sourceLineNo">352</span>    CompactionOrFlushMergeCopy cmc = new CompactionOrFlushMergeCopy(false);<a name="line.352"></a>
+<span class="sourceLineNo">353</span>    cmc.deleteResults(compactedFiles);<a name="line.353"></a>
+<span class="sourceLineNo">354</span>    debugDumpState("Deleted compaction results");<a name="line.354"></a>
+<span class="sourceLineNo">355</span>  }<a name="line.355"></a>
+<span class="sourceLineNo">356</span><a name="line.356"></a>
+<span class="sourceLineNo">357</span>  @Override<a name="line.357"></a>
+<span class="sourceLineNo">358</span>  public int getStoreCompactionPriority() {<a name="line.358"></a>
+<span class="sourceLineNo">359</span>    // If there's only L0, do what the default store does.<a name="line.359"></a>
+<span class="sourceLineNo">360</span>    // If we are in critical priority, do the same - we don't want to trump all stores all<a name="line.360"></a>
+<span class="sourceLineNo">361</span>    // the time due to how many files we have.<a name="line.361"></a>
+<span class="sourceLineNo">362</span>    int fc = getStorefileCount();<a name="line.362"></a>
+<span class="sourceLineNo">363</span>    if (state.stripeFiles.isEmpty() || (this.blockingFileCount &lt;= fc)) {<a name="line.363"></a>
+<span class="sourceLineNo">364</span>      return this.blockingFileCount - fc;<a name="line.364"></a>
+<span class="sourceLineNo">365</span>    }<a name="line.365"></a>
+<span class="sourceLineNo">366</span>    // If we are in good shape, we don't want to be trumped by all other stores due to how<a name="line.366"></a>
+<span class="sourceLineNo">367</span>    // many files we have, so do an approximate mapping to normal priority range; L0 counts<a name="line.367"></a>
+<span class="sourceLineNo">368</span>    // for all stripes.<a name="line.368"></a>
+<span class="sourceLineNo">369</span>    int l0 = state.level0Files.size(), sc = state.stripeFiles.size();<a name="line.369"></a>
+<span class="sourceLineNo">370</span>    int priority = (int)Math.ceil(((double)(this.blockingFileCount - fc + l0) / sc) - l0);<a name="line.370"></a>
+<span class="sourceLineNo">371</span>    return (priority &lt;= HStore.PRIORITY_USER) ? (HStore.PRIORITY_USER + 1) : priority;<a name="line.371"></a>
+<span class="sourceLineNo">372</span>  }<a name="line.372"></a>
+<span class="sourceLineNo">373</span><a name="line.373"></a>
+<span class="sourceLineNo">374</span>  /**<a name="line.374"></a>
+<span class="sourceLineNo">375</span>   * Gets the total size of all files in the stripe.<a name="line.375"></a>
+<span class="sourceLineNo">376</span>   * @param stripeIndex Stripe index.<a name="line.376"></a>
+<span class="sourceLineNo">377</span>   * @return Size.<a name="line.377"></a>
+<span class="sourceLineNo">378</span>   */<a name="line.378"></a>
+<span class="sourceLineNo">379</span>  private long getStripeFilesSize(int stripeIndex) {<a name="line.379"></a>
+<span class="sourceLineNo">380</span>    long result = 0;<a name="line.380"></a>
+<span class="sourceLineNo">381</span>    for (StoreFile sf : state.stripeFiles.get(stripeIndex)) {<a name="line.381"></a>
+<span class="sourceLineNo">382</span>      result += sf.getReader().length();<a name="line.382"></a>
+<span class="sourceLineNo">383</span>    }<a name="line.383"></a>
+<span class="sourceLineNo">384</span>    return result;<a name="line.384"></a>
+<span class="sourceLineNo">385</span>  }<a name="line.385"></a>
+<span class="sourceLineNo">386</span><a name="line.386"></a>
+<span class="sourceLineNo">387</span>  /**<a name="line.387"></a>
+<span class="sourceLineNo">388</span>   * Loads initial store files that were picked up from some physical location pertaining to<a name="line.388"></a>
+<span class="sourceLineNo">389</span>   * this store (presumably). Unlike adding files after compaction, assumes empty initial<a name="line.389"></a>
+<span class="sourceLineNo">390</span>   * sets, and is forgiving with regard to stripe constraints - at worst, many/all files will<a name="line.390"></a>
+<span class="sourceLineNo">391</span>   * go to level 0.<a name="line.391"></a>
+<span class="sourceLineNo">392</span>   * @param storeFiles Store files to add.<a name="line.392"></a>
+<span class="sourceLineNo">393</span>   */<a name="line.393"></a>
+<span class="sourceLineNo">394</span>  private void loadUnclassifiedStoreFiles(List&lt;StoreFile&gt; storeFiles) {<a name="line.394"></a>
+<span class="sourceLineNo">395</span>    LOG.debug("Attempting to load " + storeFiles.size() + " store files.");<a name="line.395"></a>
+<span class="sourceLineNo">396</span>    TreeMap&lt;byte[], ArrayList&lt;StoreFile&gt;&gt; candidateStripes = new TreeMap&lt;&gt;(MAP_COMPARATOR);<a name="line.396"></a>
+<span class="sourceLineNo">397</span>    ArrayList&lt;StoreFile&gt; level0Files = new ArrayList&lt;&gt;();<a name="line.397"></a>
+<span class="sourceLineNo">398</span>    // Separate the files into tentative stripes; then validate. Currently, we rely on metadata.<a name="line.398"></a>
+<span class="sourceLineNo">399</span>    // If needed, we could dynamically determine the stripes in future.<a name="line.399"></a>
+<span class="sourceLineNo">400</span>    for (StoreFile sf : storeFiles) {<a name="line.400"></a>
+<span class="sourceLineNo">401</span>      byte[] startRow = startOf(sf), endRow = endOf(sf);<a name="line.401"></a>
+<span class="sourceLineNo">402</span>      // Validate the range and put the files into place.<a name="line.402"></a>
+<span class="sourceLineNo">403</span>      if (isInvalid(startRow) || isInvalid(endRow)) {<a name="line.403"></a>
+<span class="sourceLineNo">404</span>        insertFileIntoStripe(level0Files, sf); // No metadata - goes to L0.<a name="line.404"></a>
+<span class="sourceLineNo">405</span>        ensureLevel0Metadata(sf);<a name="line.405"></a>
+<span class="sourceLineNo">406</span>      } else if (!isOpen(startRow) &amp;&amp; !isOpen(endRow) &amp;&amp;<a name="line.406"></a>
+<span class="sourceLineNo">407</span>          nonOpenRowCompare(startRow, endRow) &gt;= 0) {<a name="line.407"></a>
+<span class="sourceLineNo">408</span>        LOG.error("Unexpected metadata - start row [" + Bytes.toString(startRow) + "], end row ["<a name="line.408"></a>
+<span class="sourceLineNo">409</span>          + Bytes.toString(endRow) + "] in file [" + sf.getPath() + "], pushing to L0");<a name="line.409"></a>
+<span class="sourceLineNo">410</span>        insertFileIntoStripe(level0Files, sf); // Bad metadata - goes to L0 also.<a name="line.410"></a>
+<span class="sourceLineNo">411</span>        ensureLevel0Metadata(sf);<a name="line.411"></a>
+<span class="sourceLineNo">412</span>      } else {<a name="line.412"></a>
+<span class="sourceLineNo">413</span>        ArrayList&lt;StoreFile&gt; stripe = candidateStripes.get(endRow);<a name="line.413"></a>
+<span class="sourceLineNo">414</span>        if (stripe == null) {<a name="line.414"></a>
+<span class="sourceLineNo">415</span>          stripe = new ArrayList&lt;&gt;();<a name="line.415"></a>
+<span class="sourceLineNo">416</span>          candidateStripes.put(endRow, stripe);<a name="line.416"></a>
+<span class="sourceLineNo">417</span>        }<a name="line.417"></a>
+<span class="sourceLineNo">418</span>        insertFileIntoStripe(stripe, sf);<a name="line.418"></a>
+<span class="sourceLineNo">419</span>      }<a name="line.419"></a>
+<span class="sourceLineNo">420</span>    }<a name="line.420"></a>
+<span class="sourceLineNo">421</span>    // Possible improvement - for variable-count stripes, if all the files are in L0, we can<a name="line.421"></a>
+<span class="sourceLineNo">422</span>    // instead create single, open-ended stripe with all files.<a name="line.422"></a>
+<span class="sourceLineNo">423</span><a name="line.423"></a>
+<span class="sourceLineNo">424</span>    boolean hasOverlaps = false;<a name="line.424"></a>
+<span class="sourceLineNo">425</span>    byte[] expectedStartRow = null; // first stripe can start wherever<a name="line.425"></a>
+<span class="sourceLineNo">426</span>    Iterator&lt;Map.Entry&lt;byte[], ArrayList&lt;StoreFile&gt;&gt;&gt; entryIter =<a name="line.426"></a>
+<span class="sourceLineNo">427</span>        candidateStripes.entrySet().iterator();<a name="line.427"></a>
+<span class="sourceLineNo">428</span>    while (entryIter.hasNext()) {<a name="line.428"></a>
+<span class="sourceLineNo">429</span>      Map.Entry&lt;byte[], ArrayList&lt;StoreFile&gt;&gt; entry = entryIter.next();<a name="line.429"></a>
+<span class="sourceLineNo">430</span>      ArrayList&lt;StoreFile&gt; files = entry.getValue();<a name="line.430"></a>
+<span class="sourceLineNo">431</span>      // Validate the file start rows, and remove the bad ones to level 0.<a name="line.431"></a>
+<span class="sourceLineNo">432</span>      for (int i = 0; i &lt; files.size(); ++i) {<a name="line.432"></a>
+<span class="sourceLineNo">433</span>        StoreFile sf = files.get(i);<a name="line.433"></a>
+<span class="sourceLineNo">434</span>        byte[] startRow = startOf(sf);<a name="line.434"></a>
+<span class="sourceLineNo">435</span>        if (expectedStartRow == null) {<a name="line.435"></a>
+<span class="sourceLineNo">436</span>          expectedStartRow = startRow; // ensure that first stripe is still consistent<a name="line.436"></a>
+<span class="sourceLineNo">437</span>        } else if (!rowEquals(expectedStartRow, startRow)) {<a name="line.437"></a>
+<span class="sourceLineNo">438</span>          hasOverlaps = true;<a name="line.438"></a>
+<span class="sourceLineNo">439</span>          LOG.warn("Store file doesn't fit into the tentative stripes - expected to start at ["<a name="line.439"></a>
+<span class="sourceLineNo">440</span>              + Bytes.toString(expectedStartRow) + "], but starts at [" + Bytes.toString(startRow)<a name="line.440"></a>
+<span class="sourceLineNo">441</span>              + "], to L0 it goes");<a name="line.441"></a>
+<span class="sourceLineNo">442</span>          StoreFile badSf = files.remove(i);<a name="line.442"></a>
+<span class="sourceLineNo">443</span>          insertFileIntoStripe(level0Files, badSf);<a name="line.443"></a>
+<span class="sourceLineNo">444</span>          ensureLevel0Metadata(badSf);<a name="line.444"></a>
+<span class="sourceLineNo">445</span>          --i;<a name="line.445"></a>
+<span class="sourceLineNo">446</span>        }<a name="line.446"></a>
+<span class="sourceLineNo">447</span>      }<a name="line.447"></a>
+<span class="sourceLineNo">448</span>      // Check if any files from the candidate stripe are valid. If so, add a stripe.<a name="line.448"></a>
+<span class="sourceLineNo">449</span>      byte[] endRow = entry.getKey();<a name="line.449"></a>
+<span class="sourceLineNo">450</span>      if (!files.isEmpty()) {<a name="line.450"></a>
+<span class="sourceLineNo">451</span>        expectedStartRow = endRow; // Next stripe must start exactly at that key.<a name="line.451"></a>
+<span class="sourceLineNo">452</span>      } else {<a name="line.452"></a>
+<span class="sourceLineNo">453</span>        entryIter.remove();<a name="line.453"></a>
+<span class="sourceLineNo">454</span>      }<a name="line.454"></a>
+<span class="sourceLineNo">455</span>    }<a name="line.455"></a>
+<span class="sourceLineNo">456</span><a name="line.456"></a>
+<span class="sourceLineNo">457</span>    // In the end, there must be open ends on two sides. If not, and there were no errors i.e.<a name="line.457"></a>
+<span class="sourceLineNo">458</span>    // files are consistent, they might be coming from a split. We will treat the boundaries<a name="line.458"></a>
+<span class="sourceLineNo">459</span>    // as open keys anyway, and log the message.<a name="line.459"></a>
+<span class="sourceLineNo">460</span>    // If there were errors, we'll play it safe and dump everything into L0.<a name="line.460"></a>
+<span class="sourceLineNo">461</span>    if (!candidateStripes.isEmpty()) {<a name="line.461"></a>
+<span class="sourceLineNo">462</span>      StoreFile firstFile = candidateStripes.firstEntry().getValue().get(0);<a name="line.462"></a>
+<span class="sourceLineNo">463</span>      boolean isOpen = isOpen(startOf(firstFile)) &amp;&amp; isOpen(candidateStripes.lastKey());<a name="line.463"></a>
+<span class="sourceLineNo">464</span>      if (!isOpen) {<a name="line.464"></a>
+<span class="sourceLineNo">465</span>        LOG.warn("The range of the loaded files does not cover full key space: from ["<a name="line.465"></a>
+<span class="sourceLineNo">466</span>            + Bytes.toString(startOf(firstFile)) + "], to ["<a name="line.466"></a>
+<span class="sourceLineNo">467</span>            + Bytes.toString(candidateStripes.lastKey()) + "]");<a name="line.467"></a>
+<span class="sourceLineNo">468</span>        if (!hasOverlaps) {<a name="line.468"></a>
+<span class="sourceLineNo">469</span>          ensureEdgeStripeMetadata(candidateStripes.firstEntry().getValue(), true);<a name="line.469"></a>
+<span class="sourceLineNo">470</span>          ensureEdgeStripeMetadata(candidateStripes.lastEntry().getValue(), false);<a name="line.470"></a>
+<span class="sourceLineNo">471</span>        } else {<a name="line.471"></a>
+<span class="sourceLineNo">472</span>          LOG.warn("Inconsistent files, everything goes to L0.");<a name="line.472"></a>
+<span class="sourceLineNo">473</span>          for (ArrayList&lt;StoreFile&gt; files : candidateStripes.values()) {<a name="line.473"></a>
+<span class="sourceLineNo">474</span>            for (StoreFile sf : files) {<a name="line.474"></a>
+<span class="sourceLineNo">475</span>              insertFileIntoStripe(level0Files, sf);<a name="line.475"></a>
+<span class="sourceLineNo">476</span>              ensureLevel0Metadata(sf);<a name="line.476"></a>
+<span class="sourceLineNo">477</span>            }<a name="line.477"></a>
+<span class="sourceLineNo">478</span>          }<a name="line.478"></a>
+<span class="sourceLineNo">479</span>          candidateStripes.clear();<a name="line.479"></a>
+<span class="sourceLineNo">480</span>        }<a name="line.480"></a>
+<span class="sourceLineNo">481</span>      }<a name="line.481"></a>
+<span class="sourceLineNo">482</span>    }<a name="line.482"></a>
+<span class="sourceLineNo">483</span><a name="line.483"></a>
+<span class="sourceLineNo">484</span>    // Copy the results into the fields.<a name="line.484"></a>
+<span class="sourceLineNo">485</span>    State state = new State();<a name="line.485"></a>
+<span class="sourceLineNo">486</span>    state.level0Files = ImmutableList.copyOf(level0Files);<a name="line.486"></a>
+<span class="sourceLineNo">487</span>    state.stripeFiles = new ArrayList&lt;&gt;(candidateStripes.size());<a name="line.487"></a>
+<span class="sourceLineNo">488</span>    state.stripeEndRows = new byte[Math.max(0, candidateStripes.size() - 1)][];<a name="line.488"></a>
+<span class="sourceLineNo">489</span>    ArrayList&lt;StoreFile&gt; newAllFiles = new ArrayList&lt;&gt;(level0Files);<a name="line.489"></a>
+<span class="sourceLineNo">490</span>    int i = candidateStripes.size() - 1;<a name="line.490"></a>
+<span class="sourceLineNo">491</span>    for (Map.Entry&lt;byte[], ArrayList&lt;StoreFile&gt;&gt; entry : candidateStripes.entrySet()) {<a name="line.491"></a>
+<span class="sourceLineNo">492</span>      state.stripeFiles.add(ImmutableList.copyOf(entry.getValue()));<a name="line.492"></a>
+<span class="sourceLineNo">493</span>      newAllFiles.addAll(entry.getValue());<a name="line.493"></a>
+<span class="sourceLineNo">494</span>      if (i &gt; 0) {<a name="line.494"></a>
+<span class="sourceLineNo">495</span>        state.stripeEndRows[state.stripeFiles.size() - 1] = entry.getKey();<a name="line.495"></a>
+<span class="sourceLineNo">496</span>      }<a name="line.496"></a>
+<span class="sourceLineNo">497</span>      --i;<a name="line.497"></a>
+<span class="sourceLineNo">498</span>    }<a name="line.498"></a>
+<span class="sourceLineNo">499</span>    state.allFilesCached = ImmutableList.copyOf(newAllFiles);<a name="line.499"></a>
+<span class="sourceLineNo">500</span>    this.state = state;<a name="line.500"></a>
+<span class="sourceLineNo">501</span>    debugDumpState("Files loaded");<a name="line.501"></a>
+<span class="sourceLineNo">502</span>  }<a name="line.502"></a>
+<span class="sourceLineNo">503</span><a name="line.503"></a>
+<span class="sourceLineNo">504</span>  private void ensureEdgeStripeMetadata(ArrayList&lt;StoreFile&gt; stripe, boolean isFirst) {<a name="line.504"></a>
+<span class="sourceLineNo">505</span>    HashMap&lt;StoreFile, byte[]&gt; targetMap = isFirst ? fileStarts : fileEnds;<a name="line.505"></a>
+<span class="sourceLineNo">506</span>    for (StoreFile sf : stripe) {<a name="line.506"></a>
+<span class="sourceLineNo">507</span>      targetMap.put(sf, OPEN_KEY);<a name="line.507"></a>
+<span class="sourceLineNo">508</span>    }<a name="line.508"></a>
 <span class="sourceLineNo">509</span>  }<a name="line.509"></a>
 <span class="sourceLineNo">510</span><a name="line.510"></a>
-<span class="sourceLineNo">511</span>  private void debugDumpState(String string) {<a name="line.511"></a>
-<span class="sourceLineNo">512</span>    if (!LOG.isDebugEnabled()) return;<a name="line.512"></a>
-<span class="sourceLineNo">513</span>    StringBuilder sb = new StringBuilder();<a name="line.513"></a>
-<span class="sourceLineNo">514</span>    sb.append("\n" + string + "; current stripe state is as such:");<a name="line.514"></a>
-<span class="sourceLineNo">515</span>    sb.append("\n level 0 with ")<a name="line.515"></a>
-<span class="sourceLineNo">516</span>        .append(state.level0Files.size())<a name="line.516"></a>
-<span class="sourceLineNo">517</span>        .append(<a name="line.517"></a>
-<span class="sourceLineNo">518</span>          " files: "<a name="line.518"></a>
-<span class="sourceLineNo">519</span>              + TraditionalBinaryPrefix.long2String(<a name="line.519"></a>
-<span class="sourceLineNo">520</span>                StripeCompactionPolicy.getTotalFileSize(state.level0Files), "", 1) + ";");<a name="line.520"></a>
-<span class="sourceLineNo">521</span>    for (int i = 0; i &lt; state.stripeFiles.size(); ++i) {<a name="line.521"></a>
-<span class="sourceLineNo">522</span>      String endRow = (i == state.stripeEndRows.length)<a name="line.522"></a>
-<span class="sourceLineNo">523</span>          ? "(end)" : "[" + Bytes.toString(state.stripeEndRows[i]) + "]";<a name="line.523"></a>
-<span class="sourceLineNo">524</span>      sb.append("\n stripe ending in ")<a name="line.524"></a>
-<span class="sourceLineNo">525</span>          .append(endRow)<a name="line.525"></a>
-<span class="sourceLineNo">526</span>          .append(" with ")<a name="line.526"></a>
-<span class="sourceLineNo">527</span>          .append(state.stripeFiles.get(i).size())<a name="line.527"></a>
-<span class="sourceLineNo">528</span>          .append(<a name="line.528"></a>
-<span class="sourceLineNo">529</span>            " files: "<a name="line.529"></a>
-<span class="sourceLineNo">530</span>                + TraditionalBinaryPrefix.long2String(<a name="line.530"></a>
-<span class="sourceLineNo">531</span>                  StripeCompactionPolicy.getTotalFileSize(state.stripeFiles.get(i)), "", 1) + ";");<a name="line.531"></a>
-<span class="sourceLineNo">532</span>    }<a name="line.532"></a>
-<span class="sourceLineNo">533</span>    sb.append("\n").append(state.stripeFiles.size()).append(" stripes total.");<a name="line.533"></a>
-<span class="sourceLineNo">534</span>    sb.append("\n").append(getStorefileCount()).append(" files total.");<a name="line.534"></a>
-<span class="sourceLineNo">535</span>    LOG.debug(sb.toString());<a name="line.535"></a>
-<span class="sourceLineNo">536</span>  }<a name="line.536"></a>
-<span class="sourceLineNo">537</span><a name="line.537"></a>
-<span class="sourceLineNo">538</span>  /**<a name="line.538"></a>
-<span class="sourceLineNo">539</span>   * Checks whether the key indicates an open interval boundary (i.e. infinity).<a name="line.539"></a>
-<span class="sourceLineNo">540</span>   */<a name="line.540"></a>
-<span class="sourceLineNo">541</span>  private static final boolean isOpen(byte[] key) {<a name="line.541"></a>
-<span class="sourceLineNo">542</span>    return key != null &amp;&amp; key.length == 0;<a name="line.542"></a>
-<span class="sourceLineNo">543</span>  }<a name="line.543"></a>
-<span class="sourceLineNo">544</span><a name="line.544"></a>
-<span class="sourceLineNo">545</span>  private static final boolean isOpen(Cell key) {<a name="line.545"></a>
-<span class="sourceLineNo">546</span>    return key != null &amp;&amp; key.getRowLength() == 0;<a name="line.546"></a>
-<span class="sourceLineNo">547</span>  }<a name="line.547"></a>
-<span class="sourceLineNo">548</span><a name="line.548"></a>
-<span class="sourceLineNo">549</span>  /**<a name="line.549"></a>
-<span class="sourceLineNo">550</span>   * Checks whether the key is invalid (e.g. from an L0 file, or non-stripe-compacted files).<a name="line.550"></a>
-<span class="sourceLineNo">551</span>   */<a name="line.551"></a>
-<span class="sourceLineNo">552</span>  private static final boolean isInvalid(byte[] key) {<a name="line.552"></a>
-<span class="sourceLineNo">553</span>    // No need to use Arrays.equals because INVALID_KEY is null<a name="line.553"></a>
-<span class="sourceLineNo">554</span>    return key == INVALID_KEY;<a name="line.554"></a>
-<span class="sourceLineNo">555</span>  }<a name="line.555"></a>
-<span class="sourceLineNo">556</span><a name="line.556"></a>
-<span class="sourceLineNo">557</span>  /**<a name="line.557"></a>
-<span class="sourceLineNo">558</span>   * Compare two keys for equality.<a name="line.558"></a>
-<span class="sourceLineNo">559</span>   */<a name="line.559"></a>
-<span class="sourceLineNo">560</span>  private final boolean rowEquals(byte[] k1, byte[] k2) {<a name="line.560"></a>
-<span class="sourceLineNo">561</span>    return Bytes.equals(k1, 0, k1.length, k2, 0, k2.length);<a name="line.561"></a>
-<span class="sourceLineNo">562</span>  }<a name="line.562"></a>
-<span class="sourceLineNo">563</span><a name="line.563"></a>
-<span class="sourceLineNo">564</span>  /**<a name="line.564"></a>
-<span class="sourceLineNo">565</span>   * Compare two keys. Keys must not be open (isOpen(row) == false).<a name="line.565"></a>
-<span class="sourceLineNo">566</span>   */<a name="line.566"></a>
-<span class="sourceLineNo">567</span>  private final int nonOpenRowCompare(byte[] k1, byte[] k2) {<a name="line.567"></a>
-<span class="sourceLineNo">568</span>    assert !isOpen(k1) &amp;&amp; !isOpen(k2);<a name="line.568"></a>
-<span class="sourceLineNo">569</span>    return Bytes.compareTo(k1, k2);<a name="line.569"></a>
-<span class="sourceLineNo">570</span>  }<a name="line.570"></a>
-<span class="sourceLineNo">571</span><a name="line.571"></a>
-<span class="sourceLineNo">572</span>  private final int nonOpenRowCompare(Cell k1, byte[] k2) {<a name="line.572"></a>
+<span class="sourceLineNo">511</span>  private void ensureLevel0Metadata(StoreFile sf) {<a name="line.511"></a>
+<span class="sourceLineNo">512</span>    if (!isInvalid(startOf(sf))) this.fileStarts.put(sf, INVALID_KEY_IN_MAP);<a name="line.512"></a>
+<span class="sourceLineNo">513</span>    if (!isInvalid(endOf(sf))) this.fileEnds.put(sf, INVALID_KEY_IN_MAP);<a name="line.513"></a>
+<span class="sourceLineNo">514</span>  }<a name="line.514"></a>
+<span class="sourceLineNo">515</span><a name="line.515"></a>
+<span class="sourceLineNo">516</span>  private void debugDumpState(String string) {<a name="line.516"></a>
+<span class="sourceLineNo">517</span>    if (!LOG.isDebugEnabled()) return;<a name="line.517"></a>
+<span class="sourceLineNo">518</span>    StringBuilder sb = new StringBuilder();<a name="line.518"></a>
+<span class="sourceLineNo">519</span>    sb.append("\n" + string + "; current stripe state is as such:");<a name="line.519"></a>
+<span class="sourceLineNo">520</span>    sb.append("\n level 0 with ")<a name="line.520"></a>
+<span class="sourceLineNo">521</span>        .append(state.level0Files.size())<a name="line.521"></a>
+<span class="sourceLineNo">522</span>        .append(<a name="line.522"></a>
+<span class="sourceLineNo">523</span>          " files: "<a name="line.523"></a>
+<span class="sourceLineNo">524</span>              + TraditionalBinaryPrefix.long2String(<a name="line.524"></a>
+<span class="sourceLineNo">525</span>                StripeCompactionPolicy.getTotalFileSize(state.level0Files), "", 1) + ";");<a name="line.525"></a>
+<span class="sourceLineNo">526</span>    for (int i = 0; i &lt; state.stripeFiles.size(); ++i) {<a name="line.526"></a>
+<span class="sourceLineNo">527</span>      String endRow = (i == state.stripeEndRows.length)<a name="line.527"></a>
+<span class="sourceLineNo">528</span>          ? "(end)" : "[" + Bytes.toString(state.stripeEndRows[i]) + "]";<a name="line.528"></a>
+<span class="sourceLineNo">529</span>      sb.append("\n stripe ending in ")<a name="line.529"></a>
+<span class="sourceLineNo">530</span>          .append(endRow)<a name="line.530"></a>
+<span class="sourceLineNo">531</span>          .append(" with ")<a name="line.531"></a>
+<span class="sourceLineNo">532</span>          .append(state.stripeFiles.get(i).size())<a name="line.532"></a>
+<span class="sourceLineNo">533</span>          .append(<a name="line.533"></a>
+<span class="sourceLineNo">534</span>            " files: "<a name="line.534"></a>
+<span class="sourceLineNo">535</span>                + TraditionalBinaryPrefix.long2String(<a name="line.535"></a>
+<span class="sourceLineNo">536</span>                  StripeCompactionPolicy.getTotalFileSize(state.stripeFiles.get(i)), "", 1) + ";");<a name="line.536"></a>
+<span class="sourceLineNo">537</span>    }<a name="line.537"></a>
+<span class="sourceLineNo">538</span>    sb.append("\n").append(state.stripeFiles.size()).append(" stripes total.");<a name="line.538"></a>
+<span class="sourceLineNo">539</span>    sb.append("\n").append(getStorefileCount()).append(" files total.");<a name="line.539"></a>
+<span class="sourceLineNo">540</span>    LOG.debug(sb.toString());<a name="line.540"></a>
+<span class="sourceLineNo">541</span>  }<a name="line.541"></a>
+<span class="sourceLineNo">542</span><a name="line.542"></a>
+<span class="sourceLineNo">543</span>  /**<a name="line.543"></a>
+<span class="sourceLineNo">544</span>   * Checks whether the key indicates an open interval boundary (i.e. infinity).<a name="line.544"></a>
+<span class="sourceLineNo">545</span>   */<a name="line.545"></a>
+<span class="sourceLineNo">546</span>  private static final boolean isOpen(byte[] key) {<a name="line.546"></a>
+<span class="sourceLineNo">547</span>    return key != null &amp;&amp; key.length == 0;<a name="line.547"></a>
+<span class="sourceLineNo">548</span>  }<a name="line.548"></a>
+<span class="sourceLineNo">549</span><a name="line.549"></a>
+<span class="sourceLineNo">550</span>  private static final boolean isOpen(Cell key) {<a name="line.550"></a>
+<span class="sourceLineNo">551</span>    return key != null &amp;&amp; key.getRowLength() == 0;<a name="line.551"></a>
+<span class="sourceLineNo">552</span>  }<a name="line.552"></a>
+<span class="sourceLineNo">553</span><a name="line.553"></a>
+<span class="sourceLineNo">554</span>  /**<a name="line.554"></a>
+<span class="sourceLineNo">555</span>   * Checks whether the key is invalid (e.g. from an L0 file, or non-stripe-compacted files).<a name="line.555"></a>
+<span class="sourceLineNo">556</span>   */<a name="line.556"></a>
+<span class="sourceLineNo">557</span>  private static final boolean isInvalid(byte[] key) {<a name="line.557"></a>
+<span class="sourceLineNo">558</span>    // No need to use Arrays.equals because INVALID_KEY is null<a name="line.558"></a>
+<span class="sourceLineNo">559</span>    return key == INVALID_KEY;<a name="line.559"></a>
+<span class="sourceLineNo">560</span>  }<a name="line.560"></a>
+<span class="sourceLineNo">561</span><a name="line.561"></a>
+<span class="sourceLineNo">562</span>  /**<a name="line.562"></a>
+<span class="sourceLineNo">563</span>   * Compare two keys for equality.<a name="line.563"></a>
+<span class="sourceLineNo">564</span>   */<a name="line.564"></a>
+<span class="sourceLineNo">565</span>  private final boolean rowEquals(byte[] k1, byte[] k2) {<a name="line.565"></a>
+<span class="sourceLineNo">566</span>    return Bytes.equals(k1, 0, k1.length, k2, 0, k2.length);<a name="line.566"></a>
+<span class="sourceLineNo">567</span>  }<a name="line.567"></a>
+<span class="sourceLineNo">568</span><a name="line.568"></a>
+<span class="sourceLineNo">569</span>  /**<a name="line.569"></a>
+<span class="sourceLineNo">570</span>   * Compare two keys. Keys must not be open (isOpen(row) == false).<a name="line.570"></a>
+<span class="sourceLineNo">571</span>   */<a name="line.571"></a>
+<span class="sourceLineNo">572</span>  private final int nonOpenRowCompare(byte[] k1, byte[] k2) {<a name="line.572"></a>
 <span class="sourceLineNo">573</span>    assert !isOpen(k1) &amp;&amp; !isOpen(k2);<a name="line.573"></a>
-<span class="sourceLineNo">574</span>    return cellComparator.compareRows(k1, k2, 0, k2.length);<a name="line.574"></a>
+<span class="sourceLineNo">574</span>    return Bytes.compareTo(k1, k2);<a name="line.574"></a>
 <span cl

<TRUNCATED>

Mime
View raw message