hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [18/51] [partial] hbase-site git commit: Published site at .
Date Mon, 23 Oct 2017 15:16:20 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/41a7fcc5/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 12fe16f..b1e0997 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
@@ -1960,6279 +1960,6285 @@
 <span class="sourceLineNo">1952</span>  protected void doRegionCompactionPrep() throws IOException {<a name="line.1952"></a>
 <span class="sourceLineNo">1953</span>  }<a name="line.1953"></a>
 <span class="sourceLineNo">1954</span><a name="line.1954"></a>
-<span class="sourceLineNo">1955</span>  @Override<a name="line.1955"></a>
-<span class="sourceLineNo">1956</span>  public void triggerMajorCompaction() throws IOException {<a name="line.1956"></a>
-<span class="sourceLineNo">1957</span>    stores.values().forEach(HStore::triggerMajorCompaction);<a name="line.1957"></a>
-<span class="sourceLineNo">1958</span>  }<a name="line.1958"></a>
-<span class="sourceLineNo">1959</span><a name="line.1959"></a>
-<span class="sourceLineNo">1960</span>  /**<a name="line.1960"></a>
-<span class="sourceLineNo">1961</span>   * Synchronously compact all stores in the region.<a name="line.1961"></a>
-<span class="sourceLineNo">1962</span>   * &lt;p&gt;This operation could block for a long time, so don't call it from a<a name="line.1962"></a>
-<span class="sourceLineNo">1963</span>   * time-sensitive thread.<a name="line.1963"></a>
-<span class="sourceLineNo">1964</span>   * &lt;p&gt;Note that no locks are taken to prevent possible conflicts between<a name="line.1964"></a>
-<span class="sourceLineNo">1965</span>   * compaction and splitting activities. The regionserver does not normally compact<a name="line.1965"></a>
-<span class="sourceLineNo">1966</span>   * and split in parallel. However by calling this method you may introduce<a name="line.1966"></a>
-<span class="sourceLineNo">1967</span>   * unexpected and unhandled concurrency. Don't do this unless you know what<a name="line.1967"></a>
-<span class="sourceLineNo">1968</span>   * you are doing.<a name="line.1968"></a>
-<span class="sourceLineNo">1969</span>   *<a name="line.1969"></a>
-<span class="sourceLineNo">1970</span>   * @param majorCompaction True to force a major compaction regardless of thresholds<a name="line.1970"></a>
-<span class="sourceLineNo">1971</span>   * @throws IOException<a name="line.1971"></a>
-<span class="sourceLineNo">1972</span>   */<a name="line.1972"></a>
-<span class="sourceLineNo">1973</span>  public void compact(boolean majorCompaction) throws IOException {<a name="line.1973"></a>
-<span class="sourceLineNo">1974</span>    if (majorCompaction) {<a name="line.1974"></a>
-<span class="sourceLineNo">1975</span>      triggerMajorCompaction();<a name="line.1975"></a>
-<span class="sourceLineNo">1976</span>    }<a name="line.1976"></a>
-<span class="sourceLineNo">1977</span>    for (HStore s : stores.values()) {<a name="line.1977"></a>
-<span class="sourceLineNo">1978</span>      Optional&lt;CompactionContext&gt; compaction = s.requestCompaction();<a name="line.1978"></a>
-<span class="sourceLineNo">1979</span>      if (compaction.isPresent()) {<a name="line.1979"></a>
-<span class="sourceLineNo">1980</span>        ThroughputController controller = null;<a name="line.1980"></a>
-<span class="sourceLineNo">1981</span>        if (rsServices != null) {<a name="line.1981"></a>
-<span class="sourceLineNo">1982</span>          controller = CompactionThroughputControllerFactory.create(rsServices, conf);<a name="line.1982"></a>
-<span class="sourceLineNo">1983</span>        }<a name="line.1983"></a>
-<span class="sourceLineNo">1984</span>        if (controller == null) {<a name="line.1984"></a>
-<span class="sourceLineNo">1985</span>          controller = NoLimitThroughputController.INSTANCE;<a name="line.1985"></a>
-<span class="sourceLineNo">1986</span>        }<a name="line.1986"></a>
-<span class="sourceLineNo">1987</span>        compact(compaction.get(), s, controller, null);<a name="line.1987"></a>
-<span class="sourceLineNo">1988</span>      }<a name="line.1988"></a>
-<span class="sourceLineNo">1989</span>    }<a name="line.1989"></a>
-<span class="sourceLineNo">1990</span>  }<a name="line.1990"></a>
-<span class="sourceLineNo">1991</span><a name="line.1991"></a>
-<span class="sourceLineNo">1992</span>  /**<a name="line.1992"></a>
-<span class="sourceLineNo">1993</span>   * This is a helper function that compact all the stores synchronously.<a name="line.1993"></a>
-<span class="sourceLineNo">1994</span>   * &lt;p&gt;<a name="line.1994"></a>
-<span class="sourceLineNo">1995</span>   * It is used by utilities and testing<a name="line.1995"></a>
-<span class="sourceLineNo">1996</span>   */<a name="line.1996"></a>
-<span class="sourceLineNo">1997</span>  @VisibleForTesting<a name="line.1997"></a>
-<span class="sourceLineNo">1998</span>  public void compactStores() throws IOException {<a name="line.1998"></a>
-<span class="sourceLineNo">1999</span>    for (HStore s : stores.values()) {<a name="line.1999"></a>
-<span class="sourceLineNo">2000</span>      Optional&lt;CompactionContext&gt; compaction = s.requestCompaction();<a name="line.2000"></a>
-<span class="sourceLineNo">2001</span>      if (compaction.isPresent()) {<a name="line.2001"></a>
-<span class="sourceLineNo">2002</span>        compact(compaction.get(), s, NoLimitThroughputController.INSTANCE, null);<a name="line.2002"></a>
-<span class="sourceLineNo">2003</span>      }<a name="line.2003"></a>
-<span class="sourceLineNo">2004</span>    }<a name="line.2004"></a>
-<span class="sourceLineNo">2005</span>  }<a name="line.2005"></a>
-<span class="sourceLineNo">2006</span><a name="line.2006"></a>
-<span class="sourceLineNo">2007</span>  /**<a name="line.2007"></a>
-<span class="sourceLineNo">2008</span>   * This is a helper function that compact the given store.<a name="line.2008"></a>
-<span class="sourceLineNo">2009</span>   * &lt;p&gt;<a name="line.2009"></a>
-<span class="sourceLineNo">2010</span>   * It is used by utilities and testing<a name="line.2010"></a>
-<span class="sourceLineNo">2011</span>   */<a name="line.2011"></a>
-<span class="sourceLineNo">2012</span>  @VisibleForTesting<a name="line.2012"></a>
-<span class="sourceLineNo">2013</span>  void compactStore(byte[] family, ThroughputController throughputController) throws IOException {<a name="line.2013"></a>
-<span class="sourceLineNo">2014</span>    HStore s = getStore(family);<a name="line.2014"></a>
-<span class="sourceLineNo">2015</span>    Optional&lt;CompactionContext&gt; compaction = s.requestCompaction();<a name="line.2015"></a>
-<span class="sourceLineNo">2016</span>    if (compaction.isPresent()) {<a name="line.2016"></a>
-<span class="sourceLineNo">2017</span>      compact(compaction.get(), s, throughputController, null);<a name="line.2017"></a>
-<span class="sourceLineNo">2018</span>    }<a name="line.2018"></a>
-<span class="sourceLineNo">2019</span>  }<a name="line.2019"></a>
-<span class="sourceLineNo">2020</span><a name="line.2020"></a>
-<span class="sourceLineNo">2021</span>  /**<a name="line.2021"></a>
-<span class="sourceLineNo">2022</span>   * Called by compaction thread and after region is opened to compact the<a name="line.2022"></a>
-<span class="sourceLineNo">2023</span>   * HStores if necessary.<a name="line.2023"></a>
-<span class="sourceLineNo">2024</span>   *<a name="line.2024"></a>
-<span class="sourceLineNo">2025</span>   * &lt;p&gt;This operation could block for a long time, so don't call it from a<a name="line.2025"></a>
-<span class="sourceLineNo">2026</span>   * time-sensitive thread.<a name="line.2026"></a>
-<span class="sourceLineNo">2027</span>   *<a name="line.2027"></a>
-<span class="sourceLineNo">2028</span>   * Note that no locking is necessary at this level because compaction only<a name="line.2028"></a>
-<span class="sourceLineNo">2029</span>   * conflicts with a region split, and that cannot happen because the region<a name="line.2029"></a>
-<span class="sourceLineNo">2030</span>   * server does them sequentially and not in parallel.<a name="line.2030"></a>
-<span class="sourceLineNo">2031</span>   *<a name="line.2031"></a>
-<span class="sourceLineNo">2032</span>   * @param compaction Compaction details, obtained by requestCompaction()<a name="line.2032"></a>
-<span class="sourceLineNo">2033</span>   * @param throughputController<a name="line.2033"></a>
-<span class="sourceLineNo">2034</span>   * @return whether the compaction completed<a name="line.2034"></a>
-<span class="sourceLineNo">2035</span>   */<a name="line.2035"></a>
+<span class="sourceLineNo">1955</span>  /**<a name="line.1955"></a>
+<span class="sourceLineNo">1956</span>   * Synchronously compact all stores in the region.<a name="line.1956"></a>
+<span class="sourceLineNo">1957</span>   * &lt;p&gt;This operation could block for a long time, so don't call it from a<a name="line.1957"></a>
+<span class="sourceLineNo">1958</span>   * time-sensitive thread.<a name="line.1958"></a>
+<span class="sourceLineNo">1959</span>   * &lt;p&gt;Note that no locks are taken to prevent possible conflicts between<a name="line.1959"></a>
+<span class="sourceLineNo">1960</span>   * compaction and splitting activities. The regionserver does not normally compact<a name="line.1960"></a>
+<span class="sourceLineNo">1961</span>   * and split in parallel. However by calling this method you may introduce<a name="line.1961"></a>
+<span class="sourceLineNo">1962</span>   * unexpected and unhandled concurrency. Don't do this unless you know what<a name="line.1962"></a>
+<span class="sourceLineNo">1963</span>   * you are doing.<a name="line.1963"></a>
+<span class="sourceLineNo">1964</span>   *<a name="line.1964"></a>
+<span class="sourceLineNo">1965</span>   * @param majorCompaction True to force a major compaction regardless of thresholds<a name="line.1965"></a>
+<span class="sourceLineNo">1966</span>   * @throws IOException<a name="line.1966"></a>
+<span class="sourceLineNo">1967</span>   */<a name="line.1967"></a>
+<span class="sourceLineNo">1968</span>  public void compact(boolean majorCompaction) throws IOException {<a name="line.1968"></a>
+<span class="sourceLineNo">1969</span>    if (majorCompaction) {<a name="line.1969"></a>
+<span class="sourceLineNo">1970</span>      stores.values().forEach(HStore::triggerMajorCompaction);<a name="line.1970"></a>
+<span class="sourceLineNo">1971</span>    }<a name="line.1971"></a>
+<span class="sourceLineNo">1972</span>    for (HStore s : stores.values()) {<a name="line.1972"></a>
+<span class="sourceLineNo">1973</span>      Optional&lt;CompactionContext&gt; compaction = s.requestCompaction();<a name="line.1973"></a>
+<span class="sourceLineNo">1974</span>      if (compaction.isPresent()) {<a name="line.1974"></a>
+<span class="sourceLineNo">1975</span>        ThroughputController controller = null;<a name="line.1975"></a>
+<span class="sourceLineNo">1976</span>        if (rsServices != null) {<a name="line.1976"></a>
+<span class="sourceLineNo">1977</span>          controller = CompactionThroughputControllerFactory.create(rsServices, conf);<a name="line.1977"></a>
+<span class="sourceLineNo">1978</span>        }<a name="line.1978"></a>
+<span class="sourceLineNo">1979</span>        if (controller == null) {<a name="line.1979"></a>
+<span class="sourceLineNo">1980</span>          controller = NoLimitThroughputController.INSTANCE;<a name="line.1980"></a>
+<span class="sourceLineNo">1981</span>        }<a name="line.1981"></a>
+<span class="sourceLineNo">1982</span>        compact(compaction.get(), s, controller, null);<a name="line.1982"></a>
+<span class="sourceLineNo">1983</span>      }<a name="line.1983"></a>
+<span class="sourceLineNo">1984</span>    }<a name="line.1984"></a>
+<span class="sourceLineNo">1985</span>  }<a name="line.1985"></a>
+<span class="sourceLineNo">1986</span><a name="line.1986"></a>
+<span class="sourceLineNo">1987</span>  /**<a name="line.1987"></a>
+<span class="sourceLineNo">1988</span>   * This is a helper function that compact all the stores synchronously.<a name="line.1988"></a>
+<span class="sourceLineNo">1989</span>   * &lt;p&gt;<a name="line.1989"></a>
+<span class="sourceLineNo">1990</span>   * It is used by utilities and testing<a name="line.1990"></a>
+<span class="sourceLineNo">1991</span>   */<a name="line.1991"></a>
+<span class="sourceLineNo">1992</span>  @VisibleForTesting<a name="line.1992"></a>
+<span class="sourceLineNo">1993</span>  public void compactStores() throws IOException {<a name="line.1993"></a>
+<span class="sourceLineNo">1994</span>    for (HStore s : stores.values()) {<a name="line.1994"></a>
+<span class="sourceLineNo">1995</span>      Optional&lt;CompactionContext&gt; compaction = s.requestCompaction();<a name="line.1995"></a>
+<span class="sourceLineNo">1996</span>      if (compaction.isPresent()) {<a name="line.1996"></a>
+<span class="sourceLineNo">1997</span>        compact(compaction.get(), s, NoLimitThroughputController.INSTANCE, null);<a name="line.1997"></a>
+<span class="sourceLineNo">1998</span>      }<a name="line.1998"></a>
+<span class="sourceLineNo">1999</span>    }<a name="line.1999"></a>
+<span class="sourceLineNo">2000</span>  }<a name="line.2000"></a>
+<span class="sourceLineNo">2001</span><a name="line.2001"></a>
+<span class="sourceLineNo">2002</span>  /**<a name="line.2002"></a>
+<span class="sourceLineNo">2003</span>   * This is a helper function that compact the given store.<a name="line.2003"></a>
+<span class="sourceLineNo">2004</span>   * &lt;p&gt;<a name="line.2004"></a>
+<span class="sourceLineNo">2005</span>   * It is used by utilities and testing<a name="line.2005"></a>
+<span class="sourceLineNo">2006</span>   */<a name="line.2006"></a>
+<span class="sourceLineNo">2007</span>  @VisibleForTesting<a name="line.2007"></a>
+<span class="sourceLineNo">2008</span>  void compactStore(byte[] family, ThroughputController throughputController) throws IOException {<a name="line.2008"></a>
+<span class="sourceLineNo">2009</span>    HStore s = getStore(family);<a name="line.2009"></a>
+<span class="sourceLineNo">2010</span>    Optional&lt;CompactionContext&gt; compaction = s.requestCompaction();<a name="line.2010"></a>
+<span class="sourceLineNo">2011</span>    if (compaction.isPresent()) {<a name="line.2011"></a>
+<span class="sourceLineNo">2012</span>      compact(compaction.get(), s, throughputController, null);<a name="line.2012"></a>
+<span class="sourceLineNo">2013</span>    }<a name="line.2013"></a>
+<span class="sourceLineNo">2014</span>  }<a name="line.2014"></a>
+<span class="sourceLineNo">2015</span><a name="line.2015"></a>
+<span class="sourceLineNo">2016</span>  /**<a name="line.2016"></a>
+<span class="sourceLineNo">2017</span>   * Called by compaction thread and after region is opened to compact the<a name="line.2017"></a>
+<span class="sourceLineNo">2018</span>   * HStores if necessary.<a name="line.2018"></a>
+<span class="sourceLineNo">2019</span>   *<a name="line.2019"></a>
+<span class="sourceLineNo">2020</span>   * &lt;p&gt;This operation could block for a long time, so don't call it from a<a name="line.2020"></a>
+<span class="sourceLineNo">2021</span>   * time-sensitive thread.<a name="line.2021"></a>
+<span class="sourceLineNo">2022</span>   *<a name="line.2022"></a>
+<span class="sourceLineNo">2023</span>   * Note that no locking is necessary at this level because compaction only<a name="line.2023"></a>
+<span class="sourceLineNo">2024</span>   * conflicts with a region split, and that cannot happen because the region<a name="line.2024"></a>
+<span class="sourceLineNo">2025</span>   * server does them sequentially and not in parallel.<a name="line.2025"></a>
+<span class="sourceLineNo">2026</span>   *<a name="line.2026"></a>
+<span class="sourceLineNo">2027</span>   * @param compaction Compaction details, obtained by requestCompaction()<a name="line.2027"></a>
+<span class="sourceLineNo">2028</span>   * @param throughputController<a name="line.2028"></a>
+<span class="sourceLineNo">2029</span>   * @return whether the compaction completed<a name="line.2029"></a>
+<span class="sourceLineNo">2030</span>   */<a name="line.2030"></a>
+<span class="sourceLineNo">2031</span>  public boolean compact(CompactionContext compaction, HStore store,<a name="line.2031"></a>
+<span class="sourceLineNo">2032</span>      ThroughputController throughputController) throws IOException {<a name="line.2032"></a>
+<span class="sourceLineNo">2033</span>    return compact(compaction, store, throughputController, null);<a name="line.2033"></a>
+<span class="sourceLineNo">2034</span>  }<a name="line.2034"></a>
+<span class="sourceLineNo">2035</span><a name="line.2035"></a>
 <span class="sourceLineNo">2036</span>  public boolean compact(CompactionContext compaction, HStore store,<a name="line.2036"></a>
-<span class="sourceLineNo">2037</span>      ThroughputController throughputController) throws IOException {<a name="line.2037"></a>
-<span class="sourceLineNo">2038</span>    return compact(compaction, store, throughputController, null);<a name="line.2038"></a>
-<span class="sourceLineNo">2039</span>  }<a name="line.2039"></a>
-<span class="sourceLineNo">2040</span><a name="line.2040"></a>
-<span class="sourceLineNo">2041</span>  public boolean compact(CompactionContext compaction, HStore store,<a name="line.2041"></a>
-<span class="sourceLineNo">2042</span>      ThroughputController throughputController, User user) throws IOException {<a name="line.2042"></a>
-<span class="sourceLineNo">2043</span>    assert compaction != null &amp;&amp; compaction.hasSelection();<a name="line.2043"></a>
-<span class="sourceLineNo">2044</span>    assert !compaction.getRequest().getFiles().isEmpty();<a name="line.2044"></a>
-<span class="sourceLineNo">2045</span>    if (this.closing.get() || this.closed.get()) {<a name="line.2045"></a>
-<span class="sourceLineNo">2046</span>      LOG.debug("Skipping compaction on " + this + " because closing/closed");<a name="line.2046"></a>
-<span class="sourceLineNo">2047</span>      store.cancelRequestedCompaction(compaction);<a name="line.2047"></a>
-<span class="sourceLineNo">2048</span>      return false;<a name="line.2048"></a>
-<span class="sourceLineNo">2049</span>    }<a name="line.2049"></a>
-<span class="sourceLineNo">2050</span>    MonitoredTask status = null;<a name="line.2050"></a>
-<span class="sourceLineNo">2051</span>    boolean requestNeedsCancellation = true;<a name="line.2051"></a>
-<span class="sourceLineNo">2052</span>    /*<a name="line.2052"></a>
-<span class="sourceLineNo">2053</span>     * We are trying to remove / relax the region read lock for compaction.<a name="line.2053"></a>
-<span class="sourceLineNo">2054</span>     * Let's see what are the potential race conditions among the operations (user scan,<a name="line.2054"></a>
-<span class="sourceLineNo">2055</span>     * region split, region close and region bulk load).<a name="line.2055"></a>
+<span class="sourceLineNo">2037</span>      ThroughputController throughputController, User user) throws IOException {<a name="line.2037"></a>
+<span class="sourceLineNo">2038</span>    assert compaction != null &amp;&amp; compaction.hasSelection();<a name="line.2038"></a>
+<span class="sourceLineNo">2039</span>    assert !compaction.getRequest().getFiles().isEmpty();<a name="line.2039"></a>
+<span class="sourceLineNo">2040</span>    if (this.closing.get() || this.closed.get()) {<a name="line.2040"></a>
+<span class="sourceLineNo">2041</span>      LOG.debug("Skipping compaction on " + this + " because closing/closed");<a name="line.2041"></a>
+<span class="sourceLineNo">2042</span>      store.cancelRequestedCompaction(compaction);<a name="line.2042"></a>
+<span class="sourceLineNo">2043</span>      return false;<a name="line.2043"></a>
+<span class="sourceLineNo">2044</span>    }<a name="line.2044"></a>
+<span class="sourceLineNo">2045</span>    MonitoredTask status = null;<a name="line.2045"></a>
+<span class="sourceLineNo">2046</span>    boolean requestNeedsCancellation = true;<a name="line.2046"></a>
+<span class="sourceLineNo">2047</span>    /*<a name="line.2047"></a>
+<span class="sourceLineNo">2048</span>     * We are trying to remove / relax the region read lock for compaction.<a name="line.2048"></a>
+<span class="sourceLineNo">2049</span>     * Let's see what are the potential race conditions among the operations (user scan,<a name="line.2049"></a>
+<span class="sourceLineNo">2050</span>     * region split, region close and region bulk load).<a name="line.2050"></a>
+<span class="sourceLineNo">2051</span>     *<a name="line.2051"></a>
+<span class="sourceLineNo">2052</span>     *  user scan ---&gt; region read lock<a name="line.2052"></a>
+<span class="sourceLineNo">2053</span>     *  region split --&gt; region close first --&gt; region write lock<a name="line.2053"></a>
+<span class="sourceLineNo">2054</span>     *  region close --&gt; region write lock<a name="line.2054"></a>
+<span class="sourceLineNo">2055</span>     *  region bulk load --&gt; region write lock<a name="line.2055"></a>
 <span class="sourceLineNo">2056</span>     *<a name="line.2056"></a>
-<span class="sourceLineNo">2057</span>     *  user scan ---&gt; region read lock<a name="line.2057"></a>
-<span class="sourceLineNo">2058</span>     *  region split --&gt; region close first --&gt; region write lock<a name="line.2058"></a>
-<span class="sourceLineNo">2059</span>     *  region close --&gt; region write lock<a name="line.2059"></a>
-<span class="sourceLineNo">2060</span>     *  region bulk load --&gt; region write lock<a name="line.2060"></a>
+<span class="sourceLineNo">2057</span>     * read lock is compatible with read lock. ---&gt; no problem with user scan/read<a name="line.2057"></a>
+<span class="sourceLineNo">2058</span>     * region bulk load does not cause problem for compaction (no consistency problem, store lock<a name="line.2058"></a>
+<span class="sourceLineNo">2059</span>     *  will help the store file accounting).<a name="line.2059"></a>
+<span class="sourceLineNo">2060</span>     * They can run almost concurrently at the region level.<a name="line.2060"></a>
 <span class="sourceLineNo">2061</span>     *<a name="line.2061"></a>
-<span class="sourceLineNo">2062</span>     * read lock is compatible with read lock. ---&gt; no problem with user scan/read<a name="line.2062"></a>
-<span class="sourceLineNo">2063</span>     * region bulk load does not cause problem for compaction (no consistency problem, store lock<a name="line.2063"></a>
-<span class="sourceLineNo">2064</span>     *  will help the store file accounting).<a name="line.2064"></a>
-<span class="sourceLineNo">2065</span>     * They can run almost concurrently at the region level.<a name="line.2065"></a>
-<span class="sourceLineNo">2066</span>     *<a name="line.2066"></a>
-<span class="sourceLineNo">2067</span>     * The only remaining race condition is between the region close and compaction.<a name="line.2067"></a>
-<span class="sourceLineNo">2068</span>     * So we will evaluate, below, how region close intervenes with compaction if compaction does<a name="line.2068"></a>
-<span class="sourceLineNo">2069</span>     * not acquire region read lock.<a name="line.2069"></a>
-<span class="sourceLineNo">2070</span>     *<a name="line.2070"></a>
-<span class="sourceLineNo">2071</span>     * Here are the steps for compaction:<a name="line.2071"></a>
-<span class="sourceLineNo">2072</span>     * 1. obtain list of StoreFile's<a name="line.2072"></a>
-<span class="sourceLineNo">2073</span>     * 2. create StoreFileScanner's based on list from #1<a name="line.2073"></a>
-<span class="sourceLineNo">2074</span>     * 3. perform compaction and save resulting files under tmp dir<a name="line.2074"></a>
-<span class="sourceLineNo">2075</span>     * 4. swap in compacted files<a name="line.2075"></a>
-<span class="sourceLineNo">2076</span>     *<a name="line.2076"></a>
-<span class="sourceLineNo">2077</span>     * #1 is guarded by store lock. This patch does not change this --&gt; no worse or better<a name="line.2077"></a>
-<span class="sourceLineNo">2078</span>     * For #2, we obtain smallest read point (for region) across all the Scanners (for both default<a name="line.2078"></a>
-<span class="sourceLineNo">2079</span>     * compactor and stripe compactor).<a name="line.2079"></a>
-<span class="sourceLineNo">2080</span>     * The read points are for user scans. Region keeps the read points for all currently open<a name="line.2080"></a>
-<span class="sourceLineNo">2081</span>     * user scanners.<a name="line.2081"></a>
-<span class="sourceLineNo">2082</span>     * Compaction needs to know the smallest read point so that during re-write of the hfiles,<a name="line.2082"></a>
-<span class="sourceLineNo">2083</span>     * it can remove the mvcc points for the cells if their mvccs are older than the smallest<a name="line.2083"></a>
-<span class="sourceLineNo">2084</span>     * since they are not needed anymore.<a name="line.2084"></a>
-<span class="sourceLineNo">2085</span>     * This will not conflict with compaction.<a name="line.2085"></a>
-<span class="sourceLineNo">2086</span>     * For #3, it can be performed in parallel to other operations.<a name="line.2086"></a>
-<span class="sourceLineNo">2087</span>     * For #4 bulk load and compaction don't conflict with each other on the region level<a name="line.2087"></a>
-<span class="sourceLineNo">2088</span>     *   (for multi-family atomicy).<a name="line.2088"></a>
-<span class="sourceLineNo">2089</span>     * Region close and compaction are guarded pretty well by the 'writestate'.<a name="line.2089"></a>
-<span class="sourceLineNo">2090</span>     * In HRegion#doClose(), we have :<a name="line.2090"></a>
-<span class="sourceLineNo">2091</span>     * synchronized (writestate) {<a name="line.2091"></a>
-<span class="sourceLineNo">2092</span>     *   // Disable compacting and flushing by background threads for this<a name="line.2092"></a>
-<span class="sourceLineNo">2093</span>     *   // region.<a name="line.2093"></a>
-<span class="sourceLineNo">2094</span>     *   canFlush = !writestate.readOnly;<a name="line.2094"></a>
-<span class="sourceLineNo">2095</span>     *   writestate.writesEnabled = false;<a name="line.2095"></a>
-<span class="sourceLineNo">2096</span>     *   LOG.debug("Closing " + this + ": disabling compactions &amp; flushes");<a name="line.2096"></a>
-<span class="sourceLineNo">2097</span>     *   waitForFlushesAndCompactions();<a name="line.2097"></a>
-<span class="sourceLineNo">2098</span>     * }<a name="line.2098"></a>
-<span class="sourceLineNo">2099</span>     * waitForFlushesAndCompactions() would wait for writestate.compacting to come down to 0.<a name="line.2099"></a>
-<span class="sourceLineNo">2100</span>     * and in HRegion.compact()<a name="line.2100"></a>
-<span class="sourceLineNo">2101</span>     *  try {<a name="line.2101"></a>
-<span class="sourceLineNo">2102</span>     *    synchronized (writestate) {<a name="line.2102"></a>
-<span class="sourceLineNo">2103</span>     *    if (writestate.writesEnabled) {<a name="line.2103"></a>
-<span class="sourceLineNo">2104</span>     *      wasStateSet = true;<a name="line.2104"></a>
-<span class="sourceLineNo">2105</span>     *      ++writestate.compacting;<a name="line.2105"></a>
-<span class="sourceLineNo">2106</span>     *    } else {<a name="line.2106"></a>
-<span class="sourceLineNo">2107</span>     *      String msg = "NOT compacting region " + this + ". Writes disabled.";<a name="line.2107"></a>
-<span class="sourceLineNo">2108</span>     *      LOG.info(msg);<a name="line.2108"></a>
-<span class="sourceLineNo">2109</span>     *      status.abort(msg);<a name="line.2109"></a>
-<span class="sourceLineNo">2110</span>     *      return false;<a name="line.2110"></a>
-<span class="sourceLineNo">2111</span>     *    }<a name="line.2111"></a>
-<span class="sourceLineNo">2112</span>     *  }<a name="line.2112"></a>
-<span class="sourceLineNo">2113</span>     * Also in compactor.performCompaction():<a name="line.2113"></a>
-<span class="sourceLineNo">2114</span>     * check periodically to see if a system stop is requested<a name="line.2114"></a>
-<span class="sourceLineNo">2115</span>     * if (closeCheckInterval &gt; 0) {<a name="line.2115"></a>
-<span class="sourceLineNo">2116</span>     *   bytesWritten += len;<a name="line.2116"></a>
-<span class="sourceLineNo">2117</span>     *   if (bytesWritten &gt; closeCheckInterval) {<a name="line.2117"></a>
-<span class="sourceLineNo">2118</span>     *     bytesWritten = 0;<a name="line.2118"></a>
-<span class="sourceLineNo">2119</span>     *     if (!store.areWritesEnabled()) {<a name="line.2119"></a>
-<span class="sourceLineNo">2120</span>     *       progress.cancel();<a name="line.2120"></a>
-<span class="sourceLineNo">2121</span>     *       return false;<a name="line.2121"></a>
-<span class="sourceLineNo">2122</span>     *     }<a name="line.2122"></a>
-<span class="sourceLineNo">2123</span>     *   }<a name="line.2123"></a>
-<span class="sourceLineNo">2124</span>     * }<a name="line.2124"></a>
-<span class="sourceLineNo">2125</span>     */<a name="line.2125"></a>
-<span class="sourceLineNo">2126</span>    try {<a name="line.2126"></a>
-<span class="sourceLineNo">2127</span>      byte[] cf = Bytes.toBytes(store.getColumnFamilyName());<a name="line.2127"></a>
-<span class="sourceLineNo">2128</span>      if (stores.get(cf) != store) {<a name="line.2128"></a>
-<span class="sourceLineNo">2129</span>        LOG.warn("Store " + store.getColumnFamilyName() + " on region " + this<a name="line.2129"></a>
-<span class="sourceLineNo">2130</span>            + " has been re-instantiated, cancel this compaction request. "<a name="line.2130"></a>
-<span class="sourceLineNo">2131</span>            + " It may be caused by the roll back of split transaction");<a name="line.2131"></a>
-<span class="sourceLineNo">2132</span>        return false;<a name="line.2132"></a>
-<span class="sourceLineNo">2133</span>      }<a name="line.2133"></a>
-<span class="sourceLineNo">2134</span><a name="line.2134"></a>
-<span class="sourceLineNo">2135</span>      status = TaskMonitor.get().createStatus("Compacting " + store + " in " + this);<a name="line.2135"></a>
-<span class="sourceLineNo">2136</span>      if (this.closed.get()) {<a name="line.2136"></a>
-<span class="sourceLineNo">2137</span>        String msg = "Skipping compaction on " + this + " because closed";<a name="line.2137"></a>
-<span class="sourceLineNo">2138</span>        LOG.debug(msg);<a name="line.2138"></a>
-<span class="sourceLineNo">2139</span>        status.abort(msg);<a name="line.2139"></a>
-<span class="sourceLineNo">2140</span>        return false;<a name="line.2140"></a>
-<span class="sourceLineNo">2141</span>      }<a name="line.2141"></a>
-<span class="sourceLineNo">2142</span>      boolean wasStateSet = false;<a name="line.2142"></a>
-<span class="sourceLineNo">2143</span>      try {<a name="line.2143"></a>
-<span class="sourceLineNo">2144</span>        synchronized (writestate) {<a name="line.2144"></a>
-<span class="sourceLineNo">2145</span>          if (writestate.writesEnabled) {<a name="line.2145"></a>
-<span class="sourceLineNo">2146</span>            wasStateSet = true;<a name="line.2146"></a>
-<span class="sourceLineNo">2147</span>            writestate.compacting.incrementAndGet();<a name="line.2147"></a>
-<span class="sourceLineNo">2148</span>          } else {<a name="line.2148"></a>
-<span class="sourceLineNo">2149</span>            String msg = "NOT compacting region " + this + ". Writes disabled.";<a name="line.2149"></a>
-<span class="sourceLineNo">2150</span>            LOG.info(msg);<a name="line.2150"></a>
-<span class="sourceLineNo">2151</span>            status.abort(msg);<a name="line.2151"></a>
-<span class="sourceLineNo">2152</span>            return false;<a name="line.2152"></a>
-<span class="sourceLineNo">2153</span>          }<a name="line.2153"></a>
-<span class="sourceLineNo">2154</span>        }<a name="line.2154"></a>
-<span class="sourceLineNo">2155</span>        LOG.info("Starting compaction on " + store + " in region " + this<a name="line.2155"></a>
-<span class="sourceLineNo">2156</span>            + (compaction.getRequest().isOffPeak()?" as an off-peak compaction":""));<a name="line.2156"></a>
-<span class="sourceLineNo">2157</span>        doRegionCompactionPrep();<a name="line.2157"></a>
-<span class="sourceLineNo">2158</span>        try {<a name="line.2158"></a>
-<span class="sourceLineNo">2159</span>          status.setStatus("Compacting store " + store);<a name="line.2159"></a>
-<span class="sourceLineNo">2160</span>          // We no longer need to cancel the request on the way out of this<a name="line.2160"></a>
-<span class="sourceLineNo">2161</span>          // method because Store#compact will clean up unconditionally<a name="line.2161"></a>
-<span class="sourceLineNo">2162</span>          requestNeedsCancellation = false;<a name="line.2162"></a>
-<span class="sourceLineNo">2163</span>          store.compact(compaction, throughputController, user);<a name="line.2163"></a>
-<span class="sourceLineNo">2164</span>        } catch (InterruptedIOException iioe) {<a name="line.2164"></a>
-<span class="sourceLineNo">2165</span>          String msg = "compaction interrupted";<a name="line.2165"></a>
-<span class="sourceLineNo">2166</span>          LOG.info(msg, iioe);<a name="line.2166"></a>
-<span class="sourceLineNo">2167</span>          status.abort(msg);<a name="line.2167"></a>
-<span class="sourceLineNo">2168</span>          return false;<a name="line.2168"></a>
-<span class="sourceLineNo">2169</span>        }<a name="line.2169"></a>
-<span class="sourceLineNo">2170</span>      } finally {<a name="line.2170"></a>
-<span class="sourceLineNo">2171</span>        if (wasStateSet) {<a name="line.2171"></a>
-<span class="sourceLineNo">2172</span>          synchronized (writestate) {<a name="line.2172"></a>
-<span class="sourceLineNo">2173</span>            writestate.compacting.decrementAndGet();<a name="line.2173"></a>
-<span class="sourceLineNo">2174</span>            if (writestate.compacting.get() &lt;= 0) {<a name="line.2174"></a>
-<span class="sourceLineNo">2175</span>              writestate.notifyAll();<a name="line.2175"></a>
-<span class="sourceLineNo">2176</span>            }<a name="line.2176"></a>
-<span class="sourceLineNo">2177</span>          }<a name="line.2177"></a>
-<span class="sourceLineNo">2178</span>        }<a name="line.2178"></a>
-<span class="sourceLineNo">2179</span>      }<a name="line.2179"></a>
-<span class="sourceLineNo">2180</span>      status.markComplete("Compaction complete");<a name="line.2180"></a>
-<span class="sourceLineNo">2181</span>      return true;<a name="line.2181"></a>
-<span class="sourceLineNo">2182</span>    } finally {<a name="line.2182"></a>
-<span class="sourceLineNo">2183</span>      if (requestNeedsCancellation) store.cancelRequestedCompaction(compaction);<a name="line.2183"></a>
-<span class="sourceLineNo">2184</span>      if (status != null) status.cleanup();<a name="line.2184"></a>
-<span class="sourceLineNo">2185</span>    }<a name="line.2185"></a>
-<span class="sourceLineNo">2186</span>  }<a name="line.2186"></a>
-<span class="sourceLineNo">2187</span><a name="line.2187"></a>
-<span class="sourceLineNo">2188</span>  /**<a name="line.2188"></a>
-<span class="sourceLineNo">2189</span>   * Flush the cache.<a name="line.2189"></a>
-<span class="sourceLineNo">2190</span>   *<a name="line.2190"></a>
-<span class="sourceLineNo">2191</span>   * &lt;p&gt;When this method is called the cache will be flushed unless:<a name="line.2191"></a>
-<span class="sourceLineNo">2192</span>   * &lt;ol&gt;<a name="line.2192"></a>
-<span class="sourceLineNo">2193</span>   *   &lt;li&gt;the cache is empty&lt;/li&gt;<a name="line.2193"></a>
-<span class="sourceLineNo">2194</span>   *   &lt;li&gt;the region is closed.&lt;/li&gt;<a name="line.2194"></a>
-<span class="sourceLineNo">2195</span>   *   &lt;li&gt;a flush is already in progress&lt;/li&gt;<a name="line.2195"></a>
-<span class="sourceLineNo">2196</span>   *   &lt;li&gt;writes are disabled&lt;/li&gt;<a name="line.2196"></a>
-<span class="sourceLineNo">2197</span>   * &lt;/ol&gt;<a name="line.2197"></a>
-<span class="sourceLineNo">2198</span>   *<a name="line.2198"></a>
-<span class="sourceLineNo">2199</span>   * &lt;p&gt;This method may block for some time, so it should not be called from a<a name="line.2199"></a>
-<span class="sourceLineNo">2200</span>   * time-sensitive thread.<a name="line.2200"></a>
-<span class="sourceLineNo">2201</span>   * @param force whether we want to force a flush of all stores<a name="line.2201"></a>
-<span class="sourceLineNo">2202</span>   * @return FlushResult indicating whether the flush was successful or not and if<a name="line.2202"></a>
-<span class="sourceLineNo">2203</span>   * the region needs compacting<a name="line.2203"></a>
-<span class="sourceLineNo">2204</span>   *<a name="line.2204"></a>
-<span class="sourceLineNo">2205</span>   * @throws IOException general io exceptions<a name="line.2205"></a>
-<span class="sourceLineNo">2206</span>   * because a snapshot was not properly persisted.<a name="line.2206"></a>
-<span class="sourceLineNo">2207</span>   */<a name="line.2207"></a>
-<span class="sourceLineNo">2208</span>  // TODO HBASE-18905. We might have to expose a requestFlush API for CPs<a name="line.2208"></a>
-<span class="sourceLineNo">2209</span>  public FlushResult flush(boolean force) throws IOException {<a name="line.2209"></a>
-<span class="sourceLineNo">2210</span>    return flushcache(force, false);<a name="line.2210"></a>
-<span class="sourceLineNo">2211</span>  }<a name="line.2211"></a>
-<span class="sourceLineNo">2212</span><a name="line.2212"></a>
-<span class="sourceLineNo">2213</span>  public static interface FlushResult {<a name="line.2213"></a>
-<span class="sourceLineNo">2214</span>    enum Result {<a name="line.2214"></a>
-<span class="sourceLineNo">2215</span>      FLUSHED_NO_COMPACTION_NEEDED,<a name="line.2215"></a>
-<span class="sourceLineNo">2216</span>      FLUSHED_COMPACTION_NEEDED,<a name="line.2216"></a>
-<span class="sourceLineNo">2217</span>      // Special case where a flush didn't run because there's nothing in the memstores. Used when<a name="line.2217"></a>
-<span class="sourceLineNo">2218</span>      // bulk loading to know when we can still load even if a flush didn't happen.<a name="line.2218"></a>
-<span class="sourceLineNo">2219</span>      CANNOT_FLUSH_MEMSTORE_EMPTY,<a name="line.2219"></a>
-<span class="sourceLineNo">2220</span>      CANNOT_FLUSH<a name="line.2220"></a>
-<span class="sourceLineNo">2221</span>    }<a name="line.2221"></a>
-<span class="sourceLineNo">2222</span><a name="line.2222"></a>
-<span class="sourceLineNo">2223</span>    /** @return the detailed result code */<a name="line.2223"></a>
-<span class="sourceLineNo">2224</span>    Result getResult();<a name="line.2224"></a>
-<span class="sourceLineNo">2225</span><a name="line.2225"></a>
-<span class="sourceLineNo">2226</span>    /** @return true if the memstores were flushed, else false */<a name="line.2226"></a>
-<span class="sourceLineNo">2227</span>    boolean isFlushSucceeded();<a name="line.2227"></a>
-<span class="sourceLineNo">2228</span><a name="line.2228"></a>
-<span class="sourceLineNo">2229</span>    /** @return True if the flush requested a compaction, else false */<a name="line.2229"></a>
-<span class="sourceLineNo">2230</span>    boolean isCompactionNeeded();<a name="line.2230"></a>
-<span class="sourceLineNo">2231</span>  }<a name="line.2231"></a>
-<span class="sourceLineNo">2232</span><a name="line.2232"></a>
-<span class="sourceLineNo">2233</span>  /**<a name="line.2233"></a>
-<span class="sourceLineNo">2234</span>   * Flush the cache.<a name="line.2234"></a>
-<span class="sourceLineNo">2235</span>   *<a name="line.2235"></a>
-<span class="sourceLineNo">2236</span>   * When this method is called the cache will be flushed unless:<a name="line.2236"></a>
-<span class="sourceLineNo">2237</span>   * &lt;ol&gt;<a name="line.2237"></a>
-<span class="sourceLineNo">2238</span>   *   &lt;li&gt;the cache is empty&lt;/li&gt;<a name="line.2238"></a>
-<span class="sourceLineNo">2239</span>   *   &lt;li&gt;the region is closed.&lt;/li&gt;<a name="line.2239"></a>
-<span class="sourceLineNo">2240</span>   *   &lt;li&gt;a flush is already in progress&lt;/li&gt;<a name="line.2240"></a>
-<span class="sourceLineNo">2241</span>   *   &lt;li&gt;writes are disabled&lt;/li&gt;<a name="line.2241"></a>
-<span class="sourceLineNo">2242</span>   * &lt;/ol&gt;<a name="line.2242"></a>
-<span class="sourceLineNo">2243</span>   *<a name="line.2243"></a>
-<span class="sourceLineNo">2244</span>   * &lt;p&gt;This method may block for some time, so it should not be called from a<a name="line.2244"></a>
-<span class="sourceLineNo">2245</span>   * time-sensitive thread.<a name="line.2245"></a>
-<span class="sourceLineNo">2246</span>   * @param forceFlushAllStores whether we want to flush all stores<a name="line.2246"></a>
-<span class="sourceLineNo">2247</span>   * @param writeFlushRequestWalMarker whether to write the flush request marker to WAL<a name="line.2247"></a>
-<span class="sourceLineNo">2248</span>   * @return whether the flush is success and whether the region needs compacting<a name="line.2248"></a>
-<span class="sourceLineNo">2249</span>   *<a name="line.2249"></a>
-<span class="sourceLineNo">2250</span>   * @throws IOException general io exceptions<a name="line.2250"></a>
-<span class="sourceLineNo">2251</span>   * @throws DroppedSnapshotException Thrown when replay of wal is required<a name="line.2251"></a>
-<span class="sourceLineNo">2252</span>   * because a Snapshot was not properly persisted. The region is put in closing mode, and the<a name="line.2252"></a>
-<span class="sourceLineNo">2253</span>   * caller MUST abort after this.<a name="line.2253"></a>
-<span class="sourceLineNo">2254</span>   */<a name="line.2254"></a>
-<span class="sourceLineNo">2255</span>  public FlushResultImpl flushcache(boolean forceFlushAllStores, boolean writeFlushRequestWalMarker)<a name="line.2255"></a>
-<span class="sourceLineNo">2256</span>      throws IOException {<a name="line.2256"></a>
-<span class="sourceLineNo">2257</span>    // fail-fast instead of waiting on the lock<a name="line.2257"></a>
-<span class="sourceLineNo">2258</span>    if (this.closing.get()) {<a name="line.2258"></a>
-<span class="sourceLineNo">2259</span>      String msg = "Skipping flush on " + this + " because closing";<a name="line.2259"></a>
-<span class="sourceLineNo">2260</span>      LOG.debug(msg);<a name="line.2260"></a>
-<span class="sourceLineNo">2261</span>      return new FlushResultImpl(FlushResult.Result.CANNOT_FLUSH, msg, false);<a name="line.2261"></a>
-<span class="sourceLineNo">2262</span>    }<a name="line.2262"></a>
-<span class="sourceLineNo">2263</span>    MonitoredTask status = TaskMonitor.get().createStatus("Flushing " + this);<a name="line.2263"></a>
-<span class="sourceLineNo">2264</span>    status.setStatus("Acquiring readlock on region");<a name="line.2264"></a>
-<span class="sourceLineNo">2265</span>    // block waiting for the lock for flushing cache<a name="line.2265"></a>
-<span class="sourceLineNo">2266</span>    lock.readLock().lock();<a name="line.2266"></a>
-<span class="sourceLineNo">2267</span>    try {<a name="line.2267"></a>
-<span class="sourceLineNo">2268</span>      if (this.closed.get()) {<a name="line.2268"></a>
-<span class="sourceLineNo">2269</span>        String msg = "Skipping flush on " + this + " because closed";<a name="line.2269"></a>
-<span class="sourceLineNo">2270</span>        LOG.debug(msg);<a name="line.2270"></a>
-<span class="sourceLineNo">2271</span>        status.abort(msg);<a name="line.2271"></a>
-<span class="sourceLineNo">2272</span>        return new FlushResultImpl(FlushResult.Result.CANNOT_FLUSH, msg, false);<a name="line.2272"></a>
-<span class="sourceLineNo">2273</span>      }<a name="line.2273"></a>
-<span class="sourceLineNo">2274</span>      if (coprocessorHost != null) {<a name="line.2274"></a>
-<span class="sourceLineNo">2275</span>        status.setStatus("Running coprocessor pre-flush hooks");<a name="line.2275"></a>
-<span class="sourceLineNo">2276</span>        coprocessorHost.preFlush();<a name="line.2276"></a>
-<span class="sourceLineNo">2277</span>      }<a name="line.2277"></a>
-<span class="sourceLineNo">2278</span>      // TODO: this should be managed within memstore with the snapshot, updated only after flush<a name="line.2278"></a>
-<span class="sourceLineNo">2279</span>      // successful<a name="line.2279"></a>
-<span class="sourceLineNo">2280</span>      if (numMutationsWithoutWAL.sum() &gt; 0) {<a name="line.2280"></a>
-<span class="sourceLineNo">2281</span>        numMutationsWithoutWAL.reset();<a name="line.2281"></a>
-<span class="sourceLineNo">2282</span>        dataInMemoryWithoutWAL.reset();<a name="line.2282"></a>
-<span class="sourceLineNo">2283</span>      }<a name="line.2283"></a>
-<span class="sourceLineNo">2284</span>      synchronized (writestate) {<a name="line.2284"></a>
-<span class="sourceLineNo">2285</span>        if (!writestate.flushing &amp;&amp; writestate.writesEnabled) {<a name="line.2285"></a>
-<span class="sourceLineNo">2286</span>          this.writestate.flushing = true;<a name="line.2286"></a>
-<span class="sourceLineNo">2287</span>        } else {<a name="line.2287"></a>
-<span class="sourceLineNo">2288</span>          if (LOG.isDebugEnabled()) {<a name="line.2288"></a>
-<span class="sourceLineNo">2289</span>            LOG.debug("NOT flushing memstore for region " + this<a name="line.2289"></a>
-<span class="sourceLineNo">2290</span>                + ", flushing=" + writestate.flushing + ", writesEnabled="<a name="line.2290"></a>
-<span class="sourceLineNo">2291</span>                + writestate.writesEnabled);<a name="line.2291"></a>
-<span class="sourceLineNo">2292</span>          }<a name="line.2292"></a>
-<span class="sourceLineNo">2293</span>          String msg = "Not flushing since "<a name="line.2293"></a>
-<span class="sourceLineNo">2294</span>              + (writestate.flushing ? "already flushing"<a name="line.2294"></a>
-<span class="sourceLineNo">2295</span>              : "writes not enabled");<a name="line.2295"></a>
-<span class="sourceLineNo">2296</span>          status.abort(msg);<a name="line.2296"></a>
-<span class="sourceLineNo">2297</span>          return new FlushResultImpl(FlushResult.Result.CANNOT_FLUSH, msg, false);<a name="line.2297"></a>
-<span class="sourceLineNo">2298</span>        }<a name="line.2298"></a>
-<span class="sourceLineNo">2299</span>      }<a name="line.2299"></a>
-<span class="sourceLineNo">2300</span><a name="line.2300"></a>
-<span class="sourceLineNo">2301</span>      try {<a name="line.2301"></a>
-<span class="sourceLineNo">2302</span>        Collection&lt;HStore&gt; specificStoresToFlush =<a name="line.2302"></a>
-<span class="sourceLineNo">2303</span>            forceFlushAllStores ? stores.values() : flushPolicy.selectStoresToFlush();<a name="line.2303"></a>
-<span class="sourceLineNo">2304</span>        FlushResultImpl fs =<a name="line.2304"></a>
-<span class="sourceLineNo">2305</span>            internalFlushcache(specificStoresToFlush, status, writeFlushRequestWalMarker);<a name="line.2305"></a>
+<span class="sourceLineNo">2062</span>     * The only remaining race condition is between the region close and compaction.<a name="line.2062"></a>
+<span class="sourceLineNo">2063</span>     * So we will evaluate, below, how region close intervenes with compaction if compaction does<a name="line.2063"></a>
+<span class="sourceLineNo">2064</span>     * not acquire region read lock.<a name="line.2064"></a>
+<span class="sourceLineNo">2065</span>     *<a name="line.2065"></a>
+<span class="sourceLineNo">2066</span>     * Here are the steps for compaction:<a name="line.2066"></a>
+<span class="sourceLineNo">2067</span>     * 1. obtain list of StoreFile's<a name="line.2067"></a>
+<span class="sourceLineNo">2068</span>     * 2. create StoreFileScanner's based on list from #1<a name="line.2068"></a>
+<span class="sourceLineNo">2069</span>     * 3. perform compaction and save resulting files under tmp dir<a name="line.2069"></a>
+<span class="sourceLineNo">2070</span>     * 4. swap in compacted files<a name="line.2070"></a>
+<span class="sourceLineNo">2071</span>     *<a name="line.2071"></a>
+<span class="sourceLineNo">2072</span>     * #1 is guarded by store lock. This patch does not change this --&gt; no worse or better<a name="line.2072"></a>
+<span class="sourceLineNo">2073</span>     * For #2, we obtain smallest read point (for region) across all the Scanners (for both default<a name="line.2073"></a>
+<span class="sourceLineNo">2074</span>     * compactor and stripe compactor).<a name="line.2074"></a>
+<span class="sourceLineNo">2075</span>     * The read points are for user scans. Region keeps the read points for all currently open<a name="line.2075"></a>
+<span class="sourceLineNo">2076</span>     * user scanners.<a name="line.2076"></a>
+<span class="sourceLineNo">2077</span>     * Compaction needs to know the smallest read point so that during re-write of the hfiles,<a name="line.2077"></a>
+<span class="sourceLineNo">2078</span>     * it can remove the mvcc points for the cells if their mvccs are older than the smallest<a name="line.2078"></a>
+<span class="sourceLineNo">2079</span>     * since they are not needed anymore.<a name="line.2079"></a>
+<span class="sourceLineNo">2080</span>     * This will not conflict with compaction.<a name="line.2080"></a>
+<span class="sourceLineNo">2081</span>     * For #3, it can be performed in parallel to other operations.<a name="line.2081"></a>
+<span class="sourceLineNo">2082</span>     * For #4 bulk load and compaction don't conflict with each other on the region level<a name="line.2082"></a>
+<span class="sourceLineNo">2083</span>     *   (for multi-family atomicy).<a name="line.2083"></a>
+<span class="sourceLineNo">2084</span>     * Region close and compaction are guarded pretty well by the 'writestate'.<a name="line.2084"></a>
+<span class="sourceLineNo">2085</span>     * In HRegion#doClose(), we have :<a name="line.2085"></a>
+<span class="sourceLineNo">2086</span>     * synchronized (writestate) {<a name="line.2086"></a>
+<span class="sourceLineNo">2087</span>     *   // Disable compacting and flushing by background threads for this<a name="line.2087"></a>
+<span class="sourceLineNo">2088</span>     *   // region.<a name="line.2088"></a>
+<span class="sourceLineNo">2089</span>     *   canFlush = !writestate.readOnly;<a name="line.2089"></a>
+<span class="sourceLineNo">2090</span>     *   writestate.writesEnabled = false;<a name="line.2090"></a>
+<span class="sourceLineNo">2091</span>     *   LOG.debug("Closing " + this + ": disabling compactions &amp; flushes");<a name="line.2091"></a>
+<span class="sourceLineNo">2092</span>     *   waitForFlushesAndCompactions();<a name="line.2092"></a>
+<span class="sourceLineNo">2093</span>     * }<a name="line.2093"></a>
+<span class="sourceLineNo">2094</span>     * waitForFlushesAndCompactions() would wait for writestate.compacting to come down to 0.<a name="line.2094"></a>
+<span class="sourceLineNo">2095</span>     * and in HRegion.compact()<a name="line.2095"></a>
+<span class="sourceLineNo">2096</span>     *  try {<a name="line.2096"></a>
+<span class="sourceLineNo">2097</span>     *    synchronized (writestate) {<a name="line.2097"></a>
+<span class="sourceLineNo">2098</span>     *    if (writestate.writesEnabled) {<a name="line.2098"></a>
+<span class="sourceLineNo">2099</span>     *      wasStateSet = true;<a name="line.2099"></a>
+<span class="sourceLineNo">2100</span>     *      ++writestate.compacting;<a name="line.2100"></a>
+<span class="sourceLineNo">2101</span>     *    } else {<a name="line.2101"></a>
+<span class="sourceLineNo">2102</span>     *      String msg = "NOT compacting region " + this + ". Writes disabled.";<a name="line.2102"></a>
+<span class="sourceLineNo">2103</span>     *      LOG.info(msg);<a name="line.2103"></a>
+<span class="sourceLineNo">2104</span>     *      status.abort(msg);<a name="line.2104"></a>
+<span class="sourceLineNo">2105</span>     *      return false;<a name="line.2105"></a>
+<span class="sourceLineNo">2106</span>     *    }<a name="line.2106"></a>
+<span class="sourceLineNo">2107</span>     *  }<a name="line.2107"></a>
+<span class="sourceLineNo">2108</span>     * Also in compactor.performCompaction():<a name="line.2108"></a>
+<span class="sourceLineNo">2109</span>     * check periodically to see if a system stop is requested<a name="line.2109"></a>
+<span class="sourceLineNo">2110</span>     * if (closeCheckInterval &gt; 0) {<a name="line.2110"></a>
+<span class="sourceLineNo">2111</span>     *   bytesWritten += len;<a name="line.2111"></a>
+<span class="sourceLineNo">2112</span>     *   if (bytesWritten &gt; closeCheckInterval) {<a name="line.2112"></a>
+<span class="sourceLineNo">2113</span>     *     bytesWritten = 0;<a name="line.2113"></a>
+<span class="sourceLineNo">2114</span>     *     if (!store.areWritesEnabled()) {<a name="line.2114"></a>
+<span class="sourceLineNo">2115</span>     *       progress.cancel();<a name="line.2115"></a>
+<span class="sourceLineNo">2116</span>     *       return false;<a name="line.2116"></a>
+<span class="sourceLineNo">2117</span>     *     }<a name="line.2117"></a>
+<span class="sourceLineNo">2118</span>     *   }<a name="line.2118"></a>
+<span class="sourceLineNo">2119</span>     * }<a name="line.2119"></a>
+<span class="sourceLineNo">2120</span>     */<a name="line.2120"></a>
+<span class="sourceLineNo">2121</span>    try {<a name="line.2121"></a>
+<span class="sourceLineNo">2122</span>      byte[] cf = Bytes.toBytes(store.getColumnFamilyName());<a name="line.2122"></a>
+<span class="sourceLineNo">2123</span>      if (stores.get(cf) != store) {<a name="line.2123"></a>
+<span class="sourceLineNo">2124</span>        LOG.warn("Store " + store.getColumnFamilyName() + " on region " + this<a name="line.2124"></a>
+<span class="sourceLineNo">2125</span>            + " has been re-instantiated, cancel this compaction request. "<a name="line.2125"></a>
+<span class="sourceLineNo">2126</span>            + " It may be caused by the roll back of split transaction");<a name="line.2126"></a>
+<span class="sourceLineNo">2127</span>        return false;<a name="line.2127"></a>
+<span class="sourceLineNo">2128</span>      }<a name="line.2128"></a>
+<span class="sourceLineNo">2129</span><a name="line.2129"></a>
+<span class="sourceLineNo">2130</span>      status = TaskMonitor.get().createStatus("Compacting " + store + " in " + this);<a name="line.2130"></a>
+<span class="sourceLineNo">2131</span>      if (this.closed.get()) {<a name="line.2131"></a>
+<span class="sourceLineNo">2132</span>        String msg = "Skipping compaction on " + this + " because closed";<a name="line.2132"></a>
+<span class="sourceLineNo">2133</span>        LOG.debug(msg);<a name="line.2133"></a>
+<span class="sourceLineNo">2134</span>        status.abort(msg);<a name="line.2134"></a>
+<span class="sourceLineNo">2135</span>        return false;<a name="line.2135"></a>
+<span class="sourceLineNo">2136</span>      }<a name="line.2136"></a>
+<span class="sourceLineNo">2137</span>      boolean wasStateSet = false;<a name="line.2137"></a>
+<span class="sourceLineNo">2138</span>      try {<a name="line.2138"></a>
+<span class="sourceLineNo">2139</span>        synchronized (writestate) {<a name="line.2139"></a>
+<span class="sourceLineNo">2140</span>          if (writestate.writesEnabled) {<a name="line.2140"></a>
+<span class="sourceLineNo">2141</span>            wasStateSet = true;<a name="line.2141"></a>
+<span class="sourceLineNo">2142</span>            writestate.compacting.incrementAndGet();<a name="line.2142"></a>
+<span class="sourceLineNo">2143</span>          } else {<a name="line.2143"></a>
+<span class="sourceLineNo">2144</span>            String msg = "NOT compacting region " + this + ". Writes disabled.";<a name="line.2144"></a>
+<span class="sourceLineNo">2145</span>            LOG.info(msg);<a name="line.2145"></a>
+<span class="sourceLineNo">2146</span>            status.abort(msg);<a name="line.2146"></a>
+<span class="sourceLineNo">2147</span>            return false;<a name="line.2147"></a>
+<span class="sourceLineNo">2148</span>          }<a name="line.2148"></a>
+<span class="sourceLineNo">2149</span>        }<a name="line.2149"></a>
+<span class="sourceLineNo">2150</span>        LOG.info("Starting compaction on " + store + " in region " + this<a name="line.2150"></a>
+<span class="sourceLineNo">2151</span>            + (compaction.getRequest().isOffPeak()?" as an off-peak compaction":""));<a name="line.2151"></a>
+<span class="sourceLineNo">2152</span>        doRegionCompactionPrep();<a name="line.2152"></a>
+<span class="sourceLineNo">2153</span>        try {<a name="line.2153"></a>
+<span class="sourceLineNo">2154</span>          status.setStatus("Compacting store " + store);<a name="line.2154"></a>
+<span class="sourceLineNo">2155</span>          // We no longer need to cancel the request on the way out of this<a name="line.2155"></a>
+<span class="sourceLineNo">2156</span>          // method because Store#compact will clean up unconditionally<a name="line.2156"></a>
+<span class="sourceLineNo">2157</span>          requestNeedsCancellation = false;<a name="line.2157"></a>
+<span class="sourceLineNo">2158</span>          store.compact(compaction, throughputController, user);<a name="line.2158"></a>
+<span class="sourceLineNo">2159</span>        } catch (InterruptedIOException iioe) {<a name="line.2159"></a>
+<span class="sourceLineNo">2160</span>          String msg = "compaction interrupted";<a name="line.2160"></a>
+<span class="sourceLineNo">2161</span>          LOG.info(msg, iioe);<a name="line.2161"></a>
+<span class="sourceLineNo">2162</span>          status.abort(msg);<a name="line.2162"></a>
+<span class="sourceLineNo">2163</span>          return false;<a name="line.2163"></a>
+<span class="sourceLineNo">2164</span>        }<a name="line.2164"></a>
+<span class="sourceLineNo">2165</span>      } finally {<a name="line.2165"></a>
+<span class="sourceLineNo">2166</span>        if (wasStateSet) {<a name="line.2166"></a>
+<span class="sourceLineNo">2167</span>          synchronized (writestate) {<a name="line.2167"></a>
+<span class="sourceLineNo">2168</span>            writestate.compacting.decrementAndGet();<a name="line.2168"></a>
+<span class="sourceLineNo">2169</span>            if (writestate.compacting.get() &lt;= 0) {<a name="line.2169"></a>
+<span class="sourceLineNo">2170</span>              writestate.notifyAll();<a name="line.2170"></a>
+<span class="sourceLineNo">2171</span>            }<a name="line.2171"></a>
+<span class="sourceLineNo">2172</span>          }<a name="line.2172"></a>
+<span class="sourceLineNo">2173</span>        }<a name="line.2173"></a>
+<span class="sourceLineNo">2174</span>      }<a name="line.2174"></a>
+<span class="sourceLineNo">2175</span>      status.markComplete("Compaction complete");<a name="line.2175"></a>
+<span class="sourceLineNo">2176</span>      return true;<a name="line.2176"></a>
+<span class="sourceLineNo">2177</span>    } finally {<a name="line.2177"></a>
+<span class="sourceLineNo">2178</span>      if (requestNeedsCancellation) store.cancelRequestedCompaction(compaction);<a name="line.2178"></a>
+<span class="sourceLineNo">2179</span>      if (status != null) status.cleanup();<a name="line.2179"></a>
+<span class="sourceLineNo">2180</span>    }<a name="line.2180"></a>
+<span class="sourceLineNo">2181</span>  }<a name="line.2181"></a>
+<span class="sourceLineNo">2182</span><a name="line.2182"></a>
+<span class="sourceLineNo">2183</span>  /**<a name="line.2183"></a>
+<span class="sourceLineNo">2184</span>   * Flush the cache.<a name="line.2184"></a>
+<span class="sourceLineNo">2185</span>   *<a name="line.2185"></a>
+<span class="sourceLineNo">2186</span>   * &lt;p&gt;When this method is called the cache will be flushed unless:<a name="line.2186"></a>
+<span class="sourceLineNo">2187</span>   * &lt;ol&gt;<a name="line.2187"></a>
+<span class="sourceLineNo">2188</span>   *   &lt;li&gt;the cache is empty&lt;/li&gt;<a name="line.2188"></a>
+<span class="sourceLineNo">2189</span>   *   &lt;li&gt;the region is closed.&lt;/li&gt;<a name="line.2189"></a>
+<span class="sourceLineNo">2190</span>   *   &lt;li&gt;a flush is already in progress&lt;/li&gt;<a name="line.2190"></a>
+<span class="sourceLineNo">2191</span>   *   &lt;li&gt;writes are disabled&lt;/li&gt;<a name="line.2191"></a>
+<span class="sourceLineNo">2192</span>   * &lt;/ol&gt;<a name="line.2192"></a>
+<span class="sourceLineNo">2193</span>   *<a name="line.2193"></a>
+<span class="sourceLineNo">2194</span>   * &lt;p&gt;This method may block for some time, so it should not be called from a<a name="line.2194"></a>
+<span class="sourceLineNo">2195</span>   * time-sensitive thread.<a name="line.2195"></a>
+<span class="sourceLineNo">2196</span>   * @param force whether we want to force a flush of all stores<a name="line.2196"></a>
+<span class="sourceLineNo">2197</span>   * @return FlushResult indicating whether the flush was successful or not and if<a name="line.2197"></a>
+<span class="sourceLineNo">2198</span>   * the region needs compacting<a name="line.2198"></a>
+<span class="sourceLineNo">2199</span>   *<a name="line.2199"></a>
+<span class="sourceLineNo">2200</span>   * @throws IOException general io exceptions<a name="line.2200"></a>
+<span class="sourceLineNo">2201</span>   * because a snapshot was not properly persisted.<a name="line.2201"></a>
+<span class="sourceLineNo">2202</span>   */<a name="line.2202"></a>
+<span class="sourceLineNo">2203</span>  // TODO HBASE-18905. We might have to expose a requestFlush API for CPs<a name="line.2203"></a>
+<span class="sourceLineNo">2204</span>  public FlushResult flush(boolean force) throws IOException {<a name="line.2204"></a>
+<span class="sourceLineNo">2205</span>    return flushcache(force, false);<a name="line.2205"></a>
+<span class="sourceLineNo">2206</span>  }<a name="line.2206"></a>
+<span class="sourceLineNo">2207</span><a name="line.2207"></a>
+<span class="sourceLineNo">2208</span>  public static interface FlushResult {<a name="line.2208"></a>
+<span class="sourceLineNo">2209</span>    enum Result {<a name="line.2209"></a>
+<span class="sourceLineNo">2210</span>      FLUSHED_NO_COMPACTION_NEEDED,<a name="line.2210"></a>
+<span class="sourceLineNo">2211</span>      FLUSHED_COMPACTION_NEEDED,<a name="line.2211"></a>
+<span class="sourceLineNo">2212</span>      // Special case where a flush didn't run because there's nothing in the memstores. Used when<a name="line.2212"></a>
+<span class="sourceLineNo">2213</span>      // bulk loading to know when we can still load even if a flush didn't happen.<a name="line.2213"></a>
+<span class="sourceLineNo">2214</span>      CANNOT_FLUSH_MEMSTORE_EMPTY,<a name="line.2214"></a>
+<span class="sourceLineNo">2215</span>      CANNOT_FLUSH<a name="line.2215"></a>
+<span class="sourceLineNo">2216</span>    }<a name="line.2216"></a>
+<span class="sourceLineNo">2217</span><a name="line.2217"></a>
+<span class="sourceLineNo">2218</span>    /** @return the detailed result code */<a name="line.2218"></a>
+<span class="sourceLineNo">2219</span>    Result getResult();<a name="line.2219"></a>
+<span class="sourceLineNo">2220</span><a name="line.2220"></a>
+<span class="sourceLineNo">2221</span>    /** @return true if the memstores were flushed, else false */<a name="line.2221"></a>
+<span class="sourceLineNo">2222</span>    boolean isFlushSucceeded();<a name="line.2222"></a>
+<span class="sourceLineNo">2223</span><a name="line.2223"></a>
+<span class="sourceLineNo">2224</span>    /** @return True if the flush requested a compaction, else false */<a name="line.2224"></a>
+<span class="sourceLineNo">2225</span>    boolean isCompactionNeeded();<a name="line.2225"></a>
+<span class="sourceLineNo">2226</span>  }<a name="line.2226"></a>
+<span class="sourceLineNo">2227</span><a name="line.2227"></a>
+<span class="sourceLineNo">2228</span>  /**<a name="line.2228"></a>
+<span class="sourceLineNo">2229</span>   * Flush the cache.<a name="line.2229"></a>
+<span class="sourceLineNo">2230</span>   *<a name="line.2230"></a>
+<span class="sourceLineNo">2231</span>   * When this method is called the cache will be flushed unless:<a name="line.2231"></a>
+<span class="sourceLineNo">2232</span>   * &lt;ol&gt;<a name="line.2232"></a>
+<span class="sourceLineNo">2233</span>   *   &lt;li&gt;the cache is empty&lt;/li&gt;<a name="line.2233"></a>
+<span class="sourceLineNo">2234</span>   *   &lt;li&gt;the region is closed.&lt;/li&gt;<a name="line.2234"></a>
+<span class="sourceLineNo">2235</span>   *   &lt;li&gt;a flush is already in progress&lt;/li&gt;<a name="line.2235"></a>
+<span class="sourceLineNo">2236</span>   *   &lt;li&gt;writes are disabled&lt;/li&gt;<a name="line.2236"></a>
+<span class="sourceLineNo">2237</span>   * &lt;/ol&gt;<a name="line.2237"></a>
+<span class="sourceLineNo">2238</span>   *<a name="line.2238"></a>
+<span class="sourceLineNo">2239</span>   * &lt;p&gt;This method may block for some time, so it should not be called from a<a name="line.2239"></a>
+<span class="sourceLineNo">2240</span>   * time-sensitive thread.<a name="line.2240"></a>
+<span class="sourceLineNo">2241</span>   * @param forceFlushAllStores whether we want to flush all stores<a name="line.2241"></a>
+<span class="sourceLineNo">2242</span>   * @param writeFlushRequestWalMarker whether to write the flush request marker to WAL<a name="line.2242"></a>
+<span class="sourceLineNo">2243</span>   * @return whether the flush is success and whether the region needs compacting<a name="line.2243"></a>
+<span class="sourceLineNo">2244</span>   *<a name="line.2244"></a>
+<span class="sourceLineNo">2245</span>   * @throws IOException general io exceptions<a name="line.2245"></a>
+<span class="sourceLineNo">2246</span>   * @throws DroppedSnapshotException Thrown when replay of wal is required<a name="line.2246"></a>
+<span class="sourceLineNo">2247</span>   * because a Snapshot was not properly persisted. The region is put in closing mode, and the<a name="line.2247"></a>
+<span class="sourceLineNo">2248</span>   * caller MUST abort after this.<a name="line.2248"></a>
+<span class="sourceLineNo">2249</span>   */<a name="line.2249"></a>
+<span class="sourceLineNo">2250</span>  public FlushResultImpl flushcache(boolean forceFlushAllStores, boolean writeFlushRequestWalMarker)<a name="line.2250"></a>
+<span class="sourceLineNo">2251</span>      throws IOException {<a name="line.2251"></a>
+<span class="sourceLineNo">2252</span>    // fail-fast instead of waiting on the lock<a name="line.2252"></a>
+<span class="sourceLineNo">2253</span>    if (this.closing.get()) {<a name="line.2253"></a>
+<span class="sourceLineNo">2254</span>      String msg = "Skipping flush on " + this + " because closing";<a name="line.2254"></a>
+<span class="sourceLineNo">2255</span>      LOG.debug(msg);<a name="line.2255"></a>
+<span class="sourceLineNo">2256</span>      return new FlushResultImpl(FlushResult.Result.CANNOT_FLUSH, msg, false);<a name="line.2256"></a>
+<span class="sourceLineNo">2257</span>    }<a name="line.2257"></a>
+<span class="sourceLineNo">2258</span>    MonitoredTask status = TaskMonitor.get().createStatus("Flushing " + this);<a name="line.2258"></a>
+<span class="sourceLineNo">2259</span>    status.setStatus("Acquiring readlock on region");<a name="line.2259"></a>
+<span class="sourceLineNo">2260</span>    // block waiting for the lock for flushing cache<a name="line.2260"></a>
+<span class="sourceLineNo">2261</span>    lock.readLock().lock();<a name="line.2261"></a>
+<span class="sourceLineNo">2262</span>    try {<a name="line.2262"></a>
+<span class="sourceLineNo">2263</span>      if (this.closed.get()) {<a name="line.2263"></a>
+<span class="sourceLineNo">2264</span>        String msg = "Skipping flush on " + this + " because closed";<a name="line.2264"></a>
+<span class="sourceLineNo">2265</span>        LOG.debug(msg);<a name="line.2265"></a>
+<span class="sourceLineNo">2266</span>        status.abort(msg);<a name="line.2266"></a>
+<span class="sourceLineNo">2267</span>        return new FlushResultImpl(FlushResult.Result.CANNOT_FLUSH, msg, false);<a name="line.2267"></a>
+<span class="sourceLineNo">2268</span>      }<a name="line.2268"></a>
+<span class="sourceLineNo">2269</span>      if (coprocessorHost != null) {<a name="line.2269"></a>
+<span class="sourceLineNo">2270</span>        status.setStatus("Running coprocessor pre-flush hooks");<a name="line.2270"></a>
+<span class="sourceLineNo">2271</span>        coprocessorHost.preFlush();<a name="line.2271"></a>
+<span class="sourceLineNo">2272</span>      }<a name="line.2272"></a>
+<span class="sourceLineNo">2273</span>      // TODO: this should be managed within memstore with the snapshot, updated only after flush<a name="line.2273"></a>
+<span class="sourceLineNo">2274</span>      // successful<a name="line.2274"></a>
+<span class="sourceLineNo">2275</span>      if (numMutationsWithoutWAL.sum() &gt; 0) {<a name="line.2275"></a>
+<span class="sourceLineNo">2276</span>        numMutationsWithoutWAL.reset();<a name="line.2276"></a>
+<span class="sourceLineNo">2277</span>        dataInMemoryWithoutWAL.reset();<a name="line.2277"></a>
+<span class="sourceLineNo">2278</span>      }<a name="line.2278"></a>
+<span class="sourceLineNo">2279</span>      synchronized (writestate) {<a name="line.2279"></a>
+<span class="sourceLineNo">2280</span>        if (!writestate.flushing &amp;&amp; writestate.writesEnabled) {<a name="line.2280"></a>
+<span class="sourceLineNo">2281</span>          this.writestate.flushing = true;<a name="line.2281"></a>
+<span class="sourceLineNo">2282</span>        } else {<a name="line.2282"></a>
+<span class="sourceLineNo">2283</span>          if (LOG.isDebugEnabled()) {<a name="line.2283"></a>
+<span class="sourceLineNo">2284</span>            LOG.debug("NOT flushing memstore for region " + this<a name="line.2284"></a>
+<span class="sourceLineNo">2285</span>                + ", flushing=" + writestate.flushing + ", writesEnabled="<a name="line.2285"></a>
+<span class="sourceLineNo">2286</span>                + writestate.writesEnabled);<a name="line.2286"></a>
+<span class="sourceLineNo">2287</span>          }<a name="line.2287"></a>
+<span class="sourceLineNo">2288</span>          String msg = "Not flushing since "<a name="line.2288"></a>
+<span class="sourceLineNo">2289</span>              + (writestate.flushing ? "already flushing"<a name="line.2289"></a>
+<span class="sourceLineNo">2290</span>              : "writes not enabled");<a name="line.2290"></a>
+<span class="sourceLineNo">2291</span>          status.abort(msg);<a name="line.2291"></a>
+<span class="sourceLineNo">2292</span>          return new FlushResultImpl(FlushResult.Result.CANNOT_FLUSH, msg, false);<a name="line.2292"></a>
+<span class="sourceLineNo">2293</span>        }<a name="line.2293"></a>
+<span class="sourceLineNo">2294</span>      }<a name="line.2294"></a>
+<span class="sourceLineNo">2295</span><a name="line.2295"></a>
+<span class="sourceLineNo">2296</span>      try {<a name="line.2296"></a>
+<span class="sourceLineNo">2297</span>        Collection&lt;HStore&gt; specificStoresToFlush =<a name="line.2297"></a>
+<span class="sourceLineNo">2298</span>            forceFlushAllStores ? stores.values() : flushPolicy.selectStoresToFlush();<a name="line.2298"></a>
+<span class="sourceLineNo">2299</span>        FlushResultImpl fs =<a name="line.2299"></a>
+<span class="sourceLineNo">2300</span>            internalFlushcache(specificStoresToFlush, status, writeFlushRequestWalMarker);<a name="line.2300"></a>
+<span class="sourceLineNo">2301</span><a name="line.2301"></a>
+<span class="sourceLineNo">2302</span>        if (coprocessorHost != null) {<a name="line.2302"></a>
+<span class="sourceLineNo">2303</span>          status.setStatus("Running post-flush coprocessor hooks");<a name="line.2303"></a>
+<span class="sourceLineNo">2304</span>          coprocessorHost.postFlush();<a name="line.2304"></a>
+<span class="sourceLineNo">2305</span>        }<a name="line.2305"></a>
 <span class="sourceLineNo">2306</span><a name="line.2306"></a>
-<span class="sourceLineNo">2307</span>        if (coprocessorHost != null) {<a name="line.2307"></a>
-<span class="sourceLineNo">2308</span>          status.setStatus("Running post-flush coprocessor hooks");<a name="line.2308"></a>
-<span class="sourceLineNo">2309</span>          coprocessorHost.postFlush();<a name="line.2309"></a>
-<span class="sourceLineNo">2310</span>        }<a name="line.2310"></a>
-<span class="sourceLineNo">2311</span><a name="line.2311"></a>
-<span class="sourceLineNo">2312</span>        if(fs.isFlushSucceeded()) {<a name="line.2312"></a>
-<span class="sourceLineNo">2313</span>          flushesQueued.reset();<a name="line.2313"></a>
-<span class="sourceLineNo">2314</span>        }<a name="line.2314"></a>
-<span class="sourceLineNo">2315</span><a name="line.2315"></a>
-<span class="sourceLineNo">2316</span>        status.markComplete("Flush successful");<a name="line.2316"></a>
-<span class="sourceLineNo">2317</span>        return fs;<a name="line.2317"></a>
-<span class="sourceLineNo">2318</span>      } finally {<a name="line.2318"></a>
-<span class="sourceLineNo">2319</span>        synchronized (writestate) {<a name="line.2319"></a>
-<span class="sourceLineNo">2320</span>          writestate.flushing = false;<a name="line.2320"></a>
-<span class="sourceLineNo">2321</span>          this.writestate.flushRequested = false;<a name="line.2321"></a>
-<span class="sourceLineNo">2322</span>          writestate.notifyAll();<a name="line.2322"></a>
-<span class="sourceLineNo">2323</span>        }<a name="line.2323"></a>
-<span class="sourceLineNo">2324</span>      }<a name="line.2324"></a>
-<span class="sourceLineNo">2325</span>    } finally {<a name="line.2325"></a>
-<span class="sourceLineNo">2326</span>      lock.readLock().unlock();<a name="line.2326"></a>
-<span class="sourceLineNo">2327</span>      status.cleanup();<a name="line.2327"></a>
-<span class="sourceLineNo">2328</span>    }<a name="line.2328"></a>
-<span class="sourceLineNo">2329</span>  }<a name="line.2329"></a>
-<span class="sourceLineNo">2330</span><a name="line.2330"></a>
-<span class="sourceLineNo">2331</span>  /**<a name="line.2331"></a>
-<span class="sourceLineNo">2332</span>   * Should the store be flushed because it is old enough.<a name="line.2332"></a>
-<span class="sourceLineNo">2333</span>   * &lt;p&gt;<a name="line.2333"></a>
-<span class="sourceLineNo">2334</span>   * Every FlushPolicy should call this to determine whether a store is old enough to flush (except<a name="line.2334"></a>
-<span class="sourceLineNo">2335</span>   * that you always flush all stores). Otherwise the method will always<a name="line.2335"></a>
-<span class="sourceLineNo">2336</span>   * returns true which will make a lot of flush requests.<a name="line.2336"></a>
-<span class="sourceLineNo">2337</span>   */<a name="line.2337"></a>
-<span class="sourceLineNo">2338</span>  boolean shouldFlushStore(HStore store) {<a name="line.2338"></a>
-<span class="sourceLineNo">2339</span>    long earliest = this.wal.getEarliestMemStoreSeqNum(getRegionInfo().getEncodedNameAsBytes(),<a name="line.2339"></a>
-<span class="sourceLineNo">2340</span>      store.getColumnFamilyDescriptor().getName()) - 1;<a name="line.2340"></a>
-<span class="sourceLineNo">2341</span>    if (earliest &gt; 0 &amp;&amp; earliest + flushPerChanges &lt; mvcc.getReadPoint()) {<a name="line.2341"></a>
-<span class="sourceLineNo">2342</span>      if (LOG.isDebugEnabled()) {<a name="line.2342"></a>
-<span class="sourceLineNo">2343</span>        LOG.debug("Flush column family " + store.getColumnFamilyName() + " of " +<a name="line.2343"></a>
-<span class="sourceLineNo">2344</span>          getRegionInfo().getEncodedName() + " because unflushed sequenceid=" + earliest +<a name="line.2344"></a>
-<span class="sourceLineNo">2345</span>          " is &gt; " + this.flushPerChanges + " from current=" + mvcc.getReadPoint());<a name="line.2345"></a>
-<span class="sourceLineNo">2346</span>      }<a name="line.2346"></a>
-<span class="sourceLineNo">2347</span>      return true;<a name="line.2347"></a>
-<span class="sourceLineNo">2348</span>    }<a name="line.2348"></a>
-<span class="sourceLineNo">2349</span>    if (this.flushCheckInterval &lt;= 0) {<a name="line.2349"></a>
-<span class="sourceLineNo">2350</span>      return false;<a name="line.2350"></a>
-<span class="sourceLineNo">2351</span>    }<a name="line.2351"></a>
-<span class="sourceLineNo">2352</span>    long now = EnvironmentEdgeManager.currentTime();<a name="line.2352"></a>
-<span class="sourceLineNo">2353</span>    if (store.timeOfOldestEdit() &lt; now - this.flushCheckInterval) {<a name="line.2353"></a>
-<span class="sourceLineNo">2354</span>      if (LOG.isDebugEnabled()) {<a name="line.2354"></a>
-<span class="sourceLineNo">2355</span>        LOG.debug("Flush column family: " + store.getColumnFamilyName() + " of " +<a name="line.2355"></a>
-<span class="sourceLineNo">2356</span>          getRegionInfo().getEncodedName() + " because time of oldest edit=" +<a name="line.2356"></a>
-<span class="sourceLineNo">2357</span>            store.timeOfOldestEdit() + " is &gt; " + this.flushCheckInterval + " from now =" + now);<a name="line.2357"></a>
-<span class="sourceLineNo">2358</span>      }<a name="line.2358"></a>
-<span class="sourceLineNo">2359</span>      return true;<a name="line.2359"></a>
-<span class="sourceLineNo">2360</span>    }<a name="line.2360"></a>
-<span class="sourceLineNo">2361</span>    return false;<a name="line.2361"></a>
-<span class="sourceLineNo">2362</span>  }<a name="line.2362"></a>
-<span class="sourceLineNo">2363</span><a name="line.2363"></a>
-<span class="sourceLineNo">2364</span>  /**<a name="line.2364"></a>
-<span class="sourceLineNo">2365</span>   * Should the memstore be flushed now<a name="line.2365"></a>
-<span class="sourceLineNo">2366</span>   */<a name="line.2366"></a>
-<span class="sourceLineNo">2367</span>  boolean shouldFlush(final StringBuffer whyFlush) {<a name="line.2367"></a>
-<span class="sourceLineNo">2368</span>    whyFlush.setLength(0);<a name="line.2368"></a>
-<span class="sourceLineNo">2369</span>    // This is a rough measure.<a name="line.2369"></a>
-<span class="sourceLineNo">2370</span>    if (this.maxFlushedSeqId &gt; 0<a name="line.2370"></a>
-<span class="sourceLineNo">2371</span>          &amp;&amp; (this.maxFlushedSeqId + this.flushPerChanges &lt; this.mvcc.getReadPoint())) {<a name="line.2371"></a>
-<span class="sourceLineNo">2372</span>      whyFlush.append("more than max edits, " + this.flushPerChanges + ", since last flush");<a name="line.2372"></a>
-<span class="sourceLineNo">2373</span>      return true;<a name="line.2373"></a>
+<span class="sourceLineNo">2307</span>        if(fs.isFlushSucceeded()) {<a name="line.2307"></a>
+<span class="sourceLineNo">2308</span>          flushesQueued.reset();<a name="line.2308"></a>
+<span class="sourceLineNo">2309</span>        }<a name="line.2309"></a>
+<span class="sourceLineNo">2310</span><a name="line.2310"></a>
+<span class="sourceLineNo">2311</span>        status.markComplete("Flush successful");<a name="line.2311"></a>
+<span class="sourceLineNo">2312</span>        return fs;<a name="line.2312"></a>
+<span class="sourceLineNo">2313</span>      } finally {<a name="line.2313"></a>
+<span class="sourceLineNo">2314</span>        synchronized (writestate) {<a name="line.2314"></a>
+<span class="sourceLineNo">2315</span>          writestate.flushing = false;<a name="line.2315"></a>
+<span class="sourceLineNo">2316</span>          this.writestate.flushRequested = false;<a name="line.2316"></a>
+<span class="sourceLineNo">2317</span>          writestate.notifyAll();<a name="line.2317"></a>
+<span class="sourceLineNo">2318</span>        }<a name="line.2318"></a>
+<span class="sourceLineNo">2319</span>      }<a name="line.2319"></a>
+<span class="sourceLineNo">2320</span>    } finally {<a name="line.2320"></a>
+<span class="sourceLineNo">2321</span>      lock.readLock().unlock();<a name="line.2321"></a>
+<span class="sourceLineNo">2322</span>      status.cleanup();<a name="line.2322"></a>
+<span class="sourceLineNo">2323</span>    }<a name="line.2323"></a>
+<span class="sourceLineNo">2324</span>  }<a name="line.2324"></a>
+<span class="sourceLineNo">2325</span><a name="line.2325"></a>
+<span class="sourceLineNo">2326</span>  /**<a name="line.2326"></a>
+<span class="sourceLineNo">2327</span>   * Should the store be flushed because it is old enough.<a name="line.2327"></a>
+<span class="sourceLineNo">2328</span>   * &lt;p&gt;<a name="line.2328"></a>
+<span class="sourceLineNo">2329</span>   * Every FlushPolicy should call this to determine whether a store is old enough to flush (except<a name="line.2329"></a>
+<span class="sourceLineNo">2330</span>   * that you always flush all stores). Otherwise the method will always<a name="line.2330"></a>
+<span class="sourceLineNo">2331</span>   * returns true which will make a lot of flush requests.<a name="line.2331"></a>
+<span class="sourceLineNo">2332</span>   */<a name="line.2332"></a>
+<span class="sourceLineNo">2333</span>  boolean shouldFlushStore(HStore store) {<a name="line.2333"></a>
+<span class="sourceLineNo">2334</span>    long earliest = this.wal.getEarliestMemStoreSeqNum(getRegionInfo().getEncodedNameAsBytes(),<a name="line.2334"></a>
+<span class="sourceLineNo">2335</span>      store.getColumnFamilyDescriptor().getName()) - 1;<a name="line.2335"></a>
+<span class="sourceLineNo">2336</span>    if (earliest &gt; 0 &amp;&amp; earliest + flushPerChanges &lt; mvcc.getReadPoint()) {<a name="line.2336"></a>
+<span class="sourceLineNo">2337</span>      if (LOG.isDebugEnabled()) {<a name="line.2337"></a>
+<span class="sourceLineNo">2338</span>        LOG.debug("Flush column family " + store.getColumnFamilyName() + " of " +<a name="line.2338"></a>
+<span class="sourceLineNo">2339</span>          getRegionInfo().getEncodedName() + " because unflushed sequenceid=" + earliest +<a name="line.2339"></a>
+<span class="sourceLineNo">2340</span>          " is &gt; " + this.flushPerChanges + " from current=" + mvcc.getReadPoint());<a name="line.2340"></a>
+<span class="sourceLineNo">2341</span>      }<a name="line.2341"></a>
+<span class="sourceLineNo">2342</span>      return true;<a name="line.2342"></a>
+<span class="sourceLineNo">2343</span>    }<a name="line.2343"></a>
+<span class="sourceLineNo">2344</span>    if (this.flushCheckInterval &lt;= 0) {<a name="line.2344"></a>
+<span class="sourceLineNo">2345</span>      return false;<a name="line.2345"></a>
+<span class="sourceLineNo">2346</span>    }<a name="line.2346"></a>
+<span class="sourceLineNo">2347</span>    long now = EnvironmentEdgeManager.currentTime();<a name="line.2347"></a>
+<span class="sourceLineNo">2348</span>    if (store.timeOfOldestEdit() &lt; now - this.flushCheckInterval) {<a name="line.2348"></a>
+<span class="sourceLineNo">2349</span>      if (LOG.isDebugEnabled()) {<a name="line.2349"></a>
+<span class="sourceLineNo">2350</span>        LOG.debug("Flush column family: " + store.getColumnFamilyName() + " of " +<a name="line.2350"></a>
+<span class="sourceLineNo">2351</span>          getRegionInfo().getEncodedName() + " because time of oldest edit=" +<a name="line.2351"></a>
+<span class="sourceLineNo">2352</span>            store.timeOfOldestEdit() + " is &gt; " + this.flushCheckInterval + " from now =" + now);<a name="line.2352"></a>
+<span class="sourceLineNo">2353</span>      }<a name="line.2353"></a>
+<span class="sourceLineNo">2354</span>      return true;<a name="line.2354"></a>
+<span class="sourceLineNo">2355</span>    }<a name="line.2355"></a>
+<span class="sourceLineNo">2356</span>    return false;<a name="line.2356"></a>
+<span class="sourceLineNo">2357</span>  }<a name="line.2357"></a>
+<span class="sourceLineNo">2358</span><a name="line.2358"></a>
+<span class="sourceLineNo">2359</span>  /**<a name="line.2359"></a>
+<span class="sourceLineNo">2360</span>   * Should the memstore be flushed now<a name="line.2360"></a>
+<span class="sourceLineNo">2361</span>   */<a name="line.2361"></a>
+<span class="sourceLineNo">2362</span>  boolean shouldFlush(final StringBuffer whyFlush) {<a name="line.2362"></a>
+<span class="sourceLineNo">2363</span>    whyFlush.setLength(0);<a name="line.2363"></a>
+<span class="sourceLineNo">2364</span>    // This is a rough measure.<a name="line.2364"></a>
+<span class="sourceLineNo">2365</span>    if (this.maxFlushedSeqId &gt; 0<a name="line.2365"></a>
+<span class="sourceLineNo">2366</span>          &amp;&amp; (this.maxFlushedSeqId + this.flushPerChanges &lt; this.mvcc.getReadPoint())) {<a name="line.2366"></a>
+<span class="sourceLineNo">2367</span>      whyFlush.append("more than max edits, " + this.flushPerChanges + ", since last flush");<a name="line.2367"></a>
+<span class="sourceLineNo">2368</span>      return true;<a name="line.2368"></a>
+<span class="sourceLineNo">2369</span>    }<a name="line.2369"></a>
+<span class="sourceLineNo">2370</span>    long modifiedFlushCheckInterval = flushCheckInterval;<a name="line.2370"></a>
+<span class="sourceLineNo">2371</span>    if (getRegionInfo().getTable().isSystemTable() &amp;&amp;<a name="line.2371"></a>
+<span class="sourceLineNo">2372</span>        getRegionInfo().getReplicaId() == RegionInfo.DEFAULT_REPLICA_ID) {<a name="line.2372"></a>
+<span class="sourceLineNo">2373</span>      modifiedFlushCheckInterval = SYSTEM_CACHE_FLUSH_INTERVAL;<a name="line.2373"></a>
 <span class="sourceLineNo">2374</span>    }<a name="line.2374"></a>
-<span class="sourceLineNo">2375</span>    long modifiedFlushCheckInterval = flushCheckInterval;<a name="line.2375"></a>
-<span class="sourceLineNo">2376</span>    if (getRegionInfo().getTable().isSystemTable() &amp;&amp;<a name="line.2376"></a>
-<span class="sourceLineNo">2377</span>        getRegionInfo().getReplicaId() == RegionInfo.DEFAULT_REPLICA_ID) {<a name="line.2377"></a>
-<span class="sourceLineNo">2378</span>      modifiedFlushCheckInterval = SYSTEM_CACHE_FLUSH_INTERVAL;<a name="line.2378"></a>
-<span class="sourceLineNo">2379</span>    }<a name="line.2379"></a>
-<span class="sourceLineNo">2380</span>    if (modifiedFlushCheckInterval &lt;= 0) { //disabled<a name="line.2380"></a>
+<span class="sourceLineNo">2375</span>    if (modifiedFlushCheckInterval &lt;= 0) { //disabled<a name="line.2375"></a>
+<span class="sourceLineNo">2376</span>      return false;<a name="line.2376"></a>
+<span class="sourceLineNo">2377</span>    }<a name="line.2377"></a>
+<span class="sourceLineNo">2378</span>    long now = EnvironmentEdgeManager.currentTime();<a name="line.2378"></a>
+<span class="sourceLineNo">2379</span>    //if we flushed in the recent past, we don't need to do again now<a name="line.2379"></a>
+<span class="sourceLineNo">2380</span>    if ((now - getEarliestFlushTimeForAllStores() &lt; modifiedFlushCheckInterval)) {<a name="line.2380"></a>
 <span class="sourceLineNo">2381</span>      return false;<a name="line.2381"></a>
 <span class="sourceLineNo">2382</span>    }<a name="line.2382"></a>
-<span class="sourceLineNo">2383</span>    long now = EnvironmentEdgeManager.currentTime();<a name="line.2383"></a>
-<span class="sourceLineNo">2384</span>    //if we flushed in the recent past, we don't need to do again now<a name="line.2384"></a>
-<span class="sourceLineNo">2385</span>    if ((now - getEarliestFlushTimeForAllStores() &lt; modifiedFlushCheckInterval)) {<a name="line.2385"></a>
-<span class="sourceLineNo">2386</span>      return false;<a name="line.2386"></a>
-<span class="sourceLineNo">2387</span>    }<a name="line.2387"></a>
-<span class="sourceLineNo">2388</span>    //since we didn't flush in the recent past, flush now if certain conditions<a name="line.2388"></a>
-<span class="sourceLineNo">2389</span>    //are met. Return true on first such memstore hit.<a name="line.2389"></a>
-<span class="sourceLineNo">2390</span>    for (HStore s : stores.values()) {<a name="line.2390"></a>
-<span class="sourceLineNo">2391</span>      if (s.timeOfOldestEdit() &lt; now - modifiedFlushCheckInterval) {<a name="line.2391"></a>
-<span class="sourceLineNo">2392</span>        // we have an old enough edit in the memstore, flush<a name

<TRUNCATED>

Mime
View raw message