hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject [33/45] hbase-site git commit: Published site at 04622254f7209c5cfeadcfa137a97fbed161075a.
Date Mon, 14 Dec 2015 16:38:44 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/736088b3/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HStore.StoreFlusherImpl.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HStore.StoreFlusherImpl.html b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HStore.StoreFlusherImpl.html
index a92d846..93c22b9 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HStore.StoreFlusherImpl.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HStore.StoreFlusherImpl.html
@@ -1050,7 +1050,7 @@
 <span class="sourceLineNo">1042</span>      this.lock.writeLock().unlock();<a name="line.1042"></a>
 <span class="sourceLineNo">1043</span>    }<a name="line.1043"></a>
 <span class="sourceLineNo">1044</span>    // notify to be called here - only in case of flushes<a name="line.1044"></a>
-<span class="sourceLineNo">1045</span>    notifyChangedReadersObservers();<a name="line.1045"></a>
+<span class="sourceLineNo">1045</span>    notifyChangedReadersObservers(sfs);<a name="line.1045"></a>
 <span class="sourceLineNo">1046</span>    if (LOG.isTraceEnabled()) {<a name="line.1046"></a>
 <span class="sourceLineNo">1047</span>      long totalSize = 0;<a name="line.1047"></a>
 <span class="sourceLineNo">1048</span>      for (StoreFile sf : sfs) {<a name="line.1048"></a>
@@ -1068,9 +1068,9 @@
 <span class="sourceLineNo">1060</span>   * Notify all observers that set of Readers has changed.<a name="line.1060"></a>
 <span class="sourceLineNo">1061</span>   * @throws IOException<a name="line.1061"></a>
 <span class="sourceLineNo">1062</span>   */<a name="line.1062"></a>
-<span class="sourceLineNo">1063</span>  private void notifyChangedReadersObservers() throws IOException {<a name="line.1063"></a>
+<span class="sourceLineNo">1063</span>  private void notifyChangedReadersObservers(List&lt;StoreFile&gt; sfs) throws IOException {<a name="line.1063"></a>
 <span class="sourceLineNo">1064</span>    for (ChangedReadersObserver o : this.changedReaderObservers) {<a name="line.1064"></a>
-<span class="sourceLineNo">1065</span>      o.updateReaders();<a name="line.1065"></a>
+<span class="sourceLineNo">1065</span>      o.updateReaders(sfs);<a name="line.1065"></a>
 <span class="sourceLineNo">1066</span>    }<a name="line.1066"></a>
 <span class="sourceLineNo">1067</span>  }<a name="line.1067"></a>
 <span class="sourceLineNo">1068</span><a name="line.1068"></a>
@@ -1110,1283 +1110,1307 @@
 <span class="sourceLineNo">1102</span>  }<a name="line.1102"></a>
 <span class="sourceLineNo">1103</span><a name="line.1103"></a>
 <span class="sourceLineNo">1104</span>  @Override<a name="line.1104"></a>
-<span class="sourceLineNo">1105</span>  public void addChangedReaderObserver(ChangedReadersObserver o) {<a name="line.1105"></a>
-<span class="sourceLineNo">1106</span>    this.changedReaderObservers.add(o);<a name="line.1106"></a>
-<span class="sourceLineNo">1107</span>  }<a name="line.1107"></a>
-<span class="sourceLineNo">1108</span><a name="line.1108"></a>
-<span class="sourceLineNo">1109</span>  @Override<a name="line.1109"></a>
-<span class="sourceLineNo">1110</span>  public void deleteChangedReaderObserver(ChangedReadersObserver o) {<a name="line.1110"></a>
-<span class="sourceLineNo">1111</span>    // We don't check if observer present; it may not be (legitimately)<a name="line.1111"></a>
-<span class="sourceLineNo">1112</span>    this.changedReaderObservers.remove(o);<a name="line.1112"></a>
-<span class="sourceLineNo">1113</span>  }<a name="line.1113"></a>
-<span class="sourceLineNo">1114</span><a name="line.1114"></a>
-<span class="sourceLineNo">1115</span>  //////////////////////////////////////////////////////////////////////////////<a name="line.1115"></a>
-<span class="sourceLineNo">1116</span>  // Compaction<a name="line.1116"></a>
-<span class="sourceLineNo">1117</span>  //////////////////////////////////////////////////////////////////////////////<a name="line.1117"></a>
-<span class="sourceLineNo">1118</span><a name="line.1118"></a>
-<span class="sourceLineNo">1119</span>  /**<a name="line.1119"></a>
-<span class="sourceLineNo">1120</span>   * Compact the StoreFiles.  This method may take some time, so the calling<a name="line.1120"></a>
-<span class="sourceLineNo">1121</span>   * thread must be able to block for long periods.<a name="line.1121"></a>
-<span class="sourceLineNo">1122</span>   *<a name="line.1122"></a>
-<span class="sourceLineNo">1123</span>   * &lt;p&gt;During this time, the Store can work as usual, getting values from<a name="line.1123"></a>
-<span class="sourceLineNo">1124</span>   * StoreFiles and writing new StoreFiles from the memstore.<a name="line.1124"></a>
-<span class="sourceLineNo">1125</span>   *<a name="line.1125"></a>
-<span class="sourceLineNo">1126</span>   * Existing StoreFiles are not destroyed until the new compacted StoreFile is<a name="line.1126"></a>
-<span class="sourceLineNo">1127</span>   * completely written-out to disk.<a name="line.1127"></a>
-<span class="sourceLineNo">1128</span>   *<a name="line.1128"></a>
-<span class="sourceLineNo">1129</span>   * &lt;p&gt;The compactLock prevents multiple simultaneous compactions.<a name="line.1129"></a>
-<span class="sourceLineNo">1130</span>   * The structureLock prevents us from interfering with other write operations.<a name="line.1130"></a>
-<span class="sourceLineNo">1131</span>   *<a name="line.1131"></a>
-<span class="sourceLineNo">1132</span>   * &lt;p&gt;We don't want to hold the structureLock for the whole time, as a compact()<a name="line.1132"></a>
-<span class="sourceLineNo">1133</span>   * can be lengthy and we want to allow cache-flushes during this period.<a name="line.1133"></a>
-<span class="sourceLineNo">1134</span>   *<a name="line.1134"></a>
-<span class="sourceLineNo">1135</span>   * &lt;p&gt; Compaction event should be idempotent, since there is no IO Fencing for<a name="line.1135"></a>
-<span class="sourceLineNo">1136</span>   * the region directory in hdfs. A region server might still try to complete the<a name="line.1136"></a>
-<span class="sourceLineNo">1137</span>   * compaction after it lost the region. That is why the following events are carefully<a name="line.1137"></a>
-<span class="sourceLineNo">1138</span>   * ordered for a compaction:<a name="line.1138"></a>
-<span class="sourceLineNo">1139</span>   *  1. Compaction writes new files under region/.tmp directory (compaction output)<a name="line.1139"></a>
-<span class="sourceLineNo">1140</span>   *  2. Compaction atomically moves the temporary file under region directory<a name="line.1140"></a>
-<span class="sourceLineNo">1141</span>   *  3. Compaction appends a WAL edit containing the compaction input and output files.<a name="line.1141"></a>
-<span class="sourceLineNo">1142</span>   *  Forces sync on WAL.<a name="line.1142"></a>
-<span class="sourceLineNo">1143</span>   *  4. Compaction deletes the input files from the region directory.<a name="line.1143"></a>
-<span class="sourceLineNo">1144</span>   *<a name="line.1144"></a>
-<span class="sourceLineNo">1145</span>   * Failure conditions are handled like this:<a name="line.1145"></a>
-<span class="sourceLineNo">1146</span>   *  - If RS fails before 2, compaction wont complete. Even if RS lives on and finishes<a name="line.1146"></a>
-<span class="sourceLineNo">1147</span>   *  the compaction later, it will only write the new data file to the region directory.<a name="line.1147"></a>
-<span class="sourceLineNo">1148</span>   *  Since we already have this data, this will be idempotent but we will have a redundant<a name="line.1148"></a>
-<span class="sourceLineNo">1149</span>   *  copy of the data.<a name="line.1149"></a>
-<span class="sourceLineNo">1150</span>   *  - If RS fails between 2 and 3, the region will have a redundant copy of the data. The<a name="line.1150"></a>
-<span class="sourceLineNo">1151</span>   *  RS that failed won't be able to finish snyc() for WAL because of lease recovery in WAL.<a name="line.1151"></a>
-<span class="sourceLineNo">1152</span>   *  - If RS fails after 3, the region region server who opens the region will pick up the<a name="line.1152"></a>
-<span class="sourceLineNo">1153</span>   *  the compaction marker from the WAL and replay it by removing the compaction input files.<a name="line.1153"></a>
-<span class="sourceLineNo">1154</span>   *  Failed RS can also attempt to delete those files, but the operation will be idempotent<a name="line.1154"></a>
+<span class="sourceLineNo">1105</span>  public List&lt;KeyValueScanner&gt; getScanners(List&lt;StoreFile&gt; files, boolean cacheBlocks,<a name="line.1105"></a>
+<span class="sourceLineNo">1106</span>      boolean isGet, boolean usePread, boolean isCompaction, ScanQueryMatcher matcher,<a name="line.1106"></a>
+<span class="sourceLineNo">1107</span>      byte[] startRow, byte[] stopRow, long readPt, boolean includeMemstoreScanner) throws IOException {<a name="line.1107"></a>
+<span class="sourceLineNo">1108</span>    List&lt;KeyValueScanner&gt; memStoreScanners = null;<a name="line.1108"></a>
+<span class="sourceLineNo">1109</span>    if (includeMemstoreScanner) {<a name="line.1109"></a>
+<span class="sourceLineNo">1110</span>      this.lock.readLock().lock();<a name="line.1110"></a>
+<span class="sourceLineNo">1111</span>      try {<a name="line.1111"></a>
+<span class="sourceLineNo">1112</span>        memStoreScanners = this.memstore.getScanners(readPt);<a name="line.1112"></a>
+<span class="sourceLineNo">1113</span>      } finally {<a name="line.1113"></a>
+<span class="sourceLineNo">1114</span>        this.lock.readLock().unlock();<a name="line.1114"></a>
+<span class="sourceLineNo">1115</span>      }<a name="line.1115"></a>
+<span class="sourceLineNo">1116</span>    }<a name="line.1116"></a>
+<span class="sourceLineNo">1117</span>    List&lt;StoreFileScanner&gt; sfScanners = StoreFileScanner.getScannersForStoreFiles(files,<a name="line.1117"></a>
+<span class="sourceLineNo">1118</span>      cacheBlocks, usePread, isCompaction, false, matcher, readPt, isPrimaryReplicaStore());<a name="line.1118"></a>
+<span class="sourceLineNo">1119</span>    List&lt;KeyValueScanner&gt; scanners = new ArrayList&lt;KeyValueScanner&gt;(sfScanners.size() + 1);<a name="line.1119"></a>
+<span class="sourceLineNo">1120</span>    scanners.addAll(sfScanners);<a name="line.1120"></a>
+<span class="sourceLineNo">1121</span>    // Then the memstore scanners<a name="line.1121"></a>
+<span class="sourceLineNo">1122</span>    if (memStoreScanners != null) {<a name="line.1122"></a>
+<span class="sourceLineNo">1123</span>      scanners.addAll(memStoreScanners);<a name="line.1123"></a>
+<span class="sourceLineNo">1124</span>    }<a name="line.1124"></a>
+<span class="sourceLineNo">1125</span>    return scanners;<a name="line.1125"></a>
+<span class="sourceLineNo">1126</span>  }<a name="line.1126"></a>
+<span class="sourceLineNo">1127</span><a name="line.1127"></a>
+<span class="sourceLineNo">1128</span>  @Override<a name="line.1128"></a>
+<span class="sourceLineNo">1129</span>  public void addChangedReaderObserver(ChangedReadersObserver o) {<a name="line.1129"></a>
+<span class="sourceLineNo">1130</span>    this.changedReaderObservers.add(o);<a name="line.1130"></a>
+<span class="sourceLineNo">1131</span>  }<a name="line.1131"></a>
+<span class="sourceLineNo">1132</span><a name="line.1132"></a>
+<span class="sourceLineNo">1133</span>  @Override<a name="line.1133"></a>
+<span class="sourceLineNo">1134</span>  public void deleteChangedReaderObserver(ChangedReadersObserver o) {<a name="line.1134"></a>
+<span class="sourceLineNo">1135</span>    // We don't check if observer present; it may not be (legitimately)<a name="line.1135"></a>
+<span class="sourceLineNo">1136</span>    this.changedReaderObservers.remove(o);<a name="line.1136"></a>
+<span class="sourceLineNo">1137</span>  }<a name="line.1137"></a>
+<span class="sourceLineNo">1138</span><a name="line.1138"></a>
+<span class="sourceLineNo">1139</span>  //////////////////////////////////////////////////////////////////////////////<a name="line.1139"></a>
+<span class="sourceLineNo">1140</span>  // Compaction<a name="line.1140"></a>
+<span class="sourceLineNo">1141</span>  //////////////////////////////////////////////////////////////////////////////<a name="line.1141"></a>
+<span class="sourceLineNo">1142</span><a name="line.1142"></a>
+<span class="sourceLineNo">1143</span>  /**<a name="line.1143"></a>
+<span class="sourceLineNo">1144</span>   * Compact the StoreFiles.  This method may take some time, so the calling<a name="line.1144"></a>
+<span class="sourceLineNo">1145</span>   * thread must be able to block for long periods.<a name="line.1145"></a>
+<span class="sourceLineNo">1146</span>   *<a name="line.1146"></a>
+<span class="sourceLineNo">1147</span>   * &lt;p&gt;During this time, the Store can work as usual, getting values from<a name="line.1147"></a>
+<span class="sourceLineNo">1148</span>   * StoreFiles and writing new StoreFiles from the memstore.<a name="line.1148"></a>
+<span class="sourceLineNo">1149</span>   *<a name="line.1149"></a>
+<span class="sourceLineNo">1150</span>   * Existing StoreFiles are not destroyed until the new compacted StoreFile is<a name="line.1150"></a>
+<span class="sourceLineNo">1151</span>   * completely written-out to disk.<a name="line.1151"></a>
+<span class="sourceLineNo">1152</span>   *<a name="line.1152"></a>
+<span class="sourceLineNo">1153</span>   * &lt;p&gt;The compactLock prevents multiple simultaneous compactions.<a name="line.1153"></a>
+<span class="sourceLineNo">1154</span>   * The structureLock prevents us from interfering with other write operations.<a name="line.1154"></a>
 <span class="sourceLineNo">1155</span>   *<a name="line.1155"></a>
-<span class="sourceLineNo">1156</span>   * See HBASE-2231 for details.<a name="line.1156"></a>
-<span class="sourceLineNo">1157</span>   *<a name="line.1157"></a>
-<span class="sourceLineNo">1158</span>   * @param compaction compaction details obtained from requestCompaction()<a name="line.1158"></a>
-<span class="sourceLineNo">1159</span>   * @throws IOException<a name="line.1159"></a>
-<span class="sourceLineNo">1160</span>   * @return Storefile we compacted into or null if we failed or opted out early.<a name="line.1160"></a>
-<span class="sourceLineNo">1161</span>   */<a name="line.1161"></a>
-<span class="sourceLineNo">1162</span>  @Override<a name="line.1162"></a>
-<span class="sourceLineNo">1163</span>  public List&lt;StoreFile&gt; compact(CompactionContext compaction,<a name="line.1163"></a>
-<span class="sourceLineNo">1164</span>      CompactionThroughputController throughputController) throws IOException {<a name="line.1164"></a>
-<span class="sourceLineNo">1165</span>    return compact(compaction, throughputController, null);<a name="line.1165"></a>
-<span class="sourceLineNo">1166</span>  }<a name="line.1166"></a>
-<span class="sourceLineNo">1167</span><a name="line.1167"></a>
-<span class="sourceLineNo">1168</span>  @Override<a name="line.1168"></a>
-<span class="sourceLineNo">1169</span>  public List&lt;StoreFile&gt; compact(CompactionContext compaction,<a name="line.1169"></a>
-<span class="sourceLineNo">1170</span>    CompactionThroughputController throughputController, User user) throws IOException {<a name="line.1170"></a>
-<span class="sourceLineNo">1171</span>    assert compaction != null;<a name="line.1171"></a>
-<span class="sourceLineNo">1172</span>    List&lt;StoreFile&gt; sfs = null;<a name="line.1172"></a>
-<span class="sourceLineNo">1173</span>    CompactionRequest cr = compaction.getRequest();<a name="line.1173"></a>
-<span class="sourceLineNo">1174</span>    try {<a name="line.1174"></a>
-<span class="sourceLineNo">1175</span>      // Do all sanity checking in here if we have a valid CompactionRequest<a name="line.1175"></a>
-<span class="sourceLineNo">1176</span>      // because we need to clean up after it on the way out in a finally<a name="line.1176"></a>
-<span class="sourceLineNo">1177</span>      // block below<a name="line.1177"></a>
-<span class="sourceLineNo">1178</span>      long compactionStartTime = EnvironmentEdgeManager.currentTime();<a name="line.1178"></a>
-<span class="sourceLineNo">1179</span>      assert compaction.hasSelection();<a name="line.1179"></a>
-<span class="sourceLineNo">1180</span>      Collection&lt;StoreFile&gt; filesToCompact = cr.getFiles();<a name="line.1180"></a>
-<span class="sourceLineNo">1181</span>      assert !filesToCompact.isEmpty();<a name="line.1181"></a>
-<span class="sourceLineNo">1182</span>      synchronized (filesCompacting) {<a name="line.1182"></a>
-<span class="sourceLineNo">1183</span>        // sanity check: we're compacting files that this store knows about<a name="line.1183"></a>
-<span class="sourceLineNo">1184</span>        // TODO: change this to LOG.error() after more debugging<a name="line.1184"></a>
-<span class="sourceLineNo">1185</span>        Preconditions.checkArgument(filesCompacting.containsAll(filesToCompact));<a name="line.1185"></a>
-<span class="sourceLineNo">1186</span>      }<a name="line.1186"></a>
-<span class="sourceLineNo">1187</span><a name="line.1187"></a>
-<span class="sourceLineNo">1188</span>      // Ready to go. Have list of files to compact.<a name="line.1188"></a>
-<span class="sourceLineNo">1189</span>      LOG.info("Starting compaction of " + filesToCompact.size() + " file(s) in "<a name="line.1189"></a>
-<span class="sourceLineNo">1190</span>          + this + " of " + this.getRegionInfo().getRegionNameAsString()<a name="line.1190"></a>
-<span class="sourceLineNo">1191</span>          + " into tmpdir=" + fs.getTempDir() + ", totalSize="<a name="line.1191"></a>
-<span class="sourceLineNo">1192</span>          + TraditionalBinaryPrefix.long2String(cr.getSize(), "", 1));<a name="line.1192"></a>
-<span class="sourceLineNo">1193</span><a name="line.1193"></a>
-<span class="sourceLineNo">1194</span>      // Commence the compaction.<a name="line.1194"></a>
-<span class="sourceLineNo">1195</span>      List&lt;Path&gt; newFiles = compaction.compact(throughputController, user);<a name="line.1195"></a>
-<span class="sourceLineNo">1196</span><a name="line.1196"></a>
-<span class="sourceLineNo">1197</span>      // TODO: get rid of this!<a name="line.1197"></a>
-<span class="sourceLineNo">1198</span>      if (!this.conf.getBoolean("hbase.hstore.compaction.complete", true)) {<a name="line.1198"></a>
-<span class="sourceLineNo">1199</span>        LOG.warn("hbase.hstore.compaction.complete is set to false");<a name="line.1199"></a>
-<span class="sourceLineNo">1200</span>        sfs = new ArrayList&lt;StoreFile&gt;(newFiles.size());<a name="line.1200"></a>
-<span class="sourceLineNo">1201</span>        final boolean evictOnClose =<a name="line.1201"></a>
-<span class="sourceLineNo">1202</span>            cacheConf != null? cacheConf.shouldEvictOnClose(): true;<a name="line.1202"></a>
-<span class="sourceLineNo">1203</span>        for (Path newFile : newFiles) {<a name="line.1203"></a>
-<span class="sourceLineNo">1204</span>          // Create storefile around what we wrote with a reader on it.<a name="line.1204"></a>
-<span class="sourceLineNo">1205</span>          StoreFile sf = createStoreFileAndReader(newFile);<a name="line.1205"></a>
-<span class="sourceLineNo">1206</span>          sf.closeReader(evictOnClose);<a name="line.1206"></a>
-<span class="sourceLineNo">1207</span>          sfs.add(sf);<a name="line.1207"></a>
-<span class="sourceLineNo">1208</span>        }<a name="line.1208"></a>
-<span class="sourceLineNo">1209</span>        return sfs;<a name="line.1209"></a>
+<span class="sourceLineNo">1156</span>   * &lt;p&gt;We don't want to hold the structureLock for the whole time, as a compact()<a name="line.1156"></a>
+<span class="sourceLineNo">1157</span>   * can be lengthy and we want to allow cache-flushes during this period.<a name="line.1157"></a>
+<span class="sourceLineNo">1158</span>   *<a name="line.1158"></a>
+<span class="sourceLineNo">1159</span>   * &lt;p&gt; Compaction event should be idempotent, since there is no IO Fencing for<a name="line.1159"></a>
+<span class="sourceLineNo">1160</span>   * the region directory in hdfs. A region server might still try to complete the<a name="line.1160"></a>
+<span class="sourceLineNo">1161</span>   * compaction after it lost the region. That is why the following events are carefully<a name="line.1161"></a>
+<span class="sourceLineNo">1162</span>   * ordered for a compaction:<a name="line.1162"></a>
+<span class="sourceLineNo">1163</span>   *  1. Compaction writes new files under region/.tmp directory (compaction output)<a name="line.1163"></a>
+<span class="sourceLineNo">1164</span>   *  2. Compaction atomically moves the temporary file under region directory<a name="line.1164"></a>
+<span class="sourceLineNo">1165</span>   *  3. Compaction appends a WAL edit containing the compaction input and output files.<a name="line.1165"></a>
+<span class="sourceLineNo">1166</span>   *  Forces sync on WAL.<a name="line.1166"></a>
+<span class="sourceLineNo">1167</span>   *  4. Compaction deletes the input files from the region directory.<a name="line.1167"></a>
+<span class="sourceLineNo">1168</span>   *<a name="line.1168"></a>
+<span class="sourceLineNo">1169</span>   * Failure conditions are handled like this:<a name="line.1169"></a>
+<span class="sourceLineNo">1170</span>   *  - If RS fails before 2, compaction wont complete. Even if RS lives on and finishes<a name="line.1170"></a>
+<span class="sourceLineNo">1171</span>   *  the compaction later, it will only write the new data file to the region directory.<a name="line.1171"></a>
+<span class="sourceLineNo">1172</span>   *  Since we already have this data, this will be idempotent but we will have a redundant<a name="line.1172"></a>
+<span class="sourceLineNo">1173</span>   *  copy of the data.<a name="line.1173"></a>
+<span class="sourceLineNo">1174</span>   *  - If RS fails between 2 and 3, the region will have a redundant copy of the data. The<a name="line.1174"></a>
+<span class="sourceLineNo">1175</span>   *  RS that failed won't be able to finish snyc() for WAL because of lease recovery in WAL.<a name="line.1175"></a>
+<span class="sourceLineNo">1176</span>   *  - If RS fails after 3, the region region server who opens the region will pick up the<a name="line.1176"></a>
+<span class="sourceLineNo">1177</span>   *  the compaction marker from the WAL and replay it by removing the compaction input files.<a name="line.1177"></a>
+<span class="sourceLineNo">1178</span>   *  Failed RS can also attempt to delete those files, but the operation will be idempotent<a name="line.1178"></a>
+<span class="sourceLineNo">1179</span>   *<a name="line.1179"></a>
+<span class="sourceLineNo">1180</span>   * See HBASE-2231 for details.<a name="line.1180"></a>
+<span class="sourceLineNo">1181</span>   *<a name="line.1181"></a>
+<span class="sourceLineNo">1182</span>   * @param compaction compaction details obtained from requestCompaction()<a name="line.1182"></a>
+<span class="sourceLineNo">1183</span>   * @throws IOException<a name="line.1183"></a>
+<span class="sourceLineNo">1184</span>   * @return Storefile we compacted into or null if we failed or opted out early.<a name="line.1184"></a>
+<span class="sourceLineNo">1185</span>   */<a name="line.1185"></a>
+<span class="sourceLineNo">1186</span>  @Override<a name="line.1186"></a>
+<span class="sourceLineNo">1187</span>  public List&lt;StoreFile&gt; compact(CompactionContext compaction,<a name="line.1187"></a>
+<span class="sourceLineNo">1188</span>      CompactionThroughputController throughputController) throws IOException {<a name="line.1188"></a>
+<span class="sourceLineNo">1189</span>    return compact(compaction, throughputController, null);<a name="line.1189"></a>
+<span class="sourceLineNo">1190</span>  }<a name="line.1190"></a>
+<span class="sourceLineNo">1191</span><a name="line.1191"></a>
+<span class="sourceLineNo">1192</span>  @Override<a name="line.1192"></a>
+<span class="sourceLineNo">1193</span>  public List&lt;StoreFile&gt; compact(CompactionContext compaction,<a name="line.1193"></a>
+<span class="sourceLineNo">1194</span>    CompactionThroughputController throughputController, User user) throws IOException {<a name="line.1194"></a>
+<span class="sourceLineNo">1195</span>    assert compaction != null;<a name="line.1195"></a>
+<span class="sourceLineNo">1196</span>    List&lt;StoreFile&gt; sfs = null;<a name="line.1196"></a>
+<span class="sourceLineNo">1197</span>    CompactionRequest cr = compaction.getRequest();<a name="line.1197"></a>
+<span class="sourceLineNo">1198</span>    try {<a name="line.1198"></a>
+<span class="sourceLineNo">1199</span>      // Do all sanity checking in here if we have a valid CompactionRequest<a name="line.1199"></a>
+<span class="sourceLineNo">1200</span>      // because we need to clean up after it on the way out in a finally<a name="line.1200"></a>
+<span class="sourceLineNo">1201</span>      // block below<a name="line.1201"></a>
+<span class="sourceLineNo">1202</span>      long compactionStartTime = EnvironmentEdgeManager.currentTime();<a name="line.1202"></a>
+<span class="sourceLineNo">1203</span>      assert compaction.hasSelection();<a name="line.1203"></a>
+<span class="sourceLineNo">1204</span>      Collection&lt;StoreFile&gt; filesToCompact = cr.getFiles();<a name="line.1204"></a>
+<span class="sourceLineNo">1205</span>      assert !filesToCompact.isEmpty();<a name="line.1205"></a>
+<span class="sourceLineNo">1206</span>      synchronized (filesCompacting) {<a name="line.1206"></a>
+<span class="sourceLineNo">1207</span>        // sanity check: we're compacting files that this store knows about<a name="line.1207"></a>
+<span class="sourceLineNo">1208</span>        // TODO: change this to LOG.error() after more debugging<a name="line.1208"></a>
+<span class="sourceLineNo">1209</span>        Preconditions.checkArgument(filesCompacting.containsAll(filesToCompact));<a name="line.1209"></a>
 <span class="sourceLineNo">1210</span>      }<a name="line.1210"></a>
-<span class="sourceLineNo">1211</span>      // Do the steps necessary to complete the compaction.<a name="line.1211"></a>
-<span class="sourceLineNo">1212</span>      sfs = moveCompatedFilesIntoPlace(cr, newFiles, user);<a name="line.1212"></a>
-<span class="sourceLineNo">1213</span>      writeCompactionWalRecord(filesToCompact, sfs);<a name="line.1213"></a>
-<span class="sourceLineNo">1214</span>      replaceStoreFiles(filesToCompact, sfs);<a name="line.1214"></a>
-<span class="sourceLineNo">1215</span>      if (cr.isMajor()) {<a name="line.1215"></a>
-<span class="sourceLineNo">1216</span>        majorCompactedCellsCount += getCompactionProgress().totalCompactingKVs;<a name="line.1216"></a>
-<span class="sourceLineNo">1217</span>        majorCompactedCellsSize += getCompactionProgress().totalCompactedSize;<a name="line.1217"></a>
-<span class="sourceLineNo">1218</span>      } else {<a name="line.1218"></a>
-<span class="sourceLineNo">1219</span>        compactedCellsCount += getCompactionProgress().totalCompactingKVs;<a name="line.1219"></a>
-<span class="sourceLineNo">1220</span>        compactedCellsSize += getCompactionProgress().totalCompactedSize;<a name="line.1220"></a>
-<span class="sourceLineNo">1221</span>      }<a name="line.1221"></a>
-<span class="sourceLineNo">1222</span>      // At this point the store will use new files for all new scanners.<a name="line.1222"></a>
-<span class="sourceLineNo">1223</span>      completeCompaction(filesToCompact); // update store size.<a name="line.1223"></a>
-<span class="sourceLineNo">1224</span><a name="line.1224"></a>
-<span class="sourceLineNo">1225</span>      logCompactionEndMessage(cr, sfs, compactionStartTime);<a name="line.1225"></a>
-<span class="sourceLineNo">1226</span>      return sfs;<a name="line.1226"></a>
-<span class="sourceLineNo">1227</span>    } finally {<a name="line.1227"></a>
-<span class="sourceLineNo">1228</span>      finishCompactionRequest(cr);<a name="line.1228"></a>
-<span class="sourceLineNo">1229</span>    }<a name="line.1229"></a>
-<span class="sourceLineNo">1230</span>  }<a name="line.1230"></a>
-<span class="sourceLineNo">1231</span><a name="line.1231"></a>
-<span class="sourceLineNo">1232</span>  private List&lt;StoreFile&gt; moveCompatedFilesIntoPlace(<a name="line.1232"></a>
-<span class="sourceLineNo">1233</span>      final CompactionRequest cr, List&lt;Path&gt; newFiles, User user) throws IOException {<a name="line.1233"></a>
-<span class="sourceLineNo">1234</span>    List&lt;StoreFile&gt; sfs = new ArrayList&lt;StoreFile&gt;(newFiles.size());<a name="line.1234"></a>
-<span class="sourceLineNo">1235</span>    for (Path newFile : newFiles) {<a name="line.1235"></a>
-<span class="sourceLineNo">1236</span>      assert newFile != null;<a name="line.1236"></a>
-<span class="sourceLineNo">1237</span>      final StoreFile sf = moveFileIntoPlace(newFile);<a name="line.1237"></a>
-<span class="sourceLineNo">1238</span>      if (this.getCoprocessorHost() != null) {<a name="line.1238"></a>
-<span class="sourceLineNo">1239</span>        final Store thisStore = this;<a name="line.1239"></a>
-<span class="sourceLineNo">1240</span>        if (user == null) {<a name="line.1240"></a>
-<span class="sourceLineNo">1241</span>          getCoprocessorHost().postCompact(thisStore, sf, cr);<a name="line.1241"></a>
-<span class="sourceLineNo">1242</span>        } else {<a name="line.1242"></a>
-<span class="sourceLineNo">1243</span>          try {<a name="line.1243"></a>
-<span class="sourceLineNo">1244</span>            user.getUGI().doAs(new PrivilegedExceptionAction&lt;Void&gt;() {<a name="line.1244"></a>
-<span class="sourceLineNo">1245</span>              @Override<a name="line.1245"></a>
-<span class="sourceLineNo">1246</span>              public Void run() throws Exception {<a name="line.1246"></a>
-<span class="sourceLineNo">1247</span>                getCoprocessorHost().postCompact(thisStore, sf, cr);<a name="line.1247"></a>
-<span class="sourceLineNo">1248</span>                return null;<a name="line.1248"></a>
-<span class="sourceLineNo">1249</span>              }<a name="line.1249"></a>
-<span class="sourceLineNo">1250</span>            });<a name="line.1250"></a>
-<span class="sourceLineNo">1251</span>          } catch (InterruptedException ie) {<a name="line.1251"></a>
-<span class="sourceLineNo">1252</span>            InterruptedIOException iioe = new InterruptedIOException();<a name="line.1252"></a>
-<span class="sourceLineNo">1253</span>            iioe.initCause(ie);<a name="line.1253"></a>
-<span class="sourceLineNo">1254</span>            throw iioe;<a name="line.1254"></a>
-<span class="sourceLineNo">1255</span>          }<a name="line.1255"></a>
-<span class="sourceLineNo">1256</span>        }<a name="line.1256"></a>
-<span class="sourceLineNo">1257</span>      }<a name="line.1257"></a>
-<span class="sourceLineNo">1258</span>      assert sf != null;<a name="line.1258"></a>
-<span class="sourceLineNo">1259</span>      sfs.add(sf);<a name="line.1259"></a>
-<span class="sourceLineNo">1260</span>    }<a name="line.1260"></a>
-<span class="sourceLineNo">1261</span>    return sfs;<a name="line.1261"></a>
-<span class="sourceLineNo">1262</span>  }<a name="line.1262"></a>
-<span class="sourceLineNo">1263</span><a name="line.1263"></a>
-<span class="sourceLineNo">1264</span>  // Package-visible for tests<a name="line.1264"></a>
-<span class="sourceLineNo">1265</span>  StoreFile moveFileIntoPlace(final Path newFile) throws IOException {<a name="line.1265"></a>
-<span class="sourceLineNo">1266</span>    validateStoreFile(newFile);<a name="line.1266"></a>
-<span class="sourceLineNo">1267</span>    // Move the file into the right spot<a name="line.1267"></a>
-<span class="sourceLineNo">1268</span>    Path destPath = fs.commitStoreFile(getColumnFamilyName(), newFile);<a name="line.1268"></a>
-<span class="sourceLineNo">1269</span>    return createStoreFileAndReader(destPath);<a name="line.1269"></a>
-<span class="sourceLineNo">1270</span>  }<a name="line.1270"></a>
-<span class="sourceLineNo">1271</span><a name="line.1271"></a>
-<span class="sourceLineNo">1272</span>  /**<a name="line.1272"></a>
-<span class="sourceLineNo">1273</span>   * Writes the compaction WAL record.<a name="line.1273"></a>
-<span class="sourceLineNo">1274</span>   * @param filesCompacted Files compacted (input).<a name="line.1274"></a>
-<span class="sourceLineNo">1275</span>   * @param newFiles Files from compaction.<a name="line.1275"></a>
-<span class="sourceLineNo">1276</span>   */<a name="line.1276"></a>
-<span class="sourceLineNo">1277</span>  private void writeCompactionWalRecord(Collection&lt;StoreFile&gt; filesCompacted,<a name="line.1277"></a>
-<span class="sourceLineNo">1278</span>      Collection&lt;StoreFile&gt; newFiles) throws IOException {<a name="line.1278"></a>
-<span class="sourceLineNo">1279</span>    if (region.getWAL() == null) return;<a name="line.1279"></a>
-<span class="sourceLineNo">1280</span>    List&lt;Path&gt; inputPaths = new ArrayList&lt;Path&gt;(filesCompacted.size());<a name="line.1280"></a>
-<span class="sourceLineNo">1281</span>    for (StoreFile f : filesCompacted) {<a name="line.1281"></a>
-<span class="sourceLineNo">1282</span>      inputPaths.add(f.getPath());<a name="line.1282"></a>
-<span class="sourceLineNo">1283</span>    }<a name="line.1283"></a>
-<span class="sourceLineNo">1284</span>    List&lt;Path&gt; outputPaths = new ArrayList&lt;Path&gt;(newFiles.size());<a name="line.1284"></a>
-<span class="sourceLineNo">1285</span>    for (StoreFile f : newFiles) {<a name="line.1285"></a>
-<span class="sourceLineNo">1286</span>      outputPaths.add(f.getPath());<a name="line.1286"></a>
-<span class="sourceLineNo">1287</span>    }<a name="line.1287"></a>
-<span class="sourceLineNo">1288</span>    HRegionInfo info = this.region.getRegionInfo();<a name="line.1288"></a>
-<span class="sourceLineNo">1289</span>    CompactionDescriptor compactionDescriptor = ProtobufUtil.toCompactionDescriptor(info,<a name="line.1289"></a>
-<span class="sourceLineNo">1290</span>        family.getName(), inputPaths, outputPaths, fs.getStoreDir(getFamily().getNameAsString()));<a name="line.1290"></a>
-<span class="sourceLineNo">1291</span>    WALUtil.writeCompactionMarker(region.getWAL(), this.region.getTableDesc(),<a name="line.1291"></a>
-<span class="sourceLineNo">1292</span>        this.region.getRegionInfo(), compactionDescriptor, region.getMVCC());<a name="line.1292"></a>
-<span class="sourceLineNo">1293</span>  }<a name="line.1293"></a>
-<span class="sourceLineNo">1294</span><a name="line.1294"></a>
-<span class="sourceLineNo">1295</span>  @VisibleForTesting<a name="line.1295"></a>
-<span class="sourceLineNo">1296</span>  void replaceStoreFiles(final Collection&lt;StoreFile&gt; compactedFiles,<a name="line.1296"></a>
-<span class="sourceLineNo">1297</span>      final Collection&lt;StoreFile&gt; result) throws IOException {<a name="line.1297"></a>
-<span class="sourceLineNo">1298</span>    this.lock.writeLock().lock();<a name="line.1298"></a>
-<span class="sourceLineNo">1299</span>    try {<a name="line.1299"></a>
-<span class="sourceLineNo">1300</span>      this.storeEngine.getStoreFileManager().addCompactionResults(compactedFiles, result);<a name="line.1300"></a>
-<span class="sourceLineNo">1301</span>      filesCompacting.removeAll(compactedFiles); // safe bc: lock.writeLock();<a name="line.1301"></a>
-<span class="sourceLineNo">1302</span>    } finally {<a name="line.1302"></a>
-<span class="sourceLineNo">1303</span>      this.lock.writeLock().unlock();<a name="line.1303"></a>
-<span class="sourceLineNo">1304</span>    }<a name="line.1304"></a>
-<span class="sourceLineNo">1305</span>  }<a name="line.1305"></a>
-<span class="sourceLineNo">1306</span><a name="line.1306"></a>
-<span class="sourceLineNo">1307</span>  /**<a name="line.1307"></a>
-<span class="sourceLineNo">1308</span>   * Log a very elaborate compaction completion message.<a name="line.1308"></a>
-<span class="sourceLineNo">1309</span>   * @param cr Request.<a name="line.1309"></a>
-<span class="sourceLineNo">1310</span>   * @param sfs Resulting files.<a name="line.1310"></a>
-<span class="sourceLineNo">1311</span>   * @param compactionStartTime Start time.<a name="line.1311"></a>
-<span class="sourceLineNo">1312</span>   */<a name="line.1312"></a>
-<span class="sourceLineNo">1313</span>  private void logCompactionEndMessage(<a name="line.1313"></a>
-<span class="sourceLineNo">1314</span>      CompactionRequest cr, List&lt;StoreFile&gt; sfs, long compactionStartTime) {<a name="line.1314"></a>
-<span class="sourceLineNo">1315</span>    long now = EnvironmentEdgeManager.currentTime();<a name="line.1315"></a>
-<span class="sourceLineNo">1316</span>    StringBuilder message = new StringBuilder(<a name="line.1316"></a>
-<span class="sourceLineNo">1317</span>      "Completed" + (cr.isMajor() ? " major" : "") + " compaction of "<a name="line.1317"></a>
-<span class="sourceLineNo">1318</span>      + cr.getFiles().size() + (cr.isAllFiles() ? " (all)" : "") + " file(s) in "<a name="line.1318"></a>
-<span class="sourceLineNo">1319</span>      + this + " of " + this.getRegionInfo().getRegionNameAsString() + " into ");<a name="line.1319"></a>
-<span class="sourceLineNo">1320</span>    if (sfs.isEmpty()) {<a name="line.1320"></a>
-<span class="sourceLineNo">1321</span>      message.append("none, ");<a name="line.1321"></a>
-<span class="sourceLineNo">1322</span>    } else {<a name="line.1322"></a>
-<span class="sourceLineNo">1323</span>      for (StoreFile sf: sfs) {<a name="line.1323"></a>
-<span class="sourceLineNo">1324</span>        message.append(sf.getPath().getName());<a name="line.1324"></a>
-<span class="sourceLineNo">1325</span>        message.append("(size=");<a name="line.1325"></a>
-<span class="sourceLineNo">1326</span>        message.append(TraditionalBinaryPrefix.long2String(sf.getReader().length(), "", 1));<a name="line.1326"></a>
-<span class="sourceLineNo">1327</span>        message.append("), ");<a name="line.1327"></a>
-<span class="sourceLineNo">1328</span>      }<a name="line.1328"></a>
-<span class="sourceLineNo">1329</span>    }<a name="line.1329"></a>
-<span class="sourceLineNo">1330</span>    message.append("total size for store is ")<a name="line.1330"></a>
-<span class="sourceLineNo">1331</span>      .append(StringUtils.TraditionalBinaryPrefix.long2String(storeSize, "", 1))<a name="line.1331"></a>
-<span class="sourceLineNo">1332</span>      .append(". This selection was in queue for ")<a name="line.1332"></a>
-<span class="sourceLineNo">1333</span>      .append(StringUtils.formatTimeDiff(compactionStartTime, cr.getSelectionTime()))<a name="line.1333"></a>
-<span class="sourceLineNo">1334</span>      .append(", and took ").append(StringUtils.formatTimeDiff(now, compactionStartTime))<a name="line.1334"></a>
-<span class="sourceLineNo">1335</span>      .append(" to execute.");<a name="line.1335"></a>
-<span class="sourceLineNo">1336</span>    LOG.info(message.toString());<a name="line.1336"></a>
-<span class="sourceLineNo">1337</span>    if (LOG.isTraceEnabled()) {<a name="line.1337"></a>
-<span class="sourceLineNo">1338</span>      int fileCount = storeEngine.getStoreFileManager().getStorefileCount();<a name="line.1338"></a>
-<span class="sourceLineNo">1339</span>      long resultSize = 0;<a name="line.1339"></a>
-<span class="sourceLineNo">1340</span>      for (StoreFile sf : sfs) {<a name="line.1340"></a>
-<span class="sourceLineNo">1341</span>        resultSize += sf.getReader().length();<a name="line.1341"></a>
-<span class="sourceLineNo">1342</span>      }<a name="line.1342"></a>
-<span class="sourceLineNo">1343</span>      String traceMessage = "COMPACTION start,end,size out,files in,files out,store size,"<a name="line.1343"></a>
-<span class="sourceLineNo">1344</span>        + "store files [" + compactionStartTime + "," + now + "," + resultSize + ","<a name="line.1344"></a>
-<span class="sourceLineNo">1345</span>          + cr.getFiles().size() + "," + sfs.size() + "," +  storeSize + "," + fileCount + "]";<a name="line.1345"></a>
-<span class="sourceLineNo">1346</span>      LOG.trace(traceMessage);<a name="line.1346"></a>
-<span class="sourceLineNo">1347</span>    }<a name="line.1347"></a>
-<span class="sourceLineNo">1348</span>  }<a name="line.1348"></a>
-<span class="sourceLineNo">1349</span><a name="line.1349"></a>
-<span class="sourceLineNo">1350</span>  /**<a name="line.1350"></a>
-<span class="sourceLineNo">1351</span>   * Call to complete a compaction. Its for the case where we find in the WAL a compaction<a name="line.1351"></a>
-<span class="sourceLineNo">1352</span>   * that was not finished.  We could find one recovering a WAL after a regionserver crash.<a name="line.1352"></a>
-<span class="sourceLineNo">1353</span>   * See HBASE-2231.<a name="line.1353"></a>
-<span class="sourceLineNo">1354</span>   * @param compaction<a name="line.1354"></a>
-<span class="sourceLineNo">1355</span>   */<a name="line.1355"></a>
-<span class="sourceLineNo">1356</span>  @Override<a name="line.1356"></a>
-<span class="sourceLineNo">1357</span>  public void replayCompactionMarker(CompactionDescriptor compaction,<a name="line.1357"></a>
-<span class="sourceLineNo">1358</span>      boolean pickCompactionFiles, boolean removeFiles)<a name="line.1358"></a>
-<span class="sourceLineNo">1359</span>      throws IOException {<a name="line.1359"></a>
-<span class="sourceLineNo">1360</span>    LOG.debug("Completing compaction from the WAL marker");<a name="line.1360"></a>
-<span class="sourceLineNo">1361</span>    List&lt;String&gt; compactionInputs = compaction.getCompactionInputList();<a name="line.1361"></a>
-<span class="sourceLineNo">1362</span>    List&lt;String&gt; compactionOutputs = Lists.newArrayList(compaction.getCompactionOutputList());<a name="line.1362"></a>
-<span class="sourceLineNo">1363</span><a name="line.1363"></a>
-<span class="sourceLineNo">1364</span>    // The Compaction Marker is written after the compaction is completed,<a name="line.1364"></a>
-<span class="sourceLineNo">1365</span>    // and the files moved into the region/family folder.<a name="line.1365"></a>
-<span class="sourceLineNo">1366</span>    //<a name="line.1366"></a>
-<span class="sourceLineNo">1367</span>    // If we crash after the entry is written, we may not have removed the<a name="line.1367"></a>
-<span class="sourceLineNo">1368</span>    // input files, but the output file is present.<a name="line.1368"></a>
-<span class="sourceLineNo">1369</span>    // (The unremoved input files will be removed by this function)<a name="line.1369"></a>
-<span class="sourceLineNo">1370</span>    //<a name="line.1370"></a>
-<span class="sourceLineNo">1371</span>    // If we scan the directory and the file is not present, it can mean that:<a name="line.1371"></a>
-<span class="sourceLineNo">1372</span>    //   - The file was manually removed by the user<a name="line.1372"></a>
-<span class="sourceLineNo">1373</span>    //   - The file was removed as consequence of subsequent compaction<a name="line.1373"></a>
-<span class="sourceLineNo">1374</span>    // so, we can't do anything with the "compaction output list" because those<a name="line.1374"></a>
-<span class="sourceLineNo">1375</span>    // files have already been loaded when opening the region (by virtue of<a name="line.1375"></a>
-<span class="sourceLineNo">1376</span>    // being in the store's folder) or they may be missing due to a compaction.<a name="line.1376"></a>
-<span class="sourceLineNo">1377</span><a name="line.1377"></a>
-<span class="sourceLineNo">1378</span>    String familyName = this.getColumnFamilyName();<a name="line.1378"></a>
-<span class="sourceLineNo">1379</span>    List&lt;String&gt; inputFiles = new ArrayList&lt;String&gt;(compactionInputs.size());<a name="line.1379"></a>
-<span class="sourceLineNo">1380</span>    for (String compactionInput : compactionInputs) {<a name="line.1380"></a>
-<span class="sourceLineNo">1381</span>      Path inputPath = fs.getStoreFilePath(familyName, compactionInput);<a name="line.1381"></a>
-<span class="sourceLineNo">1382</span>      inputFiles.add(inputPath.getName());<a name="line.1382"></a>
-<span class="sourceLineNo">1383</span>    }<a name="line.1383"></a>
-<span class="sourceLineNo">1384</span><a name="line.1384"></a>
-<span class="sourceLineNo">1385</span>    //some of the input files might already be deleted<a name="line.1385"></a>
-<span class="sourceLineNo">1386</span>    List&lt;StoreFile&gt; inputStoreFiles = new ArrayList&lt;StoreFile&gt;(compactionInputs.size());<a name="line.1386"></a>
-<span class="sourceLineNo">1387</span>    for (StoreFile sf : this.getStorefiles()) {<a name="line.1387"></a>
-<span class="sourceLineNo">1388</span>      if (inputFiles.contains(sf.getPath().getName())) {<a name="line.1388"></a>
-<span class="sourceLineNo">1389</span>        inputStoreFiles.add(sf);<a name="line.1389"></a>
-<span class="sourceLineNo">1390</span>      }<a name="line.1390"></a>
-<span class="sourceLineNo">1391</span>    }<a name="line.1391"></a>
-<span class="sourceLineNo">1392</span><a name="line.1392"></a>
-<span class="sourceLineNo">1393</span>    // check whether we need to pick up the new files<a name="line.1393"></a>
-<span class="sourceLineNo">1394</span>    List&lt;StoreFile&gt; outputStoreFiles = new ArrayList&lt;StoreFile&gt;(compactionOutputs.size());<a name="line.1394"></a>
-<span class="sourceLineNo">1395</span><a name="line.1395"></a>
-<span class="sourceLineNo">1396</span>    if (pickCompactionFiles) {<a name="line.1396"></a>
-<span class="sourceLineNo">1397</span>      for (StoreFile sf : this.getStorefiles()) {<a name="line.1397"></a>
-<span class="sourceLineNo">1398</span>        compactionOutputs.remove(sf.getPath().getName());<a name="line.1398"></a>
-<span class="sourceLineNo">1399</span>      }<a name="line.1399"></a>
-<span class="sourceLineNo">1400</span>      for (String compactionOutput : compactionOutputs) {<a name="line.1400"></a>
-<span class="sourceLineNo">1401</span>        StoreFileInfo storeFileInfo = fs.getStoreFileInfo(getColumnFamilyName(), compactionOutput);<a name="line.1401"></a>
-<span class="sourceLineNo">1402</span>        StoreFile storeFile = createStoreFileAndReader(storeFileInfo);<a name="line.1402"></a>
-<span class="sourceLineNo">1403</span>        outputStoreFiles.add(storeFile);<a name="line.1403"></a>
-<span class="sourceLineNo">1404</span>      }<a name="line.1404"></a>
-<span class="sourceLineNo">1405</span>    }<a name="line.1405"></a>
-<span class="sourceLineNo">1406</span><a name="line.1406"></a>
-<span class="sourceLineNo">1407</span>    if (!inputStoreFiles.isEmpty() || !outputStoreFiles.isEmpty()) {<a name="line.1407"></a>
-<span class="sourceLineNo">1408</span>      LOG.info("Replaying compaction marker, replacing input files: " +<a name="line.1408"></a>
-<span class="sourceLineNo">1409</span>          inputStoreFiles + " with output files : " + outputStoreFiles);<a name="line.1409"></a>
-<span class="sourceLineNo">1410</span>      this.replaceStoreFiles(inputStoreFiles, outputStoreFiles);<a name="line.1410"></a>
-<span class="sourceLineNo">1411</span>      this.completeCompaction(inputStoreFiles);<a name="line.1411"></a>
-<span class="sourceLineNo">1412</span>    }<a name="line.1412"></a>
-<span class="sourceLineNo">1413</span>  }<a name="line.1413"></a>
-<span class="sourceLineNo">1414</span><a name="line.1414"></a>
-<span class="sourceLineNo">1415</span>  /**<a name="line.1415"></a>
-<span class="sourceLineNo">1416</span>   * This method tries to compact N recent files for testing.<a name="line.1416"></a>
-<span class="sourceLineNo">1417</span>   * Note that because compacting "recent" files only makes sense for some policies,<a name="line.1417"></a>
-<span class="sourceLineNo">1418</span>   * e.g. the default one, it assumes default policy is used. It doesn't use policy,<a name="line.1418"></a>
-<span class="sourceLineNo">1419</span>   * but instead makes a compaction candidate list by itself.<a name="line.1419"></a>
-<span class="sourceLineNo">1420</span>   * @param N Number of files.<a name="line.1420"></a>
-<span class="sourceLineNo">1421</span>   */<a name="line.1421"></a>
-<span class="sourceLineNo">1422</span>  public void compactRecentForTestingAssumingDefaultPolicy(int N) throws IOException {<a name="line.1422"></a>
-<span class="sourceLineNo">1423</span>    List&lt;StoreFile&gt; filesToCompact;<a name="line.1423"></a>
-<span class="sourceLineNo">1424</span>    boolean isMajor;<a name="line.1424"></a>
-<span class="sourceLineNo">1425</span><a name="line.1425"></a>
-<span class="sourceLineNo">1426</span>    this.lock.readLock().lock();<a name="line.1426"></a>
-<span class="sourceLineNo">1427</span>    try {<a name="line.1427"></a>
-<span class="sourceLineNo">1428</span>      synchronized (filesCompacting) {<a name="line.1428"></a>
-<span class="sourceLineNo">1429</span>        filesToCompact = Lists.newArrayList(storeEngine.getStoreFileManager().getStorefiles());<a name="line.1429"></a>
-<span class="sourceLineNo">1430</span>        if (!filesCompacting.isEmpty()) {<a name="line.1430"></a>
-<span class="sourceLineNo">1431</span>          // exclude all files older than the newest file we're currently<a name="line.1431"></a>
-<span class="sourceLineNo">1432</span>          // compacting. this allows us to preserve contiguity (HBASE-2856)<a name="line.1432"></a>
-<span class="sourceLineNo">1433</span>          StoreFile last = filesCompacting.get(filesCompacting.size() - 1);<a name="line.1433"></a>
-<span class="sourceLineNo">1434</span>          int idx = filesToCompact.indexOf(last);<a name="line.1434"></a>
-<span class="sourceLineNo">1435</span>          Preconditions.checkArgument(idx != -1);<a name="line.1435"></a>
-<span class="sourceLineNo">1436</span>          filesToCompact.subList(0, idx + 1).clear();<a name="line.1436"></a>
-<span class="sourceLineNo">1437</span>        }<a name="line.1437"></a>
-<span class="sourceLineNo">1438</span>        int count = filesToCompact.size();<a name="line.1438"></a>
-<span class="sourceLineNo">1439</span>        if (N &gt; count) {<a name="line.1439"></a>
-<span class="sourceLineNo">1440</span>          throw new RuntimeException("Not enough files");<a name="line.1440"></a>
-<span class="sourceLineNo">1441</span>        }<a name="line.1441"></a>
-<span class="sourceLineNo">1442</span><a name="line.1442"></a>
-<span class="sourceLineNo">1443</span>        filesToCompact = filesToCompact.subList(count - N, count);<a name="line.1443"></a>
-<span class="sourceLineNo">1444</span>        isMajor = (filesToCompact.size() == storeEngine.getStoreFileManager().getStorefileCount());<a name="line.1444"></a>
-<span class="sourceLineNo">1445</span>        filesCompacting.addAll(filesToCompact);<a name="line.1445"></a>
-<span class="sourceLineNo">1446</span>        Collections.sort(filesCompacting, StoreFile.Comparators.SEQ_ID);<a name="line.1446"></a>
-<span class="sourceLineNo">1447</span>      }<a name="line.1447"></a>
-<span class="sourceLineNo">1448</span>    } finally {<a name="line.1448"></a>
-<span class="sourceLineNo">1449</span>      this.lock.readLock().unlock();<a name="line.1449"></a>
-<span class="sourceLineNo">1450</span>    }<a name="line.1450"></a>
-<span class="sourceLineNo">1451</span><a name="line.1451"></a>
-<span class="sourceLineNo">1452</span>    try {<a name="line.1452"></a>
-<span class="sourceLineNo">1453</span>      // Ready to go. Have list of files to compact.<a name="line.1453"></a>
-<span class="sourceLineNo">1454</span>      List&lt;Path&gt; newFiles = ((DefaultCompactor)this.storeEngine.getCompactor())<a name="line.1454"></a>
-<span class="sourceLineNo">1455</span>          .compactForTesting(filesToCompact, isMajor);<a name="line.1455"></a>
-<span class="sourceLineNo">1456</span>      for (Path newFile: newFiles) {<a name="line.1456"></a>
-<span class="sourceLineNo">1457</span>        // Move the compaction into place.<a name="line.1457"></a>
-<span class="sourceLineNo">1458</span>        StoreFile sf = moveFileIntoPlace(newFile);<a name="line.1458"></a>
-<span class="sourceLineNo">1459</span>        if (this.getCoprocessorHost() != null) {<a name="line.1459"></a>
-<span class="sourceLineNo">1460</span>          this.getCoprocessorHost().postCompact(this, sf, null);<a name="line.1460"></a>
+<span class="sourceLineNo">1211</span><a name="line.1211"></a>
+<span class="sourceLineNo">1212</span>      // Ready to go. Have list of files to compact.<a name="line.1212"></a>
+<span class="sourceLineNo">1213</span>      LOG.info("Starting compaction of " + filesToCompact.size() + " file(s) in "<a name="line.1213"></a>
+<span class="sourceLineNo">1214</span>          + this + " of " + this.getRegionInfo().getRegionNameAsString()<a name="line.1214"></a>
+<span class="sourceLineNo">1215</span>          + " into tmpdir=" + fs.getTempDir() + ", totalSize="<a name="line.1215"></a>
+<span class="sourceLineNo">1216</span>          + TraditionalBinaryPrefix.long2String(cr.getSize(), "", 1));<a name="line.1216"></a>
+<span class="sourceLineNo">1217</span><a name="line.1217"></a>
+<span class="sourceLineNo">1218</span>      // Commence the compaction.<a name="line.1218"></a>
+<span class="sourceLineNo">1219</span>      List&lt;Path&gt; newFiles = compaction.compact(throughputController, user);<a name="line.1219"></a>
+<span class="sourceLineNo">1220</span><a name="line.1220"></a>
+<span class="sourceLineNo">1221</span>      // TODO: get rid of this!<a name="line.1221"></a>
+<span class="sourceLineNo">1222</span>      if (!this.conf.getBoolean("hbase.hstore.compaction.complete", true)) {<a name="line.1222"></a>
+<span class="sourceLineNo">1223</span>        LOG.warn("hbase.hstore.compaction.complete is set to false");<a name="line.1223"></a>
+<span class="sourceLineNo">1224</span>        sfs = new ArrayList&lt;StoreFile&gt;(newFiles.size());<a name="line.1224"></a>
+<span class="sourceLineNo">1225</span>        final boolean evictOnClose =<a name="line.1225"></a>
+<span class="sourceLineNo">1226</span>            cacheConf != null? cacheConf.shouldEvictOnClose(): true;<a name="line.1226"></a>
+<span class="sourceLineNo">1227</span>        for (Path newFile : newFiles) {<a name="line.1227"></a>
+<span class="sourceLineNo">1228</span>          // Create storefile around what we wrote with a reader on it.<a name="line.1228"></a>
+<span class="sourceLineNo">1229</span>          StoreFile sf = createStoreFileAndReader(newFile);<a name="line.1229"></a>
+<span class="sourceLineNo">1230</span>          sf.closeReader(evictOnClose);<a name="line.1230"></a>
+<span class="sourceLineNo">1231</span>          sfs.add(sf);<a name="line.1231"></a>
+<span class="sourceLineNo">1232</span>        }<a name="line.1232"></a>
+<span class="sourceLineNo">1233</span>        return sfs;<a name="line.1233"></a>
+<span class="sourceLineNo">1234</span>      }<a name="line.1234"></a>
+<span class="sourceLineNo">1235</span>      // Do the steps necessary to complete the compaction.<a name="line.1235"></a>
+<span class="sourceLineNo">1236</span>      sfs = moveCompatedFilesIntoPlace(cr, newFiles, user);<a name="line.1236"></a>
+<span class="sourceLineNo">1237</span>      writeCompactionWalRecord(filesToCompact, sfs);<a name="line.1237"></a>
+<span class="sourceLineNo">1238</span>      replaceStoreFiles(filesToCompact, sfs);<a name="line.1238"></a>
+<span class="sourceLineNo">1239</span>      if (cr.isMajor()) {<a name="line.1239"></a>
+<span class="sourceLineNo">1240</span>        majorCompactedCellsCount += getCompactionProgress().totalCompactingKVs;<a name="line.1240"></a>
+<span class="sourceLineNo">1241</span>        majorCompactedCellsSize += getCompactionProgress().totalCompactedSize;<a name="line.1241"></a>
+<span class="sourceLineNo">1242</span>      } else {<a name="line.1242"></a>
+<span class="sourceLineNo">1243</span>        compactedCellsCount += getCompactionProgress().totalCompactingKVs;<a name="line.1243"></a>
+<span class="sourceLineNo">1244</span>        compactedCellsSize += getCompactionProgress().totalCompactedSize;<a name="line.1244"></a>
+<span class="sourceLineNo">1245</span>      }<a name="line.1245"></a>
+<span class="sourceLineNo">1246</span>      // At this point the store will use new files for all new scanners.<a name="line.1246"></a>
+<span class="sourceLineNo">1247</span>      completeCompaction(filesToCompact); // update store size.<a name="line.1247"></a>
+<span class="sourceLineNo">1248</span><a name="line.1248"></a>
+<span class="sourceLineNo">1249</span>      logCompactionEndMessage(cr, sfs, compactionStartTime);<a name="line.1249"></a>
+<span class="sourceLineNo">1250</span>      return sfs;<a name="line.1250"></a>
+<span class="sourceLineNo">1251</span>    } finally {<a name="line.1251"></a>
+<span class="sourceLineNo">1252</span>      finishCompactionRequest(cr);<a name="line.1252"></a>
+<span class="sourceLineNo">1253</span>    }<a name="line.1253"></a>
+<span class="sourceLineNo">1254</span>  }<a name="line.1254"></a>
+<span class="sourceLineNo">1255</span><a name="line.1255"></a>
+<span class="sourceLineNo">1256</span>  private List&lt;StoreFile&gt; moveCompatedFilesIntoPlace(<a name="line.1256"></a>
+<span class="sourceLineNo">1257</span>      final CompactionRequest cr, List&lt;Path&gt; newFiles, User user) throws IOException {<a name="line.1257"></a>
+<span class="sourceLineNo">1258</span>    List&lt;StoreFile&gt; sfs = new ArrayList&lt;StoreFile&gt;(newFiles.size());<a name="line.1258"></a>
+<span class="sourceLineNo">1259</span>    for (Path newFile : newFiles) {<a name="line.1259"></a>
+<span class="sourceLineNo">1260</span>      assert newFile != null;<a name="line.1260"></a>
+<span class="sourceLineNo">1261</span>      final StoreFile sf = moveFileIntoPlace(newFile);<a name="line.1261"></a>
+<span class="sourceLineNo">1262</span>      if (this.getCoprocessorHost() != null) {<a name="line.1262"></a>
+<span class="sourceLineNo">1263</span>        final Store thisStore = this;<a name="line.1263"></a>
+<span class="sourceLineNo">1264</span>        if (user == null) {<a name="line.1264"></a>
+<span class="sourceLineNo">1265</span>          getCoprocessorHost().postCompact(thisStore, sf, cr);<a name="line.1265"></a>
+<span class="sourceLineNo">1266</span>        } else {<a name="line.1266"></a>
+<span class="sourceLineNo">1267</span>          try {<a name="line.1267"></a>
+<span class="sourceLineNo">1268</span>            user.getUGI().doAs(new PrivilegedExceptionAction&lt;Void&gt;() {<a name="line.1268"></a>
+<span class="sourceLineNo">1269</span>              @Override<a name="line.1269"></a>
+<span class="sourceLineNo">1270</span>              public Void run() throws Exception {<a name="line.1270"></a>
+<span class="sourceLineNo">1271</span>                getCoprocessorHost().postCompact(thisStore, sf, cr);<a name="line.1271"></a>
+<span class="sourceLineNo">1272</span>                return null;<a name="line.1272"></a>
+<span class="sourceLineNo">1273</span>              }<a name="line.1273"></a>
+<span class="sourceLineNo">1274</span>            });<a name="line.1274"></a>
+<span class="sourceLineNo">1275</span>          } catch (InterruptedException ie) {<a name="line.1275"></a>
+<span class="sourceLineNo">1276</span>            InterruptedIOException iioe = new InterruptedIOException();<a name="line.1276"></a>
+<span class="sourceLineNo">1277</span>            iioe.initCause(ie);<a name="line.1277"></a>
+<span class="sourceLineNo">1278</span>            throw iioe;<a name="line.1278"></a>
+<span class="sourceLineNo">1279</span>          }<a name="line.1279"></a>
+<span class="sourceLineNo">1280</span>        }<a name="line.1280"></a>
+<span class="sourceLineNo">1281</span>      }<a name="line.1281"></a>
+<span class="sourceLineNo">1282</span>      assert sf != null;<a name="line.1282"></a>
+<span class="sourceLineNo">1283</span>      sfs.add(sf);<a name="line.1283"></a>
+<span class="sourceLineNo">1284</span>    }<a name="line.1284"></a>
+<span class="sourceLineNo">1285</span>    return sfs;<a name="line.1285"></a>
+<span class="sourceLineNo">1286</span>  }<a name="line.1286"></a>
+<span class="sourceLineNo">1287</span><a name="line.1287"></a>
+<span class="sourceLineNo">1288</span>  // Package-visible for tests<a name="line.1288"></a>
+<span class="sourceLineNo">1289</span>  StoreFile moveFileIntoPlace(final Path newFile) throws IOException {<a name="line.1289"></a>
+<span class="sourceLineNo">1290</span>    validateStoreFile(newFile);<a name="line.1290"></a>
+<span class="sourceLineNo">1291</span>    // Move the file into the right spot<a name="line.1291"></a>
+<span class="sourceLineNo">1292</span>    Path destPath = fs.commitStoreFile(getColumnFamilyName(), newFile);<a name="line.1292"></a>
+<span class="sourceLineNo">1293</span>    return createStoreFileAndReader(destPath);<a name="line.1293"></a>
+<span class="sourceLineNo">1294</span>  }<a name="line.1294"></a>
+<span class="sourceLineNo">1295</span><a name="line.1295"></a>
+<span class="sourceLineNo">1296</span>  /**<a name="line.1296"></a>
+<span class="sourceLineNo">1297</span>   * Writes the compaction WAL record.<a name="line.1297"></a>
+<span class="sourceLineNo">1298</span>   * @param filesCompacted Files compacted (input).<a name="line.1298"></a>
+<span class="sourceLineNo">1299</span>   * @param newFiles Files from compaction.<a name="line.1299"></a>
+<span class="sourceLineNo">1300</span>   */<a name="line.1300"></a>
+<span class="sourceLineNo">1301</span>  private void writeCompactionWalRecord(Collection&lt;StoreFile&gt; filesCompacted,<a name="line.1301"></a>
+<span class="sourceLineNo">1302</span>      Collection&lt;StoreFile&gt; newFiles) throws IOException {<a name="line.1302"></a>
+<span class="sourceLineNo">1303</span>    if (region.getWAL() == null) return;<a name="line.1303"></a>
+<span class="sourceLineNo">1304</span>    List&lt;Path&gt; inputPaths = new ArrayList&lt;Path&gt;(filesCompacted.size());<a name="line.1304"></a>
+<span class="sourceLineNo">1305</span>    for (StoreFile f : filesCompacted) {<a name="line.1305"></a>
+<span class="sourceLineNo">1306</span>      inputPaths.add(f.getPath());<a name="line.1306"></a>
+<span class="sourceLineNo">1307</span>    }<a name="line.1307"></a>
+<span class="sourceLineNo">1308</span>    List&lt;Path&gt; outputPaths = new ArrayList&lt;Path&gt;(newFiles.size());<a name="line.1308"></a>
+<span class="sourceLineNo">1309</span>    for (StoreFile f : newFiles) {<a name="line.1309"></a>
+<span class="sourceLineNo">1310</span>      outputPaths.add(f.getPath());<a name="line.1310"></a>
+<span class="sourceLineNo">1311</span>    }<a name="line.1311"></a>
+<span class="sourceLineNo">1312</span>    HRegionInfo info = this.region.getRegionInfo();<a name="line.1312"></a>
+<span class="sourceLineNo">1313</span>    CompactionDescriptor compactionDescriptor = ProtobufUtil.toCompactionDescriptor(info,<a name="line.1313"></a>
+<span class="sourceLineNo">1314</span>        family.getName(), inputPaths, outputPaths, fs.getStoreDir(getFamily().getNameAsString()));<a name="line.1314"></a>
+<span class="sourceLineNo">1315</span>    WALUtil.writeCompactionMarker(region.getWAL(), this.region.getTableDesc(),<a name="line.1315"></a>
+<span class="sourceLineNo">1316</span>        this.region.getRegionInfo(), compactionDescriptor, region.getMVCC());<a name="line.1316"></a>
+<span class="sourceLineNo">1317</span>  }<a name="line.1317"></a>
+<span class="sourceLineNo">1318</span><a name="line.1318"></a>
+<span class="sourceLineNo">1319</span>  @VisibleForTesting<a name="line.1319"></a>
+<span class="sourceLineNo">1320</span>  void replaceStoreFiles(final Collection&lt;StoreFile&gt; compactedFiles,<a name="line.1320"></a>
+<span class="sourceLineNo">1321</span>      final Collection&lt;StoreFile&gt; result) throws IOException {<a name="line.1321"></a>
+<span class="sourceLineNo">1322</span>    this.lock.writeLock().lock();<a name="line.1322"></a>
+<span class="sourceLineNo">1323</span>    try {<a name="line.1323"></a>
+<span class="sourceLineNo">1324</span>      this.storeEngine.getStoreFileManager().addCompactionResults(compactedFiles, result);<a name="line.1324"></a>
+<span class="sourceLineNo">1325</span>      filesCompacting.removeAll(compactedFiles); // safe bc: lock.writeLock();<a name="line.1325"></a>
+<span class="sourceLineNo">1326</span>    } finally {<a name="line.1326"></a>
+<span class="sourceLineNo">1327</span>      this.lock.writeLock().unlock();<a name="line.1327"></a>
+<span class="sourceLineNo">1328</span>    }<a name="line.1328"></a>
+<span class="sourceLineNo">1329</span>  }<a name="line.1329"></a>
+<span class="sourceLineNo">1330</span><a name="line.1330"></a>
+<span class="sourceLineNo">1331</span>  /**<a name="line.1331"></a>
+<span class="sourceLineNo">1332</span>   * Log a very elaborate compaction completion message.<a name="line.1332"></a>
+<span class="sourceLineNo">1333</span>   * @param cr Request.<a name="line.1333"></a>
+<span class="sourceLineNo">1334</span>   * @param sfs Resulting files.<a name="line.1334"></a>
+<span class="sourceLineNo">1335</span>   * @param compactionStartTime Start time.<a name="line.1335"></a>
+<span class="sourceLineNo">1336</span>   */<a name="line.1336"></a>
+<span class="sourceLineNo">1337</span>  private void logCompactionEndMessage(<a name="line.1337"></a>
+<span class="sourceLineNo">1338</span>      CompactionRequest cr, List&lt;StoreFile&gt; sfs, long compactionStartTime) {<a name="line.1338"></a>
+<span class="sourceLineNo">1339</span>    long now = EnvironmentEdgeManager.currentTime();<a name="line.1339"></a>
+<span class="sourceLineNo">1340</span>    StringBuilder message = new StringBuilder(<a name="line.1340"></a>
+<span class="sourceLineNo">1341</span>      "Completed" + (cr.isMajor() ? " major" : "") + " compaction of "<a name="line.1341"></a>
+<span class="sourceLineNo">1342</span>      + cr.getFiles().size() + (cr.isAllFiles() ? " (all)" : "") + " file(s) in "<a name="line.1342"></a>
+<span class="sourceLineNo">1343</span>      + this + " of " + this.getRegionInfo().getRegionNameAsString() + " into ");<a name="line.1343"></a>
+<span class="sourceLineNo">1344</span>    if (sfs.isEmpty()) {<a name="line.1344"></a>
+<span class="sourceLineNo">1345</span>      message.append("none, ");<a name="line.1345"></a>
+<span class="sourceLineNo">1346</span>    } else {<a name="line.1346"></a>
+<span class="sourceLineNo">1347</span>      for (StoreFile sf: sfs) {<a name="line.1347"></a>
+<span class="sourceLineNo">1348</span>        message.append(sf.getPath().getName());<a name="line.1348"></a>
+<span class="sourceLineNo">1349</span>        message.append("(size=");<a name="line.1349"></a>
+<span class="sourceLineNo">1350</span>        message.append(TraditionalBinaryPrefix.long2String(sf.getReader().length(), "", 1));<a name="line.1350"></a>
+<span class="sourceLineNo">1351</span>        message.append("), ");<a name="line.1351"></a>
+<span class="sourceLineNo">1352</span>      }<a name="line.1352"></a>
+<span class="sourceLineNo">1353</span>    }<a name="line.1353"></a>
+<span class="sourceLineNo">1354</span>    message.append("total size for store is ")<a name="line.1354"></a>
+<span class="sourceLineNo">1355</span>      .append(StringUtils.TraditionalBinaryPrefix.long2String(storeSize, "", 1))<a name="line.1355"></a>
+<span class="sourceLineNo">1356</span>      .append(". This selection was in queue for ")<a name="line.1356"></a>
+<span class="sourceLineNo">1357</span>      .append(StringUtils.formatTimeDiff(compactionStartTime, cr.getSelectionTime()))<a name="line.1357"></a>
+<span class="sourceLineNo">1358</span>      .append(", and took ").append(StringUtils.formatTimeDiff(now, compactionStartTime))<a name="line.1358"></a>
+<span class="sourceLineNo">1359</span>      .append(" to execute.");<a name="line.1359"></a>
+<span class="sourceLineNo">1360</span>    LOG.info(message.toString());<a name="line.1360"></a>
+<span class="sourceLineNo">1361</span>    if (LOG.isTraceEnabled()) {<a name="line.1361"></a>
+<span class="sourceLineNo">1362</span>      int fileCount = storeEngine.getStoreFileManager().getStorefileCount();<a name="line.1362"></a>
+<span class="sourceLineNo">1363</span>      long resultSize = 0;<a name="line.1363"></a>
+<span class="sourceLineNo">1364</span>      for (StoreFile sf : sfs) {<a name="line.1364"></a>
+<span class="sourceLineNo">1365</span>        resultSize += sf.getReader().length();<a name="line.1365"></a>
+<span class="sourceLineNo">1366</span>      }<a name="line.1366"></a>
+<span class="sourceLineNo">1367</span>      String traceMessage = "COMPACTION start,end,size out,files in,files out,store size,"<a name="line.1367"></a>
+<span class="sourceLineNo">1368</span>        + "store files [" + compactionStartTime + "," + now + "," + resultSize + ","<a name="line.1368"></a>
+<span class="sourceLineNo">1369</span>          + cr.getFiles().size() + "," + sfs.size() + "," +  storeSize + "," + fileCount + "]";<a name="line.1369"></a>
+<span class="sourceLineNo">1370</span>      LOG.trace(traceMessage);<a name="line.1370"></a>
+<span class="sourceLineNo">1371</span>    }<a name="line.1371"></a>
+<span class="sourceLineNo">1372</span>  }<a name="line.1372"></a>
+<span class="sourceLineNo">1373</span><a name="line.1373"></a>
+<span class="sourceLineNo">1374</span>  /**<a name="line.1374"></a>
+<span class="sourceLineNo">1375</span>   * Call to complete a compaction. Its for the case where we find in the WAL a compaction<a name="line.1375"></a>
+<span class="sourceLineNo">1376</span>   * that was not finished.  We could find one recovering a WAL after a regionserver crash.<a name="line.1376"></a>
+<span class="sourceLineNo">1377</span>   * See HBASE-2231.<a name="line.1377"></a>
+<span class="sourceLineNo">1378</span>   * @param compaction<a name="line.1378"></a>
+<span class="sourceLineNo">1379</span>   */<a name="line.1379"></a>
+<span class="sourceLineNo">1380</span>  @Override<a name="line.1380"></a>
+<span class="sourceLineNo">1381</span>  public void replayCompactionMarker(CompactionDescriptor compaction,<a name="line.1381"></a>
+<span class="sourceLineNo">1382</span>      boolean pickCompactionFiles, boolean removeFiles)<a name="line.1382"></a>
+<span class="sourceLineNo">1383</span>      throws IOException {<a name="line.1383"></a>
+<span class="sourceLineNo">1384</span>    LOG.debug("Completing compaction from the WAL marker");<a name="line.1384"></a>
+<span class="sourceLineNo">1385</span>    List&lt;String&gt; compactionInputs = compaction.getCompactionInputList();<a name="line.1385"></a>
+<span class="sourceLineNo">1386</span>    List&lt;String&gt; compactionOutputs = Lists.newArrayList(compaction.getCompactionOutputList());<a name="line.1386"></a>
+<span class="sourceLineNo">1387</span><a name="line.1387"></a>
+<span class="sourceLineNo">1388</span>    // The Compaction Marker is written after the compaction is completed,<a name="line.1388"></a>
+<span class="sourceLineNo">1389</span>    // and the files moved into the region/family folder.<a name="line.1389"></a>
+<span class="sourceLineNo">1390</span>    //<a name="line.1390"></a>
+<span class="sourceLineNo">1391</span>    // If we crash after the entry is written, we may not have removed the<a name="line.1391"></a>
+<span class="sourceLineNo">1392</span>    // input files, but the output file is present.<a name="line.1392"></a>
+<span class="sourceLineNo">1393</span>    // (The unremoved input files will be removed by this function)<a name="line.1393"></a>
+<span class="sourceLineNo">1394</span>    //<a name="line.1394"></a>
+<span class="sourceLineNo">1395</span>    // If we scan the directory and the file is not present, it can mean that:<a name="line.1395"></a>
+<span class="sourceLineNo">1396</span>    //   - The file was manually removed by the user<a name="line.1396"></a>
+<span class="sourceLineNo">1397</span>    //   - The file was removed as consequence of subsequent compaction<a name="line.1397"></a>
+<span class="sourceLineNo">1398</span>    // so, we can't do anything with the "compaction output list" because those<a name="line.1398"></a>
+<span class="sourceLineNo">1399</span>    // files have already been loaded when opening the region (by virtue of<a name="line.1399"></a>
+<span class="sourceLineNo">1400</span>    // being in the store's folder) or they may be missing due to a compaction.<a name="line.1400"></a>
+<span class="sourceLineNo">1401</span><a name="line.1401"></a>
+<span class="sourceLineNo">1402</span>    String familyName = this.getColumnFamilyName();<a name="line.1402"></a>
+<span class="sourceLineNo">1403</span>    List&lt;String&gt; inputFiles = new ArrayList&lt;String&gt;(compactionInputs.size());<a name="line.1403"></a>
+<span class="sourceLineNo">1404</span>    for (String compactionInput : compactionInputs) {<a name="line.1404"></a>
+<span class="sourceLineNo">1405</span>      Path inputPath = fs.getStoreFilePath(familyName, compactionInput);<a name="line.1405"></a>
+<span class="sourceLineNo">1406</span>      inputFiles.add(inputPath.getName());<a name="line.1406"></a>
+<span class="sourceLineNo">1407</span>    }<a name="line.1407"></a>
+<span class="sourceLineNo">1408</span><a name="line.1408"></a>
+<span class="sourceLineNo">1409</span>    //some of the input files might already be deleted<a name="line.1409"></a>
+<span class="sourceLineNo">1410</span>    List&lt;StoreFile&gt; inputStoreFiles = new ArrayList&lt;StoreFile&gt;(compactionInputs.size());<a name="line.1410"></a>
+<span class="sourceLineNo">1411</span>    for (StoreFile sf : this.getStorefiles()) {<a name="line.1411"></a>
+<span class="sourceLineNo">1412</span>      if (inputFiles.contains(sf.getPath().getName())) {<a name="line.1412"></a>
+<span class="sourceLineNo">1413</span>        inputStoreFiles.add(sf);<a name="line.1413"></a>
+<span class="sourceLineNo">1414</span>      }<a name="line.1414"></a>
+<span class="sourceLineNo">1415</span>    }<a name="line.1415"></a>
+<span class="sourceLineNo">1416</span><a name="line.1416"></a>
+<span class="sourceLineNo">1417</span>    // check whether we need to pick up the new files<a name="line.1417"></a>
+<span class="sourceLineNo">1418</span>    List&lt;StoreFile&gt; outputStoreFiles = new ArrayList&lt;StoreFile&gt;(compactionOutputs.size());<a name="line.1418"></a>
+<span class="sourceLineNo">1419</span><a name="line.1419"></a>
+<span class="sourceLineNo">1420</span>    if (pickCompactionFiles) {<a name="line.1420"></a>
+<span class="sourceLineNo">1421</span>      for (StoreFile sf : this.getStorefiles()) {<a name="line.1421"></a>
+<span class="sourceLineNo">1422</span>        compactionOutputs.remove(sf.getPath().getName());<a name="line.1422"></a>
+<span class="sourceLineNo">1423</span>      }<a name="line.1423"></a>
+<span class="sourceLineNo">1424</span>      for (String compactionOutput : compactionOutputs) {<a name="line.1424"></a>
+<span class="sourceLineNo">1425</span>        StoreFileInfo storeFileInfo = fs.getStoreFileInfo(getColumnFamilyName(), compactionOutput);<a name="line.1425"></a>
+<span class="sourceLineNo">1426</span>        StoreFile storeFile = createStoreFileAndReader(storeFileInfo);<a name="line.1426"></a>
+<span class="sourceLineNo">1427</span>        outputStoreFiles.add(storeFile);<a name="line.1427"></a>
+<span class="sourceLineNo">1428</span>      }<a name="line.1428"></a>
+<span class="sourceLineNo">1429</span>    }<a name="line.1429"></a>
+<span class="sourceLineNo">1430</span><a name="line.1430"></a>
+<span class="sourceLineNo">1431</span>    if (!inputStoreFiles.isEmpty() || !outputStoreFiles.isEmpty()) {<a name="line.1431"></a>
+<span class="sourceLineNo">1432</span>      LOG.info("Replaying compaction marker, replacing input files: " +<a name="line.1432"></a>
+<span class="sourceLineNo">1433</span>          inputStoreFiles + " with output files : " + outputStoreFiles);<a name="line.1433"></a>
+<span class="sourceLineNo">1434</span>      this.replaceStoreFiles(inputStoreFiles, outputStoreFiles);<a name="line.1434"></a>
+<span class="sourceLineNo">1435</span>      this.completeCompaction(inputStoreFiles);<a name="line.1435"></a>
+<span class="sourceLineNo">1436</span>    }<a name="line.1436"></a>
+<span class="sourceLineNo">1437</span>  }<a name="line.1437"></a>
+<span class="sourceLineNo">1438</span><a name="line.1438"></a>
+<span class="sourceLineNo">1439</span>  /**<a name="line.1439"></a>
+<span class="sourceLineNo">1440</span>   * This method tries to compact N recent files for testing.<a name="line.1440"></a>
+<span class="sourceLineNo">1441</span>   * Note that because compacting "recent" files only makes sense for some policies,<a name="line.1441"></a>
+<span class="sourceLineNo">1442</span>   * e.g. the default one, it assumes default policy is used. It doesn't use policy,<a name="line.1442"></a>
+<span class="sourceLineNo">1443</span>   * but instead makes a compaction candidate list by itself.<a name="line.1443"></a>
+<span class="sourceLineNo">1444</span>   * @param N Number of files.<a name="line.1444"></a>
+<span class="sourceLineNo">1445</span>   */<a name="line.1445"></a>
+<span class="sourceLineNo">1446</span>  public void compactRecentForTestingAssumingDefaultPolicy(int N) throws IOException {<a name="line.1446"></a>
+<span class="sourceLineNo">1447</span>    List&lt;StoreFile&gt; filesToCompact;<a name="line.1447"></a>
+<span class="sourceLineNo">1448</span>    boolean isMajor;<a name="line.1448"></a>
+<span class="sourceLineNo">1449</span><a name="line.1449"></a>
+<span class="sourceLineNo">1450</span>    this.lock.readLock().lock();<a name="line.1450"></a>
+<span class="sourceLineNo">1451</span>    try {<a name="line.1451"></a>
+<span class="sourceLineNo">1452</span>      synchronized (filesCompacting) {<a name="line.1452"></a>
+<span class="sourceLineNo">1453</span>        filesToCompact = Lists.newArrayList(storeEngine.getStoreFileManager().getStorefiles());<a name="line.1453"></a>
+<span class="sourceLineNo">1454</span>        if (!filesCompacting.isEmpty()) {<a name="line.1454"></a>
+<span class="sourceLineNo">1455</span>          // exclude all files older than the newest file we're currently<a name="line.1455"></a>
+<span class="sourceLineNo">1456</span>          // compacting. this allows us to preserve contiguity (HBASE-2856)<a name="line.1456"></a>
+<span class="sourceLineNo">1457</span>          StoreFile last = filesCompacting.get(filesCompacting.size() - 1);<a name="line.1457"></a>
+<span class="sourceLineNo">1458</span>          int idx = filesToCompact.indexOf(last);<a name="line.1458"></a>
+<span class="sourceLineNo">1459</span>          Preconditions.checkArgument(idx != -1);<a name="line.1459"></a>
+<span class="sourceLineNo">1460</span>          filesToCompact.subList(0, idx + 1).clear();<a name="line.1460"></a>
 <span class="sourceLineNo">1461</span>        }<a name="line.1461"></a>
-<span class="sourceLineNo">1462</span>        replaceStoreFiles(filesToCompact, Lists.newArrayList(sf));<a name="line.1462"></a>
-<span class="sourceLineNo">1463</span>        completeCompaction(filesToCompact);<a name="line.1463"></a>
-<span class="sourceLineNo">1464</span>      }<a name="line.1464"></a>
-<span class="sourceLineNo">1465</span>    } finally {<a name="line.1465"></a>
-<span class="sourceLineNo">1466</span>      synchronized (filesCompacting) {<a name="line.1466"></a>
-<span class="sourceLineNo">1467</span>        filesCompacting.removeAll(filesToCompact);<a name="line.1467"></a>
-<span class="sourceLineNo">1468</span>      }<a name="line.1468"></a>
-<span class="sourceLineNo">1469</span>    }<a name="line.1469"></a>
-<span class="sourceLineNo">1470</span>  }<a name="line.1470"></a>
-<span class="sourceLineNo">1471</span><a name="line.1471"></a>
-<span class="sourceLineNo">1472</span>  @Override<a name="line.1472"></a>
-<span class="sourceLineNo">1473</span>  public boolean hasReferences() {<a name="line.1473"></a>
-<span class="sourceLineNo">1474</span>    return StoreUtils.hasReferences(this.storeEngine.getStoreFileManager().getStorefiles());<a name="line.1474"></a>
-<span class="sourceLineNo">1475</span>  }<a name="line.1475"></a>
-<span class="sourceLineNo">1476</span><a name="line.1476"></a>
-<span class="sourceLineNo">1477</span>  @Override<a name="line.1477"></a>
-<span class="sourceLineNo">1478</span>  public CompactionProgress getCompactionProgress() {<a name="line.1478"></a>
-<span class="sourceLineNo">1479</span>    return this.storeEngine.getCompactor().getProgress();<a name="line.1479"></a>
-<span class="sourceLineNo">1480</span>  }<a name="line.1480"></a>
-<span class="sourceLineNo">1481</span><a name="line.1481"></a>
-<span class="sourceLineNo">1482</span>  @Override<a name="line.1482"></a>
-<span class="sourceLineNo">1483</span>  public boolean isMajorCompaction() throws IOException {<a name="line.1483"></a>
-<span class="sourceLineNo">1484</span>    for (StoreFile sf : this.storeEngine.getStoreFileManager().getStorefiles()) {<a name="line.1484"></a>
-<span class="sourceLineNo">1485</span>      // TODO: what are these reader checks all over the place?<a name="line.1485"></a>
-<span class="sourceLineNo">1486</span>      if (sf.getReader() == null) {<a name="line.1486"></a>
-<span class="sourceLineNo">1487</span>        LOG.debug("StoreFile " + sf + " has null Reader");<a name="line.1487"></a>
-<span class="sourceLineNo">1488</span>        return false;<a name="line.1488"></a>
-<span class="sourceLineNo">1489</span>      }<a name="line.1489"></a>
-<span class="sourceLineNo">1490</span>    }<a name="line.1490"></a>
-<span class="sourceLineNo">1491</span>    return storeEngine.getCompactionPolicy().isMajorCompaction(<a name="line.1491"></a>
-<span class="sourceLineNo">1492</span>        this.storeEngine.getStoreFileManager().getStorefiles());<a name="line.1492"></a>
-<span class="sourceLineNo">1493</span>  }<a name="line.1493"></a>
-<span class="sourceLineNo">1494</span><a name="line.1494"></a>
-<span class="sourceLineNo">1495</span>  @Override<a name="line.1495"></a>
-<span class="sourceLineNo">1496</span>  public CompactionContext requestCompaction() throws IOException {<a name="line.1496"></a>
-<span class="sourceLineNo">1497</span>    return requestCompaction(Store.NO_PRIORITY, null);<a name="line.1497"></a>
-<span class="sourceLineNo">1498</span>  }<a name="line.1498"></a>
-<span class="sourceLineNo">1499</span><a name="line.1499"></a>
-<span class="sourceLineNo">1500</span>  @Override<a name="line.1500"></a>
-<span class="sourceLineNo">1501</span>  public CompactionContext requestCompaction(int priority, CompactionRequest baseRequest)<a name="line.1501"></a>
-<span class="sourceLineNo">1502</span>      throws IOException {<a name="line.1502"></a>
-<span class="sourceLineNo">1503</span>    return requestCompaction(priority, baseRequest, null);<a name="line.1503"></a>
+<span class="sourceLineNo">1462</span>        int count = filesToCompact.size();<a name="line.1462"></a>
+<span class="sourceLineNo">1463</span>        if (N &gt; count) {<a name="line.1463"></a>
+<span class="sourceLineNo">1464</span>          throw new RuntimeException("Not enough files");<a name="line.1464"></a>
+<span class="sourceLineNo">1465</span>        }<a name="line.1465"></a>
+<span class="sourceLineNo">1466</span><a name="line.1466"></a>
+<span class="sourceLineNo">1467</span>        filesToCompact = filesToCompact.subList(count - N, count);<a name="line.1467"></a>
+<span class="sourceLineNo">1468</span>        isMajor = (filesToCompact.size() == storeEngine.getStoreFileManager().getStorefileCount());<a name="line.1468"></a>
+<span class="sourceLineNo">1469</span>        filesCompacting.addAll(filesToCompact);<a name="line.1469"></a>
+<span class="sourceLineNo">1470</span>        Collections.sort(filesCompacting, StoreFile.Comparators.SEQ_ID);<a name="line.1470"></a>
+<span class="sourceLineNo">1471</span>      }<a name="line.1471"></a>
+<span class="sourceLineNo">1472</span>    } finally {<a name="line.1472"></a>
+<span class="sourceLineNo">1473</span>      this.lock.readLock().unlock();<a name="line.1473"></a>
+<span class="sourceLineNo">1474</span>    }<a name="line.1474"></a>
+<span class="sourceLineNo">1475</span><a name="line.1475"></a>
+<span class="sourceLineNo">1476</span>    try {<a name="line.1476"></a>
+<span class="sourceLineNo">1477</span>      // Ready to go. Have list of files to compact.<a name="line.1477"></a>
+<span class="sourceLineNo">1478</span>      List&lt;Path&gt; newFiles = ((DefaultCompactor)this.storeEngine.getCompactor())<a name="line.1478"></a>
+<span class="sourceLineNo">1479</span>          .compactForTesting(filesToCompact, isMajor);<a name="line.1479"></a>
+<span class="sourceLineNo">1480</span>      for (Path newFile: newFiles) {<a name="line.1480"></a>
+<span class="sourceLineNo">1481</span>        // Move the compaction into place.<a name="line.1481"></a>
+<span class="sourceLineNo">1482</span>        StoreFile sf = moveFileIntoPlace(newFile);<a name="line.1482"></a>
+<span class="sourceLineNo">1483</span>        if (this.getCoprocessorHost() != null) {<a name="line.1483"></a>
+<span class="sourceLineNo">1484</span>          this.getCoprocessorHost().postCompact(this, sf, null);<a name="line.1484"></a>
+<span class="sourceLineNo">1485</span>        }<a name="line.1485"></a>
+<span class="sourceLineNo">1486</span>        replaceStoreFiles(filesToCompact, Lists.newArrayList(sf));<a name="line.1486"></a>
+<span class="sourceLineNo">1487</span>        completeCompaction(filesToCompact);<a name="line.1487"></a>
+<span class="sourceLineNo">1488</span>      }<a name="line.1488"></a>
+<span class="sourceLineNo">1489</span>    } finally {<a name="line.1489"></a>
+<span class="sourceLineNo">1490</span>      synchronized (filesCompacting) {<a name="line.1490"></a>
+<span class="sourceLineNo">1491</span>        filesCompacting.removeAll(filesToCompact);<a name="line.1491"></a>
+<span class="sourceLineNo">1492</span>      }<a name="line.1492"></a>
+<span class="sourceLineNo">1493</span>    }<a name="line.1493"></a>
+<span class="sourceLineNo">1494</span>  }<a name="line.1494"></a>
+<span class="sourceLineNo">1495</span><a name="line.1495"></a>
+<span class="sourceLineNo">1496</span>  @Override<a name="line.1496"></a>
+<span class="sourceLineNo">1497</span>  public boolean hasReferences() {<a name="line.1497"></a>
+<span class="sourceLineNo">1498</span>    return StoreUtils.hasReferences(this.storeEngine.getStoreFileManager().getStorefiles());<a name="line.1498"></a>
+<span class="sourceLineNo">1499</span>  }<a name="line.1499"></a>
+<span class="sourceLineNo">1500</span><a name="line.1500"></a>
+<span class="sourceLineNo">1501</span>  @Override<a name="line.1501"></a>
+<span class="sourceLineNo">1502</span>  public CompactionProgress getCompactionProgress() {<a name="line.1502"></a>
+<span class="sourceLineNo">1503</span>    return this.storeEngine.getCompactor().getProgress();<a name="line.1503"></a>
 <span class="sourceLineNo">1504</span>  }<a name="line.1504"></a>
-<span class="sourceLineNo">1505</span>  @Override<a name="line.1505"></a>
-<span class="sourceLineNo">1506</span>  public CompactionContext requestCompaction(int priority, final CompactionRequest baseRequest,<a name="line.1506"></a>
-<span class="sourceLineNo">1507</span>      User user) throws IOException {<a name="line.1507"></a>
-<span class="sourceLineNo">1508</span>    // don't even select for compaction if writes are disabled<a name="line.1508"></a>
-<span class="sourceLineNo">1509</span>    if (!this.areWritesEnabled()) {<a name="line.1509"></a>
-<span class="sourceLineNo">1510</span>      return null;<a name="line.1510"></a>
-<span class="sourceLineNo">1511</span>    }<a name="line.1511"></a>
-<span class="sourceLineNo">1512</span><a name="line.1512"></a>
-<span class="sourceLineNo">1513</span>    // Before we do compaction, try to get rid of unneeded files to simplify things.<a name="line.1513"></a>
-<span class="sourceLineNo">1514</span>    removeUnneededFiles();<a name="line.1514"></a>
-<span class="sourceLineNo">1515</span><a name="line.1515"></a>
-<span class="sourceLineNo">1516</span>    final CompactionContext compaction = storeEngine.createCompaction();<a name="line.1516"></a>
-<span class="sourceLineNo">1517</span>    CompactionRequest request = null;<a name="line.1517"></a>
-<span class="sourceLineNo">1518</span>    this.lock.readLock().lock();<a name="line.1518"></a>
-<span class="sourceLineNo">1519</span>    try {<a name="line.1519"></a>
-<span class="sourceLineNo">1520</span>      synchronized (filesCompacting) {<a name="line.1520"></a>
-<span class="sourceLineNo">1521</span>        final Store thisStore = this;<a name="line.1521"></a>
-<span class="sourceLineNo">1522</span>        // First, see if coprocessor would want to override selection.<a name="line.1522"></a>
-<span class="sourceLineNo">1523</span>        if (this.getCoprocessorHost() != nu

<TRUNCATED>

Mime
View raw message