blob: 1e0f0cebf2d14a36734a2ef8ca744b8448b5a55d [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<title>Source code</title>
<link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style">
</head>
<body>
<div class="sourceContainer">
<pre><span class="sourceLineNo">001</span>/*<a name="line.1"></a>
<span class="sourceLineNo">002</span> * Licensed to the Apache Software Foundation (ASF) under one<a name="line.2"></a>
<span class="sourceLineNo">003</span> * or more contributor license agreements. See the NOTICE file<a name="line.3"></a>
<span class="sourceLineNo">004</span> * distributed with this work for additional information<a name="line.4"></a>
<span class="sourceLineNo">005</span> * regarding copyright ownership. The ASF licenses this file<a name="line.5"></a>
<span class="sourceLineNo">006</span> * to you under the Apache License, Version 2.0 (the<a name="line.6"></a>
<span class="sourceLineNo">007</span> * "License"); you may not use this file except in compliance<a name="line.7"></a>
<span class="sourceLineNo">008</span> * with the License. You may obtain a copy of the License at<a name="line.8"></a>
<span class="sourceLineNo">009</span> *<a name="line.9"></a>
<span class="sourceLineNo">010</span> * http://www.apache.org/licenses/LICENSE-2.0<a name="line.10"></a>
<span class="sourceLineNo">011</span> *<a name="line.11"></a>
<span class="sourceLineNo">012</span> * Unless required by applicable law or agreed to in writing, software<a name="line.12"></a>
<span class="sourceLineNo">013</span> * distributed under the License is distributed on an "AS IS" BASIS,<a name="line.13"></a>
<span class="sourceLineNo">014</span> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<a name="line.14"></a>
<span class="sourceLineNo">015</span> * See the License for the specific language governing permissions and<a name="line.15"></a>
<span class="sourceLineNo">016</span> * limitations under the License.<a name="line.16"></a>
<span class="sourceLineNo">017</span> */<a name="line.17"></a>
<span class="sourceLineNo">018</span>package org.apache.hadoop.hbase.regionserver;<a name="line.18"></a>
<span class="sourceLineNo">019</span><a name="line.19"></a>
<span class="sourceLineNo">020</span>import com.google.errorprone.annotations.RestrictedApi;<a name="line.20"></a>
<span class="sourceLineNo">021</span>import java.io.IOException;<a name="line.21"></a>
<span class="sourceLineNo">022</span>import java.io.InterruptedIOException;<a name="line.22"></a>
<span class="sourceLineNo">023</span>import java.net.InetSocketAddress;<a name="line.23"></a>
<span class="sourceLineNo">024</span>import java.util.ArrayList;<a name="line.24"></a>
<span class="sourceLineNo">025</span>import java.util.Collection;<a name="line.25"></a>
<span class="sourceLineNo">026</span>import java.util.Collections;<a name="line.26"></a>
<span class="sourceLineNo">027</span>import java.util.HashMap;<a name="line.27"></a>
<span class="sourceLineNo">028</span>import java.util.HashSet;<a name="line.28"></a>
<span class="sourceLineNo">029</span>import java.util.Iterator;<a name="line.29"></a>
<span class="sourceLineNo">030</span>import java.util.List;<a name="line.30"></a>
<span class="sourceLineNo">031</span>import java.util.Map;<a name="line.31"></a>
<span class="sourceLineNo">032</span>import java.util.Map.Entry;<a name="line.32"></a>
<span class="sourceLineNo">033</span>import java.util.NavigableSet;<a name="line.33"></a>
<span class="sourceLineNo">034</span>import java.util.Optional;<a name="line.34"></a>
<span class="sourceLineNo">035</span>import java.util.OptionalDouble;<a name="line.35"></a>
<span class="sourceLineNo">036</span>import java.util.OptionalInt;<a name="line.36"></a>
<span class="sourceLineNo">037</span>import java.util.OptionalLong;<a name="line.37"></a>
<span class="sourceLineNo">038</span>import java.util.Set;<a name="line.38"></a>
<span class="sourceLineNo">039</span>import java.util.concurrent.Callable;<a name="line.39"></a>
<span class="sourceLineNo">040</span>import java.util.concurrent.CompletionService;<a name="line.40"></a>
<span class="sourceLineNo">041</span>import java.util.concurrent.ConcurrentHashMap;<a name="line.41"></a>
<span class="sourceLineNo">042</span>import java.util.concurrent.ExecutionException;<a name="line.42"></a>
<span class="sourceLineNo">043</span>import java.util.concurrent.ExecutorCompletionService;<a name="line.43"></a>
<span class="sourceLineNo">044</span>import java.util.concurrent.Future;<a name="line.44"></a>
<span class="sourceLineNo">045</span>import java.util.concurrent.ThreadPoolExecutor;<a name="line.45"></a>
<span class="sourceLineNo">046</span>import java.util.concurrent.atomic.AtomicBoolean;<a name="line.46"></a>
<span class="sourceLineNo">047</span>import java.util.concurrent.atomic.AtomicInteger;<a name="line.47"></a>
<span class="sourceLineNo">048</span>import java.util.concurrent.atomic.AtomicLong;<a name="line.48"></a>
<span class="sourceLineNo">049</span>import java.util.concurrent.atomic.LongAdder;<a name="line.49"></a>
<span class="sourceLineNo">050</span>import java.util.concurrent.locks.ReentrantLock;<a name="line.50"></a>
<span class="sourceLineNo">051</span>import java.util.function.Consumer;<a name="line.51"></a>
<span class="sourceLineNo">052</span>import java.util.function.Supplier;<a name="line.52"></a>
<span class="sourceLineNo">053</span>import java.util.function.ToLongFunction;<a name="line.53"></a>
<span class="sourceLineNo">054</span>import java.util.stream.Collectors;<a name="line.54"></a>
<span class="sourceLineNo">055</span>import java.util.stream.LongStream;<a name="line.55"></a>
<span class="sourceLineNo">056</span>import org.apache.hadoop.conf.Configuration;<a name="line.56"></a>
<span class="sourceLineNo">057</span>import org.apache.hadoop.fs.FileSystem;<a name="line.57"></a>
<span class="sourceLineNo">058</span>import org.apache.hadoop.fs.Path;<a name="line.58"></a>
<span class="sourceLineNo">059</span>import org.apache.hadoop.fs.permission.FsAction;<a name="line.59"></a>
<span class="sourceLineNo">060</span>import org.apache.hadoop.hbase.Cell;<a name="line.60"></a>
<span class="sourceLineNo">061</span>import org.apache.hadoop.hbase.CellComparator;<a name="line.61"></a>
<span class="sourceLineNo">062</span>import org.apache.hadoop.hbase.CellUtil;<a name="line.62"></a>
<span class="sourceLineNo">063</span>import org.apache.hadoop.hbase.HConstants;<a name="line.63"></a>
<span class="sourceLineNo">064</span>import org.apache.hadoop.hbase.InnerStoreCellComparator;<a name="line.64"></a>
<span class="sourceLineNo">065</span>import org.apache.hadoop.hbase.MemoryCompactionPolicy;<a name="line.65"></a>
<span class="sourceLineNo">066</span>import org.apache.hadoop.hbase.MetaCellComparator;<a name="line.66"></a>
<span class="sourceLineNo">067</span>import org.apache.hadoop.hbase.TableName;<a name="line.67"></a>
<span class="sourceLineNo">068</span>import org.apache.hadoop.hbase.backup.FailedArchiveException;<a name="line.68"></a>
<span class="sourceLineNo">069</span>import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;<a name="line.69"></a>
<span class="sourceLineNo">070</span>import org.apache.hadoop.hbase.client.RegionInfo;<a name="line.70"></a>
<span class="sourceLineNo">071</span>import org.apache.hadoop.hbase.client.Scan;<a name="line.71"></a>
<span class="sourceLineNo">072</span>import org.apache.hadoop.hbase.conf.ConfigurationManager;<a name="line.72"></a>
<span class="sourceLineNo">073</span>import org.apache.hadoop.hbase.conf.PropagatingConfigurationObserver;<a name="line.73"></a>
<span class="sourceLineNo">074</span>import org.apache.hadoop.hbase.coprocessor.ReadOnlyConfiguration;<a name="line.74"></a>
<span class="sourceLineNo">075</span>import org.apache.hadoop.hbase.io.HeapSize;<a name="line.75"></a>
<span class="sourceLineNo">076</span>import org.apache.hadoop.hbase.io.hfile.CacheConfig;<a name="line.76"></a>
<span class="sourceLineNo">077</span>import org.apache.hadoop.hbase.io.hfile.HFile;<a name="line.77"></a>
<span class="sourceLineNo">078</span>import org.apache.hadoop.hbase.io.hfile.HFileDataBlockEncoder;<a name="line.78"></a>
<span class="sourceLineNo">079</span>import org.apache.hadoop.hbase.io.hfile.HFileDataBlockEncoderImpl;<a name="line.79"></a>
<span class="sourceLineNo">080</span>import org.apache.hadoop.hbase.io.hfile.HFileScanner;<a name="line.80"></a>
<span class="sourceLineNo">081</span>import org.apache.hadoop.hbase.io.hfile.InvalidHFileException;<a name="line.81"></a>
<span class="sourceLineNo">082</span>import org.apache.hadoop.hbase.monitoring.MonitoredTask;<a name="line.82"></a>
<span class="sourceLineNo">083</span>import org.apache.hadoop.hbase.quotas.RegionSizeStore;<a name="line.83"></a>
<span class="sourceLineNo">084</span>import org.apache.hadoop.hbase.regionserver.compactions.CompactionContext;<a name="line.84"></a>
<span class="sourceLineNo">085</span>import org.apache.hadoop.hbase.regionserver.compactions.CompactionLifeCycleTracker;<a name="line.85"></a>
<span class="sourceLineNo">086</span>import org.apache.hadoop.hbase.regionserver.compactions.CompactionProgress;<a name="line.86"></a>
<span class="sourceLineNo">087</span>import org.apache.hadoop.hbase.regionserver.compactions.CompactionRequestImpl;<a name="line.87"></a>
<span class="sourceLineNo">088</span>import org.apache.hadoop.hbase.regionserver.compactions.OffPeakHours;<a name="line.88"></a>
<span class="sourceLineNo">089</span>import org.apache.hadoop.hbase.regionserver.querymatcher.ScanQueryMatcher;<a name="line.89"></a>
<span class="sourceLineNo">090</span>import org.apache.hadoop.hbase.regionserver.throttle.ThroughputController;<a name="line.90"></a>
<span class="sourceLineNo">091</span>import org.apache.hadoop.hbase.regionserver.wal.WALUtil;<a name="line.91"></a>
<span class="sourceLineNo">092</span>import org.apache.hadoop.hbase.security.EncryptionUtil;<a name="line.92"></a>
<span class="sourceLineNo">093</span>import org.apache.hadoop.hbase.security.User;<a name="line.93"></a>
<span class="sourceLineNo">094</span>import org.apache.hadoop.hbase.util.Bytes;<a name="line.94"></a>
<span class="sourceLineNo">095</span>import org.apache.hadoop.hbase.util.ClassSize;<a name="line.95"></a>
<span class="sourceLineNo">096</span>import org.apache.hadoop.hbase.util.CommonFSUtils;<a name="line.96"></a>
<span class="sourceLineNo">097</span>import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;<a name="line.97"></a>
<span class="sourceLineNo">098</span>import org.apache.hadoop.hbase.util.Pair;<a name="line.98"></a>
<span class="sourceLineNo">099</span>import org.apache.hadoop.hbase.util.ReflectionUtils;<a name="line.99"></a>
<span class="sourceLineNo">100</span>import org.apache.hadoop.util.StringUtils;<a name="line.100"></a>
<span class="sourceLineNo">101</span>import org.apache.hadoop.util.StringUtils.TraditionalBinaryPrefix;<a name="line.101"></a>
<span class="sourceLineNo">102</span>import org.apache.yetus.audience.InterfaceAudience;<a name="line.102"></a>
<span class="sourceLineNo">103</span>import org.slf4j.Logger;<a name="line.103"></a>
<span class="sourceLineNo">104</span>import org.slf4j.LoggerFactory;<a name="line.104"></a>
<span class="sourceLineNo">105</span><a name="line.105"></a>
<span class="sourceLineNo">106</span>import org.apache.hbase.thirdparty.com.google.common.base.Preconditions;<a name="line.106"></a>
<span class="sourceLineNo">107</span>import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableCollection;<a name="line.107"></a>
<span class="sourceLineNo">108</span>import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableList;<a name="line.108"></a>
<span class="sourceLineNo">109</span>import org.apache.hbase.thirdparty.com.google.common.collect.Lists;<a name="line.109"></a>
<span class="sourceLineNo">110</span>import org.apache.hbase.thirdparty.com.google.common.collect.Maps;<a name="line.110"></a>
<span class="sourceLineNo">111</span>import org.apache.hbase.thirdparty.org.apache.commons.collections4.CollectionUtils;<a name="line.111"></a>
<span class="sourceLineNo">112</span>import org.apache.hbase.thirdparty.org.apache.commons.collections4.IterableUtils;<a name="line.112"></a>
<span class="sourceLineNo">113</span><a name="line.113"></a>
<span class="sourceLineNo">114</span>import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;<a name="line.114"></a>
<span class="sourceLineNo">115</span>import org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.CompactionDescriptor;<a name="line.115"></a>
<span class="sourceLineNo">116</span><a name="line.116"></a>
<span class="sourceLineNo">117</span>/**<a name="line.117"></a>
<span class="sourceLineNo">118</span> * A Store holds a column family in a Region. Its a memstore and a set of zero or more StoreFiles,<a name="line.118"></a>
<span class="sourceLineNo">119</span> * which stretch backwards over time.<a name="line.119"></a>
<span class="sourceLineNo">120</span> * &lt;p&gt;<a name="line.120"></a>
<span class="sourceLineNo">121</span> * There's no reason to consider append-logging at this level; all logging and locking is handled at<a name="line.121"></a>
<span class="sourceLineNo">122</span> * the HRegion level. Store just provides services to manage sets of StoreFiles. One of the most<a name="line.122"></a>
<span class="sourceLineNo">123</span> * important of those services is compaction services where files are aggregated once they pass a<a name="line.123"></a>
<span class="sourceLineNo">124</span> * configurable threshold.<a name="line.124"></a>
<span class="sourceLineNo">125</span> * &lt;p&gt;<a name="line.125"></a>
<span class="sourceLineNo">126</span> * Locking and transactions are handled at a higher level. This API should not be called directly<a name="line.126"></a>
<span class="sourceLineNo">127</span> * but by an HRegion manager.<a name="line.127"></a>
<span class="sourceLineNo">128</span> */<a name="line.128"></a>
<span class="sourceLineNo">129</span>@InterfaceAudience.Private<a name="line.129"></a>
<span class="sourceLineNo">130</span>public class HStore<a name="line.130"></a>
<span class="sourceLineNo">131</span> implements Store, HeapSize, StoreConfigInformation, PropagatingConfigurationObserver {<a name="line.131"></a>
<span class="sourceLineNo">132</span> public static final String MEMSTORE_CLASS_NAME = "hbase.regionserver.memstore.class";<a name="line.132"></a>
<span class="sourceLineNo">133</span> public static final String COMPACTCHECKER_INTERVAL_MULTIPLIER_KEY =<a name="line.133"></a>
<span class="sourceLineNo">134</span> "hbase.server.compactchecker.interval.multiplier";<a name="line.134"></a>
<span class="sourceLineNo">135</span> public static final String BLOCKING_STOREFILES_KEY = "hbase.hstore.blockingStoreFiles";<a name="line.135"></a>
<span class="sourceLineNo">136</span> public static final String BLOCK_STORAGE_POLICY_KEY = "hbase.hstore.block.storage.policy";<a name="line.136"></a>
<span class="sourceLineNo">137</span> // "NONE" is not a valid storage policy and means we defer the policy to HDFS<a name="line.137"></a>
<span class="sourceLineNo">138</span> public static final String DEFAULT_BLOCK_STORAGE_POLICY = "NONE";<a name="line.138"></a>
<span class="sourceLineNo">139</span> public static final int DEFAULT_COMPACTCHECKER_INTERVAL_MULTIPLIER = 1000;<a name="line.139"></a>
<span class="sourceLineNo">140</span> public static final int DEFAULT_BLOCKING_STOREFILE_COUNT = 16;<a name="line.140"></a>
<span class="sourceLineNo">141</span><a name="line.141"></a>
<span class="sourceLineNo">142</span> // HBASE-24428 : Update compaction priority for recently split daughter regions<a name="line.142"></a>
<span class="sourceLineNo">143</span> // so as to prioritize their compaction.<a name="line.143"></a>
<span class="sourceLineNo">144</span> // Any compaction candidate with higher priority than compaction of newly split daugher regions<a name="line.144"></a>
<span class="sourceLineNo">145</span> // should have priority value &lt; (Integer.MIN_VALUE + 1000)<a name="line.145"></a>
<span class="sourceLineNo">146</span> private static final int SPLIT_REGION_COMPACTION_PRIORITY = Integer.MIN_VALUE + 1000;<a name="line.146"></a>
<span class="sourceLineNo">147</span><a name="line.147"></a>
<span class="sourceLineNo">148</span> private static final Logger LOG = LoggerFactory.getLogger(HStore.class);<a name="line.148"></a>
<span class="sourceLineNo">149</span><a name="line.149"></a>
<span class="sourceLineNo">150</span> protected final MemStore memstore;<a name="line.150"></a>
<span class="sourceLineNo">151</span> // This stores directory in the filesystem.<a name="line.151"></a>
<span class="sourceLineNo">152</span> private final HRegion region;<a name="line.152"></a>
<span class="sourceLineNo">153</span> protected Configuration conf;<a name="line.153"></a>
<span class="sourceLineNo">154</span> private long lastCompactSize = 0;<a name="line.154"></a>
<span class="sourceLineNo">155</span> volatile boolean forceMajor = false;<a name="line.155"></a>
<span class="sourceLineNo">156</span> private AtomicLong storeSize = new AtomicLong();<a name="line.156"></a>
<span class="sourceLineNo">157</span> private AtomicLong totalUncompressedBytes = new AtomicLong();<a name="line.157"></a>
<span class="sourceLineNo">158</span> private LongAdder memstoreOnlyRowReadsCount = new LongAdder();<a name="line.158"></a>
<span class="sourceLineNo">159</span> // rows that has cells from both memstore and files (or only files)<a name="line.159"></a>
<span class="sourceLineNo">160</span> private LongAdder mixedRowReadsCount = new LongAdder();<a name="line.160"></a>
<span class="sourceLineNo">161</span><a name="line.161"></a>
<span class="sourceLineNo">162</span> /**<a name="line.162"></a>
<span class="sourceLineNo">163</span> * Lock specific to archiving compacted store files. This avoids races around the combination of<a name="line.163"></a>
<span class="sourceLineNo">164</span> * retrieving the list of compacted files and moving them to the archive directory. Since this is<a name="line.164"></a>
<span class="sourceLineNo">165</span> * usually a background process (other than on close), we don't want to handle this with the store<a name="line.165"></a>
<span class="sourceLineNo">166</span> * write lock, which would block readers and degrade performance. Locked by: -<a name="line.166"></a>
<span class="sourceLineNo">167</span> * CompactedHFilesDispatchHandler via closeAndArchiveCompactedFiles() - close()<a name="line.167"></a>
<span class="sourceLineNo">168</span> */<a name="line.168"></a>
<span class="sourceLineNo">169</span> final ReentrantLock archiveLock = new ReentrantLock();<a name="line.169"></a>
<span class="sourceLineNo">170</span><a name="line.170"></a>
<span class="sourceLineNo">171</span> private final boolean verifyBulkLoads;<a name="line.171"></a>
<span class="sourceLineNo">172</span><a name="line.172"></a>
<span class="sourceLineNo">173</span> /**<a name="line.173"></a>
<span class="sourceLineNo">174</span> * Use this counter to track concurrent puts. If TRACE-log is enabled, if we are over the<a name="line.174"></a>
<span class="sourceLineNo">175</span> * threshold set by hbase.region.store.parallel.put.print.threshold (Default is 50) we will log a<a name="line.175"></a>
<span class="sourceLineNo">176</span> * message that identifies the Store experience this high-level of concurrency.<a name="line.176"></a>
<span class="sourceLineNo">177</span> */<a name="line.177"></a>
<span class="sourceLineNo">178</span> private final AtomicInteger currentParallelPutCount = new AtomicInteger(0);<a name="line.178"></a>
<span class="sourceLineNo">179</span> private final int parallelPutCountPrintThreshold;<a name="line.179"></a>
<span class="sourceLineNo">180</span><a name="line.180"></a>
<span class="sourceLineNo">181</span> private ScanInfo scanInfo;<a name="line.181"></a>
<span class="sourceLineNo">182</span><a name="line.182"></a>
<span class="sourceLineNo">183</span> // All access must be synchronized.<a name="line.183"></a>
<span class="sourceLineNo">184</span> // TODO: ideally, this should be part of storeFileManager, as we keep passing this to it.<a name="line.184"></a>
<span class="sourceLineNo">185</span> private final List&lt;HStoreFile&gt; filesCompacting = Lists.newArrayList();<a name="line.185"></a>
<span class="sourceLineNo">186</span><a name="line.186"></a>
<span class="sourceLineNo">187</span> // All access must be synchronized.<a name="line.187"></a>
<span class="sourceLineNo">188</span> private final Set&lt;ChangedReadersObserver&gt; changedReaderObservers =<a name="line.188"></a>
<span class="sourceLineNo">189</span> Collections.newSetFromMap(new ConcurrentHashMap&lt;ChangedReadersObserver, Boolean&gt;());<a name="line.189"></a>
<span class="sourceLineNo">190</span><a name="line.190"></a>
<span class="sourceLineNo">191</span> private HFileDataBlockEncoder dataBlockEncoder;<a name="line.191"></a>
<span class="sourceLineNo">192</span><a name="line.192"></a>
<span class="sourceLineNo">193</span> final StoreEngine&lt;?, ?, ?, ?&gt; storeEngine;<a name="line.193"></a>
<span class="sourceLineNo">194</span><a name="line.194"></a>
<span class="sourceLineNo">195</span> private static final AtomicBoolean offPeakCompactionTracker = new AtomicBoolean();<a name="line.195"></a>
<span class="sourceLineNo">196</span> private volatile OffPeakHours offPeakHours;<a name="line.196"></a>
<span class="sourceLineNo">197</span><a name="line.197"></a>
<span class="sourceLineNo">198</span> private static final int DEFAULT_FLUSH_RETRIES_NUMBER = 10;<a name="line.198"></a>
<span class="sourceLineNo">199</span> private int flushRetriesNumber;<a name="line.199"></a>
<span class="sourceLineNo">200</span> private int pauseTime;<a name="line.200"></a>
<span class="sourceLineNo">201</span><a name="line.201"></a>
<span class="sourceLineNo">202</span> private long blockingFileCount;<a name="line.202"></a>
<span class="sourceLineNo">203</span> private int compactionCheckMultiplier;<a name="line.203"></a>
<span class="sourceLineNo">204</span><a name="line.204"></a>
<span class="sourceLineNo">205</span> private AtomicLong flushedCellsCount = new AtomicLong();<a name="line.205"></a>
<span class="sourceLineNo">206</span> private AtomicLong compactedCellsCount = new AtomicLong();<a name="line.206"></a>
<span class="sourceLineNo">207</span> private AtomicLong majorCompactedCellsCount = new AtomicLong();<a name="line.207"></a>
<span class="sourceLineNo">208</span> private AtomicLong flushedCellsSize = new AtomicLong();<a name="line.208"></a>
<span class="sourceLineNo">209</span> private AtomicLong flushedOutputFileSize = new AtomicLong();<a name="line.209"></a>
<span class="sourceLineNo">210</span> private AtomicLong compactedCellsSize = new AtomicLong();<a name="line.210"></a>
<span class="sourceLineNo">211</span> private AtomicLong majorCompactedCellsSize = new AtomicLong();<a name="line.211"></a>
<span class="sourceLineNo">212</span><a name="line.212"></a>
<span class="sourceLineNo">213</span> private final StoreContext storeContext;<a name="line.213"></a>
<span class="sourceLineNo">214</span><a name="line.214"></a>
<span class="sourceLineNo">215</span> // Used to track the store files which are currently being written. For compaction, if we want to<a name="line.215"></a>
<span class="sourceLineNo">216</span> // compact store file [a, b, c] to [d], then here we will record 'd'. And we will also use it to<a name="line.216"></a>
<span class="sourceLineNo">217</span> // track the store files being written when flushing.<a name="line.217"></a>
<span class="sourceLineNo">218</span> // Notice that the creation is in the background compaction or flush thread and we will get the<a name="line.218"></a>
<span class="sourceLineNo">219</span> // files in other thread, so it needs to be thread safe.<a name="line.219"></a>
<span class="sourceLineNo">220</span> private static final class StoreFileWriterCreationTracker implements Consumer&lt;Path&gt; {<a name="line.220"></a>
<span class="sourceLineNo">221</span><a name="line.221"></a>
<span class="sourceLineNo">222</span> private final Set&lt;Path&gt; files = Collections.newSetFromMap(new ConcurrentHashMap&lt;&gt;());<a name="line.222"></a>
<span class="sourceLineNo">223</span><a name="line.223"></a>
<span class="sourceLineNo">224</span> @Override<a name="line.224"></a>
<span class="sourceLineNo">225</span> public void accept(Path t) {<a name="line.225"></a>
<span class="sourceLineNo">226</span> files.add(t);<a name="line.226"></a>
<span class="sourceLineNo">227</span> }<a name="line.227"></a>
<span class="sourceLineNo">228</span><a name="line.228"></a>
<span class="sourceLineNo">229</span> public Set&lt;Path&gt; get() {<a name="line.229"></a>
<span class="sourceLineNo">230</span> return Collections.unmodifiableSet(files);<a name="line.230"></a>
<span class="sourceLineNo">231</span> }<a name="line.231"></a>
<span class="sourceLineNo">232</span> }<a name="line.232"></a>
<span class="sourceLineNo">233</span><a name="line.233"></a>
<span class="sourceLineNo">234</span> // We may have multiple compaction running at the same time, and flush can also happen at the same<a name="line.234"></a>
<span class="sourceLineNo">235</span> // time, so here we need to use a collection, and the collection needs to be thread safe.<a name="line.235"></a>
<span class="sourceLineNo">236</span> // The implementation of StoreFileWriterCreationTracker is very simple and we will not likely to<a name="line.236"></a>
<span class="sourceLineNo">237</span> // implement hashCode or equals for it, so here we just use ConcurrentHashMap. Changed to<a name="line.237"></a>
<span class="sourceLineNo">238</span> // IdentityHashMap if later we want to implement hashCode or equals.<a name="line.238"></a>
<span class="sourceLineNo">239</span> private final Set&lt;StoreFileWriterCreationTracker&gt; storeFileWriterCreationTrackers =<a name="line.239"></a>
<span class="sourceLineNo">240</span> Collections.newSetFromMap(new ConcurrentHashMap&lt;&gt;());<a name="line.240"></a>
<span class="sourceLineNo">241</span><a name="line.241"></a>
<span class="sourceLineNo">242</span> // For the SFT implementation which we will write tmp store file first, we do not need to clean up<a name="line.242"></a>
<span class="sourceLineNo">243</span> // the broken store files under the data directory, which means we do not need to track the store<a name="line.243"></a>
<span class="sourceLineNo">244</span> // file writer creation. So here we abstract a factory to return different trackers for different<a name="line.244"></a>
<span class="sourceLineNo">245</span> // SFT implementations.<a name="line.245"></a>
<span class="sourceLineNo">246</span> private final Supplier&lt;StoreFileWriterCreationTracker&gt; storeFileWriterCreationTrackerFactory;<a name="line.246"></a>
<span class="sourceLineNo">247</span><a name="line.247"></a>
<span class="sourceLineNo">248</span> private final boolean warmup;<a name="line.248"></a>
<span class="sourceLineNo">249</span><a name="line.249"></a>
<span class="sourceLineNo">250</span> /**<a name="line.250"></a>
<span class="sourceLineNo">251</span> * Constructor<a name="line.251"></a>
<span class="sourceLineNo">252</span> * @param family HColumnDescriptor for this column<a name="line.252"></a>
<span class="sourceLineNo">253</span> * @param confParam configuration object failed. Can be null.<a name="line.253"></a>
<span class="sourceLineNo">254</span> */<a name="line.254"></a>
<span class="sourceLineNo">255</span> protected HStore(final HRegion region, final ColumnFamilyDescriptor family,<a name="line.255"></a>
<span class="sourceLineNo">256</span> final Configuration confParam, boolean warmup) throws IOException {<a name="line.256"></a>
<span class="sourceLineNo">257</span> this.conf = StoreUtils.createStoreConfiguration(confParam, region.getTableDescriptor(), family);<a name="line.257"></a>
<span class="sourceLineNo">258</span><a name="line.258"></a>
<span class="sourceLineNo">259</span> this.region = region;<a name="line.259"></a>
<span class="sourceLineNo">260</span> this.storeContext = initializeStoreContext(family);<a name="line.260"></a>
<span class="sourceLineNo">261</span><a name="line.261"></a>
<span class="sourceLineNo">262</span> // Assemble the store's home directory and Ensure it exists.<a name="line.262"></a>
<span class="sourceLineNo">263</span> region.getRegionFileSystem().createStoreDir(family.getNameAsString());<a name="line.263"></a>
<span class="sourceLineNo">264</span><a name="line.264"></a>
<span class="sourceLineNo">265</span> // set block storage policy for store directory<a name="line.265"></a>
<span class="sourceLineNo">266</span> String policyName = family.getStoragePolicy();<a name="line.266"></a>
<span class="sourceLineNo">267</span> if (null == policyName) {<a name="line.267"></a>
<span class="sourceLineNo">268</span> policyName = this.conf.get(BLOCK_STORAGE_POLICY_KEY, DEFAULT_BLOCK_STORAGE_POLICY);<a name="line.268"></a>
<span class="sourceLineNo">269</span> }<a name="line.269"></a>
<span class="sourceLineNo">270</span> region.getRegionFileSystem().setStoragePolicy(family.getNameAsString(), policyName.trim());<a name="line.270"></a>
<span class="sourceLineNo">271</span><a name="line.271"></a>
<span class="sourceLineNo">272</span> this.dataBlockEncoder = new HFileDataBlockEncoderImpl(family.getDataBlockEncoding());<a name="line.272"></a>
<span class="sourceLineNo">273</span><a name="line.273"></a>
<span class="sourceLineNo">274</span> // used by ScanQueryMatcher<a name="line.274"></a>
<span class="sourceLineNo">275</span> long timeToPurgeDeletes = Math.max(conf.getLong("hbase.hstore.time.to.purge.deletes", 0), 0);<a name="line.275"></a>
<span class="sourceLineNo">276</span> LOG.trace("Time to purge deletes set to {}ms in {}", timeToPurgeDeletes, this);<a name="line.276"></a>
<span class="sourceLineNo">277</span> // Get TTL<a name="line.277"></a>
<span class="sourceLineNo">278</span> long ttl = determineTTLFromFamily(family);<a name="line.278"></a>
<span class="sourceLineNo">279</span> // Why not just pass a HColumnDescriptor in here altogether? Even if have<a name="line.279"></a>
<span class="sourceLineNo">280</span> // to clone it?<a name="line.280"></a>
<span class="sourceLineNo">281</span> scanInfo =<a name="line.281"></a>
<span class="sourceLineNo">282</span> new ScanInfo(conf, family, ttl, timeToPurgeDeletes, this.storeContext.getComparator());<a name="line.282"></a>
<span class="sourceLineNo">283</span> this.memstore = getMemstore();<a name="line.283"></a>
<span class="sourceLineNo">284</span><a name="line.284"></a>
<span class="sourceLineNo">285</span> this.offPeakHours = OffPeakHours.getInstance(conf);<a name="line.285"></a>
<span class="sourceLineNo">286</span><a name="line.286"></a>
<span class="sourceLineNo">287</span> this.verifyBulkLoads = conf.getBoolean("hbase.hstore.bulkload.verify", false);<a name="line.287"></a>
<span class="sourceLineNo">288</span><a name="line.288"></a>
<span class="sourceLineNo">289</span> this.blockingFileCount = conf.getInt(BLOCKING_STOREFILES_KEY, DEFAULT_BLOCKING_STOREFILE_COUNT);<a name="line.289"></a>
<span class="sourceLineNo">290</span> this.compactionCheckMultiplier = conf.getInt(COMPACTCHECKER_INTERVAL_MULTIPLIER_KEY,<a name="line.290"></a>
<span class="sourceLineNo">291</span> DEFAULT_COMPACTCHECKER_INTERVAL_MULTIPLIER);<a name="line.291"></a>
<span class="sourceLineNo">292</span> if (this.compactionCheckMultiplier &lt;= 0) {<a name="line.292"></a>
<span class="sourceLineNo">293</span> LOG.error("Compaction check period multiplier must be positive, setting default: {}",<a name="line.293"></a>
<span class="sourceLineNo">294</span> DEFAULT_COMPACTCHECKER_INTERVAL_MULTIPLIER);<a name="line.294"></a>
<span class="sourceLineNo">295</span> this.compactionCheckMultiplier = DEFAULT_COMPACTCHECKER_INTERVAL_MULTIPLIER;<a name="line.295"></a>
<span class="sourceLineNo">296</span> }<a name="line.296"></a>
<span class="sourceLineNo">297</span><a name="line.297"></a>
<span class="sourceLineNo">298</span> this.warmup = warmup;<a name="line.298"></a>
<span class="sourceLineNo">299</span> this.storeEngine = createStoreEngine(this, this.conf, region.getCellComparator());<a name="line.299"></a>
<span class="sourceLineNo">300</span> storeEngine.initialize(warmup);<a name="line.300"></a>
<span class="sourceLineNo">301</span> // if require writing to tmp dir first, then we just return null, which indicate that we do not<a name="line.301"></a>
<span class="sourceLineNo">302</span> // need to track the creation of store file writer, otherwise we return a new<a name="line.302"></a>
<span class="sourceLineNo">303</span> // StoreFileWriterCreationTracker.<a name="line.303"></a>
<span class="sourceLineNo">304</span> this.storeFileWriterCreationTrackerFactory = storeEngine.requireWritingToTmpDirFirst()<a name="line.304"></a>
<span class="sourceLineNo">305</span> ? () -&gt; null<a name="line.305"></a>
<span class="sourceLineNo">306</span> : () -&gt; new StoreFileWriterCreationTracker();<a name="line.306"></a>
<span class="sourceLineNo">307</span> refreshStoreSizeAndTotalBytes();<a name="line.307"></a>
<span class="sourceLineNo">308</span><a name="line.308"></a>
<span class="sourceLineNo">309</span> flushRetriesNumber =<a name="line.309"></a>
<span class="sourceLineNo">310</span> conf.getInt("hbase.hstore.flush.retries.number", DEFAULT_FLUSH_RETRIES_NUMBER);<a name="line.310"></a>
<span class="sourceLineNo">311</span> pauseTime = conf.getInt(HConstants.HBASE_SERVER_PAUSE, HConstants.DEFAULT_HBASE_SERVER_PAUSE);<a name="line.311"></a>
<span class="sourceLineNo">312</span> if (flushRetriesNumber &lt;= 0) {<a name="line.312"></a>
<span class="sourceLineNo">313</span> throw new IllegalArgumentException(<a name="line.313"></a>
<span class="sourceLineNo">314</span> "hbase.hstore.flush.retries.number must be &gt; 0, not " + flushRetriesNumber);<a name="line.314"></a>
<span class="sourceLineNo">315</span> }<a name="line.315"></a>
<span class="sourceLineNo">316</span><a name="line.316"></a>
<span class="sourceLineNo">317</span> int confPrintThreshold =<a name="line.317"></a>
<span class="sourceLineNo">318</span> this.conf.getInt("hbase.region.store.parallel.put.print.threshold", 50);<a name="line.318"></a>
<span class="sourceLineNo">319</span> if (confPrintThreshold &lt; 10) {<a name="line.319"></a>
<span class="sourceLineNo">320</span> confPrintThreshold = 10;<a name="line.320"></a>
<span class="sourceLineNo">321</span> }<a name="line.321"></a>
<span class="sourceLineNo">322</span> this.parallelPutCountPrintThreshold = confPrintThreshold;<a name="line.322"></a>
<span class="sourceLineNo">323</span><a name="line.323"></a>
<span class="sourceLineNo">324</span> LOG.info(<a name="line.324"></a>
<span class="sourceLineNo">325</span> "Store={}, memstore type={}, storagePolicy={}, verifyBulkLoads={}, "<a name="line.325"></a>
<span class="sourceLineNo">326</span> + "parallelPutCountPrintThreshold={}, encoding={}, compression={}",<a name="line.326"></a>
<span class="sourceLineNo">327</span> this, memstore.getClass().getSimpleName(), policyName, verifyBulkLoads,<a name="line.327"></a>
<span class="sourceLineNo">328</span> parallelPutCountPrintThreshold, family.getDataBlockEncoding(), family.getCompressionType());<a name="line.328"></a>
<span class="sourceLineNo">329</span> }<a name="line.329"></a>
<span class="sourceLineNo">330</span><a name="line.330"></a>
<span class="sourceLineNo">331</span> private StoreContext initializeStoreContext(ColumnFamilyDescriptor family) throws IOException {<a name="line.331"></a>
<span class="sourceLineNo">332</span> return new StoreContext.Builder().withBlockSize(family.getBlocksize())<a name="line.332"></a>
<span class="sourceLineNo">333</span> .withEncryptionContext(EncryptionUtil.createEncryptionContext(conf, family))<a name="line.333"></a>
<span class="sourceLineNo">334</span> .withBloomType(family.getBloomFilterType()).withCacheConfig(createCacheConf(family))<a name="line.334"></a>
<span class="sourceLineNo">335</span> .withCellComparator(region.getTableDescriptor().isMetaTable() || conf<a name="line.335"></a>
<span class="sourceLineNo">336</span> .getBoolean(HRegion.USE_META_CELL_COMPARATOR, HRegion.DEFAULT_USE_META_CELL_COMPARATOR)<a name="line.336"></a>
<span class="sourceLineNo">337</span> ? MetaCellComparator.META_COMPARATOR<a name="line.337"></a>
<span class="sourceLineNo">338</span> : InnerStoreCellComparator.INNER_STORE_COMPARATOR)<a name="line.338"></a>
<span class="sourceLineNo">339</span> .withColumnFamilyDescriptor(family).withCompactedFilesSupplier(this::getCompactedFiles)<a name="line.339"></a>
<span class="sourceLineNo">340</span> .withRegionFileSystem(region.getRegionFileSystem())<a name="line.340"></a>
<span class="sourceLineNo">341</span> .withFavoredNodesSupplier(this::getFavoredNodes)<a name="line.341"></a>
<span class="sourceLineNo">342</span> .withFamilyStoreDirectoryPath(<a name="line.342"></a>
<span class="sourceLineNo">343</span> region.getRegionFileSystem().getStoreDir(family.getNameAsString()))<a name="line.343"></a>
<span class="sourceLineNo">344</span> .withRegionCoprocessorHost(region.getCoprocessorHost()).build();<a name="line.344"></a>
<span class="sourceLineNo">345</span> }<a name="line.345"></a>
<span class="sourceLineNo">346</span><a name="line.346"></a>
<span class="sourceLineNo">347</span> private InetSocketAddress[] getFavoredNodes() {<a name="line.347"></a>
<span class="sourceLineNo">348</span> InetSocketAddress[] favoredNodes = null;<a name="line.348"></a>
<span class="sourceLineNo">349</span> if (region.getRegionServerServices() != null) {<a name="line.349"></a>
<span class="sourceLineNo">350</span> favoredNodes = region.getRegionServerServices()<a name="line.350"></a>
<span class="sourceLineNo">351</span> .getFavoredNodesForRegion(region.getRegionInfo().getEncodedName());<a name="line.351"></a>
<span class="sourceLineNo">352</span> }<a name="line.352"></a>
<span class="sourceLineNo">353</span> return favoredNodes;<a name="line.353"></a>
<span class="sourceLineNo">354</span> }<a name="line.354"></a>
<span class="sourceLineNo">355</span><a name="line.355"></a>
<span class="sourceLineNo">356</span> /** Returns MemStore Instance to use in this store. */<a name="line.356"></a>
<span class="sourceLineNo">357</span> private MemStore getMemstore() {<a name="line.357"></a>
<span class="sourceLineNo">358</span> MemStore ms = null;<a name="line.358"></a>
<span class="sourceLineNo">359</span> // Check if in-memory-compaction configured. Note MemoryCompactionPolicy is an enum!<a name="line.359"></a>
<span class="sourceLineNo">360</span> MemoryCompactionPolicy inMemoryCompaction = null;<a name="line.360"></a>
<span class="sourceLineNo">361</span> if (this.getTableName().isSystemTable()) {<a name="line.361"></a>
<span class="sourceLineNo">362</span> inMemoryCompaction = MemoryCompactionPolicy<a name="line.362"></a>
<span class="sourceLineNo">363</span> .valueOf(conf.get("hbase.systemtables.compacting.memstore.type", "NONE"));<a name="line.363"></a>
<span class="sourceLineNo">364</span> } else {<a name="line.364"></a>
<span class="sourceLineNo">365</span> inMemoryCompaction = getColumnFamilyDescriptor().getInMemoryCompaction();<a name="line.365"></a>
<span class="sourceLineNo">366</span> }<a name="line.366"></a>
<span class="sourceLineNo">367</span> if (inMemoryCompaction == null) {<a name="line.367"></a>
<span class="sourceLineNo">368</span> inMemoryCompaction =<a name="line.368"></a>
<span class="sourceLineNo">369</span> MemoryCompactionPolicy.valueOf(conf.get(CompactingMemStore.COMPACTING_MEMSTORE_TYPE_KEY,<a name="line.369"></a>
<span class="sourceLineNo">370</span> CompactingMemStore.COMPACTING_MEMSTORE_TYPE_DEFAULT).toUpperCase());<a name="line.370"></a>
<span class="sourceLineNo">371</span> }<a name="line.371"></a>
<span class="sourceLineNo">372</span><a name="line.372"></a>
<span class="sourceLineNo">373</span> switch (inMemoryCompaction) {<a name="line.373"></a>
<span class="sourceLineNo">374</span> case NONE:<a name="line.374"></a>
<span class="sourceLineNo">375</span> Class&lt;? extends MemStore&gt; memStoreClass =<a name="line.375"></a>
<span class="sourceLineNo">376</span> conf.getClass(MEMSTORE_CLASS_NAME, DefaultMemStore.class, MemStore.class);<a name="line.376"></a>
<span class="sourceLineNo">377</span> ms = ReflectionUtils.newInstance(memStoreClass,<a name="line.377"></a>
<span class="sourceLineNo">378</span> new Object[] { conf, getComparator(), this.getHRegion().getRegionServicesForStores() });<a name="line.378"></a>
<span class="sourceLineNo">379</span> break;<a name="line.379"></a>
<span class="sourceLineNo">380</span> default:<a name="line.380"></a>
<span class="sourceLineNo">381</span> Class&lt;? extends CompactingMemStore&gt; compactingMemStoreClass =<a name="line.381"></a>
<span class="sourceLineNo">382</span> conf.getClass(MEMSTORE_CLASS_NAME, CompactingMemStore.class, CompactingMemStore.class);<a name="line.382"></a>
<span class="sourceLineNo">383</span> ms =<a name="line.383"></a>
<span class="sourceLineNo">384</span> ReflectionUtils.newInstance(compactingMemStoreClass, new Object[] { conf, getComparator(),<a name="line.384"></a>
<span class="sourceLineNo">385</span> this, this.getHRegion().getRegionServicesForStores(), inMemoryCompaction });<a name="line.385"></a>
<span class="sourceLineNo">386</span> }<a name="line.386"></a>
<span class="sourceLineNo">387</span> return ms;<a name="line.387"></a>
<span class="sourceLineNo">388</span> }<a name="line.388"></a>
<span class="sourceLineNo">389</span><a name="line.389"></a>
<span class="sourceLineNo">390</span> /**<a name="line.390"></a>
<span class="sourceLineNo">391</span> * Creates the cache config.<a name="line.391"></a>
<span class="sourceLineNo">392</span> * @param family The current column family.<a name="line.392"></a>
<span class="sourceLineNo">393</span> */<a name="line.393"></a>
<span class="sourceLineNo">394</span> protected CacheConfig createCacheConf(final ColumnFamilyDescriptor family) {<a name="line.394"></a>
<span class="sourceLineNo">395</span> CacheConfig cacheConf = new CacheConfig(conf, family, region.getBlockCache(),<a name="line.395"></a>
<span class="sourceLineNo">396</span> region.getRegionServicesForStores().getByteBuffAllocator());<a name="line.396"></a>
<span class="sourceLineNo">397</span> LOG.info("Created cacheConfig: {}, for column family {} of region {} ", cacheConf,<a name="line.397"></a>
<span class="sourceLineNo">398</span> family.getNameAsString(), region.getRegionInfo().getEncodedName());<a name="line.398"></a>
<span class="sourceLineNo">399</span> return cacheConf;<a name="line.399"></a>
<span class="sourceLineNo">400</span> }<a name="line.400"></a>
<span class="sourceLineNo">401</span><a name="line.401"></a>
<span class="sourceLineNo">402</span> /**<a name="line.402"></a>
<span class="sourceLineNo">403</span> * Creates the store engine configured for the given Store.<a name="line.403"></a>
<span class="sourceLineNo">404</span> * @param store The store. An unfortunate dependency needed due to it being passed to<a name="line.404"></a>
<span class="sourceLineNo">405</span> * coprocessors via the compactor.<a name="line.405"></a>
<span class="sourceLineNo">406</span> * @param conf Store configuration.<a name="line.406"></a>
<span class="sourceLineNo">407</span> * @param kvComparator KVComparator for storeFileManager.<a name="line.407"></a>
<span class="sourceLineNo">408</span> * @return StoreEngine to use.<a name="line.408"></a>
<span class="sourceLineNo">409</span> */<a name="line.409"></a>
<span class="sourceLineNo">410</span> protected StoreEngine&lt;?, ?, ?, ?&gt; createStoreEngine(HStore store, Configuration conf,<a name="line.410"></a>
<span class="sourceLineNo">411</span> CellComparator kvComparator) throws IOException {<a name="line.411"></a>
<span class="sourceLineNo">412</span> return StoreEngine.create(store, conf, kvComparator);<a name="line.412"></a>
<span class="sourceLineNo">413</span> }<a name="line.413"></a>
<span class="sourceLineNo">414</span><a name="line.414"></a>
<span class="sourceLineNo">415</span> /** Returns TTL in seconds of the specified family */<a name="line.415"></a>
<span class="sourceLineNo">416</span> public static long determineTTLFromFamily(final ColumnFamilyDescriptor family) {<a name="line.416"></a>
<span class="sourceLineNo">417</span> // HCD.getTimeToLive returns ttl in seconds. Convert to milliseconds.<a name="line.417"></a>
<span class="sourceLineNo">418</span> long ttl = family.getTimeToLive();<a name="line.418"></a>
<span class="sourceLineNo">419</span> if (ttl == HConstants.FOREVER) {<a name="line.419"></a>
<span class="sourceLineNo">420</span> // Default is unlimited ttl.<a name="line.420"></a>
<span class="sourceLineNo">421</span> ttl = Long.MAX_VALUE;<a name="line.421"></a>
<span class="sourceLineNo">422</span> } else if (ttl == -1) {<a name="line.422"></a>
<span class="sourceLineNo">423</span> ttl = Long.MAX_VALUE;<a name="line.423"></a>
<span class="sourceLineNo">424</span> } else {<a name="line.424"></a>
<span class="sourceLineNo">425</span> // Second -&gt; ms adjust for user data<a name="line.425"></a>
<span class="sourceLineNo">426</span> ttl *= 1000;<a name="line.426"></a>
<span class="sourceLineNo">427</span> }<a name="line.427"></a>
<span class="sourceLineNo">428</span> return ttl;<a name="line.428"></a>
<span class="sourceLineNo">429</span> }<a name="line.429"></a>
<span class="sourceLineNo">430</span><a name="line.430"></a>
<span class="sourceLineNo">431</span> StoreContext getStoreContext() {<a name="line.431"></a>
<span class="sourceLineNo">432</span> return storeContext;<a name="line.432"></a>
<span class="sourceLineNo">433</span> }<a name="line.433"></a>
<span class="sourceLineNo">434</span><a name="line.434"></a>
<span class="sourceLineNo">435</span> @Override<a name="line.435"></a>
<span class="sourceLineNo">436</span> public String getColumnFamilyName() {<a name="line.436"></a>
<span class="sourceLineNo">437</span> return this.storeContext.getFamily().getNameAsString();<a name="line.437"></a>
<span class="sourceLineNo">438</span> }<a name="line.438"></a>
<span class="sourceLineNo">439</span><a name="line.439"></a>
<span class="sourceLineNo">440</span> @Override<a name="line.440"></a>
<span class="sourceLineNo">441</span> public TableName getTableName() {<a name="line.441"></a>
<span class="sourceLineNo">442</span> return this.getRegionInfo().getTable();<a name="line.442"></a>
<span class="sourceLineNo">443</span> }<a name="line.443"></a>
<span class="sourceLineNo">444</span><a name="line.444"></a>
<span class="sourceLineNo">445</span> @Override<a name="line.445"></a>
<span class="sourceLineNo">446</span> public FileSystem getFileSystem() {<a name="line.446"></a>
<span class="sourceLineNo">447</span> return storeContext.getRegionFileSystem().getFileSystem();<a name="line.447"></a>
<span class="sourceLineNo">448</span> }<a name="line.448"></a>
<span class="sourceLineNo">449</span><a name="line.449"></a>
<span class="sourceLineNo">450</span> public HRegionFileSystem getRegionFileSystem() {<a name="line.450"></a>
<span class="sourceLineNo">451</span> return storeContext.getRegionFileSystem();<a name="line.451"></a>
<span class="sourceLineNo">452</span> }<a name="line.452"></a>
<span class="sourceLineNo">453</span><a name="line.453"></a>
<span class="sourceLineNo">454</span> /* Implementation of StoreConfigInformation */<a name="line.454"></a>
<span class="sourceLineNo">455</span> @Override<a name="line.455"></a>
<span class="sourceLineNo">456</span> public long getStoreFileTtl() {<a name="line.456"></a>
<span class="sourceLineNo">457</span> // TTL only applies if there's no MIN_VERSIONs setting on the column.<a name="line.457"></a>
<span class="sourceLineNo">458</span> return (this.scanInfo.getMinVersions() == 0) ? this.scanInfo.getTtl() : Long.MAX_VALUE;<a name="line.458"></a>
<span class="sourceLineNo">459</span> }<a name="line.459"></a>
<span class="sourceLineNo">460</span><a name="line.460"></a>
<span class="sourceLineNo">461</span> @Override<a name="line.461"></a>
<span class="sourceLineNo">462</span> public long getMemStoreFlushSize() {<a name="line.462"></a>
<span class="sourceLineNo">463</span> // TODO: Why is this in here? The flushsize of the region rather than the store? St.Ack<a name="line.463"></a>
<span class="sourceLineNo">464</span> return this.region.memstoreFlushSize;<a name="line.464"></a>
<span class="sourceLineNo">465</span> }<a name="line.465"></a>
<span class="sourceLineNo">466</span><a name="line.466"></a>
<span class="sourceLineNo">467</span> @Override<a name="line.467"></a>
<span class="sourceLineNo">468</span> public MemStoreSize getFlushableSize() {<a name="line.468"></a>
<span class="sourceLineNo">469</span> return this.memstore.getFlushableSize();<a name="line.469"></a>
<span class="sourceLineNo">470</span> }<a name="line.470"></a>
<span class="sourceLineNo">471</span><a name="line.471"></a>
<span class="sourceLineNo">472</span> @Override<a name="line.472"></a>
<span class="sourceLineNo">473</span> public MemStoreSize getSnapshotSize() {<a name="line.473"></a>
<span class="sourceLineNo">474</span> return this.memstore.getSnapshotSize();<a name="line.474"></a>
<span class="sourceLineNo">475</span> }<a name="line.475"></a>
<span class="sourceLineNo">476</span><a name="line.476"></a>
<span class="sourceLineNo">477</span> @Override<a name="line.477"></a>
<span class="sourceLineNo">478</span> public long getCompactionCheckMultiplier() {<a name="line.478"></a>
<span class="sourceLineNo">479</span> return this.compactionCheckMultiplier;<a name="line.479"></a>
<span class="sourceLineNo">480</span> }<a name="line.480"></a>
<span class="sourceLineNo">481</span><a name="line.481"></a>
<span class="sourceLineNo">482</span> @Override<a name="line.482"></a>
<span class="sourceLineNo">483</span> public long getBlockingFileCount() {<a name="line.483"></a>
<span class="sourceLineNo">484</span> return blockingFileCount;<a name="line.484"></a>
<span class="sourceLineNo">485</span> }<a name="line.485"></a>
<span class="sourceLineNo">486</span> /* End implementation of StoreConfigInformation */<a name="line.486"></a>
<span class="sourceLineNo">487</span><a name="line.487"></a>
<span class="sourceLineNo">488</span> @Override<a name="line.488"></a>
<span class="sourceLineNo">489</span> public ColumnFamilyDescriptor getColumnFamilyDescriptor() {<a name="line.489"></a>
<span class="sourceLineNo">490</span> return this.storeContext.getFamily();<a name="line.490"></a>
<span class="sourceLineNo">491</span> }<a name="line.491"></a>
<span class="sourceLineNo">492</span><a name="line.492"></a>
<span class="sourceLineNo">493</span> @Override<a name="line.493"></a>
<span class="sourceLineNo">494</span> public OptionalLong getMaxSequenceId() {<a name="line.494"></a>
<span class="sourceLineNo">495</span> return StoreUtils.getMaxSequenceIdInList(this.getStorefiles());<a name="line.495"></a>
<span class="sourceLineNo">496</span> }<a name="line.496"></a>
<span class="sourceLineNo">497</span><a name="line.497"></a>
<span class="sourceLineNo">498</span> @Override<a name="line.498"></a>
<span class="sourceLineNo">499</span> public OptionalLong getMaxMemStoreTS() {<a name="line.499"></a>
<span class="sourceLineNo">500</span> return StoreUtils.getMaxMemStoreTSInList(this.getStorefiles());<a name="line.500"></a>
<span class="sourceLineNo">501</span> }<a name="line.501"></a>
<span class="sourceLineNo">502</span><a name="line.502"></a>
<span class="sourceLineNo">503</span> /** Returns the data block encoder */<a name="line.503"></a>
<span class="sourceLineNo">504</span> public HFileDataBlockEncoder getDataBlockEncoder() {<a name="line.504"></a>
<span class="sourceLineNo">505</span> return dataBlockEncoder;<a name="line.505"></a>
<span class="sourceLineNo">506</span> }<a name="line.506"></a>
<span class="sourceLineNo">507</span><a name="line.507"></a>
<span class="sourceLineNo">508</span> /**<a name="line.508"></a>
<span class="sourceLineNo">509</span> * Should be used only in tests.<a name="line.509"></a>
<span class="sourceLineNo">510</span> * @param blockEncoder the block delta encoder to use<a name="line.510"></a>
<span class="sourceLineNo">511</span> */<a name="line.511"></a>
<span class="sourceLineNo">512</span> void setDataBlockEncoderInTest(HFileDataBlockEncoder blockEncoder) {<a name="line.512"></a>
<span class="sourceLineNo">513</span> this.dataBlockEncoder = blockEncoder;<a name="line.513"></a>
<span class="sourceLineNo">514</span> }<a name="line.514"></a>
<span class="sourceLineNo">515</span><a name="line.515"></a>
<span class="sourceLineNo">516</span> private void postRefreshStoreFiles() throws IOException {<a name="line.516"></a>
<span class="sourceLineNo">517</span> // Advance the memstore read point to be at least the new store files seqIds so that<a name="line.517"></a>
<span class="sourceLineNo">518</span> // readers might pick it up. This assumes that the store is not getting any writes (otherwise<a name="line.518"></a>
<span class="sourceLineNo">519</span> // in-flight transactions might be made visible)<a name="line.519"></a>
<span class="sourceLineNo">520</span> getMaxSequenceId().ifPresent(region.getMVCC()::advanceTo);<a name="line.520"></a>
<span class="sourceLineNo">521</span> refreshStoreSizeAndTotalBytes();<a name="line.521"></a>
<span class="sourceLineNo">522</span> }<a name="line.522"></a>
<span class="sourceLineNo">523</span><a name="line.523"></a>
<span class="sourceLineNo">524</span> @Override<a name="line.524"></a>
<span class="sourceLineNo">525</span> public void refreshStoreFiles() throws IOException {<a name="line.525"></a>
<span class="sourceLineNo">526</span> storeEngine.refreshStoreFiles();<a name="line.526"></a>
<span class="sourceLineNo">527</span> postRefreshStoreFiles();<a name="line.527"></a>
<span class="sourceLineNo">528</span> }<a name="line.528"></a>
<span class="sourceLineNo">529</span><a name="line.529"></a>
<span class="sourceLineNo">530</span> /**<a name="line.530"></a>
<span class="sourceLineNo">531</span> * Replaces the store files that the store has with the given files. Mainly used by secondary<a name="line.531"></a>
<span class="sourceLineNo">532</span> * region replicas to keep up to date with the primary region files.<a name="line.532"></a>
<span class="sourceLineNo">533</span> */<a name="line.533"></a>
<span class="sourceLineNo">534</span> public void refreshStoreFiles(Collection&lt;String&gt; newFiles) throws IOException {<a name="line.534"></a>
<span class="sourceLineNo">535</span> storeEngine.refreshStoreFiles(newFiles);<a name="line.535"></a>
<span class="sourceLineNo">536</span> postRefreshStoreFiles();<a name="line.536"></a>
<span class="sourceLineNo">537</span> }<a name="line.537"></a>
<span class="sourceLineNo">538</span><a name="line.538"></a>
<span class="sourceLineNo">539</span> /**<a name="line.539"></a>
<span class="sourceLineNo">540</span> * This message intends to inform the MemStore that next coming updates are going to be part of<a name="line.540"></a>
<span class="sourceLineNo">541</span> * the replaying edits from WAL<a name="line.541"></a>
<span class="sourceLineNo">542</span> */<a name="line.542"></a>
<span class="sourceLineNo">543</span> public void startReplayingFromWAL() {<a name="line.543"></a>
<span class="sourceLineNo">544</span> this.memstore.startReplayingFromWAL();<a name="line.544"></a>
<span class="sourceLineNo">545</span> }<a name="line.545"></a>
<span class="sourceLineNo">546</span><a name="line.546"></a>
<span class="sourceLineNo">547</span> /**<a name="line.547"></a>
<span class="sourceLineNo">548</span> * This message intends to inform the MemStore that the replaying edits from WAL are done<a name="line.548"></a>
<span class="sourceLineNo">549</span> */<a name="line.549"></a>
<span class="sourceLineNo">550</span> public void stopReplayingFromWAL() {<a name="line.550"></a>
<span class="sourceLineNo">551</span> this.memstore.stopReplayingFromWAL();<a name="line.551"></a>
<span class="sourceLineNo">552</span> }<a name="line.552"></a>
<span class="sourceLineNo">553</span><a name="line.553"></a>
<span class="sourceLineNo">554</span> /**<a name="line.554"></a>
<span class="sourceLineNo">555</span> * Adds a value to the memstore<a name="line.555"></a>
<span class="sourceLineNo">556</span> */<a name="line.556"></a>
<span class="sourceLineNo">557</span> public void add(final Cell cell, MemStoreSizing memstoreSizing) {<a name="line.557"></a>
<span class="sourceLineNo">558</span> storeEngine.readLock();<a name="line.558"></a>
<span class="sourceLineNo">559</span> try {<a name="line.559"></a>
<span class="sourceLineNo">560</span> if (this.currentParallelPutCount.getAndIncrement() &gt; this.parallelPutCountPrintThreshold) {<a name="line.560"></a>
<span class="sourceLineNo">561</span> LOG.trace("tableName={}, encodedName={}, columnFamilyName={} is too busy!",<a name="line.561"></a>
<span class="sourceLineNo">562</span> this.getTableName(), this.getRegionInfo().getEncodedName(), this.getColumnFamilyName());<a name="line.562"></a>
<span class="sourceLineNo">563</span> }<a name="line.563"></a>
<span class="sourceLineNo">564</span> this.memstore.add(cell, memstoreSizing);<a name="line.564"></a>
<span class="sourceLineNo">565</span> } finally {<a name="line.565"></a>
<span class="sourceLineNo">566</span> storeEngine.readUnlock();<a name="line.566"></a>
<span class="sourceLineNo">567</span> currentParallelPutCount.decrementAndGet();<a name="line.567"></a>
<span class="sourceLineNo">568</span> }<a name="line.568"></a>
<span class="sourceLineNo">569</span> }<a name="line.569"></a>
<span class="sourceLineNo">570</span><a name="line.570"></a>
<span class="sourceLineNo">571</span> /**<a name="line.571"></a>
<span class="sourceLineNo">572</span> * Adds the specified value to the memstore<a name="line.572"></a>
<span class="sourceLineNo">573</span> */<a name="line.573"></a>
<span class="sourceLineNo">574</span> public void add(final Iterable&lt;Cell&gt; cells, MemStoreSizing memstoreSizing) {<a name="line.574"></a>
<span class="sourceLineNo">575</span> storeEngine.readLock();<a name="line.575"></a>
<span class="sourceLineNo">576</span> try {<a name="line.576"></a>
<span class="sourceLineNo">577</span> if (this.currentParallelPutCount.getAndIncrement() &gt; this.parallelPutCountPrintThreshold) {<a name="line.577"></a>
<span class="sourceLineNo">578</span> LOG.trace("tableName={}, encodedName={}, columnFamilyName={} is too busy!",<a name="line.578"></a>
<span class="sourceLineNo">579</span> this.getTableName(), this.getRegionInfo().getEncodedName(), this.getColumnFamilyName());<a name="line.579"></a>
<span class="sourceLineNo">580</span> }<a name="line.580"></a>
<span class="sourceLineNo">581</span> memstore.add(cells, memstoreSizing);<a name="line.581"></a>
<span class="sourceLineNo">582</span> } finally {<a name="line.582"></a>
<span class="sourceLineNo">583</span> storeEngine.readUnlock();<a name="line.583"></a>
<span class="sourceLineNo">584</span> currentParallelPutCount.decrementAndGet();<a name="line.584"></a>
<span class="sourceLineNo">585</span> }<a name="line.585"></a>
<span class="sourceLineNo">586</span> }<a name="line.586"></a>
<span class="sourceLineNo">587</span><a name="line.587"></a>
<span class="sourceLineNo">588</span> @Override<a name="line.588"></a>
<span class="sourceLineNo">589</span> public long timeOfOldestEdit() {<a name="line.589"></a>
<span class="sourceLineNo">590</span> return memstore.timeOfOldestEdit();<a name="line.590"></a>
<span class="sourceLineNo">591</span> }<a name="line.591"></a>
<span class="sourceLineNo">592</span><a name="line.592"></a>
<span class="sourceLineNo">593</span> /** Returns All store files. */<a name="line.593"></a>
<span class="sourceLineNo">594</span> @Override<a name="line.594"></a>
<span class="sourceLineNo">595</span> public Collection&lt;HStoreFile&gt; getStorefiles() {<a name="line.595"></a>
<span class="sourceLineNo">596</span> return this.storeEngine.getStoreFileManager().getStoreFiles();<a name="line.596"></a>
<span class="sourceLineNo">597</span> }<a name="line.597"></a>
<span class="sourceLineNo">598</span><a name="line.598"></a>
<span class="sourceLineNo">599</span> @Override<a name="line.599"></a>
<span class="sourceLineNo">600</span> public Collection&lt;HStoreFile&gt; getCompactedFiles() {<a name="line.600"></a>
<span class="sourceLineNo">601</span> return this.storeEngine.getStoreFileManager().getCompactedfiles();<a name="line.601"></a>
<span class="sourceLineNo">602</span> }<a name="line.602"></a>
<span class="sourceLineNo">603</span><a name="line.603"></a>
<span class="sourceLineNo">604</span> /**<a name="line.604"></a>
<span class="sourceLineNo">605</span> * This throws a WrongRegionException if the HFile does not fit in this region, or an<a name="line.605"></a>
<span class="sourceLineNo">606</span> * InvalidHFileException if the HFile is not valid.<a name="line.606"></a>
<span class="sourceLineNo">607</span> */<a name="line.607"></a>
<span class="sourceLineNo">608</span> public void assertBulkLoadHFileOk(Path srcPath) throws IOException {<a name="line.608"></a>
<span class="sourceLineNo">609</span> HFile.Reader reader = null;<a name="line.609"></a>
<span class="sourceLineNo">610</span> try {<a name="line.610"></a>
<span class="sourceLineNo">611</span> LOG.info("Validating hfile at " + srcPath + " for inclusion in " + this);<a name="line.611"></a>
<span class="sourceLineNo">612</span> FileSystem srcFs = srcPath.getFileSystem(conf);<a name="line.612"></a>
<span class="sourceLineNo">613</span> srcFs.access(srcPath, FsAction.READ_WRITE);<a name="line.613"></a>
<span class="sourceLineNo">614</span> reader = HFile.createReader(srcFs, srcPath, getCacheConfig(), isPrimaryReplicaStore(), conf);<a name="line.614"></a>
<span class="sourceLineNo">615</span><a name="line.615"></a>
<span class="sourceLineNo">616</span> Optional&lt;byte[]&gt; firstKey = reader.getFirstRowKey();<a name="line.616"></a>
<span class="sourceLineNo">617</span> Preconditions.checkState(firstKey.isPresent(), "First key can not be null");<a name="line.617"></a>
<span class="sourceLineNo">618</span> Optional&lt;Cell&gt; lk = reader.getLastKey();<a name="line.618"></a>
<span class="sourceLineNo">619</span> Preconditions.checkState(lk.isPresent(), "Last key can not be null");<a name="line.619"></a>
<span class="sourceLineNo">620</span> byte[] lastKey = CellUtil.cloneRow(lk.get());<a name="line.620"></a>
<span class="sourceLineNo">621</span><a name="line.621"></a>
<span class="sourceLineNo">622</span> if (LOG.isDebugEnabled()) {<a name="line.622"></a>
<span class="sourceLineNo">623</span> LOG.debug("HFile bounds: first=" + Bytes.toStringBinary(firstKey.get()) + " last="<a name="line.623"></a>
<span class="sourceLineNo">624</span> + Bytes.toStringBinary(lastKey));<a name="line.624"></a>
<span class="sourceLineNo">625</span> LOG.debug("Region bounds: first=" + Bytes.toStringBinary(getRegionInfo().getStartKey())<a name="line.625"></a>
<span class="sourceLineNo">626</span> + " last=" + Bytes.toStringBinary(getRegionInfo().getEndKey()));<a name="line.626"></a>
<span class="sourceLineNo">627</span> }<a name="line.627"></a>
<span class="sourceLineNo">628</span><a name="line.628"></a>
<span class="sourceLineNo">629</span> if (!this.getRegionInfo().containsRange(firstKey.get(), lastKey)) {<a name="line.629"></a>
<span class="sourceLineNo">630</span> throw new WrongRegionException("Bulk load file " + srcPath.toString()<a name="line.630"></a>
<span class="sourceLineNo">631</span> + " does not fit inside region " + this.getRegionInfo().getRegionNameAsString());<a name="line.631"></a>
<span class="sourceLineNo">632</span> }<a name="line.632"></a>
<span class="sourceLineNo">633</span><a name="line.633"></a>
<span class="sourceLineNo">634</span> if (<a name="line.634"></a>
<span class="sourceLineNo">635</span> reader.length()<a name="line.635"></a>
<span class="sourceLineNo">636</span> &gt; conf.getLong(HConstants.HREGION_MAX_FILESIZE, HConstants.DEFAULT_MAX_FILE_SIZE)<a name="line.636"></a>
<span class="sourceLineNo">637</span> ) {<a name="line.637"></a>
<span class="sourceLineNo">638</span> LOG.warn("Trying to bulk load hfile " + srcPath + " with size: " + reader.length()<a name="line.638"></a>
<span class="sourceLineNo">639</span> + " bytes can be problematic as it may lead to oversplitting.");<a name="line.639"></a>
<span class="sourceLineNo">640</span> }<a name="line.640"></a>
<span class="sourceLineNo">641</span><a name="line.641"></a>
<span class="sourceLineNo">642</span> if (verifyBulkLoads) {<a name="line.642"></a>
<span class="sourceLineNo">643</span> long verificationStartTime = EnvironmentEdgeManager.currentTime();<a name="line.643"></a>
<span class="sourceLineNo">644</span> LOG.info("Full verification started for bulk load hfile: {}", srcPath);<a name="line.644"></a>
<span class="sourceLineNo">645</span> Cell prevCell = null;<a name="line.645"></a>
<span class="sourceLineNo">646</span> HFileScanner scanner = reader.getScanner(conf, false, false, false);<a name="line.646"></a>
<span class="sourceLineNo">647</span> scanner.seekTo();<a name="line.647"></a>
<span class="sourceLineNo">648</span> do {<a name="line.648"></a>
<span class="sourceLineNo">649</span> Cell cell = scanner.getCell();<a name="line.649"></a>
<span class="sourceLineNo">650</span> if (prevCell != null) {<a name="line.650"></a>
<span class="sourceLineNo">651</span> if (getComparator().compareRows(prevCell, cell) &gt; 0) {<a name="line.651"></a>
<span class="sourceLineNo">652</span> throw new InvalidHFileException("Previous row is greater than" + " current row: path="<a name="line.652"></a>
<span class="sourceLineNo">653</span> + srcPath + " previous=" + CellUtil.getCellKeyAsString(prevCell) + " current="<a name="line.653"></a>
<span class="sourceLineNo">654</span> + CellUtil.getCellKeyAsString(cell));<a name="line.654"></a>
<span class="sourceLineNo">655</span> }<a name="line.655"></a>
<span class="sourceLineNo">656</span> if (CellComparator.getInstance().compareFamilies(prevCell, cell) != 0) {<a name="line.656"></a>
<span class="sourceLineNo">657</span> throw new InvalidHFileException("Previous key had different"<a name="line.657"></a>
<span class="sourceLineNo">658</span> + " family compared to current key: path=" + srcPath + " previous="<a name="line.658"></a>
<span class="sourceLineNo">659</span> + Bytes.toStringBinary(prevCell.getFamilyArray(), prevCell.getFamilyOffset(),<a name="line.659"></a>
<span class="sourceLineNo">660</span> prevCell.getFamilyLength())<a name="line.660"></a>
<span class="sourceLineNo">661</span> + " current=" + Bytes.toStringBinary(cell.getFamilyArray(), cell.getFamilyOffset(),<a name="line.661"></a>
<span class="sourceLineNo">662</span> cell.getFamilyLength()));<a name="line.662"></a>
<span class="sourceLineNo">663</span> }<a name="line.663"></a>
<span class="sourceLineNo">664</span> }<a name="line.664"></a>
<span class="sourceLineNo">665</span> prevCell = cell;<a name="line.665"></a>
<span class="sourceLineNo">666</span> } while (scanner.next());<a name="line.666"></a>
<span class="sourceLineNo">667</span> LOG.info("Full verification complete for bulk load hfile: " + srcPath.toString() + " took "<a name="line.667"></a>
<span class="sourceLineNo">668</span> + (EnvironmentEdgeManager.currentTime() - verificationStartTime) + " ms");<a name="line.668"></a>
<span class="sourceLineNo">669</span> }<a name="line.669"></a>
<span class="sourceLineNo">670</span> } finally {<a name="line.670"></a>
<span class="sourceLineNo">671</span> if (reader != null) {<a name="line.671"></a>
<span class="sourceLineNo">672</span> reader.close();<a name="line.672"></a>
<span class="sourceLineNo">673</span> }<a name="line.673"></a>
<span class="sourceLineNo">674</span> }<a name="line.674"></a>
<span class="sourceLineNo">675</span> }<a name="line.675"></a>
<span class="sourceLineNo">676</span><a name="line.676"></a>
<span class="sourceLineNo">677</span> /**<a name="line.677"></a>
<span class="sourceLineNo">678</span> * This method should only be called from Region. It is assumed that the ranges of values in the<a name="line.678"></a>
<span class="sourceLineNo">679</span> * HFile fit within the stores assigned region. (assertBulkLoadHFileOk checks this)<a name="line.679"></a>
<span class="sourceLineNo">680</span> * @param seqNum sequence Id associated with the HFile<a name="line.680"></a>
<span class="sourceLineNo">681</span> */<a name="line.681"></a>
<span class="sourceLineNo">682</span> public Pair&lt;Path, Path&gt; preBulkLoadHFile(String srcPathStr, long seqNum) throws IOException {<a name="line.682"></a>
<span class="sourceLineNo">683</span> Path srcPath = new Path(srcPathStr);<a name="line.683"></a>
<span class="sourceLineNo">684</span> return getRegionFileSystem().bulkLoadStoreFile(getColumnFamilyName(), srcPath, seqNum);<a name="line.684"></a>
<span class="sourceLineNo">685</span> }<a name="line.685"></a>
<span class="sourceLineNo">686</span><a name="line.686"></a>
<span class="sourceLineNo">687</span> public Path bulkLoadHFile(byte[] family, String srcPathStr, Path dstPath) throws IOException {<a name="line.687"></a>
<span class="sourceLineNo">688</span> Path srcPath = new Path(srcPathStr);<a name="line.688"></a>
<span class="sourceLineNo">689</span> try {<a name="line.689"></a>
<span class="sourceLineNo">690</span> getRegionFileSystem().commitStoreFile(srcPath, dstPath);<a name="line.690"></a>
<span class="sourceLineNo">691</span> } finally {<a name="line.691"></a>
<span class="sourceLineNo">692</span> if (this.getCoprocessorHost() != null) {<a name="line.692"></a>
<span class="sourceLineNo">693</span> this.getCoprocessorHost().postCommitStoreFile(family, srcPath, dstPath);<a name="line.693"></a>
<span class="sourceLineNo">694</span> }<a name="line.694"></a>
<span class="sourceLineNo">695</span> }<a name="line.695"></a>
<span class="sourceLineNo">696</span><a name="line.696"></a>
<span class="sourceLineNo">697</span> LOG.info("Loaded HFile " + srcPath + " into " + this + " as " + dstPath<a name="line.697"></a>
<span class="sourceLineNo">698</span> + " - updating store file list.");<a name="line.698"></a>
<span class="sourceLineNo">699</span><a name="line.699"></a>
<span class="sourceLineNo">700</span> HStoreFile sf = storeEngine.createStoreFileAndReader(dstPath);<a name="line.700"></a>
<span class="sourceLineNo">701</span> bulkLoadHFile(sf);<a name="line.701"></a>
<span class="sourceLineNo">702</span><a name="line.702"></a>
<span class="sourceLineNo">703</span> LOG.info("Successfully loaded {} into {} (new location: {})", srcPath, this, dstPath);<a name="line.703"></a>
<span class="sourceLineNo">704</span><a name="line.704"></a>
<span class="sourceLineNo">705</span> return dstPath;<a name="line.705"></a>
<span class="sourceLineNo">706</span> }<a name="line.706"></a>
<span class="sourceLineNo">707</span><a name="line.707"></a>
<span class="sourceLineNo">708</span> public void bulkLoadHFile(StoreFileInfo fileInfo) throws IOException {<a name="line.708"></a>
<span class="sourceLineNo">709</span> HStoreFile sf = storeEngine.createStoreFileAndReader(fileInfo);<a name="line.709"></a>
<span class="sourceLineNo">710</span> bulkLoadHFile(sf);<a name="line.710"></a>
<span class="sourceLineNo">711</span> }<a name="line.711"></a>
<span class="sourceLineNo">712</span><a name="line.712"></a>
<span class="sourceLineNo">713</span> private void bulkLoadHFile(HStoreFile sf) throws IOException {<a name="line.713"></a>
<span class="sourceLineNo">714</span> StoreFileReader r = sf.getReader();<a name="line.714"></a>
<span class="sourceLineNo">715</span> this.storeSize.addAndGet(r.length());<a name="line.715"></a>
<span class="sourceLineNo">716</span> this.totalUncompressedBytes.addAndGet(r.getTotalUncompressedBytes());<a name="line.716"></a>
<span class="sourceLineNo">717</span> storeEngine.addStoreFiles(Lists.newArrayList(sf), () -&gt; {<a name="line.717"></a>
<span class="sourceLineNo">718</span> });<a name="line.718"></a>
<span class="sourceLineNo">719</span> LOG.info("Loaded HFile " + sf.getFileInfo() + " into " + this);<a name="line.719"></a>
<span class="sourceLineNo">720</span> if (LOG.isTraceEnabled()) {<a name="line.720"></a>
<span class="sourceLineNo">721</span> String traceMessage = "BULK LOAD time,size,store size,store files ["<a name="line.721"></a>
<span class="sourceLineNo">722</span> + EnvironmentEdgeManager.currentTime() + "," + r.length() + "," + storeSize + ","<a name="line.722"></a>
<span class="sourceLineNo">723</span> + storeEngine.getStoreFileManager().getStorefileCount() + "]";<a name="line.723"></a>
<span class="sourceLineNo">724</span> LOG.trace(traceMessage);<a name="line.724"></a>
<span class="sourceLineNo">725</span> }<a name="line.725"></a>
<span class="sourceLineNo">726</span> }<a name="line.726"></a>
<span class="sourceLineNo">727</span><a name="line.727"></a>
<span class="sourceLineNo">728</span> private ImmutableCollection&lt;HStoreFile&gt; closeWithoutLock() throws IOException {<a name="line.728"></a>
<span class="sourceLineNo">729</span> memstore.close();<a name="line.729"></a>
<span class="sourceLineNo">730</span> // Clear so metrics doesn't find them.<a name="line.730"></a>
<span class="sourceLineNo">731</span> ImmutableCollection&lt;HStoreFile&gt; result = storeEngine.getStoreFileManager().clearFiles();<a name="line.731"></a>
<span class="sourceLineNo">732</span> Collection&lt;HStoreFile&gt; compactedfiles = storeEngine.getStoreFileManager().clearCompactedFiles();<a name="line.732"></a>
<span class="sourceLineNo">733</span> // clear the compacted files<a name="line.733"></a>
<span class="sourceLineNo">734</span> if (CollectionUtils.isNotEmpty(compactedfiles)) {<a name="line.734"></a>
<span class="sourceLineNo">735</span> removeCompactedfiles(compactedfiles,<a name="line.735"></a>
<span class="sourceLineNo">736</span> getCacheConfig() != null ? getCacheConfig().shouldEvictOnClose() : true);<a name="line.736"></a>
<span class="sourceLineNo">737</span> }<a name="line.737"></a>
<span class="sourceLineNo">738</span> if (!result.isEmpty()) {<a name="line.738"></a>
<span class="sourceLineNo">739</span> // initialize the thread pool for closing store files in parallel.<a name="line.739"></a>
<span class="sourceLineNo">740</span> ThreadPoolExecutor storeFileCloserThreadPool =<a name="line.740"></a>
<span class="sourceLineNo">741</span> this.region.getStoreFileOpenAndCloseThreadPool("StoreFileCloser-"<a name="line.741"></a>
<span class="sourceLineNo">742</span> + this.region.getRegionInfo().getEncodedName() + "-" + this.getColumnFamilyName());<a name="line.742"></a>
<span class="sourceLineNo">743</span><a name="line.743"></a>
<span class="sourceLineNo">744</span> // close each store file in parallel<a name="line.744"></a>
<span class="sourceLineNo">745</span> CompletionService&lt;Void&gt; completionService =<a name="line.745"></a>
<span class="sourceLineNo">746</span> new ExecutorCompletionService&lt;&gt;(storeFileCloserThreadPool);<a name="line.746"></a>
<span class="sourceLineNo">747</span> for (HStoreFile f : result) {<a name="line.747"></a>
<span class="sourceLineNo">748</span> completionService.submit(new Callable&lt;Void&gt;() {<a name="line.748"></a>
<span class="sourceLineNo">749</span> @Override<a name="line.749"></a>
<span class="sourceLineNo">750</span> public Void call() throws IOException {<a name="line.750"></a>
<span class="sourceLineNo">751</span> boolean evictOnClose =<a name="line.751"></a>
<span class="sourceLineNo">752</span> getCacheConfig() != null ? getCacheConfig().shouldEvictOnClose() : true;<a name="line.752"></a>
<span class="sourceLineNo">753</span> f.closeStoreFile(!warmup &amp;&amp; evictOnClose);<a name="line.753"></a>
<span class="sourceLineNo">754</span> return null;<a name="line.754"></a>
<span class="sourceLineNo">755</span> }<a name="line.755"></a>
<span class="sourceLineNo">756</span> });<a name="line.756"></a>
<span class="sourceLineNo">757</span> }<a name="line.757"></a>
<span class="sourceLineNo">758</span><a name="line.758"></a>
<span class="sourceLineNo">759</span> IOException ioe = null;<a name="line.759"></a>
<span class="sourceLineNo">760</span> try {<a name="line.760"></a>
<span class="sourceLineNo">761</span> for (int i = 0; i &lt; result.size(); i++) {<a name="line.761"></a>
<span class="sourceLineNo">762</span> try {<a name="line.762"></a>
<span class="sourceLineNo">763</span> Future&lt;Void&gt; future = completionService.take();<a name="line.763"></a>
<span class="sourceLineNo">764</span> future.get();<a name="line.764"></a>
<span class="sourceLineNo">765</span> } catch (InterruptedException e) {<a name="line.765"></a>
<span class="sourceLineNo">766</span> if (ioe == null) {<a name="line.766"></a>
<span class="sourceLineNo">767</span> ioe = new InterruptedIOException();<a name="line.767"></a>
<span class="sourceLineNo">768</span> ioe.initCause(e);<a name="line.768"></a>
<span class="sourceLineNo">769</span> }<a name="line.769"></a>
<span class="sourceLineNo">770</span> } catch (ExecutionException e) {<a name="line.770"></a>
<span class="sourceLineNo">771</span> if (ioe == null) {<a name="line.771"></a>
<span class="sourceLineNo">772</span> ioe = new IOException(e.getCause());<a name="line.772"></a>
<span class="sourceLineNo">773</span> }<a name="line.773"></a>
<span class="sourceLineNo">774</span> }<a name="line.774"></a>
<span class="sourceLineNo">775</span> }<a name="line.775"></a>
<span class="sourceLineNo">776</span> } finally {<a name="line.776"></a>
<span class="sourceLineNo">777</span> storeFileCloserThreadPool.shutdownNow();<a name="line.777"></a>
<span class="sourceLineNo">778</span> }<a name="line.778"></a>
<span class="sourceLineNo">779</span> if (ioe != null) {<a name="line.779"></a>
<span class="sourceLineNo">780</span> throw ioe;<a name="line.780"></a>
<span class="sourceLineNo">781</span> }<a name="line.781"></a>
<span class="sourceLineNo">782</span> }<a name="line.782"></a>
<span class="sourceLineNo">783</span> LOG.trace("Closed {}", this);<a name="line.783"></a>
<span class="sourceLineNo">784</span> return result;<a name="line.784"></a>
<span class="sourceLineNo">785</span> }<a name="line.785"></a>
<span class="sourceLineNo">786</span><a name="line.786"></a>
<span class="sourceLineNo">787</span> /**<a name="line.787"></a>
<span class="sourceLineNo">788</span> * Close all the readers We don't need to worry about subsequent requests because the Region holds<a name="line.788"></a>
<span class="sourceLineNo">789</span> * a write lock that will prevent any more reads or writes.<a name="line.789"></a>
<span class="sourceLineNo">790</span> * @return the {@link StoreFile StoreFiles} that were previously being used.<a name="line.790"></a>
<span class="sourceLineNo">791</span> * @throws IOException on failure<a name="line.791"></a>
<span class="sourceLineNo">792</span> */<a name="line.792"></a>
<span class="sourceLineNo">793</span> public ImmutableCollection&lt;HStoreFile&gt; close() throws IOException {<a name="line.793"></a>
<span class="sourceLineNo">794</span> // findbugs can not recognize storeEngine.writeLock is just a lock operation so it will report<a name="line.794"></a>
<span class="sourceLineNo">795</span> // UL_UNRELEASED_LOCK_EXCEPTION_PATH, so here we have to use two try finally...<a name="line.795"></a>
<span class="sourceLineNo">796</span> // Change later if findbugs becomes smarter in the future.<a name="line.796"></a>
<span class="sourceLineNo">797</span> this.archiveLock.lock();<a name="line.797"></a>
<span class="sourceLineNo">798</span> try {<a name="line.798"></a>
<span class="sourceLineNo">799</span> this.storeEngine.writeLock();<a name="line.799"></a>
<span class="sourceLineNo">800</span> try {<a name="line.800"></a>
<span class="sourceLineNo">801</span> return closeWithoutLock();<a name="line.801"></a>
<span class="sourceLineNo">802</span> } finally {<a name="line.802"></a>
<span class="sourceLineNo">803</span> this.storeEngine.writeUnlock();<a name="line.803"></a>
<span class="sourceLineNo">804</span> }<a name="line.804"></a>
<span class="sourceLineNo">805</span> } finally {<a name="line.805"></a>
<span class="sourceLineNo">806</span> this.archiveLock.unlock();<a name="line.806"></a>
<span class="sourceLineNo">807</span> }<a name="line.807"></a>
<span class="sourceLineNo">808</span> }<a name="line.808"></a>
<span class="sourceLineNo">809</span><a name="line.809"></a>
<span class="sourceLineNo">810</span> /**<a name="line.810"></a>
<span class="sourceLineNo">811</span> * Write out current snapshot. Presumes {@code StoreFlusherImpl.prepare()} has been called<a name="line.811"></a>
<span class="sourceLineNo">812</span> * previously.<a name="line.812"></a>
<span class="sourceLineNo">813</span> * @param logCacheFlushId flush sequence number<a name="line.813"></a>
<span class="sourceLineNo">814</span> * @return The path name of the tmp file to which the store was flushed<a name="line.814"></a>
<span class="sourceLineNo">815</span> * @throws IOException if exception occurs during process<a name="line.815"></a>
<span class="sourceLineNo">816</span> */<a name="line.816"></a>
<span class="sourceLineNo">817</span> protected List&lt;Path&gt; flushCache(final long logCacheFlushId, MemStoreSnapshot snapshot,<a name="line.817"></a>
<span class="sourceLineNo">818</span> MonitoredTask status, ThroughputController throughputController, FlushLifeCycleTracker tracker,<a name="line.818"></a>
<span class="sourceLineNo">819</span> Consumer&lt;Path&gt; writerCreationTracker) throws IOException {<a name="line.819"></a>
<span class="sourceLineNo">820</span> // If an exception happens flushing, we let it out without clearing<a name="line.820"></a>
<span class="sourceLineNo">821</span> // the memstore snapshot. The old snapshot will be returned when we say<a name="line.821"></a>
<span class="sourceLineNo">822</span> // 'snapshot', the next time flush comes around.<a name="line.822"></a>
<span class="sourceLineNo">823</span> // Retry after catching exception when flushing, otherwise server will abort<a name="line.823"></a>
<span class="sourceLineNo">824</span> // itself<a name="line.824"></a>
<span class="sourceLineNo">825</span> StoreFlusher flusher = storeEngine.getStoreFlusher();<a name="line.825"></a>
<span class="sourceLineNo">826</span> IOException lastException = null;<a name="line.826"></a>
<span class="sourceLineNo">827</span> for (int i = 0; i &lt; flushRetriesNumber; i++) {<a name="line.827"></a>
<span class="sourceLineNo">828</span> try {<a name="line.828"></a>
<span class="sourceLineNo">829</span> List&lt;Path&gt; pathNames = flusher.flushSnapshot(snapshot, logCacheFlushId, status,<a name="line.829"></a>
<span class="sourceLineNo">830</span> throughputController, tracker, writerCreationTracker);<a name="line.830"></a>
<span class="sourceLineNo">831</span> Path lastPathName = null;<a name="line.831"></a>
<span class="sourceLineNo">832</span> try {<a name="line.832"></a>
<span class="sourceLineNo">833</span> for (Path pathName : pathNames) {<a name="line.833"></a>
<span class="sourceLineNo">834</span> lastPathName = pathName;<a name="line.834"></a>
<span class="sourceLineNo">835</span> storeEngine.validateStoreFile(pathName);<a name="line.835"></a>
<span class="sourceLineNo">836</span> }<a name="line.836"></a>
<span class="sourceLineNo">837</span> return pathNames;<a name="line.837"></a>
<span class="sourceLineNo">838</span> } catch (Exception e) {<a name="line.838"></a>
<span class="sourceLineNo">839</span> LOG.warn("Failed validating store file {}, retrying num={}", lastPathName, i, e);<a name="line.839"></a>
<span class="sourceLineNo">840</span> if (e instanceof IOException) {<a name="line.840"></a>
<span class="sourceLineNo">841</span> lastException = (IOException) e;<a name="line.841"></a>
<span class="sourceLineNo">842</span> } else {<a name="line.842"></a>
<span class="sourceLineNo">843</span> lastException = new IOException(e);<a name="line.843"></a>
<span class="sourceLineNo">844</span> }<a name="line.844"></a>
<span class="sourceLineNo">845</span> }<a name="line.845"></a>
<span class="sourceLineNo">846</span> } catch (IOException e) {<a name="line.846"></a>
<span class="sourceLineNo">847</span> LOG.warn("Failed flushing store file for {}, retrying num={}", this, i, e);<a name="line.847"></a>
<span class="sourceLineNo">848</span> lastException = e;<a name="line.848"></a>
<span class="sourceLineNo">849</span> }<a name="line.849"></a>
<span class="sourceLineNo">850</span> if (lastException != null &amp;&amp; i &lt; (flushRetriesNumber - 1)) {<a name="line.850"></a>
<span class="sourceLineNo">851</span> try {<a name="line.851"></a>
<span class="sourceLineNo">852</span> Thread.sleep(pauseTime);<a name="line.852"></a>
<span class="sourceLineNo">853</span> } catch (InterruptedException e) {<a name="line.853"></a>
<span class="sourceLineNo">854</span> IOException iie = new InterruptedIOException();<a name="line.854"></a>
<span class="sourceLineNo">855</span> iie.initCause(e);<a name="line.855"></a>
<span class="sourceLineNo">856</span> throw iie;<a name="line.856"></a>
<span class="sourceLineNo">857</span> }<a name="line.857"></a>
<span class="sourceLineNo">858</span> }<a name="line.858"></a>
<span class="sourceLineNo">859</span> }<a name="line.859"></a>
<span class="sourceLineNo">860</span> throw lastException;<a name="line.860"></a>
<span class="sourceLineNo">861</span> }<a name="line.861"></a>
<span class="sourceLineNo">862</span><a name="line.862"></a>
<span class="sourceLineNo">863</span> public HStoreFile tryCommitRecoveredHFile(Path path) throws IOException {<a name="line.863"></a>
<span class="sourceLineNo">864</span> LOG.info("Validating recovered hfile at {} for inclusion in store {}", path, this);<a name="line.864"></a>
<span class="sourceLineNo">865</span> FileSystem srcFs = path.getFileSystem(conf);<a name="line.865"></a>
<span class="sourceLineNo">866</span> srcFs.access(path, FsAction.READ_WRITE);<a name="line.866"></a>
<span class="sourceLineNo">867</span> try (HFile.Reader reader =<a name="line.867"></a>
<span class="sourceLineNo">868</span> HFile.createReader(srcFs, path, getCacheConfig(), isPrimaryReplicaStore(), conf)) {<a name="line.868"></a>
<span class="sourceLineNo">869</span> Optional&lt;byte[]&gt; firstKey = reader.getFirstRowKey();<a name="line.869"></a>
<span class="sourceLineNo">870</span> Preconditions.checkState(firstKey.isPresent(), "First key can not be null");<a name="line.870"></a>
<span class="sourceLineNo">871</span> Optional&lt;Cell&gt; lk = reader.getLastKey();<a name="line.871"></a>
<span class="sourceLineNo">872</span> Preconditions.checkState(lk.isPresent(), "Last key can not be null");<a name="line.872"></a>
<span class="sourceLineNo">873</span> byte[] lastKey = CellUtil.cloneRow(lk.get());<a name="line.873"></a>
<span class="sourceLineNo">874</span> if (!this.getRegionInfo().containsRange(firstKey.get(), lastKey)) {<a name="line.874"></a>
<span class="sourceLineNo">875</span> throw new WrongRegionException("Recovered hfile " + path.toString()<a name="line.875"></a>
<span class="sourceLineNo">876</span> + " does not fit inside region " + this.getRegionInfo().getRegionNameAsString());<a name="line.876"></a>
<span class="sourceLineNo">877</span> }<a name="line.877"></a>
<span class="sourceLineNo">878</span> }<a name="line.878"></a>
<span class="sourceLineNo">879</span><a name="line.879"></a>
<span class="sourceLineNo">880</span> Path dstPath = getRegionFileSystem().commitStoreFile(getColumnFamilyName(), path);<a name="line.880"></a>
<span class="sourceLineNo">881</span> HStoreFile sf = storeEngine.createStoreFileAndReader(dstPath);<a name="line.881"></a>
<span class="sourceLineNo">882</span> StoreFileReader r = sf.getReader();<a name="line.882"></a>
<span class="sourceLineNo">883</span> this.storeSize.addAndGet(r.length());<a name="line.883"></a>
<span class="sourceLineNo">884</span> this.totalUncompressedBytes.addAndGet(r.getTotalUncompressedBytes());<a name="line.884"></a>
<span class="sourceLineNo">885</span><a name="line.885"></a>
<span class="sourceLineNo">886</span> storeEngine.addStoreFiles(Lists.newArrayList(sf), () -&gt; {<a name="line.886"></a>
<span class="sourceLineNo">887</span> });<a name="line.887"></a>
<span class="sourceLineNo">888</span><a name="line.888"></a>
<span class="sourceLineNo">889</span> LOG.info("Loaded recovered hfile to {}, entries={}, sequenceid={}, filesize={}", sf,<a name="line.889"></a>
<span class="sourceLineNo">890</span> r.getEntries(), r.getSequenceID(), TraditionalBinaryPrefix.long2String(r.length(), "B", 1));<a name="line.890"></a>
<span class="sourceLineNo">891</span> return sf;<a name="line.891"></a>
<span class="sourceLineNo">892</span> }<a name="line.892"></a>
<span class="sourceLineNo">893</span><a name="line.893"></a>
<span class="sourceLineNo">894</span> private long getTotalSize(Collection&lt;HStoreFile&gt; sfs) {<a name="line.894"></a>
<span class="sourceLineNo">895</span> return sfs.stream().mapToLong(sf -&gt; sf.getReader().length()).sum();<a name="line.895"></a>
<span class="sourceLineNo">896</span> }<a name="line.896"></a>
<span class="sourceLineNo">897</span><a name="line.897"></a>
<span class="sourceLineNo">898</span> private boolean completeFlush(final List&lt;HStoreFile&gt; sfs, long snapshotId) throws IOException {<a name="line.898"></a>
<span class="sourceLineNo">899</span> // NOTE:we should keep clearSnapshot method inside the write lock because clearSnapshot may<a name="line.899"></a>
<span class="sourceLineNo">900</span> // close {@link DefaultMemStore#snapshot}, which may be used by<a name="line.900"></a>
<span class="sourceLineNo">901</span> // {@link DefaultMemStore#getScanners}.<a name="line.901"></a>
<span class="sourceLineNo">902</span> storeEngine.addStoreFiles(sfs,<a name="line.902"></a>
<span class="sourceLineNo">903</span> // NOTE: here we must increase the refCount for storeFiles because we would open the<a name="line.903"></a>
<span class="sourceLineNo">904</span> // storeFiles and get the StoreFileScanners for them in HStore.notifyChangedReadersObservers.<a name="line.904"></a>
<span class="sourceLineNo">905</span> // If we don't increase the refCount here, HStore.closeAndArchiveCompactedFiles called by<a name="line.905"></a>
<span class="sourceLineNo">906</span> // CompactedHFilesDischarger may archive the storeFiles after a concurrent compaction.Because<a name="line.906"></a>
<span class="sourceLineNo">907</span> // HStore.requestCompaction is under storeEngine lock, so here we increase the refCount under<a name="line.907"></a>
<span class="sourceLineNo">908</span> // storeEngine lock. see HBASE-27519 for more details.<a name="line.908"></a>
<span class="sourceLineNo">909</span> snapshotId &gt; 0 ? () -&gt; {<a name="line.909"></a>
<span class="sourceLineNo">910</span> this.memstore.clearSnapshot(snapshotId);<a name="line.910"></a>
<span class="sourceLineNo">911</span> HStoreFile.increaseStoreFilesRefeCount(sfs);<a name="line.911"></a>
<span class="sourceLineNo">912</span> } : () -&gt; {<a name="line.912"></a>
<span class="sourceLineNo">913</span> HStoreFile.increaseStoreFilesRefeCount(sfs);<a name="line.913"></a>
<span class="sourceLineNo">914</span> });<a name="line.914"></a>
<span class="sourceLineNo">915</span> // notify to be called here - only in case of flushes<a name="line.915"></a>
<span class="sourceLineNo">916</span> try {<a name="line.916"></a>
<span class="sourceLineNo">917</span> notifyChangedReadersObservers(sfs);<a name="line.917"></a>
<span class="sourceLineNo">918</span> } finally {<a name="line.918"></a>
<span class="sourceLineNo">919</span> HStoreFile.decreaseStoreFilesRefeCount(sfs);<a name="line.919"></a>
<span class="sourceLineNo">920</span> }<a name="line.920"></a>
<span class="sourceLineNo">921</span> if (LOG.isTraceEnabled()) {<a name="line.921"></a>
<span class="sourceLineNo">922</span> long totalSize = getTotalSize(sfs);<a name="line.922"></a>
<span class="sourceLineNo">923</span> String traceMessage = "FLUSH time,count,size,store size,store files ["<a name="line.923"></a>
<span class="sourceLineNo">924</span> + EnvironmentEdgeManager.currentTime() + "," + sfs.size() + "," + totalSize + ","<a name="line.924"></a>
<span class="sourceLineNo">925</span> + storeSize + "," + storeEngine.getStoreFileManager().getStorefileCount() + "]";<a name="line.925"></a>
<span class="sourceLineNo">926</span> LOG.trace(traceMessage);<a name="line.926"></a>
<span class="sourceLineNo">927</span> }<a name="line.927"></a>
<span class="sourceLineNo">928</span> return needsCompaction();<a name="line.928"></a>
<span class="sourceLineNo">929</span> }<a name="line.929"></a>
<span class="sourceLineNo">930</span><a name="line.930"></a>
<span class="sourceLineNo">931</span> /**<a name="line.931"></a>
<span class="sourceLineNo">932</span> * Notify all observers that set of Readers has changed.<a name="line.932"></a>
<span class="sourceLineNo">933</span> */<a name="line.933"></a>
<span class="sourceLineNo">934</span> private void notifyChangedReadersObservers(List&lt;HStoreFile&gt; sfs) throws IOException {<a name="line.934"></a>
<span class="sourceLineNo">935</span> for (ChangedReadersObserver o : this.changedReaderObservers) {<a name="line.935"></a>
<span class="sourceLineNo">936</span> List&lt;KeyValueScanner&gt; memStoreScanners;<a name="line.936"></a>
<span class="sourceLineNo">937</span> this.storeEngine.readLock();<a name="line.937"></a>
<span class="sourceLineNo">938</span> try {<a name="line.938"></a>
<span class="sourceLineNo">939</span> memStoreScanners = this.memstore.getScanners(o.getReadPoint());<a name="line.939"></a>
<span class="sourceLineNo">940</span> } finally {<a name="line.940"></a>
<span class="sourceLineNo">941</span> this.storeEngine.readUnlock();<a name="line.941"></a>
<span class="sourceLineNo">942</span> }<a name="line.942"></a>
<span class="sourceLineNo">943</span> o.updateReaders(sfs, memStoreScanners);<a name="line.943"></a>
<span class="sourceLineNo">944</span> }<a name="line.944"></a>
<span class="sourceLineNo">945</span> }<a name="line.945"></a>
<span class="sourceLineNo">946</span><a name="line.946"></a>
<span class="sourceLineNo">947</span> /**<a name="line.947"></a>
<span class="sourceLineNo">948</span> * Get all scanners with no filtering based on TTL (that happens further down the line).<a name="line.948"></a>
<span class="sourceLineNo">949</span> * @param cacheBlocks cache the blocks or not<a name="line.949"></a>
<span class="sourceLineNo">950</span> * @param usePread true to use pread, false if not<a name="line.950"></a>
<span class="sourceLineNo">951</span> * @param isCompaction true if the scanner is created for compaction<a name="line.951"></a>
<span class="sourceLineNo">952</span> * @param matcher the scan query matcher<a name="line.952"></a>
<span class="sourceLineNo">953</span> * @param startRow the start row<a name="line.953"></a>
<span class="sourceLineNo">954</span> * @param stopRow the stop row<a name="line.954"></a>
<span class="sourceLineNo">955</span> * @param readPt the read point of the current scan<a name="line.955"></a>
<span class="sourceLineNo">956</span> * @return all scanners for this store<a name="line.956"></a>
<span class="sourceLineNo">957</span> */<a name="line.957"></a>
<span class="sourceLineNo">958</span> public List&lt;KeyValueScanner&gt; getScanners(boolean cacheBlocks, boolean isGet, boolean usePread,<a name="line.958"></a>
<span class="sourceLineNo">959</span> boolean isCompaction, ScanQueryMatcher matcher, byte[] startRow, byte[] stopRow, long readPt,<a name="line.959"></a>
<span class="sourceLineNo">960</span> boolean onlyLatestVersion) throws IOException {<a name="line.960"></a>
<span class="sourceLineNo">961</span> return getScanners(cacheBlocks, usePread, isCompaction, matcher, startRow, true, stopRow, false,<a name="line.961"></a>
<span class="sourceLineNo">962</span> readPt, onlyLatestVersion);<a name="line.962"></a>
<span class="sourceLineNo">963</span> }<a name="line.963"></a>
<span class="sourceLineNo">964</span><a name="line.964"></a>
<span class="sourceLineNo">965</span> /**<a name="line.965"></a>
<span class="sourceLineNo">966</span> * Get all scanners with no filtering based on TTL (that happens further down the line).<a name="line.966"></a>
<span class="sourceLineNo">967</span> * @param cacheBlocks cache the blocks or not<a name="line.967"></a>
<span class="sourceLineNo">968</span> * @param usePread true to use pread, false if not<a name="line.968"></a>
<span class="sourceLineNo">969</span> * @param isCompaction true if the scanner is created for compaction<a name="line.969"></a>
<span class="sourceLineNo">970</span> * @param matcher the scan query matcher<a name="line.970"></a>
<span class="sourceLineNo">971</span> * @param startRow the start row<a name="line.971"></a>
<span class="sourceLineNo">972</span> * @param includeStartRow true to include start row, false if not<a name="line.972"></a>
<span class="sourceLineNo">973</span> * @param stopRow the stop row<a name="line.973"></a>
<span class="sourceLineNo">974</span> * @param includeStopRow true to include stop row, false if not<a name="line.974"></a>
<span class="sourceLineNo">975</span> * @param readPt the read point of the current scan<a name="line.975"></a>
<span class="sourceLineNo">976</span> * @return all scanners for this store<a name="line.976"></a>
<span class="sourceLineNo">977</span> */<a name="line.977"></a>
<span class="sourceLineNo">978</span> public List&lt;KeyValueScanner&gt; getScanners(boolean cacheBlocks, boolean usePread,<a name="line.978"></a>
<span class="sourceLineNo">979</span> boolean isCompaction, ScanQueryMatcher matcher, byte[] startRow, boolean includeStartRow,<a name="line.979"></a>
<span class="sourceLineNo">980</span> byte[] stopRow, boolean includeStopRow, long readPt, boolean onlyLatestVersion)<a name="line.980"></a>
<span class="sourceLineNo">981</span> throws IOException {<a name="line.981"></a>
<span class="sourceLineNo">982</span> Collection&lt;HStoreFile&gt; storeFilesToScan;<a name="line.982"></a>
<span class="sourceLineNo">983</span> List&lt;KeyValueScanner&gt; memStoreScanners;<a name="line.983"></a>
<span class="sourceLineNo">984</span> this.storeEngine.readLock();<a name="line.984"></a>
<span class="sourceLineNo">985</span> try {<a name="line.985"></a>
<span class="sourceLineNo">986</span> storeFilesToScan = this.storeEngine.getStoreFileManager().getFilesForScan(startRow,<a name="line.986"></a>
<span class="sourceLineNo">987</span> includeStartRow, stopRow, includeStopRow, onlyLatestVersion);<a name="line.987"></a>
<span class="sourceLineNo">988</span> memStoreScanners = this.memstore.getScanners(readPt);<a name="line.988"></a>
<span class="sourceLineNo">989</span> // NOTE: here we must increase the refCount for storeFiles because we would open the<a name="line.989"></a>
<span class="sourceLineNo">990</span> // storeFiles and get the StoreFileScanners for them.If we don't increase the refCount here,<a name="line.990"></a>
<span class="sourceLineNo">991</span> // HStore.closeAndArchiveCompactedFiles called by CompactedHFilesDischarger may archive the<a name="line.991"></a>
<span class="sourceLineNo">992</span> // storeFiles after a concurrent compaction.Because HStore.requestCompaction is under<a name="line.992"></a>
<span class="sourceLineNo">993</span> // storeEngine lock, so here we increase the refCount under storeEngine lock. see HBASE-27484<a name="line.993"></a>
<span class="sourceLineNo">994</span> // for more details.<a name="line.994"></a>
<span class="sourceLineNo">995</span> HStoreFile.increaseStoreFilesRefeCount(storeFilesToScan);<a name="line.995"></a>
<span class="sourceLineNo">996</span> } finally {<a name="line.996"></a>
<span class="sourceLineNo">997</span> this.storeEngine.readUnlock();<a name="line.997"></a>
<span class="sourceLineNo">998</span> }<a name="line.998"></a>
<span class="sourceLineNo">999</span> try {<a name="line.999"></a>
<span class="sourceLineNo">1000</span> // First the store file scanners<a name="line.1000"></a>
<span class="sourceLineNo">1001</span><a name="line.1001"></a>
<span class="sourceLineNo">1002</span> // TODO this used to get the store files in descending order,<a name="line.1002"></a>
<span class="sourceLineNo">1003</span> // but now we get them in ascending order, which I think is<a name="line.1003"></a>
<span class="sourceLineNo">1004</span> // actually more correct, since memstore get put at the end.<a name="line.1004"></a>
<span class="sourceLineNo">1005</span> List&lt;StoreFileScanner&gt; sfScanners = StoreFileScanner.getScannersForStoreFiles(<a name="line.1005"></a>
<span class="sourceLineNo">1006</span> storeFilesToScan, cacheBlocks, usePread, isCompaction, false, matcher, readPt);<a name="line.1006"></a>
<span class="sourceLineNo">1007</span> List&lt;KeyValueScanner&gt; scanners = new ArrayList&lt;&gt;(sfScanners.size() + 1);<a name="line.1007"></a>
<span class="sourceLineNo">1008</span> scanners.addAll(sfScanners);<a name="line.1008"></a>
<span class="sourceLineNo">1009</span> // Then the memstore scanners<a name="line.1009"></a>
<span class="sourceLineNo">1010</span> scanners.addAll(memStoreScanners);<a name="line.1010"></a>
<span class="sourceLineNo">1011</span> return scanners;<a name="line.1011"></a>
<span class="sourceLineNo">1012</span> } catch (Throwable t) {<a name="line.1012"></a>
<span class="sourceLineNo">1013</span> clearAndClose(memStoreScanners);<a name="line.1013"></a>
<span class="sourceLineNo">1014</span> throw t instanceof IOException ? (IOException) t : new IOException(t);<a name="line.1014"></a>
<span class="sourceLineNo">1015</span> } finally {<a name="line.1015"></a>
<span class="sourceLineNo">1016</span> HStoreFile.decreaseStoreFilesRefeCount(storeFilesToScan);<a name="line.1016"></a>
<span class="sourceLineNo">1017</span> }<a name="line.1017"></a>
<span class="sourceLineNo">1018</span> }<a name="line.1018"></a>
<span class="sourceLineNo">1019</span><a name="line.1019"></a>
<span class="sourceLineNo">1020</span> private static void clearAndClose(List&lt;KeyValueScanner&gt; scanners) {<a name="line.1020"></a>
<span class="sourceLineNo">1021</span> if (scanners == null) {<a name="line.1021"></a>
<span class="sourceLineNo">1022</span> return;<a name="line.1022"></a>
<span class="sourceLineNo">1023</span> }<a name="line.1023"></a>
<span class="sourceLineNo">1024</span> for (KeyValueScanner s : scanners) {<a name="line.1024"></a>
<span class="sourceLineNo">1025</span> s.close();<a name="line.1025"></a>
<span class="sourceLineNo">1026</span> }<a name="line.1026"></a>
<span class="sourceLineNo">1027</span> scanners.clear();<a name="line.1027"></a>
<span class="sourceLineNo">1028</span> }<a name="line.1028"></a>
<span class="sourceLineNo">1029</span><a name="line.1029"></a>
<span class="sourceLineNo">1030</span> /**<a name="line.1030"></a>
<span class="sourceLineNo">1031</span> * Create scanners on the given files and if needed on the memstore with no filtering based on TTL<a name="line.1031"></a>
<span class="sourceLineNo">1032</span> * (that happens further down the line).<a name="line.1032"></a>
<span class="sourceLineNo">1033</span> * @param files the list of files on which the scanners has to be created<a name="line.1033"></a>
<span class="sourceLineNo">1034</span> * @param cacheBlocks cache the blocks or not<a name="line.1034"></a>
<span class="sourceLineNo">1035</span> * @param usePread true to use pread, false if not<a name="line.1035"></a>
<span class="sourceLineNo">1036</span> * @param isCompaction true if the scanner is created for compaction<a name="line.1036"></a>
<span class="sourceLineNo">1037</span> * @param matcher the scan query matcher<a name="line.1037"></a>
<span class="sourceLineNo">1038</span> * @param startRow the start row<a name="line.1038"></a>
<span class="sourceLineNo">1039</span> * @param stopRow the stop row<a name="line.1039"></a>
<span class="sourceLineNo">1040</span> * @param readPt the read point of the current scan<a name="line.1040"></a>
<span class="sourceLineNo">1041</span> * @param includeMemstoreScanner true if memstore has to be included<a name="line.1041"></a>
<span class="sourceLineNo">1042</span> * @return scanners on the given files and on the memstore if specified<a name="line.1042"></a>
<span class="sourceLineNo">1043</span> */<a name="line.1043"></a>
<span class="sourceLineNo">1044</span> public List&lt;KeyValueScanner&gt; getScanners(List&lt;HStoreFile&gt; files, boolean cacheBlocks,<a name="line.1044"></a>
<span class="sourceLineNo">1045</span> boolean isGet, boolean usePread, boolean isCompaction, ScanQueryMatcher matcher,<a name="line.1045"></a>
<span class="sourceLineNo">1046</span> byte[] startRow, byte[] stopRow, long readPt, boolean includeMemstoreScanner,<a name="line.1046"></a>
<span class="sourceLineNo">1047</span> boolean onlyLatestVersion) throws IOException {<a name="line.1047"></a>
<span class="sourceLineNo">1048</span> return getScanners(files, cacheBlocks, usePread, isCompaction, matcher, startRow, true, stopRow,<a name="line.1048"></a>
<span class="sourceLineNo">1049</span> false, readPt, includeMemstoreScanner, onlyLatestVersion);<a name="line.1049"></a>
<span class="sourceLineNo">1050</span> }<a name="line.1050"></a>
<span class="sourceLineNo">1051</span><a name="line.1051"></a>
<span class="sourceLineNo">1052</span> /**<a name="line.1052"></a>
<span class="sourceLineNo">1053</span> * Create scanners on the given files and if needed on the memstore with no filtering based on TTL<a name="line.1053"></a>
<span class="sourceLineNo">1054</span> * (that happens further down the line).<a name="line.1054"></a>
<span class="sourceLineNo">1055</span> * @param files the list of files on which the scanners has to be created<a name="line.1055"></a>
<span class="sourceLineNo">1056</span> * @param cacheBlocks ache the blocks or not<a name="line.1056"></a>
<span class="sourceLineNo">1057</span> * @param usePread true to use pread, false if not<a name="line.1057"></a>
<span class="sourceLineNo">1058</span> * @param isCompaction true if the scanner is created for compaction<a name="line.1058"></a>
<span class="sourceLineNo">1059</span> * @param matcher the scan query matcher<a name="line.1059"></a>
<span class="sourceLineNo">1060</span> * @param startRow the start row<a name="line.1060"></a>
<span class="sourceLineNo">1061</span> * @param includeStartRow true to include start row, false if not<a name="line.1061"></a>
<span class="sourceLineNo">1062</span> * @param stopRow the stop row<a name="line.1062"></a>
<span class="sourceLineNo">1063</span> * @param includeStopRow true to include stop row, false if not<a name="line.1063"></a>
<span class="sourceLineNo">1064</span> * @param readPt the read point of the current scan<a name="line.1064"></a>
<span class="sourceLineNo">1065</span> * @param includeMemstoreScanner true if memstore has to be included<a name="line.1065"></a>
<span class="sourceLineNo">1066</span> * @return scanners on the given files and on the memstore if specified<a name="line.1066"></a>
<span class="sourceLineNo">1067</span> */<a name="line.1067"></a>
<span class="sourceLineNo">1068</span> public List&lt;KeyValueScanner&gt; getScanners(List&lt;HStoreFile&gt; files, boolean cacheBlocks,<a name="line.1068"></a>
<span class="sourceLineNo">1069</span> boolean usePread, boolean isCompaction, ScanQueryMatcher matcher, byte[] startRow,<a name="line.1069"></a>
<span class="sourceLineNo">1070</span> boolean includeStartRow, byte[] stopRow, boolean includeStopRow, long readPt,<a name="line.1070"></a>
<span class="sourceLineNo">1071</span> boolean includeMemstoreScanner, boolean onlyLatestVersion) throws IOException {<a name="line.1071"></a>
<span class="sourceLineNo">1072</span> List&lt;KeyValueScanner&gt; memStoreScanners = null;<a name="line.1072"></a>
<span class="sourceLineNo">1073</span> if (includeMemstoreScanner) {<a name="line.1073"></a>
<span class="sourceLineNo">1074</span> this.storeEngine.readLock();<a name="line.1074"></a>
<span class="sourceLineNo">1075</span> try {<a name="line.1075"></a>
<span class="sourceLineNo">1076</span> memStoreScanners = this.memstore.getScanners(readPt);<a name="line.1076"></a>
<span class="sourceLineNo">1077</span> } finally {<a name="line.1077"></a>
<span class="sourceLineNo">1078</span> this.storeEngine.readUnlock();<a name="line.1078"></a>
<span class="sourceLineNo">1079</span> }<a name="line.1079"></a>
<span class="sourceLineNo">1080</span> }<a name="line.1080"></a>
<span class="sourceLineNo">1081</span> try {<a name="line.1081"></a>
<span class="sourceLineNo">1082</span> List&lt;StoreFileScanner&gt; sfScanners = StoreFileScanner.getScannersForStoreFiles(files,<a name="line.1082"></a>
<span class="sourceLineNo">1083</span> cacheBlocks, usePread, isCompaction, false, matcher, readPt);<a name="line.1083"></a>
<span class="sourceLineNo">1084</span> List&lt;KeyValueScanner&gt; scanners = new ArrayList&lt;&gt;(sfScanners.size() + 1);<a name="line.1084"></a>
<span class="sourceLineNo">1085</span> scanners.addAll(sfScanners);<a name="line.1085"></a>
<span class="sourceLineNo">1086</span> // Then the memstore scanners<a name="line.1086"></a>
<span class="sourceLineNo">1087</span> if (memStoreScanners != null) {<a name="line.1087"></a>
<span class="sourceLineNo">1088</span> scanners.addAll(memStoreScanners);<a name="line.1088"></a>
<span class="sourceLineNo">1089</span> }<a name="line.1089"></a>
<span class="sourceLineNo">1090</span> return scanners;<a name="line.1090"></a>
<span class="sourceLineNo">1091</span> } catch (Throwable t) {<a name="line.1091"></a>
<span class="sourceLineNo">1092</span> clearAndClose(memStoreScanners);<a name="line.1092"></a>
<span class="sourceLineNo">1093</span> throw t instanceof IOException ? (IOException) t : new IOException(t);<a name="line.1093"></a>
<span class="sourceLineNo">1094</span> }<a name="line.1094"></a>
<span class="sourceLineNo">1095</span> }<a name="line.1095"></a>
<span class="sourceLineNo">1096</span><a name="line.1096"></a>
<span class="sourceLineNo">1097</span> /**<a name="line.1097"></a>
<span class="sourceLineNo">1098</span> * @param o Observer who wants to know about changes in set of Readers<a name="line.1098"></a>
<span class="sourceLineNo">1099</span> */<a name="line.1099"></a>
<span class="sourceLineNo">1100</span> public void addChangedReaderObserver(ChangedReadersObserver o) {<a name="line.1100"></a>
<span class="sourceLineNo">1101</span> this.changedReaderObservers.add(o);<a name="line.1101"></a>
<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> /**<a name="line.1104"></a>
<span class="sourceLineNo">1105</span> * @param o Observer no longer interested in changes in set of Readers.<a name="line.1105"></a>
<span class="sourceLineNo">1106</span> */<a name="line.1106"></a>
<span class="sourceLineNo">1107</span> public void deleteChangedReaderObserver(ChangedReadersObserver o) {<a name="line.1107"></a>
<span class="sourceLineNo">1108</span> // We don't check if observer present; it may not be (legitimately)<a name="line.1108"></a>
<span class="sourceLineNo">1109</span> this.changedReaderObservers.remove(o);<a name="line.1109"></a>
<span class="sourceLineNo">1110</span> }<a name="line.1110"></a>
<span class="sourceLineNo">1111</span><a name="line.1111"></a>
<span class="sourceLineNo">1112</span> //////////////////////////////////////////////////////////////////////////////<a name="line.1112"></a>
<span class="sourceLineNo">1113</span> // Compaction<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> /**<a name="line.1116"></a>
<span class="sourceLineNo">1117</span> * Compact the StoreFiles. This method may take some time, so the calling thread must be able to<a name="line.1117"></a>
<span class="sourceLineNo">1118</span> * block for long periods.<a name="line.1118"></a>
<span class="sourceLineNo">1119</span> * &lt;p&gt;<a name="line.1119"></a>
<span class="sourceLineNo">1120</span> * During this time, the Store can work as usual, getting values from StoreFiles and writing new<a name="line.1120"></a>
<span class="sourceLineNo">1121</span> * StoreFiles from the memstore. Existing StoreFiles are not destroyed until the new compacted<a name="line.1121"></a>
<span class="sourceLineNo">1122</span> * StoreFile is completely written-out to disk.<a name="line.1122"></a>
<span class="sourceLineNo">1123</span> * &lt;p&gt;<a name="line.1123"></a>
<span class="sourceLineNo">1124</span> * The compactLock prevents multiple simultaneous compactions. The structureLock prevents us from<a name="line.1124"></a>
<span class="sourceLineNo">1125</span> * interfering with other write operations.<a name="line.1125"></a>
<span class="sourceLineNo">1126</span> * &lt;p&gt;<a name="line.1126"></a>
<span class="sourceLineNo">1127</span> * We don't want to hold the structureLock for the whole time, as a compact() can be lengthy and<a name="line.1127"></a>
<span class="sourceLineNo">1128</span> * we want to allow cache-flushes during this period.<a name="line.1128"></a>
<span class="sourceLineNo">1129</span> * &lt;p&gt;<a name="line.1129"></a>
<span class="sourceLineNo">1130</span> * Compaction event should be idempotent, since there is no IO Fencing for the region directory in<a name="line.1130"></a>
<span class="sourceLineNo">1131</span> * hdfs. A region server might still try to complete the compaction after it lost the region. That<a name="line.1131"></a>
<span class="sourceLineNo">1132</span> * is why the following events are carefully ordered for a compaction: 1. Compaction writes new<a name="line.1132"></a>
<span class="sourceLineNo">1133</span> * files under region/.tmp directory (compaction output) 2. Compaction atomically moves the<a name="line.1133"></a>
<span class="sourceLineNo">1134</span> * temporary file under region directory 3. Compaction appends a WAL edit containing the<a name="line.1134"></a>
<span class="sourceLineNo">1135</span> * compaction input and output files. Forces sync on WAL. 4. Compaction deletes the input files<a name="line.1135"></a>
<span class="sourceLineNo">1136</span> * from the region directory. Failure conditions are handled like this: - If RS fails before 2,<a name="line.1136"></a>
<span class="sourceLineNo">1137</span> * compaction wont complete. Even if RS lives on and finishes the compaction later, it will only<a name="line.1137"></a>
<span class="sourceLineNo">1138</span> * write the new data file to the region directory. Since we already have this data, this will be<a name="line.1138"></a>
<span class="sourceLineNo">1139</span> * idempotent but we will have a redundant copy of the data. - If RS fails between 2 and 3, the<a name="line.1139"></a>
<span class="sourceLineNo">1140</span> * region will have a redundant copy of the data. The RS that failed won't be able to finish<a name="line.1140"></a>
<span class="sourceLineNo">1141</span> * sync() for WAL because of lease recovery in WAL. - If RS fails after 3, the region region<a name="line.1141"></a>
<span class="sourceLineNo">1142</span> * server who opens the region will pick up the the compaction marker from the WAL and replay it<a name="line.1142"></a>
<span class="sourceLineNo">1143</span> * by removing the compaction input files. Failed RS can also attempt to delete those files, but<a name="line.1143"></a>
<span class="sourceLineNo">1144</span> * the operation will be idempotent See HBASE-2231 for details.<a name="line.1144"></a>
<span class="sourceLineNo">1145</span> * @param compaction compaction details obtained from requestCompaction()<a name="line.1145"></a>
<span class="sourceLineNo">1146</span> * @return Storefile we compacted into or null if we failed or opted out early.<a name="line.1146"></a>
<span class="sourceLineNo">1147</span> */<a name="line.1147"></a>
<span class="sourceLineNo">1148</span> public List&lt;HStoreFile&gt; compact(CompactionContext compaction,<a name="line.1148"></a>
<span class="sourceLineNo">1149</span> ThroughputController throughputController, User user) throws IOException {<a name="line.1149"></a>
<span class="sourceLineNo">1150</span> assert compaction != null;<a name="line.1150"></a>
<span class="sourceLineNo">1151</span> CompactionRequestImpl cr = compaction.getRequest();<a name="line.1151"></a>
<span class="sourceLineNo">1152</span> StoreFileWriterCreationTracker writerCreationTracker =<a name="line.1152"></a>
<span class="sourceLineNo">1153</span> storeFileWriterCreationTrackerFactory.get();<a name="line.1153"></a>
<span class="sourceLineNo">1154</span> if (writerCreationTracker != null) {<a name="line.1154"></a>
<span class="sourceLineNo">1155</span> cr.setWriterCreationTracker(writerCreationTracker);<a name="line.1155"></a>
<span class="sourceLineNo">1156</span> storeFileWriterCreationTrackers.add(writerCreationTracker);<a name="line.1156"></a>
<span class="sourceLineNo">1157</span> }<a name="line.1157"></a>
<span class="sourceLineNo">1158</span> try {<a name="line.1158"></a>
<span class="sourceLineNo">1159</span> // Do all sanity checking in here if we have a valid CompactionRequestImpl<a name="line.1159"></a>
<span class="sourceLineNo">1160</span> // because we need to clean up after it on the way out in a finally<a name="line.1160"></a>
<span class="sourceLineNo">1161</span> // block below<a name="line.1161"></a>
<span class="sourceLineNo">1162</span> long compactionStartTime = EnvironmentEdgeManager.currentTime();<a name="line.1162"></a>
<span class="sourceLineNo">1163</span> assert compaction.hasSelection();<a name="line.1163"></a>
<span class="sourceLineNo">1164</span> Collection&lt;HStoreFile&gt; filesToCompact = cr.getFiles();<a name="line.1164"></a>
<span class="sourceLineNo">1165</span> assert !filesToCompact.isEmpty();<a name="line.1165"></a>
<span class="sourceLineNo">1166</span> synchronized (filesCompacting) {<a name="line.1166"></a>
<span class="sourceLineNo">1167</span> // sanity check: we're compacting files that this store knows about<a name="line.1167"></a>
<span class="sourceLineNo">1168</span> // TODO: change this to LOG.error() after more debugging<a name="line.1168"></a>
<span class="sourceLineNo">1169</span> Preconditions.checkArgument(filesCompacting.containsAll(filesToCompact));<a name="line.1169"></a>
<span class="sourceLineNo">1170</span> }<a name="line.1170"></a>
<span class="sourceLineNo">1171</span><a name="line.1171"></a>
<span class="sourceLineNo">1172</span> // Ready to go. Have list of files to compact.<a name="line.1172"></a>
<span class="sourceLineNo">1173</span> LOG.info("Starting compaction of " + filesToCompact + " into tmpdir="<a name="line.1173"></a>
<span class="sourceLineNo">1174</span> + getRegionFileSystem().getTempDir() + ", totalSize="<a name="line.1174"></a>
<span class="sourceLineNo">1175</span> + TraditionalBinaryPrefix.long2String(cr.getSize(), "", 1));<a name="line.1175"></a>
<span class="sourceLineNo">1176</span><a name="line.1176"></a>
<span class="sourceLineNo">1177</span> return doCompaction(cr, filesToCompact, user, compactionStartTime,<a name="line.1177"></a>
<span class="sourceLineNo">1178</span> compaction.compact(throughputController, user));<a name="line.1178"></a>
<span class="sourceLineNo">1179</span> } finally {<a name="line.1179"></a>
<span class="sourceLineNo">1180</span> finishCompactionRequest(cr);<a name="line.1180"></a>
<span class="sourceLineNo">1181</span> }<a name="line.1181"></a>
<span class="sourceLineNo">1182</span> }<a name="line.1182"></a>
<span class="sourceLineNo">1183</span><a name="line.1183"></a>
<span class="sourceLineNo">1184</span> protected List&lt;HStoreFile&gt; doCompaction(CompactionRequestImpl cr,<a name="line.1184"></a>
<span class="sourceLineNo">1185</span> Collection&lt;HStoreFile&gt; filesToCompact, User user, long compactionStartTime, List&lt;Path&gt; newFiles)<a name="line.1185"></a>
<span class="sourceLineNo">1186</span> throws IOException {<a name="line.1186"></a>
<span class="sourceLineNo">1187</span> // Do the steps necessary to complete the compaction.<a name="line.1187"></a>
<span class="sourceLineNo">1188</span> setStoragePolicyFromFileName(newFiles);<a name="line.1188"></a>
<span class="sourceLineNo">1189</span> List&lt;HStoreFile&gt; sfs = storeEngine.commitStoreFiles(newFiles, true);<a name="line.1189"></a>
<span class="sourceLineNo">1190</span> if (this.getCoprocessorHost() != null) {<a name="line.1190"></a>
<span class="sourceLineNo">1191</span> for (HStoreFile sf : sfs) {<a name="line.1191"></a>
<span class="sourceLineNo">1192</span> getCoprocessorHost().postCompact(this, sf, cr.getTracker(), cr, user);<a name="line.1192"></a>
<span class="sourceLineNo">1193</span> }<a name="line.1193"></a>
<span class="sourceLineNo">1194</span> }<a name="line.1194"></a>
<span class="sourceLineNo">1195</span> replaceStoreFiles(filesToCompact, sfs, true);<a name="line.1195"></a>
<span class="sourceLineNo">1196</span><a name="line.1196"></a>
<span class="sourceLineNo">1197</span> long outputBytes = getTotalSize(sfs);<a name="line.1197"></a>
<span class="sourceLineNo">1198</span><a name="line.1198"></a>
<span class="sourceLineNo">1199</span> // At this point the store will use new files for all new scanners.<a name="line.1199"></a>
<span class="sourceLineNo">1200</span> refreshStoreSizeAndTotalBytes(); // update store size.<a name="line.1200"></a>
<span class="sourceLineNo">1201</span><a name="line.1201"></a>
<span class="sourceLineNo">1202</span> long now = EnvironmentEdgeManager.currentTime();<a name="line.1202"></a>
<span class="sourceLineNo">1203</span> if (<a name="line.1203"></a>
<span class="sourceLineNo">1204</span> region.getRegionServerServices() != null<a name="line.1204"></a>
<span class="sourceLineNo">1205</span> &amp;&amp; region.getRegionServerServices().getMetrics() != null<a name="line.1205"></a>
<span class="sourceLineNo">1206</span> ) {<a name="line.1206"></a>
<span class="sourceLineNo">1207</span> region.getRegionServerServices().getMetrics().updateCompaction(<a name="line.1207"></a>
<span class="sourceLineNo">1208</span> region.getTableDescriptor().getTableName().getNameAsString(), cr.isMajor(),<a name="line.1208"></a>
<span class="sourceLineNo">1209</span> now - compactionStartTime, cr.getFiles().size(), newFiles.size(), cr.getSize(),<a name="line.1209"></a>
<span class="sourceLineNo">1210</span> outputBytes);<a name="line.1210"></a>
<span class="sourceLineNo">1211</span><a name="line.1211"></a>
<span class="sourceLineNo">1212</span> }<a name="line.1212"></a>
<span class="sourceLineNo">1213</span><a name="line.1213"></a>
<span class="sourceLineNo">1214</span> logCompactionEndMessage(cr, sfs, now, compactionStartTime);<a name="line.1214"></a>
<span class="sourceLineNo">1215</span> return sfs;<a name="line.1215"></a>
<span class="sourceLineNo">1216</span> }<a name="line.1216"></a>
<span class="sourceLineNo">1217</span><a name="line.1217"></a>
<span class="sourceLineNo">1218</span> // Set correct storage policy from the file name of DTCP.<a name="line.1218"></a>
<span class="sourceLineNo">1219</span> // Rename file will not change the storage policy.<a name="line.1219"></a>
<span class="sourceLineNo">1220</span> private void setStoragePolicyFromFileName(List&lt;Path&gt; newFiles) throws IOException {<a name="line.1220"></a>
<span class="sourceLineNo">1221</span> String prefix = HConstants.STORAGE_POLICY_PREFIX;<a name="line.1221"></a>
<span class="sourceLineNo">1222</span> for (Path newFile : newFiles) {<a name="line.1222"></a>
<span class="sourceLineNo">1223</span> if (newFile.getParent().getName().startsWith(prefix)) {<a name="line.1223"></a>
<span class="sourceLineNo">1224</span> CommonFSUtils.setStoragePolicy(getRegionFileSystem().getFileSystem(), newFile,<a name="line.1224"></a>
<span class="sourceLineNo">1225</span> newFile.getParent().getName().substring(prefix.length()));<a name="line.1225"></a>
<span class="sourceLineNo">1226</span> }<a name="line.1226"></a>
<span class="sourceLineNo">1227</span> }<a name="line.1227"></a>
<span class="sourceLineNo">1228</span> }<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> * Writes the compaction WAL record.<a name="line.1231"></a>
<span class="sourceLineNo">1232</span> * @param filesCompacted Files compacted (input).<a name="line.1232"></a>
<span class="sourceLineNo">1233</span> * @param newFiles Files from compaction.<a name="line.1233"></a>
<span class="sourceLineNo">1234</span> */<a name="line.1234"></a>
<span class="sourceLineNo">1235</span> private void writeCompactionWalRecord(Collection&lt;HStoreFile&gt; filesCompacted,<a name="line.1235"></a>
<span class="sourceLineNo">1236</span> Collection&lt;HStoreFile&gt; newFiles) throws IOException {<a name="line.1236"></a>
<span class="sourceLineNo">1237</span> if (region.getWAL() == null) {<a name="line.1237"></a>
<span class="sourceLineNo">1238</span> return;<a name="line.1238"></a>
<span class="sourceLineNo">1239</span> }<a name="line.1239"></a>
<span class="sourceLineNo">1240</span> List&lt;Path&gt; inputPaths =<a name="line.1240"></a>
<span class="sourceLineNo">1241</span> filesCompacted.stream().map(HStoreFile::getPath).collect(Collectors.toList());<a name="line.1241"></a>
<span class="sourceLineNo">1242</span> List&lt;Path&gt; outputPaths =<a name="line.1242"></a>
<span class="sourceLineNo">1243</span> newFiles.stream().map(HStoreFile::getPath).collect(Collectors.toList());<a name="line.1243"></a>
<span class="sourceLineNo">1244</span> RegionInfo info = this.region.getRegionInfo();<a name="line.1244"></a>
<span class="sourceLineNo">1245</span> CompactionDescriptor compactionDescriptor = ProtobufUtil.toCompactionDescriptor(info,<a name="line.1245"></a>
<span class="sourceLineNo">1246</span> getColumnFamilyDescriptor().getName(), inputPaths, outputPaths,<a name="line.1246"></a>
<span class="sourceLineNo">1247</span> getRegionFileSystem().getStoreDir(getColumnFamilyDescriptor().getNameAsString()));<a name="line.1247"></a>
<span class="sourceLineNo">1248</span> // Fix reaching into Region to get the maxWaitForSeqId.<a name="line.1248"></a>
<span class="sourceLineNo">1249</span> // Does this method belong in Region altogether given it is making so many references up there?<a name="line.1249"></a>
<span class="sourceLineNo">1250</span> // Could be Region#writeCompactionMarker(compactionDescriptor);<a name="line.1250"></a>
<span class="sourceLineNo">1251</span> WALUtil.writeCompactionMarker(this.region.getWAL(), this.region.getReplicationScope(),<a name="line.1251"></a>
<span class="sourceLineNo">1252</span> this.region.getRegionInfo(), compactionDescriptor, this.region.getMVCC(),<a name="line.1252"></a>
<span class="sourceLineNo">1253</span> region.getRegionReplicationSink().orElse(null));<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> @RestrictedApi(explanation = "Should only be called in TestHStore", link = "",<a name="line.1256"></a>
<span class="sourceLineNo">1257</span> allowedOnPath = ".*/(HStore|TestHStore).java")<a name="line.1257"></a>
<span class="sourceLineNo">1258</span> void replaceStoreFiles(Collection&lt;HStoreFile&gt; compactedFiles, Collection&lt;HStoreFile&gt; result,<a name="line.1258"></a>
<span class="sourceLineNo">1259</span> boolean writeCompactionMarker) throws IOException {<a name="line.1259"></a>
<span class="sourceLineNo">1260</span> storeEngine.replaceStoreFiles(compactedFiles, result, () -&gt; {<a name="line.1260"></a>
<span class="sourceLineNo">1261</span> if (writeCompactionMarker) {<a name="line.1261"></a>
<span class="sourceLineNo">1262</span> writeCompactionWalRecord(compactedFiles, result);<a name="line.1262"></a>
<span class="sourceLineNo">1263</span> }<a name="line.1263"></a>
<span class="sourceLineNo">1264</span> }, () -&gt; {<a name="line.1264"></a>
<span class="sourceLineNo">1265</span> synchronized (filesCompacting) {<a name="line.1265"></a>
<span class="sourceLineNo">1266</span> filesCompacting.removeAll(compactedFiles);<a name="line.1266"></a>
<span class="sourceLineNo">1267</span> }<a name="line.1267"></a>
<span class="sourceLineNo">1268</span> });<a name="line.1268"></a>
<span class="sourceLineNo">1269</span> // These may be null when the RS is shutting down. The space quota Chores will fix the Region<a name="line.1269"></a>
<span class="sourceLineNo">1270</span> // sizes later so it's not super-critical if we miss these.<a name="line.1270"></a>
<span class="sourceLineNo">1271</span> RegionServerServices rsServices = region.getRegionServerServices();<a name="line.1271"></a>
<span class="sourceLineNo">1272</span> if (rsServices != null &amp;&amp; rsServices.getRegionServerSpaceQuotaManager() != null) {<a name="line.1272"></a>
<span class="sourceLineNo">1273</span> updateSpaceQuotaAfterFileReplacement(<a name="line.1273"></a>
<span class="sourceLineNo">1274</span> rsServices.getRegionServerSpaceQuotaManager().getRegionSizeStore(), getRegionInfo(),<a name="line.1274"></a>
<span class="sourceLineNo">1275</span> compactedFiles, result);<a name="line.1275"></a>
<span class="sourceLineNo">1276</span> }<a name="line.1276"></a>
<span class="sourceLineNo">1277</span> }<a name="line.1277"></a>
<span class="sourceLineNo">1278</span><a name="line.1278"></a>
<span class="sourceLineNo">1279</span> /**<a name="line.1279"></a>
<span class="sourceLineNo">1280</span> * Updates the space quota usage for this region, removing the size for files compacted away and<a name="line.1280"></a>
<span class="sourceLineNo">1281</span> * adding in the size for new files.<a name="line.1281"></a>
<span class="sourceLineNo">1282</span> * @param sizeStore The object tracking changes in region size for space quotas.<a name="line.1282"></a>
<span class="sourceLineNo">1283</span> * @param regionInfo The identifier for the region whose size is being updated.<a name="line.1283"></a>
<span class="sourceLineNo">1284</span> * @param oldFiles Files removed from this store's region.<a name="line.1284"></a>
<span class="sourceLineNo">1285</span> * @param newFiles Files added to this store's region.<a name="line.1285"></a>
<span class="sourceLineNo">1286</span> */<a name="line.1286"></a>
<span class="sourceLineNo">1287</span> void updateSpaceQuotaAfterFileReplacement(RegionSizeStore sizeStore, RegionInfo regionInfo,<a name="line.1287"></a>
<span class="sourceLineNo">1288</span> Collection&lt;HStoreFile&gt; oldFiles, Collection&lt;HStoreFile&gt; newFiles) {<a name="line.1288"></a>
<span class="sourceLineNo">1289</span> long delta = 0;<a name="line.1289"></a>
<span class="sourceLineNo">1290</span> if (oldFiles != null) {<a name="line.1290"></a>
<span class="sourceLineNo">1291</span> for (HStoreFile compactedFile : oldFiles) {<a name="line.1291"></a>
<span class="sourceLineNo">1292</span> if (compactedFile.isHFile()) {<a name="line.1292"></a>
<span class="sourceLineNo">1293</span> delta -= compactedFile.getReader().length();<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> if (newFiles != null) {<a name="line.1297"></a>
<span class="sourceLineNo">1298</span> for (HStoreFile newFile : newFiles) {<a name="line.1298"></a>
<span class="sourceLineNo">1299</span> if (newFile.isHFile()) {<a name="line.1299"></a>
<span class="sourceLineNo">1300</span> delta += newFile.getReader().length();<a name="line.1300"></a>
<span class="sourceLineNo">1301</span> }<a name="line.1301"></a>
<span class="sourceLineNo">1302</span> }<a name="line.1302"></a>
<span class="sourceLineNo">1303</span> }<a name="line.1303"></a>
<span class="sourceLineNo">1304</span> sizeStore.incrementRegionSize(regionInfo, delta);<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(CompactionRequestImpl cr, List&lt;HStoreFile&gt; sfs, long now,<a name="line.1313"></a>
<span class="sourceLineNo">1314</span> long compactionStartTime) {<a name="line.1314"></a>
<span class="sourceLineNo">1315</span> StringBuilder message = new StringBuilder("Completed" + (cr.isMajor() ? " major" : "")<a name="line.1315"></a>
<span class="sourceLineNo">1316</span> + " compaction of " + cr.getFiles().size() + (cr.isAllFiles() ? " (all)" : "")<a name="line.1316"></a>
<span class="sourceLineNo">1317</span> + " file(s) in " + this + " of " + this.getRegionInfo().getShortNameToLog() + " into ");<a name="line.1317"></a>
<span class="sourceLineNo">1318</span> if (sfs.isEmpty()) {<a name="line.1318"></a>
<span class="sourceLineNo">1319</span> message.append("none, ");<a name="line.1319"></a>
<span class="sourceLineNo">1320</span> } else {<a name="line.1320"></a>
<span class="sourceLineNo">1321</span> for (HStoreFile sf : sfs) {<a name="line.1321"></a>
<span class="sourceLineNo">1322</span> message.append(sf.getPath().getName());<a name="line.1322"></a>
<span class="sourceLineNo">1323</span> message.append("(size=");<a name="line.1323"></a>
<span class="sourceLineNo">1324</span> message.append(TraditionalBinaryPrefix.long2String(sf.getReader().length(), "", 1));<a name="line.1324"></a>
<span class="sourceLineNo">1325</span> message.append("), ");<a name="line.1325"></a>
<span class="sourceLineNo">1326</span> }<a name="line.1326"></a>
<span class="sourceLineNo">1327</span> }<a name="line.1327"></a>
<span class="sourceLineNo">1328</span> message.append("total size for store is ")<a name="line.1328"></a>
<span class="sourceLineNo">1329</span> .append(StringUtils.TraditionalBinaryPrefix.long2String(storeSize.get(), "", 1))<a name="line.1329"></a>
<span class="sourceLineNo">1330</span> .append(". This selection was in queue for ")<a name="line.1330"></a>
<span class="sourceLineNo">1331</span> .append(StringUtils.formatTimeDiff(compactionStartTime, cr.getSelectionTime()))<a name="line.1331"></a>
<span class="sourceLineNo">1332</span> .append(", and took ").append(StringUtils.formatTimeDiff(now, compactionStartTime))<a name="line.1332"></a>
<span class="sourceLineNo">1333</span> .append(" to execute.");<a name="line.1333"></a>
<span class="sourceLineNo">1334</span> LOG.info(message.toString());<a name="line.1334"></a>
<span class="sourceLineNo">1335</span> if (LOG.isTraceEnabled()) {<a name="line.1335"></a>
<span class="sourceLineNo">1336</span> int fileCount = storeEngine.getStoreFileManager().getStorefileCount();<a name="line.1336"></a>
<span class="sourceLineNo">1337</span> long resultSize = getTotalSize(sfs);<a name="line.1337"></a>
<span class="sourceLineNo">1338</span> String traceMessage = "COMPACTION start,end,size out,files in,files out,store size,"<a name="line.1338"></a>
<span class="sourceLineNo">1339</span> + "store files [" + compactionStartTime + "," + now + "," + resultSize + ","<a name="line.1339"></a>
<span class="sourceLineNo">1340</span> + cr.getFiles().size() + "," + sfs.size() + "," + storeSize + "," + fileCount + "]";<a name="line.1340"></a>
<span class="sourceLineNo">1341</span> LOG.trace(traceMessage);<a name="line.1341"></a>
<span class="sourceLineNo">1342</span> }<a name="line.1342"></a>
<span class="sourceLineNo">1343</span> }<a name="line.1343"></a>
<span class="sourceLineNo">1344</span><a name="line.1344"></a>
<span class="sourceLineNo">1345</span> /**<a name="line.1345"></a>
<span class="sourceLineNo">1346</span> * Call to complete a compaction. Its for the case where we find in the WAL a compaction that was<a name="line.1346"></a>
<span class="sourceLineNo">1347</span> * not finished. We could find one recovering a WAL after a regionserver crash. See HBASE-2231.<a name="line.1347"></a>
<span class="sourceLineNo">1348</span> */<a name="line.1348"></a>
<span class="sourceLineNo">1349</span> public void replayCompactionMarker(CompactionDescriptor compaction, boolean pickCompactionFiles,<a name="line.1349"></a>
<span class="sourceLineNo">1350</span> boolean removeFiles) throws IOException {<a name="line.1350"></a>
<span class="sourceLineNo">1351</span> LOG.debug("Completing compaction from the WAL marker");<a name="line.1351"></a>
<span class="sourceLineNo">1352</span> List&lt;String&gt; compactionInputs = compaction.getCompactionInputList();<a name="line.1352"></a>
<span class="sourceLineNo">1353</span> List&lt;String&gt; compactionOutputs = Lists.newArrayList(compaction.getCompactionOutputList());<a name="line.1353"></a>
<span class="sourceLineNo">1354</span><a name="line.1354"></a>
<span class="sourceLineNo">1355</span> // The Compaction Marker is written after the compaction is completed,<a name="line.1355"></a>
<span class="sourceLineNo">1356</span> // and the files moved into the region/family folder.<a name="line.1356"></a>
<span class="sourceLineNo">1357</span> //<a name="line.1357"></a>
<span class="sourceLineNo">1358</span> // If we crash after the entry is written, we may not have removed the<a name="line.1358"></a>
<span class="sourceLineNo">1359</span> // input files, but the output file is present.<a name="line.1359"></a>
<span class="sourceLineNo">1360</span> // (The unremoved input files will be removed by this function)<a name="line.1360"></a>
<span class="sourceLineNo">1361</span> //<a name="line.1361"></a>
<span class="sourceLineNo">1362</span> // If we scan the directory and the file is not present, it can mean that:<a name="line.1362"></a>
<span class="sourceLineNo">1363</span> // - The file was manually removed by the user<a name="line.1363"></a>
<span class="sourceLineNo">1364</span> // - The file was removed as consequence of subsequent compaction<a name="line.1364"></a>
<span class="sourceLineNo">1365</span> // so, we can't do anything with the "compaction output list" because those<a name="line.1365"></a>
<span class="sourceLineNo">1366</span> // files have already been loaded when opening the region (by virtue of<a name="line.1366"></a>
<span class="sourceLineNo">1367</span> // being in the store's folder) or they may be missing due to a compaction.<a name="line.1367"></a>
<span class="sourceLineNo">1368</span><a name="line.1368"></a>
<span class="sourceLineNo">1369</span> String familyName = this.getColumnFamilyName();<a name="line.1369"></a>
<span class="sourceLineNo">1370</span> Set&lt;String&gt; inputFiles = new HashSet&lt;&gt;();<a name="line.1370"></a>
<span class="sourceLineNo">1371</span> for (String compactionInput : compactionInputs) {<a name="line.1371"></a>
<span class="sourceLineNo">1372</span> Path inputPath = getRegionFileSystem().getStoreFilePath(familyName, compactionInput);<a name="line.1372"></a>
<span class="sourceLineNo">1373</span> inputFiles.add(inputPath.getName());<a name="line.1373"></a>
<span class="sourceLineNo">1374</span> }<a name="line.1374"></a>
<span class="sourceLineNo">1375</span><a name="line.1375"></a>
<span class="sourceLineNo">1376</span> // some of the input files might already be deleted<a name="line.1376"></a>
<span class="sourceLineNo">1377</span> List&lt;HStoreFile&gt; inputStoreFiles = new ArrayList&lt;&gt;(compactionInputs.size());<a name="line.1377"></a>
<span class="sourceLineNo">1378</span> for (HStoreFile sf : this.getStorefiles()) {<a name="line.1378"></a>
<span class="sourceLineNo">1379</span> if (inputFiles.contains(sf.getPath().getName())) {<a name="line.1379"></a>
<span class="sourceLineNo">1380</span> inputStoreFiles.add(sf);<a name="line.1380"></a>
<span class="sourceLineNo">1381</span> }<a name="line.1381"></a>
<span class="sourceLineNo">1382</span> }<a name="line.1382"></a>
<span class="sourceLineNo">1383</span><a name="line.1383"></a>
<span class="sourceLineNo">1384</span> // check whether we need to pick up the new files<a name="line.1384"></a>
<span class="sourceLineNo">1385</span> List&lt;HStoreFile&gt; outputStoreFiles = new ArrayList&lt;&gt;(compactionOutputs.size());<a name="line.1385"></a>
<span class="sourceLineNo">1386</span><a name="line.1386"></a>
<span class="sourceLineNo">1387</span> if (pickCompactionFiles) {<a name="line.1387"></a>
<span class="sourceLineNo">1388</span> for (HStoreFile sf : this.getStorefiles()) {<a name="line.1388"></a>
<span class="sourceLineNo">1389</span> compactionOutputs.remove(sf.getPath().getName());<a name="line.1389"></a>
<span class="sourceLineNo">1390</span> }<a name="line.1390"></a>
<span class="sourceLineNo">1391</span> for (String compactionOutput : compactionOutputs) {<a name="line.1391"></a>
<span class="sourceLineNo">1392</span> StoreFileInfo storeFileInfo =<a name="line.1392"></a>
<span class="sourceLineNo">1393</span> getRegionFileSystem().getStoreFileInfo(getColumnFamilyName(), compactionOutput);<a name="line.1393"></a>
<span class="sourceLineNo">1394</span> HStoreFile storeFile = storeEngine.createStoreFileAndReader(storeFileInfo);<a name="line.1394"></a>
<span class="sourceLineNo">1395</span> outputStoreFiles.add(storeFile);<a name="line.1395"></a>
<span class="sourceLineNo">1396</span> }<a name="line.1396"></a>
<span class="sourceLineNo">1397</span> }<a name="line.1397"></a>
<span class="sourceLineNo">1398</span><a name="line.1398"></a>
<span class="sourceLineNo">1399</span> if (!inputStoreFiles.isEmpty() || !outputStoreFiles.isEmpty()) {<a name="line.1399"></a>
<span class="sourceLineNo">1400</span> LOG.info("Replaying compaction marker, replacing input files: " + inputStoreFiles<a name="line.1400"></a>
<span class="sourceLineNo">1401</span> + " with output files : " + outputStoreFiles);<a name="line.1401"></a>
<span class="sourceLineNo">1402</span> this.replaceStoreFiles(inputStoreFiles, outputStoreFiles, false);<a name="line.1402"></a>
<span class="sourceLineNo">1403</span> this.refreshStoreSizeAndTotalBytes();<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> @Override<a name="line.1407"></a>
<span class="sourceLineNo">1408</span> public boolean hasReferences() {<a name="line.1408"></a>
<span class="sourceLineNo">1409</span> // Grab the read lock here, because we need to ensure that: only when the atomic<a name="line.1409"></a>
<span class="sourceLineNo">1410</span> // replaceStoreFiles(..) finished, we can get all the complete store file list.<a name="line.1410"></a>
<span class="sourceLineNo">1411</span> this.storeEngine.readLock();<a name="line.1411"></a>
<span class="sourceLineNo">1412</span> try {<a name="line.1412"></a>
<span class="sourceLineNo">1413</span> // Merge the current store files with compacted files here due to HBASE-20940.<a name="line.1413"></a>
<span class="sourceLineNo">1414</span> Collection&lt;HStoreFile&gt; allStoreFiles = new ArrayList&lt;&gt;(getStorefiles());<a name="line.1414"></a>
<span class="sourceLineNo">1415</span> allStoreFiles.addAll(getCompactedFiles());<a name="line.1415"></a>
<span class="sourceLineNo">1416</span> return StoreUtils.hasReferences(allStoreFiles);<a name="line.1416"></a>
<span class="sourceLineNo">1417</span> } finally {<a name="line.1417"></a>
<span class="sourceLineNo">1418</span> this.storeEngine.readUnlock();<a name="line.1418"></a>
<span class="sourceLineNo">1419</span> }<a name="line.1419"></a>
<span class="sourceLineNo">1420</span> }<a name="line.1420"></a>
<span class="sourceLineNo">1421</span><a name="line.1421"></a>
<span class="sourceLineNo">1422</span> /**<a name="line.1422"></a>
<span class="sourceLineNo">1423</span> * getter for CompactionProgress object<a name="line.1423"></a>
<span class="sourceLineNo">1424</span> * @return CompactionProgress object; can be null<a name="line.1424"></a>
<span class="sourceLineNo">1425</span> */<a name="line.1425"></a>
<span class="sourceLineNo">1426</span> public CompactionProgress getCompactionProgress() {<a name="line.1426"></a>
<span class="sourceLineNo">1427</span> return this.storeEngine.getCompactor().getProgress();<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> @Override<a name="line.1430"></a>
<span class="sourceLineNo">1431</span> public boolean shouldPerformMajorCompaction() throws IOException {<a name="line.1431"></a>
<span class="sourceLineNo">1432</span> for (HStoreFile sf : this.storeEngine.getStoreFileManager().getStoreFiles()) {<a name="line.1432"></a>
<span class="sourceLineNo">1433</span> // TODO: what are these reader checks all over the place?<a name="line.1433"></a>
<span class="sourceLineNo">1434</span> if (sf.getReader() == null) {<a name="line.1434"></a>
<span class="sourceLineNo">1435</span> LOG.debug("StoreFile {} has null Reader", sf);<a name="line.1435"></a>
<span class="sourceLineNo">1436</span> return false;<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> return storeEngine.getCompactionPolicy()<a name="line.1439"></a>
<span class="sourceLineNo">1440</span> .shouldPerformMajorCompaction(this.storeEngine.getStoreFileManager().getStoreFiles());<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> public Optional&lt;CompactionContext&gt; requestCompaction() throws IOException {<a name="line.1443"></a>
<span class="sourceLineNo">1444</span> return requestCompaction(NO_PRIORITY, CompactionLifeCycleTracker.DUMMY, null);<a name="line.1444"></a>
<span class="sourceLineNo">1445</span> }<a name="line.1445"></a>
<span class="sourceLineNo">1446</span><a name="line.1446"></a>
<span class="sourceLineNo">1447</span> public Optional&lt;CompactionContext&gt; requestCompaction(int priority,<a name="line.1447"></a>
<span class="sourceLineNo">1448</span> CompactionLifeCycleTracker tracker, User user) throws IOException {<a name="line.1448"></a>
<span class="sourceLineNo">1449</span> // don't even select for compaction if writes are disabled<a name="line.1449"></a>
<span class="sourceLineNo">1450</span> if (!this.areWritesEnabled()) {<a name="line.1450"></a>
<span class="sourceLineNo">1451</span> return Optional.empty();<a name="line.1451"></a>
<span class="sourceLineNo">1452</span> }<a name="line.1452"></a>
<span class="sourceLineNo">1453</span> // Before we do compaction, try to get rid of unneeded files to simplify things.<a name="line.1453"></a>
<span class="sourceLineNo">1454</span> removeUnneededFiles();<a name="line.1454"></a>
<span class="sourceLineNo">1455</span><a name="line.1455"></a>
<span class="sourceLineNo">1456</span> final CompactionContext compaction = storeEngine.createCompaction();<a name="line.1456"></a>
<span class="sourceLineNo">1457</span> CompactionRequestImpl request = null;<a name="line.1457"></a>
<span class="sourceLineNo">1458</span> this.storeEngine.readLock();<a name="line.1458"></a>
<span class="sourceLineNo">1459</span> try {<a name="line.1459"></a>
<span class="sourceLineNo">1460</span> synchronized (filesCompacting) {<a name="line.1460"></a>
<span class="sourceLineNo">1461</span> // First, see if coprocessor would want to override selection.<a name="line.1461"></a>
<span class="sourceLineNo">1462</span> if (this.getCoprocessorHost() != null) {<a name="line.1462"></a>
<span class="sourceLineNo">1463</span> final List&lt;HStoreFile&gt; candidatesForCoproc = compaction.preSelect(this.filesCompacting);<a name="line.1463"></a>
<span class="sourceLineNo">1464</span> boolean override =<a name="line.1464"></a>
<span class="sourceLineNo">1465</span> getCoprocessorHost().preCompactSelection(this, candidatesForCoproc, tracker, user);<a name="line.1465"></a>
<span class="sourceLineNo">1466</span> if (override) {<a name="line.1466"></a>
<span class="sourceLineNo">1467</span> // Coprocessor is overriding normal file selection.<a name="line.1467"></a>
<span class="sourceLineNo">1468</span> compaction.forceSelect(new CompactionRequestImpl(candidatesForCoproc));<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> // Normal case - coprocessor is not overriding file selection.<a name="line.1472"></a>
<span class="sourceLineNo">1473</span> if (!compaction.hasSelection()) {<a name="line.1473"></a>
<span class="sourceLineNo">1474</span> boolean isUserCompaction = priority == Store.PRIORITY_USER;<a name="line.1474"></a>
<span class="sourceLineNo">1475</span> boolean mayUseOffPeak =<a name="line.1475"></a>
<span class="sourceLineNo">1476</span> offPeakHours.isOffPeakHour() &amp;&amp; offPeakCompactionTracker.compareAndSet(false, true);<a name="line.1476"></a>
<span class="sourceLineNo">1477</span> try {<a name="line.1477"></a>
<span class="sourceLineNo">1478</span> compaction.select(this.filesCompacting, isUserCompaction, mayUseOffPeak,<a name="line.1478"></a>
<span class="sourceLineNo">1479</span> forceMajor &amp;&amp; filesCompacting.isEmpty());<a name="line.1479"></a>
<span class="sourceLineNo">1480</span> } catch (IOException e) {<a name="line.1480"></a>
<span class="sourceLineNo">1481</span> if (mayUseOffPeak) {<a name="line.1481"></a>
<span class="sourceLineNo">1482</span> offPeakCompactionTracker.set(false);<a name="line.1482"></a>
<span class="sourceLineNo">1483</span> }<a name="line.1483"></a>
<span class="sourceLineNo">1484</span> throw e;<a name="line.1484"></a>
<span class="sourceLineNo">1485</span> }<a name="line.1485"></a>
<span class="sourceLineNo">1486</span> assert compaction.hasSelection();<a name="line.1486"></a>
<span class="sourceLineNo">1487</span> if (mayUseOffPeak &amp;&amp; !compaction.getRequest().isOffPeak()) {<a name="line.1487"></a>
<span class="sourceLineNo">1488</span> // Compaction policy doesn't want to take advantage of off-peak.<a name="line.1488"></a>
<span class="sourceLineNo">1489</span> offPeakCompactionTracker.set(false);<a name="line.1489"></a>
<span class="sourceLineNo">1490</span> }<a name="line.1490"></a>
<span class="sourceLineNo">1491</span> }<a name="line.1491"></a>
<span class="sourceLineNo">1492</span> if (this.getCoprocessorHost() != null) {<a name="line.1492"></a>
<span class="sourceLineNo">1493</span> this.getCoprocessorHost().postCompactSelection(this,<a name="line.1493"></a>
<span class="sourceLineNo">1494</span> ImmutableList.copyOf(compaction.getRequest().getFiles()), tracker,<a name="line.1494"></a>
<span class="sourceLineNo">1495</span> compaction.getRequest(), user);<a name="line.1495"></a>
<span class="sourceLineNo">1496</span> }<a name="line.1496"></a>
<span class="sourceLineNo">1497</span> // Finally, we have the resulting files list. Check if we have any files at all.<a name="line.1497"></a>
<span class="sourceLineNo">1498</span> request = compaction.getRequest();<a name="line.1498"></a>
<span class="sourceLineNo">1499</span> Collection&lt;HStoreFile&gt; selectedFiles = request.getFiles();<a name="line.1499"></a>
<span class="sourceLineNo">1500</span> if (selectedFiles.isEmpty()) {<a name="line.1500"></a>
<span class="sourceLineNo">1501</span> return Optional.empty();<a name="line.1501"></a>
<span class="sourceLineNo">1502</span> }<a name="line.1502"></a>
<span class="sourceLineNo">1503</span><a name="line.1503"></a>
<span class="sourceLineNo">1504</span> addToCompactingFiles(selectedFiles);<a name="line.1504"></a>
<span class="sourceLineNo">1505</span><a name="line.1505"></a>
<span class="sourceLineNo">1506</span> // If we're enqueuing a major, clear the force flag.<a name="line.1506"></a>
<span class="sourceLineNo">1507</span> this.forceMajor = this.forceMajor &amp;&amp; !request.isMajor();<a name="line.1507"></a>
<span class="sourceLineNo">1508</span><a name="line.1508"></a>
<span class="sourceLineNo">1509</span> // Set common request properties.<a name="line.1509"></a>
<span class="sourceLineNo">1510</span> // Set priority, either override value supplied by caller or from store.<a name="line.1510"></a>
<span class="sourceLineNo">1511</span> final int compactionPriority =<a name="line.1511"></a>
<span class="sourceLineNo">1512</span> (priority != Store.NO_PRIORITY) ? priority : getCompactPriority();<a name="line.1512"></a>
<span class="sourceLineNo">1513</span> request.setPriority(compactionPriority);<a name="line.1513"></a>
<span class="sourceLineNo">1514</span><a name="line.1514"></a>
<span class="sourceLineNo">1515</span> if (request.isAfterSplit()) {<a name="line.1515"></a>
<span class="sourceLineNo">1516</span> // If the store belongs to recently splitted daughter regions, better we consider<a name="line.1516"></a>
<span class="sourceLineNo">1517</span> // them with the higher priority in the compaction queue.<a name="line.1517"></a>
<span class="sourceLineNo">1518</span> // Override priority if it is lower (higher int value) than<a name="line.1518"></a>
<span class="sourceLineNo">1519</span> // SPLIT_REGION_COMPACTION_PRIORITY<a name="line.1519"></a>
<span class="sourceLineNo">1520</span> final int splitHousekeepingPriority =<a name="line.1520"></a>
<span class="sourceLineNo">1521</span> Math.min(compactionPriority, SPLIT_REGION_COMPACTION_PRIORITY);<a name="line.1521"></a>
<span class="sourceLineNo">1522</span> request.setPriority(splitHousekeepingPriority);<a name="line.1522"></a>
<span class="sourceLineNo">1523</span> LOG.info(<a name="line.1523"></a>
<span class="sourceLineNo">1524</span> "Keeping/Overriding Compaction request priority to {} for CF {} since it"<a name="line.1524"></a>
<span class="sourceLineNo">1525</span> + " belongs to recently split daughter region {}",<a name="line.1525"></a>
<span class="sourceLineNo">1526</span> splitHousekeepingPriority, this.getColumnFamilyName(),<a name="line.1526"></a>
<span class="sourceLineNo">1527</span> getRegionInfo().getRegionNameAsString());<a name="line.1527"></a>
<span class="sourceLineNo">1528</span> }<a name="line.1528"></a>
<span class="sourceLineNo">1529</span> request.setDescription(getRegionInfo().getRegionNameAsString(), getColumnFamilyName());<a name="line.1529"></a>
<span class="sourceLineNo">1530</span> request.setTracker(tracker);<a name="line.1530"></a>
<span class="sourceLineNo">1531</span> }<a name="line.1531"></a>
<span class="sourceLineNo">1532</span> } finally {<a name="line.1532"></a>
<span class="sourceLineNo">1533</span> this.storeEngine.readUnlock();<a name="line.1533"></a>
<span class="sourceLineNo">1534</span> }<a name="line.1534"></a>
<span class="sourceLineNo">1535</span><a name="line.1535"></a>
<span class="sourceLineNo">1536</span> if (LOG.isDebugEnabled()) {<a name="line.1536"></a>
<span class="sourceLineNo">1537</span> LOG.debug(this + " is initiating " + (request.isMajor() ? "major" : "minor") + " compaction"<a name="line.1537"></a>
<span class="sourceLineNo">1538</span> + (request.isAllFiles() ? " (all files)" : ""));<a name="line.1538"></a>
<span class="sourceLineNo">1539</span> }<a name="line.1539"></a>
<span class="sourceLineNo">1540</span> this.region.reportCompactionRequestStart(request.isMajor());<a name="line.1540"></a>
<span class="sourceLineNo">1541</span> return Optional.of(compaction);<a name="line.1541"></a>
<span class="sourceLineNo">1542</span> }<a name="line.1542"></a>
<span class="sourceLineNo">1543</span><a name="line.1543"></a>
<span class="sourceLineNo">1544</span> /** Adds the files to compacting files. filesCompacting must be locked. */<a name="line.1544"></a>
<span class="sourceLineNo">1545</span> private void addToCompactingFiles(Collection&lt;HStoreFile&gt; filesToAdd) {<a name="line.1545"></a>
<span class="sourceLineNo">1546</span> if (CollectionUtils.isEmpty(filesToAdd)) {<a name="line.1546"></a>
<span class="sourceLineNo">1547</span> return;<a name="line.1547"></a>
<span class="sourceLineNo">1548</span> }<a name="line.1548"></a>
<span class="sourceLineNo">1549</span> // Check that we do not try to compact the same StoreFile twice.<a name="line.1549"></a>
<span class="sourceLineNo">1550</span> if (!Collections.disjoint(filesCompacting, filesToAdd)) {<a name="line.1550"></a>
<span class="sourceLineNo">1551</span> Preconditions.checkArgument(false, "%s overlaps with %s", filesToAdd, filesCompacting);<a name="line.1551"></a>
<span class="sourceLineNo">1552</span> }<a name="line.1552"></a>
<span class="sourceLineNo">1553</span> filesCompacting.addAll(filesToAdd);<a name="line.1553"></a>
<span class="sourceLineNo">1554</span> Collections.sort(filesCompacting, storeEngine.getStoreFileManager().getStoreFileComparator());<a name="line.1554"></a>
<span class="sourceLineNo">1555</span> }<a name="line.1555"></a>
<span class="sourceLineNo">1556</span><a name="line.1556"></a>
<span class="sourceLineNo">1557</span> private void removeUnneededFiles() throws IOException {<a name="line.1557"></a>
<span class="sourceLineNo">1558</span> if (!conf.getBoolean("hbase.store.delete.expired.storefile", true)) {<a name="line.1558"></a>
<span class="sourceLineNo">1559</span> return;<a name="line.1559"></a>
<span class="sourceLineNo">1560</span> }<a name="line.1560"></a>
<span class="sourceLineNo">1561</span> if (getColumnFamilyDescriptor().getMinVersions() &gt; 0) {<a name="line.1561"></a>
<span class="sourceLineNo">1562</span> LOG.debug("Skipping expired store file removal due to min version of {} being {}", this,<a name="line.1562"></a>
<span class="sourceLineNo">1563</span> getColumnFamilyDescriptor().getMinVersions());<a name="line.1563"></a>
<span class="sourceLineNo">1564</span> return;<a name="line.1564"></a>
<span class="sourceLineNo">1565</span> }<a name="line.1565"></a>
<span class="sourceLineNo">1566</span> this.storeEngine.readLock();<a name="line.1566"></a>
<span class="sourceLineNo">1567</span> Collection&lt;HStoreFile&gt; delSfs = null;<a name="line.1567"></a>
<span class="sourceLineNo">1568</span> try {<a name="line.1568"></a>
<span class="sourceLineNo">1569</span> synchronized (filesCompacting) {<a name="line.1569"></a>
<span class="sourceLineNo">1570</span> long cfTtl = getStoreFileTtl();<a name="line.1570"></a>
<span class="sourceLineNo">1571</span> if (cfTtl != Long.MAX_VALUE) {<a name="line.1571"></a>
<span class="sourceLineNo">1572</span> delSfs = storeEngine.getStoreFileManager()<a name="line.1572"></a>
<span class="sourceLineNo">1573</span> .getUnneededFiles(EnvironmentEdgeManager.currentTime() - cfTtl, filesCompacting);<a name="line.1573"></a>
<span class="sourceLineNo">1574</span> addToCompactingFiles(delSfs);<a name="line.1574"></a>
<span class="sourceLineNo">1575</span> }<a name="line.1575"></a>
<span class="sourceLineNo">1576</span> }<a name="line.1576"></a>
<span class="sourceLineNo">1577</span> } finally {<a name="line.1577"></a>
<span class="sourceLineNo">1578</span> this.storeEngine.readUnlock();<a name="line.1578"></a>
<span class="sourceLineNo">1579</span> }<a name="line.1579"></a>
<span class="sourceLineNo">1580</span><a name="line.1580"></a>
<span class="sourceLineNo">1581</span> if (CollectionUtils.isEmpty(delSfs)) {<a name="line.1581"></a>
<span class="sourceLineNo">1582</span> return;<a name="line.1582"></a>
<span class="sourceLineNo">1583</span> }<a name="line.1583"></a>
<span class="sourceLineNo">1584</span><a name="line.1584"></a>
<span class="sourceLineNo">1585</span> Collection&lt;HStoreFile&gt; newFiles = Collections.emptyList(); // No new files.<a name="line.1585"></a>
<span class="sourceLineNo">1586</span> replaceStoreFiles(delSfs, newFiles, true);<a name="line.1586"></a>
<span class="sourceLineNo">1587</span> refreshStoreSizeAndTotalBytes();<a name="line.1587"></a>
<span class="sourceLineNo">1588</span> LOG.info("Completed removal of " + delSfs.size() + " unnecessary (expired) file(s) in " + this<a name="line.1588"></a>
<span class="sourceLineNo">1589</span> + "; total size is " + TraditionalBinaryPrefix.long2String(storeSize.get(), "", 1));<a name="line.1589"></a>
<span class="sourceLineNo">1590</span> }<a name="line.1590"></a>
<span class="sourceLineNo">1591</span><a name="line.1591"></a>
<span class="sourceLineNo">1592</span> public void cancelRequestedCompaction(CompactionContext compaction) {<a name="line.1592"></a>
<span class="sourceLineNo">1593</span> finishCompactionRequest(compaction.getRequest());<a name="line.1593"></a>
<span class="sourceLineNo">1594</span> }<a name="line.1594"></a>
<span class="sourceLineNo">1595</span><a name="line.1595"></a>
<span class="sourceLineNo">1596</span> private void finishCompactionRequest(CompactionRequestImpl cr) {<a name="line.1596"></a>
<span class="sourceLineNo">1597</span> this.region.reportCompactionRequestEnd(cr.isMajor(), cr.getFiles().size(), cr.getSize());<a name="line.1597"></a>
<span class="sourceLineNo">1598</span> if (cr.isOffPeak()) {<a name="line.1598"></a>
<span class="sourceLineNo">1599</span> offPeakCompactionTracker.set(false);<a name="line.1599"></a>
<span class="sourceLineNo">1600</span> cr.setOffPeak(false);<a name="line.1600"></a>
<span class="sourceLineNo">1601</span> }<a name="line.1601"></a>
<span class="sourceLineNo">1602</span> synchronized (filesCompacting) {<a name="line.1602"></a>
<span class="sourceLineNo">1603</span> filesCompacting.removeAll(cr.getFiles());<a name="line.1603"></a>
<span class="sourceLineNo">1604</span> }<a name="line.1604"></a>
<span class="sourceLineNo">1605</span> // The tracker could be null, for example, we do not need to track the creation of store file<a name="line.1605"></a>
<span class="sourceLineNo">1606</span> // writer due to different implementation of SFT, or the compaction is canceled.<a name="line.1606"></a>
<span class="sourceLineNo">1607</span> if (cr.getWriterCreationTracker() != null) {<a name="line.1607"></a>
<span class="sourceLineNo">1608</span> storeFileWriterCreationTrackers.remove(cr.getWriterCreationTracker());<a name="line.1608"></a>
<span class="sourceLineNo">1609</span> }<a name="line.1609"></a>
<span class="sourceLineNo">1610</span> }<a name="line.1610"></a>
<span class="sourceLineNo">1611</span><a name="line.1611"></a>
<span class="sourceLineNo">1612</span> /**<a name="line.1612"></a>
<span class="sourceLineNo">1613</span> * Update counts.<a name="line.1613"></a>
<span class="sourceLineNo">1614</span> */<a name="line.1614"></a>
<span class="sourceLineNo">1615</span> protected void refreshStoreSizeAndTotalBytes() throws IOException {<a name="line.1615"></a>
<span class="sourceLineNo">1616</span> this.storeSize.set(0L);<a name="line.1616"></a>
<span class="sourceLineNo">1617</span> this.totalUncompressedBytes.set(0L);<a name="line.1617"></a>
<span class="sourceLineNo">1618</span> for (HStoreFile hsf : this.storeEngine.getStoreFileManager().getStoreFiles()) {<a name="line.1618"></a>
<span class="sourceLineNo">1619</span> StoreFileReader r = hsf.getReader();<a name="line.1619"></a>
<span class="sourceLineNo">1620</span> if (r == null) {<a name="line.1620"></a>
<span class="sourceLineNo">1621</span> LOG.debug("StoreFile {} has a null Reader", hsf);<a name="line.1621"></a>
<span class="sourceLineNo">1622</span> continue;<a name="line.1622"></a>
<span class="sourceLineNo">1623</span> }<a name="line.1623"></a>
<span class="sourceLineNo">1624</span> this.storeSize.addAndGet(r.length());<a name="line.1624"></a>
<span class="sourceLineNo">1625</span> this.totalUncompressedBytes.addAndGet(r.getTotalUncompressedBytes());<a name="line.1625"></a>
<span class="sourceLineNo">1626</span> }<a name="line.1626"></a>
<span class="sourceLineNo">1627</span> }<a name="line.1627"></a>
<span class="sourceLineNo">1628</span><a name="line.1628"></a>
<span class="sourceLineNo">1629</span> /*<a name="line.1629"></a>
<span class="sourceLineNo">1630</span> * @param wantedVersions How many versions were asked for.<a name="line.1630"></a>
<span class="sourceLineNo">1631</span> * @return wantedVersions or this families' {@link HConstants#VERSIONS}.<a name="line.1631"></a>
<span class="sourceLineNo">1632</span> */<a name="line.1632"></a>
<span class="sourceLineNo">1633</span> int versionsToReturn(final int wantedVersions) {<a name="line.1633"></a>
<span class="sourceLineNo">1634</span> if (wantedVersions &lt;= 0) {<a name="line.1634"></a>
<span class="sourceLineNo">1635</span> throw new IllegalArgumentException("Number of versions must be &gt; 0");<a name="line.1635"></a>
<span class="sourceLineNo">1636</span> }<a name="line.1636"></a>
<span class="sourceLineNo">1637</span> // Make sure we do not return more than maximum versions for this store.<a name="line.1637"></a>
<span class="sourceLineNo">1638</span> int maxVersions = getColumnFamilyDescriptor().getMaxVersions();<a name="line.1638"></a>
<span class="sourceLineNo">1639</span> return wantedVersions &gt; maxVersions ? maxVersions : wantedVersions;<a name="line.1639"></a>
<span class="sourceLineNo">1640</span> }<a name="line.1640"></a>
<span class="sourceLineNo">1641</span><a name="line.1641"></a>
<span class="sourceLineNo">1642</span> @Override<a name="line.1642"></a>
<span class="sourceLineNo">1643</span> public boolean canSplit() {<a name="line.1643"></a>
<span class="sourceLineNo">1644</span> // Not split-able if we find a reference store file present in the store.<a name="line.1644"></a>
<span class="sourceLineNo">1645</span> boolean result = !hasReferences();<a name="line.1645"></a>
<span class="sourceLineNo">1646</span> if (!result) {<a name="line.1646"></a>
<span class="sourceLineNo">1647</span> LOG.trace("Not splittable; has references: {}", this);<a name="line.1647"></a>
<span class="sourceLineNo">1648</span> }<a name="line.1648"></a>
<span class="sourceLineNo">1649</span> return result;<a name="line.1649"></a>
<span class="sourceLineNo">1650</span> }<a name="line.1650"></a>
<span class="sourceLineNo">1651</span><a name="line.1651"></a>
<span class="sourceLineNo">1652</span> /**<a name="line.1652"></a>
<span class="sourceLineNo">1653</span> * Determines if Store should be split.<a name="line.1653"></a>
<span class="sourceLineNo">1654</span> */<a name="line.1654"></a>
<span class="sourceLineNo">1655</span> public Optional&lt;byte[]&gt; getSplitPoint() {<a name="line.1655"></a>
<span class="sourceLineNo">1656</span> this.storeEngine.readLock();<a name="line.1656"></a>
<span class="sourceLineNo">1657</span> try {<a name="line.1657"></a>
<span class="sourceLineNo">1658</span> // Should already be enforced by the split policy!<a name="line.1658"></a>
<span class="sourceLineNo">1659</span> assert !this.getRegionInfo().isMetaRegion();<a name="line.1659"></a>
<span class="sourceLineNo">1660</span> // Not split-able if we find a reference store file present in the store.<a name="line.1660"></a>
<span class="sourceLineNo">1661</span> if (hasReferences()) {<a name="line.1661"></a>
<span class="sourceLineNo">1662</span> LOG.trace("Not splittable; has references: {}", this);<a name="line.1662"></a>
<span class="sourceLineNo">1663</span> return Optional.empty();<a name="line.1663"></a>
<span class="sourceLineNo">1664</span> }<a name="line.1664"></a>
<span class="sourceLineNo">1665</span> return this.storeEngine.getStoreFileManager().getSplitPoint();<a name="line.1665"></a>
<span class="sourceLineNo">1666</span> } catch (IOException e) {<a name="line.1666"></a>
<span class="sourceLineNo">1667</span> LOG.warn("Failed getting store size for {}", this, e);<a name="line.1667"></a>
<span class="sourceLineNo">1668</span> } finally {<a name="line.1668"></a>
<span class="sourceLineNo">1669</span> this.storeEngine.readUnlock();<a name="line.1669"></a>
<span class="sourceLineNo">1670</span> }<a name="line.1670"></a>
<span class="sourceLineNo">1671</span> return Optional.empty();<a name="line.1671"></a>
<span class="sourceLineNo">1672</span> }<a name="line.1672"></a>
<span class="sourceLineNo">1673</span><a name="line.1673"></a>
<span class="sourceLineNo">1674</span> @Override<a name="line.1674"></a>
<span class="sourceLineNo">1675</span> public long getLastCompactSize() {<a name="line.1675"></a>
<span class="sourceLineNo">1676</span> return this.lastCompactSize;<a name="line.1676"></a>
<span class="sourceLineNo">1677</span> }<a name="line.1677"></a>
<span class="sourceLineNo">1678</span><a name="line.1678"></a>
<span class="sourceLineNo">1679</span> @Override<a name="line.1679"></a>
<span class="sourceLineNo">1680</span> public long getSize() {<a name="line.1680"></a>
<span class="sourceLineNo">1681</span> return storeSize.get();<a name="line.1681"></a>
<span class="sourceLineNo">1682</span> }<a name="line.1682"></a>
<span class="sourceLineNo">1683</span><a name="line.1683"></a>
<span class="sourceLineNo">1684</span> public void triggerMajorCompaction() {<a name="line.1684"></a>
<span class="sourceLineNo">1685</span> this.forceMajor = true;<a name="line.1685"></a>
<span class="sourceLineNo">1686</span> }<a name="line.1686"></a>
<span class="sourceLineNo">1687</span><a name="line.1687"></a>
<span class="sourceLineNo">1688</span> //////////////////////////////////////////////////////////////////////////////<a name="line.1688"></a>
<span class="sourceLineNo">1689</span> // File administration<a name="line.1689"></a>
<span class="sourceLineNo">1690</span> //////////////////////////////////////////////////////////////////////////////<a name="line.1690"></a>
<span class="sourceLineNo">1691</span><a name="line.1691"></a>
<span class="sourceLineNo">1692</span> /**<a name="line.1692"></a>
<span class="sourceLineNo">1693</span> * Return a scanner for both the memstore and the HStore files. Assumes we are not in a<a name="line.1693"></a>
<span class="sourceLineNo">1694</span> * compaction.<a name="line.1694"></a>
<span class="sourceLineNo">1695</span> * @param scan Scan to apply when scanning the stores<a name="line.1695"></a>
<span class="sourceLineNo">1696</span> * @param targetCols columns to scan<a name="line.1696"></a>
<span class="sourceLineNo">1697</span> * @return a scanner over the current key values<a name="line.1697"></a>
<span class="sourceLineNo">1698</span> * @throws IOException on failure<a name="line.1698"></a>
<span class="sourceLineNo">1699</span> */<a name="line.1699"></a>
<span class="sourceLineNo">1700</span> public KeyValueScanner getScanner(Scan scan, final NavigableSet&lt;byte[]&gt; targetCols, long readPt)<a name="line.1700"></a>
<span class="sourceLineNo">1701</span> throws IOException {<a name="line.1701"></a>
<span class="sourceLineNo">1702</span> storeEngine.readLock();<a name="line.1702"></a>
<span class="sourceLineNo">1703</span> try {<a name="line.1703"></a>
<span class="sourceLineNo">1704</span> ScanInfo scanInfo;<a name="line.1704"></a>
<span class="sourceLineNo">1705</span> if (this.getCoprocessorHost() != null) {<a name="line.1705"></a>
<span class="sourceLineNo">1706</span> scanInfo = this.getCoprocessorHost().preStoreScannerOpen(this, scan);<a name="line.1706"></a>
<span class="sourceLineNo">1707</span> } else {<a name="line.1707"></a>
<span class="sourceLineNo">1708</span> scanInfo = getScanInfo();<a name="line.1708"></a>
<span class="sourceLineNo">1709</span> }<a name="line.1709"></a>
<span class="sourceLineNo">1710</span> return createScanner(scan, scanInfo, targetCols, readPt);<a name="line.1710"></a>
<span class="sourceLineNo">1711</span> } finally {<a name="line.1711"></a>
<span class="sourceLineNo">1712</span> storeEngine.readUnlock();<a name="line.1712"></a>
<span class="sourceLineNo">1713</span> }<a name="line.1713"></a>
<span class="sourceLineNo">1714</span> }<a name="line.1714"></a>
<span class="sourceLineNo">1715</span><a name="line.1715"></a>
<span class="sourceLineNo">1716</span> // HMobStore will override this method to return its own implementation.<a name="line.1716"></a>
<span class="sourceLineNo">1717</span> protected KeyValueScanner createScanner(Scan scan, ScanInfo scanInfo,<a name="line.1717"></a>
<span class="sourceLineNo">1718</span> NavigableSet&lt;byte[]&gt; targetCols, long readPt) throws IOException {<a name="line.1718"></a>
<span class="sourceLineNo">1719</span> return scan.isReversed()<a name="line.1719"></a>
<span class="sourceLineNo">1720</span> ? new ReversedStoreScanner(this, scanInfo, scan, targetCols, readPt)<a name="line.1720"></a>
<span class="sourceLineNo">1721</span> : new StoreScanner(this, scanInfo, scan, targetCols, readPt);<a name="line.1721"></a>
<span class="sourceLineNo">1722</span> }<a name="line.1722"></a>
<span class="sourceLineNo">1723</span><a name="line.1723"></a>
<span class="sourceLineNo">1724</span> /**<a name="line.1724"></a>
<span class="sourceLineNo">1725</span> * Recreates the scanners on the current list of active store file scanners<a name="line.1725"></a>
<span class="sourceLineNo">1726</span> * @param currentFileScanners the current set of active store file scanners<a name="line.1726"></a>
<span class="sourceLineNo">1727</span> * @param cacheBlocks cache the blocks or not<a name="line.1727"></a>
<span class="sourceLineNo">1728</span> * @param usePread use pread or not<a name="line.1728"></a>
<span class="sourceLineNo">1729</span> * @param isCompaction is the scanner for compaction<a name="line.1729"></a>
<span class="sourceLineNo">1730</span> * @param matcher the scan query matcher<a name="line.1730"></a>
<span class="sourceLineNo">1731</span> * @param startRow the scan's start row<a name="line.1731"></a>
<span class="sourceLineNo">1732</span> * @param includeStartRow should the scan include the start row<a name="line.1732"></a>
<span class="sourceLineNo">1733</span> * @param stopRow the scan's stop row<a name="line.1733"></a>
<span class="sourceLineNo">1734</span> * @param includeStopRow should the scan include the stop row<a name="line.1734"></a>
<span class="sourceLineNo">1735</span> * @param readPt the read point of the current scane<a name="line.1735"></a>
<span class="sourceLineNo">1736</span> * @param includeMemstoreScanner whether the current scanner should include memstorescanner<a name="line.1736"></a>
<span class="sourceLineNo">1737</span> * @return list of scanners recreated on the current Scanners<a name="line.1737"></a>
<span class="sourceLineNo">1738</span> */<a name="line.1738"></a>
<span class="sourceLineNo">1739</span> public List&lt;KeyValueScanner&gt; recreateScanners(List&lt;KeyValueScanner&gt; currentFileScanners,<a name="line.1739"></a>
<span class="sourceLineNo">1740</span> boolean cacheBlocks, boolean usePread, boolean isCompaction, ScanQueryMatcher matcher,<a name="line.1740"></a>
<span class="sourceLineNo">1741</span> byte[] startRow, boolean includeStartRow, byte[] stopRow, boolean includeStopRow, long readPt,<a name="line.1741"></a>
<span class="sourceLineNo">1742</span> boolean includeMemstoreScanner) throws IOException {<a name="line.1742"></a>
<span class="sourceLineNo">1743</span> this.storeEngine.readLock();<a name="line.1743"></a>
<span class="sourceLineNo">1744</span> try {<a name="line.1744"></a>
<span class="sourceLineNo">1745</span> Map&lt;String, HStoreFile&gt; name2File =<a name="line.1745"></a>
<span class="sourceLineNo">1746</span> new HashMap&lt;&gt;(getStorefilesCount() + getCompactedFilesCount());<a name="line.1746"></a>
<span class="sourceLineNo">1747</span> for (HStoreFile file : getStorefiles()) {<a name="line.1747"></a>
<span class="sourceLineNo">1748</span> name2File.put(file.getFileInfo().getActiveFileName(), file);<a name="line.1748"></a>
<span class="sourceLineNo">1749</span> }<a name="line.1749"></a>
<span class="sourceLineNo">1750</span> Collection&lt;HStoreFile&gt; compactedFiles = getCompactedFiles();<a name="line.1750"></a>
<span class="sourceLineNo">1751</span> for (HStoreFile file : IterableUtils.emptyIfNull(compactedFiles)) {<a name="line.1751"></a>
<span class="sourceLineNo">1752</span> name2File.put(file.getFileInfo().getActiveFileName(), file);<a name="line.1752"></a>
<span class="sourceLineNo">1753</span> }<a name="line.1753"></a>
<span class="sourceLineNo">1754</span> List&lt;HStoreFile&gt; filesToReopen = new ArrayList&lt;&gt;();<a name="line.1754"></a>
<span class="sourceLineNo">1755</span> for (KeyValueScanner kvs : currentFileScanners) {<a name="line.1755"></a>
<span class="sourceLineNo">1756</span> assert kvs.isFileScanner();<a name="line.1756"></a>
<span class="sourceLineNo">1757</span> if (kvs.peek() == null) {<a name="line.1757"></a>
<span class="sourceLineNo">1758</span> continue;<a name="line.1758"></a>
<span class="sourceLineNo">1759</span> }<a name="line.1759"></a>
<span class="sourceLineNo">1760</span> filesToReopen.add(name2File.get(kvs.getFilePath().getName()));<a name="line.1760"></a>
<span class="sourceLineNo">1761</span> }<a name="line.1761"></a>
<span class="sourceLineNo">1762</span> if (filesToReopen.isEmpty()) {<a name="line.1762"></a>
<span class="sourceLineNo">1763</span> return null;<a name="line.1763"></a>
<span class="sourceLineNo">1764</span> }<a name="line.1764"></a>
<span class="sourceLineNo">1765</span> return getScanners(filesToReopen, cacheBlocks, false, false, matcher, startRow,<a name="line.1765"></a>
<span class="sourceLineNo">1766</span> includeStartRow, stopRow, includeStopRow, readPt, false, false);<a name="line.1766"></a>
<span class="sourceLineNo">1767</span> } finally {<a name="line.1767"></a>
<span class="sourceLineNo">1768</span> this.storeEngine.readUnlock();<a name="line.1768"></a>
<span class="sourceLineNo">1769</span> }<a name="line.1769"></a>
<span class="sourceLineNo">1770</span> }<a name="line.1770"></a>
<span class="sourceLineNo">1771</span><a name="line.1771"></a>
<span class="sourceLineNo">1772</span> @Override<a name="line.1772"></a>
<span class="sourceLineNo">1773</span> public String toString() {<a name="line.1773"></a>
<span class="sourceLineNo">1774</span> return this.getRegionInfo().getShortNameToLog() + "/" + this.getColumnFamilyName();<a name="line.1774"></a>
<span class="sourceLineNo">1775</span> }<a name="line.1775"></a>
<span class="sourceLineNo">1776</span><a name="line.1776"></a>
<span class="sourceLineNo">1777</span> @Override<a name="line.1777"></a>
<span class="sourceLineNo">1778</span> public int getStorefilesCount() {<a name="line.1778"></a>
<span class="sourceLineNo">1779</span> return this.storeEngine.getStoreFileManager().getStorefileCount();<a name="line.1779"></a>
<span class="sourceLineNo">1780</span> }<a name="line.1780"></a>
<span class="sourceLineNo">1781</span><a name="line.1781"></a>
<span class="sourceLineNo">1782</span> @Override<a name="line.1782"></a>
<span class="sourceLineNo">1783</span> public int getCompactedFilesCount() {<a name="line.1783"></a>
<span class="sourceLineNo">1784</span> return this.storeEngine.getStoreFileManager().getCompactedFilesCount();<a name="line.1784"></a>
<span class="sourceLineNo">1785</span> }<a name="line.1785"></a>
<span class="sourceLineNo">1786</span><a name="line.1786"></a>
<span class="sourceLineNo">1787</span> private LongStream getStoreFileAgeStream() {<a name="line.1787"></a>
<span class="sourceLineNo">1788</span> return this.storeEngine.getStoreFileManager().getStoreFiles().stream().filter(sf -&gt; {<a name="line.1788"></a>
<span class="sourceLineNo">1789</span> if (sf.getReader() == null) {<a name="line.1789"></a>
<span class="sourceLineNo">1790</span> LOG.debug("StoreFile {} has a null Reader", sf);<a name="line.1790"></a>
<span class="sourceLineNo">1791</span> return false;<a name="line.1791"></a>
<span class="sourceLineNo">1792</span> } else {<a name="line.1792"></a>
<span class="sourceLineNo">1793</span> return true;<a name="line.1793"></a>
<span class="sourceLineNo">1794</span> }<a name="line.1794"></a>
<span class="sourceLineNo">1795</span> }).filter(HStoreFile::isHFile).mapToLong(sf -&gt; sf.getFileInfo().getCreatedTimestamp())<a name="line.1795"></a>
<span class="sourceLineNo">1796</span> .map(t -&gt; EnvironmentEdgeManager.currentTime() - t);<a name="line.1796"></a>
<span class="sourceLineNo">1797</span> }<a name="line.1797"></a>
<span class="sourceLineNo">1798</span><a name="line.1798"></a>
<span class="sourceLineNo">1799</span> @Override<a name="line.1799"></a>
<span class="sourceLineNo">1800</span> public OptionalLong getMaxStoreFileAge() {<a name="line.1800"></a>
<span class="sourceLineNo">1801</span> return getStoreFileAgeStream().max();<a name="line.1801"></a>
<span class="sourceLineNo">1802</span> }<a name="line.1802"></a>
<span class="sourceLineNo">1803</span><a name="line.1803"></a>
<span class="sourceLineNo">1804</span> @Override<a name="line.1804"></a>
<span class="sourceLineNo">1805</span> public OptionalLong getMinStoreFileAge() {<a name="line.1805"></a>
<span class="sourceLineNo">1806</span> return getStoreFileAgeStream().min();<a name="line.1806"></a>
<span class="sourceLineNo">1807</span> }<a name="line.1807"></a>
<span class="sourceLineNo">1808</span><a name="line.1808"></a>
<span class="sourceLineNo">1809</span> @Override<a name="line.1809"></a>
<span class="sourceLineNo">1810</span> public OptionalDouble getAvgStoreFileAge() {<a name="line.1810"></a>
<span class="sourceLineNo">1811</span> return getStoreFileAgeStream().average();<a name="line.1811"></a>
<span class="sourceLineNo">1812</span> }<a name="line.1812"></a>
<span class="sourceLineNo">1813</span><a name="line.1813"></a>
<span class="sourceLineNo">1814</span> @Override<a name="line.1814"></a>
<span class="sourceLineNo">1815</span> public long getNumReferenceFiles() {<a name="line.1815"></a>
<span class="sourceLineNo">1816</span> return this.storeEngine.getStoreFileManager().getStoreFiles().stream()<a name="line.1816"></a>
<span class="sourceLineNo">1817</span> .filter(HStoreFile::isReference).count();<a name="line.1817"></a>
<span class="sourceLineNo">1818</span> }<a name="line.1818"></a>
<span class="sourceLineNo">1819</span><a name="line.1819"></a>
<span class="sourceLineNo">1820</span> @Override<a name="line.1820"></a>
<span class="sourceLineNo">1821</span> public long getNumHFiles() {<a name="line.1821"></a>
<span class="sourceLineNo">1822</span> return this.storeEngine.getStoreFileManager().getStoreFiles().stream()<a name="line.1822"></a>
<span class="sourceLineNo">1823</span> .filter(HStoreFile::isHFile).count();<a name="line.1823"></a>
<span class="sourceLineNo">1824</span> }<a name="line.1824"></a>
<span class="sourceLineNo">1825</span><a name="line.1825"></a>
<span class="sourceLineNo">1826</span> @Override<a name="line.1826"></a>
<span class="sourceLineNo">1827</span> public long getStoreSizeUncompressed() {<a name="line.1827"></a>
<span class="sourceLineNo">1828</span> return this.totalUncompressedBytes.get();<a name="line.1828"></a>
<span class="sourceLineNo">1829</span> }<a name="line.1829"></a>
<span class="sourceLineNo">1830</span><a name="line.1830"></a>
<span class="sourceLineNo">1831</span> @Override<a name="line.1831"></a>
<span class="sourceLineNo">1832</span> public long getStorefilesSize() {<a name="line.1832"></a>
<span class="sourceLineNo">1833</span> // Include all StoreFiles<a name="line.1833"></a>
<span class="sourceLineNo">1834</span> return StoreUtils.getStorefilesSize(this.storeEngine.getStoreFileManager().getStoreFiles(),<a name="line.1834"></a>
<span class="sourceLineNo">1835</span> sf -&gt; true);<a name="line.1835"></a>
<span class="sourceLineNo">1836</span> }<a name="line.1836"></a>
<span class="sourceLineNo">1837</span><a name="line.1837"></a>
<span class="sourceLineNo">1838</span> @Override<a name="line.1838"></a>
<span class="sourceLineNo">1839</span> public long getHFilesSize() {<a name="line.1839"></a>
<span class="sourceLineNo">1840</span> // Include only StoreFiles which are HFiles<a name="line.1840"></a>
<span class="sourceLineNo">1841</span> return StoreUtils.getStorefilesSize(this.storeEngine.getStoreFileManager().getStoreFiles(),<a name="line.1841"></a>
<span class="sourceLineNo">1842</span> HStoreFile::isHFile);<a name="line.1842"></a>
<span class="sourceLineNo">1843</span> }<a name="line.1843"></a>
<span class="sourceLineNo">1844</span><a name="line.1844"></a>
<span class="sourceLineNo">1845</span> private long getStorefilesFieldSize(ToLongFunction&lt;StoreFileReader&gt; f) {<a name="line.1845"></a>
<span class="sourceLineNo">1846</span> return this.storeEngine.getStoreFileManager().getStoreFiles().stream()<a name="line.1846"></a>
<span class="sourceLineNo">1847</span> .mapToLong(file -&gt; StoreUtils.getStorefileFieldSize(file, f)).sum();<a name="line.1847"></a>
<span class="sourceLineNo">1848</span> }<a name="line.1848"></a>
<span class="sourceLineNo">1849</span><a name="line.1849"></a>
<span class="sourceLineNo">1850</span> @Override<a name="line.1850"></a>
<span class="sourceLineNo">1851</span> public long getStorefilesRootLevelIndexSize() {<a name="line.1851"></a>
<span class="sourceLineNo">1852</span> return getStorefilesFieldSize(StoreFileReader::indexSize);<a name="line.1852"></a>
<span class="sourceLineNo">1853</span> }<a name="line.1853"></a>
<span class="sourceLineNo">1854</span><a name="line.1854"></a>
<span class="sourceLineNo">1855</span> @Override<a name="line.1855"></a>
<span class="sourceLineNo">1856</span> public long getTotalStaticIndexSize() {<a name="line.1856"></a>
<span class="sourceLineNo">1857</span> return getStorefilesFieldSize(StoreFileReader::getUncompressedDataIndexSize);<a name="line.1857"></a>
<span class="sourceLineNo">1858</span> }<a name="line.1858"></a>
<span class="sourceLineNo">1859</span><a name="line.1859"></a>
<span class="sourceLineNo">1860</span> @Override<a name="line.1860"></a>
<span class="sourceLineNo">1861</span> public long getTotalStaticBloomSize() {<a name="line.1861"></a>
<span class="sourceLineNo">1862</span> return getStorefilesFieldSize(StoreFileReader::getTotalBloomSize);<a name="line.1862"></a>
<span class="sourceLineNo">1863</span> }<a name="line.1863"></a>
<span class="sourceLineNo">1864</span><a name="line.1864"></a>
<span class="sourceLineNo">1865</span> @Override<a name="line.1865"></a>
<span class="sourceLineNo">1866</span> public MemStoreSize getMemStoreSize() {<a name="line.1866"></a>
<span class="sourceLineNo">1867</span> return this.memstore.size();<a name="line.1867"></a>
<span class="sourceLineNo">1868</span> }<a name="line.1868"></a>
<span class="sourceLineNo">1869</span><a name="line.1869"></a>
<span class="sourceLineNo">1870</span> @Override<a name="line.1870"></a>
<span class="sourceLineNo">1871</span> public int getCompactPriority() {<a name="line.1871"></a>
<span class="sourceLineNo">1872</span> int priority = this.storeEngine.getStoreFileManager().getStoreCompactionPriority();<a name="line.1872"></a>
<span class="sourceLineNo">1873</span> if (priority == PRIORITY_USER) {<a name="line.1873"></a>
<span class="sourceLineNo">1874</span> LOG.warn("Compaction priority is USER despite there being no user compaction");<a name="line.1874"></a>
<span class="sourceLineNo">1875</span> }<a name="line.1875"></a>
<span class="sourceLineNo">1876</span> return priority;<a name="line.1876"></a>
<span class="sourceLineNo">1877</span> }<a name="line.1877"></a>
<span class="sourceLineNo">1878</span><a name="line.1878"></a>
<span class="sourceLineNo">1879</span> public boolean throttleCompaction(long compactionSize) {<a name="line.1879"></a>
<span class="sourceLineNo">1880</span> return storeEngine.getCompactionPolicy().throttleCompaction(compactionSize);<a name="line.1880"></a>
<span class="sourceLineNo">1881</span> }<a name="line.1881"></a>
<span class="sourceLineNo">1882</span><a name="line.1882"></a>
<span class="sourceLineNo">1883</span> public HRegion getHRegion() {<a name="line.1883"></a>
<span class="sourceLineNo">1884</span> return this.region;<a name="line.1884"></a>
<span class="sourceLineNo">1885</span> }<a name="line.1885"></a>
<span class="sourceLineNo">1886</span><a name="line.1886"></a>
<span class="sourceLineNo">1887</span> public RegionCoprocessorHost getCoprocessorHost() {<a name="line.1887"></a>
<span class="sourceLineNo">1888</span> return this.region.getCoprocessorHost();<a name="line.1888"></a>
<span class="sourceLineNo">1889</span> }<a name="line.1889"></a>
<span class="sourceLineNo">1890</span><a name="line.1890"></a>
<span class="sourceLineNo">1891</span> @Override<a name="line.1891"></a>
<span class="sourceLineNo">1892</span> public RegionInfo getRegionInfo() {<a name="line.1892"></a>
<span class="sourceLineNo">1893</span> return getRegionFileSystem().getRegionInfo();<a name="line.1893"></a>
<span class="sourceLineNo">1894</span> }<a name="line.1894"></a>
<span class="sourceLineNo">1895</span><a name="line.1895"></a>
<span class="sourceLineNo">1896</span> @Override<a name="line.1896"></a>
<span class="sourceLineNo">1897</span> public boolean areWritesEnabled() {<a name="line.1897"></a>
<span class="sourceLineNo">1898</span> return this.region.areWritesEnabled();<a name="line.1898"></a>
<span class="sourceLineNo">1899</span> }<a name="line.1899"></a>
<span class="sourceLineNo">1900</span><a name="line.1900"></a>
<span class="sourceLineNo">1901</span> @Override<a name="line.1901"></a>
<span class="sourceLineNo">1902</span> public long getSmallestReadPoint() {<a name="line.1902"></a>
<span class="sourceLineNo">1903</span> return this.region.getSmallestReadPoint();<a name="line.1903"></a>
<span class="sourceLineNo">1904</span> }<a name="line.1904"></a>
<span class="sourceLineNo">1905</span><a name="line.1905"></a>
<span class="sourceLineNo">1906</span> /**<a name="line.1906"></a>
<span class="sourceLineNo">1907</span> * Adds or replaces the specified KeyValues.<a name="line.1907"></a>
<span class="sourceLineNo">1908</span> * &lt;p&gt;<a name="line.1908"></a>
<span class="sourceLineNo">1909</span> * For each KeyValue specified, if a cell with the same row, family, and qualifier exists in<a name="line.1909"></a>
<span class="sourceLineNo">1910</span> * MemStore, it will be replaced. Otherwise, it will just be inserted to MemStore.<a name="line.1910"></a>
<span class="sourceLineNo">1911</span> * &lt;p&gt;<a name="line.1911"></a>
<span class="sourceLineNo">1912</span> * This operation is atomic on each KeyValue (row/family/qualifier) but not necessarily atomic<a name="line.1912"></a>
<span class="sourceLineNo">1913</span> * across all of them.<a name="line.1913"></a>
<span class="sourceLineNo">1914</span> * @param readpoint readpoint below which we can safely remove duplicate KVs<a name="line.1914"></a>
<span class="sourceLineNo">1915</span> */<a name="line.1915"></a>
<span class="sourceLineNo">1916</span> public void upsert(Iterable&lt;Cell&gt; cells, long readpoint, MemStoreSizing memstoreSizing) {<a name="line.1916"></a>
<span class="sourceLineNo">1917</span> this.storeEngine.readLock();<a name="line.1917"></a>
<span class="sourceLineNo">1918</span> try {<a name="line.1918"></a>
<span class="sourceLineNo">1919</span> this.memstore.upsert(cells, readpoint, memstoreSizing);<a name="line.1919"></a>
<span class="sourceLineNo">1920</span> } finally {<a name="line.1920"></a>
<span class="sourceLineNo">1921</span> this.storeEngine.readUnlock();<a name="line.1921"></a>
<span class="sourceLineNo">1922</span> }<a name="line.1922"></a>
<span class="sourceLineNo">1923</span> }<a name="line.1923"></a>
<span class="sourceLineNo">1924</span><a name="line.1924"></a>
<span class="sourceLineNo">1925</span> public StoreFlushContext createFlushContext(long cacheFlushId, FlushLifeCycleTracker tracker) {<a name="line.1925"></a>
<span class="sourceLineNo">1926</span> return new StoreFlusherImpl(cacheFlushId, tracker);<a name="line.1926"></a>
<span class="sourceLineNo">1927</span> }<a name="line.1927"></a>
<span class="sourceLineNo">1928</span><a name="line.1928"></a>
<span class="sourceLineNo">1929</span> private final class StoreFlusherImpl implements StoreFlushContext {<a name="line.1929"></a>
<span class="sourceLineNo">1930</span><a name="line.1930"></a>
<span class="sourceLineNo">1931</span> private final FlushLifeCycleTracker tracker;<a name="line.1931"></a>
<span class="sourceLineNo">1932</span> private final StoreFileWriterCreationTracker writerCreationTracker;<a name="line.1932"></a>
<span class="sourceLineNo">1933</span> private final long cacheFlushSeqNum;<a name="line.1933"></a>
<span class="sourceLineNo">1934</span> private MemStoreSnapshot snapshot;<a name="line.1934"></a>
<span class="sourceLineNo">1935</span> private List&lt;Path&gt; tempFiles;<a name="line.1935"></a>
<span class="sourceLineNo">1936</span> private List&lt;Path&gt; committedFiles;<a name="line.1936"></a>
<span class="sourceLineNo">1937</span> private long cacheFlushCount;<a name="line.1937"></a>
<span class="sourceLineNo">1938</span> private long cacheFlushSize;<a name="line.1938"></a>
<span class="sourceLineNo">1939</span> private long outputFileSize;<a name="line.1939"></a>
<span class="sourceLineNo">1940</span><a name="line.1940"></a>
<span class="sourceLineNo">1941</span> private StoreFlusherImpl(long cacheFlushSeqNum, FlushLifeCycleTracker tracker) {<a name="line.1941"></a>
<span class="sourceLineNo">1942</span> this.cacheFlushSeqNum = cacheFlushSeqNum;<a name="line.1942"></a>
<span class="sourceLineNo">1943</span> this.tracker = tracker;<a name="line.1943"></a>
<span class="sourceLineNo">1944</span> this.writerCreationTracker = storeFileWriterCreationTrackerFactory.get();<a name="line.1944"></a>
<span class="sourceLineNo">1945</span> }<a name="line.1945"></a>
<span class="sourceLineNo">1946</span><a name="line.1946"></a>
<span class="sourceLineNo">1947</span> /**<a name="line.1947"></a>
<span class="sourceLineNo">1948</span> * This is not thread safe. The caller should have a lock on the region or the store. If<a name="line.1948"></a>
<span class="sourceLineNo">1949</span> * necessary, the lock can be added with the patch provided in HBASE-10087<a name="line.1949"></a>
<span class="sourceLineNo">1950</span> */<a name="line.1950"></a>
<span class="sourceLineNo">1951</span> @Override<a name="line.1951"></a>
<span class="sourceLineNo">1952</span> public MemStoreSize prepare() {<a name="line.1952"></a>
<span class="sourceLineNo">1953</span> // passing the current sequence number of the wal - to allow bookkeeping in the memstore<a name="line.1953"></a>
<span class="sourceLineNo">1954</span> this.snapshot = memstore.snapshot();<a name="line.1954"></a>
<span class="sourceLineNo">1955</span> this.cacheFlushCount = snapshot.getCellsCount();<a name="line.1955"></a>
<span class="sourceLineNo">1956</span> this.cacheFlushSize = snapshot.getDataSize();<a name="line.1956"></a>
<span class="sourceLineNo">1957</span> committedFiles = new ArrayList&lt;&gt;(1);<a name="line.1957"></a>
<span class="sourceLineNo">1958</span> return snapshot.getMemStoreSize();<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> @Override<a name="line.1961"></a>
<span class="sourceLineNo">1962</span> public void flushCache(MonitoredTask status) throws IOException {<a name="line.1962"></a>
<span class="sourceLineNo">1963</span> RegionServerServices rsService = region.getRegionServerServices();<a name="line.1963"></a>
<span class="sourceLineNo">1964</span> ThroughputController throughputController =<a name="line.1964"></a>
<span class="sourceLineNo">1965</span> rsService == null ? null : rsService.getFlushThroughputController();<a name="line.1965"></a>
<span class="sourceLineNo">1966</span> // it could be null if we do not need to track the creation of store file writer due to<a name="line.1966"></a>
<span class="sourceLineNo">1967</span> // different SFT implementation.<a name="line.1967"></a>
<span class="sourceLineNo">1968</span> if (writerCreationTracker != null) {<a name="line.1968"></a>
<span class="sourceLineNo">1969</span> HStore.this.storeFileWriterCreationTrackers.add(writerCreationTracker);<a name="line.1969"></a>
<span class="sourceLineNo">1970</span> }<a name="line.1970"></a>
<span class="sourceLineNo">1971</span> tempFiles = HStore.this.flushCache(cacheFlushSeqNum, snapshot, status, throughputController,<a name="line.1971"></a>
<span class="sourceLineNo">1972</span> tracker, writerCreationTracker);<a name="line.1972"></a>
<span class="sourceLineNo">1973</span> }<a name="line.1973"></a>
<span class="sourceLineNo">1974</span><a name="line.1974"></a>
<span class="sourceLineNo">1975</span> @Override<a name="line.1975"></a>
<span class="sourceLineNo">1976</span> public boolean commit(MonitoredTask status) throws IOException {<a name="line.1976"></a>
<span class="sourceLineNo">1977</span> try {<a name="line.1977"></a>
<span class="sourceLineNo">1978</span> if (CollectionUtils.isEmpty(this.tempFiles)) {<a name="line.1978"></a>
<span class="sourceLineNo">1979</span> return false;<a name="line.1979"></a>
<span class="sourceLineNo">1980</span> }<a name="line.1980"></a>
<span class="sourceLineNo">1981</span> status.setStatus("Flushing " + this + ": reopening flushed file");<a name="line.1981"></a>
<span class="sourceLineNo">1982</span> List&lt;HStoreFile&gt; storeFiles = storeEngine.commitStoreFiles(tempFiles, false);<a name="line.1982"></a>
<span class="sourceLineNo">1983</span> for (HStoreFile sf : storeFiles) {<a name="line.1983"></a>
<span class="sourceLineNo">1984</span> StoreFileReader r = sf.getReader();<a name="line.1984"></a>
<span class="sourceLineNo">1985</span> if (LOG.isInfoEnabled()) {<a name="line.1985"></a>
<span class="sourceLineNo">1986</span> LOG.info("Added {}, entries={}, sequenceid={}, filesize={}", sf, r.getEntries(),<a name="line.1986"></a>
<span class="sourceLineNo">1987</span> cacheFlushSeqNum, TraditionalBinaryPrefix.long2String(r.length(), "", 1));<a name="line.1987"></a>
<span class="sourceLineNo">1988</span> }<a name="line.1988"></a>
<span class="sourceLineNo">1989</span> outputFileSize += r.length();<a name="line.1989"></a>
<span class="sourceLineNo">1990</span> storeSize.addAndGet(r.length());<a name="line.1990"></a>
<span class="sourceLineNo">1991</span> totalUncompressedBytes.addAndGet(r.getTotalUncompressedBytes());<a name="line.1991"></a>
<span class="sourceLineNo">1992</span> committedFiles.add(sf.getPath());<a name="line.1992"></a>
<span class="sourceLineNo">1993</span> }<a name="line.1993"></a>
<span class="sourceLineNo">1994</span><a name="line.1994"></a>
<span class="sourceLineNo">1995</span> flushedCellsCount.addAndGet(cacheFlushCount);<a name="line.1995"></a>
<span class="sourceLineNo">1996</span> flushedCellsSize.addAndGet(cacheFlushSize);<a name="line.1996"></a>
<span class="sourceLineNo">1997</span> flushedOutputFileSize.addAndGet(outputFileSize);<a name="line.1997"></a>
<span class="sourceLineNo">1998</span> // call coprocessor after we have done all the accounting above<a name="line.1998"></a>
<span class="sourceLineNo">1999</span> for (HStoreFile sf : storeFiles) {<a name="line.1999"></a>
<span class="sourceLineNo">2000</span> if (getCoprocessorHost() != null) {<a name="line.2000"></a>
<span class="sourceLineNo">2001</span> getCoprocessorHost().postFlush(HStore.this, sf, tracker);<a name="line.2001"></a>
<span class="sourceLineNo">2002</span> }<a name="line.2002"></a>
<span class="sourceLineNo">2003</span> }<a name="line.2003"></a>
<span class="sourceLineNo">2004</span> // Add new file to store files. Clear snapshot too while we have the Store write lock.<a name="line.2004"></a>
<span class="sourceLineNo">2005</span> return completeFlush(storeFiles, snapshot.getId());<a name="line.2005"></a>
<span class="sourceLineNo">2006</span> } finally {<a name="line.2006"></a>
<span class="sourceLineNo">2007</span> if (writerCreationTracker != null) {<a name="line.2007"></a>
<span class="sourceLineNo">2008</span> HStore.this.storeFileWriterCreationTrackers.remove(writerCreationTracker);<a name="line.2008"></a>
<span class="sourceLineNo">2009</span> }<a name="line.2009"></a>
<span class="sourceLineNo">2010</span> }<a name="line.2010"></a>
<span class="sourceLineNo">2011</span> }<a name="line.2011"></a>
<span class="sourceLineNo">2012</span><a name="line.2012"></a>
<span class="sourceLineNo">2013</span> @Override<a name="line.2013"></a>
<span class="sourceLineNo">2014</span> public long getOutputFileSize() {<a name="line.2014"></a>
<span class="sourceLineNo">2015</span> return outputFileSize;<a name="line.2015"></a>
<span class="sourceLineNo">2016</span> }<a name="line.2016"></a>
<span class="sourceLineNo">2017</span><a name="line.2017"></a>
<span class="sourceLineNo">2018</span> @Override<a name="line.2018"></a>
<span class="sourceLineNo">2019</span> public List&lt;Path&gt; getCommittedFiles() {<a name="line.2019"></a>
<span class="sourceLineNo">2020</span> return committedFiles;<a name="line.2020"></a>
<span class="sourceLineNo">2021</span> }<a name="line.2021"></a>
<span class="sourceLineNo">2022</span><a name="line.2022"></a>
<span class="sourceLineNo">2023</span> /**<a name="line.2023"></a>
<span class="sourceLineNo">2024</span> * Similar to commit, but called in secondary region replicas for replaying the flush cache from<a name="line.2024"></a>
<span class="sourceLineNo">2025</span> * primary region. Adds the new files to the store, and drops the snapshot depending on<a name="line.2025"></a>
<span class="sourceLineNo">2026</span> * dropMemstoreSnapshot argument.<a name="line.2026"></a>
<span class="sourceLineNo">2027</span> * @param fileNames names of the flushed files<a name="line.2027"></a>
<span class="sourceLineNo">2028</span> * @param dropMemstoreSnapshot whether to drop the prepared memstore snapshot<a name="line.2028"></a>
<span class="sourceLineNo">2029</span> */<a name="line.2029"></a>
<span class="sourceLineNo">2030</span> @Override<a name="line.2030"></a>
<span class="sourceLineNo">2031</span> public void replayFlush(List&lt;String&gt; fileNames, boolean dropMemstoreSnapshot)<a name="line.2031"></a>
<span class="sourceLineNo">2032</span> throws IOException {<a name="line.2032"></a>
<span class="sourceLineNo">2033</span> List&lt;HStoreFile&gt; storeFiles = new ArrayList&lt;&gt;(fileNames.size());<a name="line.2033"></a>
<span class="sourceLineNo">2034</span> for (String file : fileNames) {<a name="line.2034"></a>
<span class="sourceLineNo">2035</span> // open the file as a store file (hfile link, etc)<a name="line.2035"></a>
<span class="sourceLineNo">2036</span> StoreFileInfo storeFileInfo =<a name="line.2036"></a>
<span class="sourceLineNo">2037</span> getRegionFileSystem().getStoreFileInfo(getColumnFamilyName(), file);<a name="line.2037"></a>
<span class="sourceLineNo">2038</span> HStoreFile storeFile = storeEngine.createStoreFileAndReader(storeFileInfo);<a name="line.2038"></a>
<span class="sourceLineNo">2039</span> storeFiles.add(storeFile);<a name="line.2039"></a>
<span class="sourceLineNo">2040</span> HStore.this.storeSize.addAndGet(storeFile.getReader().length());<a name="line.2040"></a>
<span class="sourceLineNo">2041</span> HStore.this.totalUncompressedBytes<a name="line.2041"></a>
<span class="sourceLineNo">2042</span> .addAndGet(storeFile.getReader().getTotalUncompressedBytes());<a name="line.2042"></a>
<span class="sourceLineNo">2043</span> if (LOG.isInfoEnabled()) {<a name="line.2043"></a>
<span class="sourceLineNo">2044</span> LOG.info(this + " added " + storeFile + ", entries=" + storeFile.getReader().getEntries()<a name="line.2044"></a>
<span class="sourceLineNo">2045</span> + ", sequenceid=" + storeFile.getReader().getSequenceID() + ", filesize="<a name="line.2045"></a>
<span class="sourceLineNo">2046</span> + TraditionalBinaryPrefix.long2String(storeFile.getReader().length(), "", 1));<a name="line.2046"></a>
<span class="sourceLineNo">2047</span> }<a name="line.2047"></a>
<span class="sourceLineNo">2048</span> }<a name="line.2048"></a>
<span class="sourceLineNo">2049</span><a name="line.2049"></a>
<span class="sourceLineNo">2050</span> long snapshotId = -1; // -1 means do not drop<a name="line.2050"></a>
<span class="sourceLineNo">2051</span> if (dropMemstoreSnapshot &amp;&amp; snapshot != null) {<a name="line.2051"></a>
<span class="sourceLineNo">2052</span> snapshotId = snapshot.getId();<a name="line.2052"></a>
<span class="sourceLineNo">2053</span> }<a name="line.2053"></a>
<span class="sourceLineNo">2054</span> HStore.this.completeFlush(storeFiles, snapshotId);<a name="line.2054"></a>
<span class="sourceLineNo">2055</span> }<a name="line.2055"></a>
<span class="sourceLineNo">2056</span><a name="line.2056"></a>
<span class="sourceLineNo">2057</span> /**<a name="line.2057"></a>
<span class="sourceLineNo">2058</span> * Abort the snapshot preparation. Drops the snapshot if any.<a name="line.2058"></a>
<span class="sourceLineNo">2059</span> */<a name="line.2059"></a>
<span class="sourceLineNo">2060</span> @Override<a name="line.2060"></a>
<span class="sourceLineNo">2061</span> public void abort() throws IOException {<a name="line.2061"></a>
<span class="sourceLineNo">2062</span> if (snapshot != null) {<a name="line.2062"></a>
<span class="sourceLineNo">2063</span> HStore.this.completeFlush(Collections.emptyList(), snapshot.getId());<a name="line.2063"></a>
<span class="sourceLineNo">2064</span> }<a name="line.2064"></a>
<span class="sourceLineNo">2065</span> }<a name="line.2065"></a>
<span class="sourceLineNo">2066</span> }<a name="line.2066"></a>
<span class="sourceLineNo">2067</span><a name="line.2067"></a>
<span class="sourceLineNo">2068</span> @Override<a name="line.2068"></a>
<span class="sourceLineNo">2069</span> public boolean needsCompaction() {<a name="line.2069"></a>
<span class="sourceLineNo">2070</span> List&lt;HStoreFile&gt; filesCompactingClone = null;<a name="line.2070"></a>
<span class="sourceLineNo">2071</span> synchronized (filesCompacting) {<a name="line.2071"></a>
<span class="sourceLineNo">2072</span> filesCompactingClone = Lists.newArrayList(filesCompacting);<a name="line.2072"></a>
<span class="sourceLineNo">2073</span> }<a name="line.2073"></a>
<span class="sourceLineNo">2074</span> return this.storeEngine.needsCompaction(filesCompactingClone);<a name="line.2074"></a>
<span class="sourceLineNo">2075</span> }<a name="line.2075"></a>
<span class="sourceLineNo">2076</span><a name="line.2076"></a>
<span class="sourceLineNo">2077</span> /**<a name="line.2077"></a>
<span class="sourceLineNo">2078</span> * Used for tests.<a name="line.2078"></a>
<span class="sourceLineNo">2079</span> * @return cache configuration for this Store.<a name="line.2079"></a>
<span class="sourceLineNo">2080</span> */<a name="line.2080"></a>
<span class="sourceLineNo">2081</span> public CacheConfig getCacheConfig() {<a name="line.2081"></a>
<span class="sourceLineNo">2082</span> return storeContext.getCacheConf();<a name="line.2082"></a>
<span class="sourceLineNo">2083</span> }<a name="line.2083"></a>
<span class="sourceLineNo">2084</span><a name="line.2084"></a>
<span class="sourceLineNo">2085</span> public static final long FIXED_OVERHEAD = ClassSize.estimateBase(HStore.class, false);<a name="line.2085"></a>
<span class="sourceLineNo">2086</span><a name="line.2086"></a>
<span class="sourceLineNo">2087</span> public static final long DEEP_OVERHEAD = ClassSize.align(<a name="line.2087"></a>
<span class="sourceLineNo">2088</span> FIXED_OVERHEAD + ClassSize.OBJECT + ClassSize.REENTRANT_LOCK + ClassSize.CONCURRENT_SKIPLISTMAP<a name="line.2088"></a>
<span class="sourceLineNo">2089</span> + ClassSize.CONCURRENT_SKIPLISTMAP_ENTRY + ClassSize.OBJECT + ScanInfo.FIXED_OVERHEAD);<a name="line.2089"></a>
<span class="sourceLineNo">2090</span><a name="line.2090"></a>
<span class="sourceLineNo">2091</span> @Override<a name="line.2091"></a>
<span class="sourceLineNo">2092</span> public long heapSize() {<a name="line.2092"></a>
<span class="sourceLineNo">2093</span> MemStoreSize memstoreSize = this.memstore.size();<a name="line.2093"></a>
<span class="sourceLineNo">2094</span> return DEEP_OVERHEAD + memstoreSize.getHeapSize() + storeContext.heapSize();<a name="line.2094"></a>
<span class="sourceLineNo">2095</span> }<a name="line.2095"></a>
<span class="sourceLineNo">2096</span><a name="line.2096"></a>
<span class="sourceLineNo">2097</span> @Override<a name="line.2097"></a>
<span class="sourceLineNo">2098</span> public CellComparator getComparator() {<a name="line.2098"></a>
<span class="sourceLineNo">2099</span> return storeContext.getComparator();<a name="line.2099"></a>
<span class="sourceLineNo">2100</span> }<a name="line.2100"></a>
<span class="sourceLineNo">2101</span><a name="line.2101"></a>
<span class="sourceLineNo">2102</span> public ScanInfo getScanInfo() {<a name="line.2102"></a>
<span class="sourceLineNo">2103</span> return scanInfo;<a name="line.2103"></a>
<span class="sourceLineNo">2104</span> }<a name="line.2104"></a>
<span class="sourceLineNo">2105</span><a name="line.2105"></a>
<span class="sourceLineNo">2106</span> /**<a name="line.2106"></a>
<span class="sourceLineNo">2107</span> * Set scan info, used by test<a name="line.2107"></a>
<span class="sourceLineNo">2108</span> * @param scanInfo new scan info to use for test<a name="line.2108"></a>
<span class="sourceLineNo">2109</span> */<a name="line.2109"></a>
<span class="sourceLineNo">2110</span> void setScanInfo(ScanInfo scanInfo) {<a name="line.2110"></a>
<span class="sourceLineNo">2111</span> this.scanInfo = scanInfo;<a name="line.2111"></a>
<span class="sourceLineNo">2112</span> }<a name="line.2112"></a>
<span class="sourceLineNo">2113</span><a name="line.2113"></a>
<span class="sourceLineNo">2114</span> @Override<a name="line.2114"></a>
<span class="sourceLineNo">2115</span> public boolean hasTooManyStoreFiles() {<a name="line.2115"></a>
<span class="sourceLineNo">2116</span> return getStorefilesCount() &gt; this.blockingFileCount;<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> @Override<a name="line.2119"></a>
<span class="sourceLineNo">2120</span> public long getFlushedCellsCount() {<a name="line.2120"></a>
<span class="sourceLineNo">2121</span> return flushedCellsCount.get();<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> @Override<a name="line.2124"></a>
<span class="sourceLineNo">2125</span> public long getFlushedCellsSize() {<a name="line.2125"></a>
<span class="sourceLineNo">2126</span> return flushedCellsSize.get();<a name="line.2126"></a>
<span class="sourceLineNo">2127</span> }<a name="line.2127"></a>
<span class="sourceLineNo">2128</span><a name="line.2128"></a>
<span class="sourceLineNo">2129</span> @Override<a name="line.2129"></a>
<span class="sourceLineNo">2130</span> public long getFlushedOutputFileSize() {<a name="line.2130"></a>
<span class="sourceLineNo">2131</span> return flushedOutputFileSize.get();<a name="line.2131"></a>
<span class="sourceLineNo">2132</span> }<a name="line.2132"></a>
<span class="sourceLineNo">2133</span><a name="line.2133"></a>
<span class="sourceLineNo">2134</span> @Override<a name="line.2134"></a>
<span class="sourceLineNo">2135</span> public long getCompactedCellsCount() {<a name="line.2135"></a>
<span class="sourceLineNo">2136</span> return compactedCellsCount.get();<a name="line.2136"></a>
<span class="sourceLineNo">2137</span> }<a name="line.2137"></a>
<span class="sourceLineNo">2138</span><a name="line.2138"></a>
<span class="sourceLineNo">2139</span> @Override<a name="line.2139"></a>
<span class="sourceLineNo">2140</span> public long getCompactedCellsSize() {<a name="line.2140"></a>
<span class="sourceLineNo">2141</span> return compactedCellsSize.get();<a name="line.2141"></a>
<span class="sourceLineNo">2142</span> }<a name="line.2142"></a>
<span class="sourceLineNo">2143</span><a name="line.2143"></a>
<span class="sourceLineNo">2144</span> @Override<a name="line.2144"></a>
<span class="sourceLineNo">2145</span> public long getMajorCompactedCellsCount() {<a name="line.2145"></a>
<span class="sourceLineNo">2146</span> return majorCompactedCellsCount.get();<a name="line.2146"></a>
<span class="sourceLineNo">2147</span> }<a name="line.2147"></a>
<span class="sourceLineNo">2148</span><a name="line.2148"></a>
<span class="sourceLineNo">2149</span> @Override<a name="line.2149"></a>
<span class="sourceLineNo">2150</span> public long getMajorCompactedCellsSize() {<a name="line.2150"></a>
<span class="sourceLineNo">2151</span> return majorCompactedCellsSize.get();<a name="line.2151"></a>
<span class="sourceLineNo">2152</span> }<a name="line.2152"></a>
<span class="sourceLineNo">2153</span><a name="line.2153"></a>
<span class="sourceLineNo">2154</span> public void updateCompactedMetrics(boolean isMajor, CompactionProgress progress) {<a name="line.2154"></a>
<span class="sourceLineNo">2155</span> if (isMajor) {<a name="line.2155"></a>
<span class="sourceLineNo">2156</span> majorCompactedCellsCount.addAndGet(progress.getTotalCompactingKVs());<a name="line.2156"></a>
<span class="sourceLineNo">2157</span> majorCompactedCellsSize.addAndGet(progress.totalCompactedSize);<a name="line.2157"></a>
<span class="sourceLineNo">2158</span> } else {<a name="line.2158"></a>
<span class="sourceLineNo">2159</span> compactedCellsCount.addAndGet(progress.getTotalCompactingKVs());<a name="line.2159"></a>
<span class="sourceLineNo">2160</span> compactedCellsSize.addAndGet(progress.totalCompactedSize);<a name="line.2160"></a>
<span class="sourceLineNo">2161</span> }<a name="line.2161"></a>
<span class="sourceLineNo">2162</span> }<a name="line.2162"></a>
<span class="sourceLineNo">2163</span><a name="line.2163"></a>
<span class="sourceLineNo">2164</span> /**<a name="line.2164"></a>
<span class="sourceLineNo">2165</span> * Returns the StoreEngine that is backing this concrete implementation of Store.<a name="line.2165"></a>
<span class="sourceLineNo">2166</span> * @return Returns the {@link StoreEngine} object used internally inside this HStore object.<a name="line.2166"></a>
<span class="sourceLineNo">2167</span> */<a name="line.2167"></a>
<span class="sourceLineNo">2168</span> public StoreEngine&lt;?, ?, ?, ?&gt; getStoreEngine() {<a name="line.2168"></a>
<span class="sourceLineNo">2169</span> return this.storeEngine;<a name="line.2169"></a>
<span class="sourceLineNo">2170</span> }<a name="line.2170"></a>
<span class="sourceLineNo">2171</span><a name="line.2171"></a>
<span class="sourceLineNo">2172</span> protected OffPeakHours getOffPeakHours() {<a name="line.2172"></a>
<span class="sourceLineNo">2173</span> return this.offPeakHours;<a name="line.2173"></a>
<span class="sourceLineNo">2174</span> }<a name="line.2174"></a>
<span class="sourceLineNo">2175</span><a name="line.2175"></a>
<span class="sourceLineNo">2176</span> @Override<a name="line.2176"></a>
<span class="sourceLineNo">2177</span> public void onConfigurationChange(Configuration conf) {<a name="line.2177"></a>
<span class="sourceLineNo">2178</span> Configuration storeConf = StoreUtils.createStoreConfiguration(conf, region.getTableDescriptor(),<a name="line.2178"></a>
<span class="sourceLineNo">2179</span> getColumnFamilyDescriptor());<a name="line.2179"></a>
<span class="sourceLineNo">2180</span> this.conf = storeConf;<a name="line.2180"></a>
<span class="sourceLineNo">2181</span> this.storeEngine.compactionPolicy.setConf(storeConf);<a name="line.2181"></a>
<span class="sourceLineNo">2182</span> this.offPeakHours = OffPeakHours.getInstance(storeConf);<a name="line.2182"></a>
<span class="sourceLineNo">2183</span> }<a name="line.2183"></a>
<span class="sourceLineNo">2184</span><a name="line.2184"></a>
<span class="sourceLineNo">2185</span> /**<a name="line.2185"></a>
<span class="sourceLineNo">2186</span> * {@inheritDoc}<a name="line.2186"></a>
<span class="sourceLineNo">2187</span> */<a name="line.2187"></a>
<span class="sourceLineNo">2188</span> @Override<a name="line.2188"></a>
<span class="sourceLineNo">2189</span> public void registerChildren(ConfigurationManager manager) {<a name="line.2189"></a>
<span class="sourceLineNo">2190</span> CacheConfig cacheConfig = this.storeContext.getCacheConf();<a name="line.2190"></a>
<span class="sourceLineNo">2191</span> if (cacheConfig != null) {<a name="line.2191"></a>
<span class="sourceLineNo">2192</span> manager.registerObserver(cacheConfig);<a name="line.2192"></a>
<span class="sourceLineNo">2193</span> }<a name="line.2193"></a>
<span class="sourceLineNo">2194</span> }<a name="line.2194"></a>
<span class="sourceLineNo">2195</span><a name="line.2195"></a>
<span class="sourceLineNo">2196</span> /**<a name="line.2196"></a>
<span class="sourceLineNo">2197</span> * {@inheritDoc}<a name="line.2197"></a>
<span class="sourceLineNo">2198</span> */<a name="line.2198"></a>
<span class="sourceLineNo">2199</span> @Override<a name="line.2199"></a>
<span class="sourceLineNo">2200</span> public void deregisterChildren(ConfigurationManager manager) {<a name="line.2200"></a>
<span class="sourceLineNo">2201</span> // No children to deregister<a name="line.2201"></a>
<span class="sourceLineNo">2202</span> }<a name="line.2202"></a>
<span class="sourceLineNo">2203</span><a name="line.2203"></a>
<span class="sourceLineNo">2204</span> @Override<a name="line.2204"></a>
<span class="sourceLineNo">2205</span> public double getCompactionPressure() {<a name="line.2205"></a>
<span class="sourceLineNo">2206</span> return storeEngine.getStoreFileManager().getCompactionPressure();<a name="line.2206"></a>
<span class="sourceLineNo">2207</span> }<a name="line.2207"></a>
<span class="sourceLineNo">2208</span><a name="line.2208"></a>
<span class="sourceLineNo">2209</span> @Override<a name="line.2209"></a>
<span class="sourceLineNo">2210</span> public boolean isPrimaryReplicaStore() {<a name="line.2210"></a>
<span class="sourceLineNo">2211</span> return getRegionInfo().getReplicaId() == RegionInfo.DEFAULT_REPLICA_ID;<a name="line.2211"></a>
<span class="sourceLineNo">2212</span> }<a name="line.2212"></a>
<span class="sourceLineNo">2213</span><a name="line.2213"></a>
<span class="sourceLineNo">2214</span> /**<a name="line.2214"></a>
<span class="sourceLineNo">2215</span> * Sets the store up for a region level snapshot operation.<a name="line.2215"></a>
<span class="sourceLineNo">2216</span> * @see #postSnapshotOperation()<a name="line.2216"></a>
<span class="sourceLineNo">2217</span> */<a name="line.2217"></a>
<span class="sourceLineNo">2218</span> public void preSnapshotOperation() {<a name="line.2218"></a>
<span class="sourceLineNo">2219</span> archiveLock.lock();<a name="line.2219"></a>
<span class="sourceLineNo">2220</span> }<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> * Perform tasks needed after the completion of snapshot operation.<a name="line.2223"></a>
<span class="sourceLineNo">2224</span> * @see #preSnapshotOperation()<a name="line.2224"></a>
<span class="sourceLineNo">2225</span> */<a name="line.2225"></a>
<span class="sourceLineNo">2226</span> public void postSnapshotOperation() {<a name="line.2226"></a>
<span class="sourceLineNo">2227</span> archiveLock.unlock();<a name="line.2227"></a>
<span class="sourceLineNo">2228</span> }<a name="line.2228"></a>
<span class="sourceLineNo">2229</span><a name="line.2229"></a>
<span class="sourceLineNo">2230</span> /**<a name="line.2230"></a>
<span class="sourceLineNo">2231</span> * Closes and archives the compacted files under this store<a name="line.2231"></a>
<span class="sourceLineNo">2232</span> */<a name="line.2232"></a>
<span class="sourceLineNo">2233</span> public synchronized void closeAndArchiveCompactedFiles() throws IOException {<a name="line.2233"></a>
<span class="sourceLineNo">2234</span> // ensure other threads do not attempt to archive the same files on close()<a name="line.2234"></a>
<span class="sourceLineNo">2235</span> archiveLock.lock();<a name="line.2235"></a>
<span class="sourceLineNo">2236</span> try {<a name="line.2236"></a>
<span class="sourceLineNo">2237</span> storeEngine.readLock();<a name="line.2237"></a>
<span class="sourceLineNo">2238</span> Collection&lt;HStoreFile&gt; copyCompactedfiles = null;<a name="line.2238"></a>
<span class="sourceLineNo">2239</span> try {<a name="line.2239"></a>
<span class="sourceLineNo">2240</span> Collection&lt;HStoreFile&gt; compactedfiles =<a name="line.2240"></a>
<span class="sourceLineNo">2241</span> this.getStoreEngine().getStoreFileManager().getCompactedfiles();<a name="line.2241"></a>
<span class="sourceLineNo">2242</span> if (CollectionUtils.isNotEmpty(compactedfiles)) {<a name="line.2242"></a>
<span class="sourceLineNo">2243</span> // Do a copy under read lock<a name="line.2243"></a>
<span class="sourceLineNo">2244</span> copyCompactedfiles = new ArrayList&lt;&gt;(compactedfiles);<a name="line.2244"></a>
<span class="sourceLineNo">2245</span> } else {<a name="line.2245"></a>
<span class="sourceLineNo">2246</span> LOG.trace("No compacted files to archive");<a name="line.2246"></a>
<span class="sourceLineNo">2247</span> }<a name="line.2247"></a>
<span class="sourceLineNo">2248</span> } finally {<a name="line.2248"></a>
<span class="sourceLineNo">2249</span> storeEngine.readUnlock();<a name="line.2249"></a>
<span class="sourceLineNo">2250</span> }<a name="line.2250"></a>
<span class="sourceLineNo">2251</span> if (CollectionUtils.isNotEmpty(copyCompactedfiles)) {<a name="line.2251"></a>
<span class="sourceLineNo">2252</span> removeCompactedfiles(copyCompactedfiles, true);<a name="line.2252"></a>
<span class="sourceLineNo">2253</span> }<a name="line.2253"></a>
<span class="sourceLineNo">2254</span> } finally {<a name="line.2254"></a>
<span class="sourceLineNo">2255</span> archiveLock.unlock();<a name="line.2255"></a>
<span class="sourceLineNo">2256</span> }<a name="line.2256"></a>
<span class="sourceLineNo">2257</span> }<a name="line.2257"></a>
<span class="sourceLineNo">2258</span><a name="line.2258"></a>
<span class="sourceLineNo">2259</span> /**<a name="line.2259"></a>
<span class="sourceLineNo">2260</span> * Archives and removes the compacted files<a name="line.2260"></a>
<span class="sourceLineNo">2261</span> * @param compactedfiles The compacted files in this store that are not active in reads<a name="line.2261"></a>
<span class="sourceLineNo">2262</span> * @param evictOnClose true if blocks should be evicted from the cache when an HFile reader is<a name="line.2262"></a>
<span class="sourceLineNo">2263</span> * closed, false if not<a name="line.2263"></a>
<span class="sourceLineNo">2264</span> */<a name="line.2264"></a>
<span class="sourceLineNo">2265</span> private void removeCompactedfiles(Collection&lt;HStoreFile&gt; compactedfiles, boolean evictOnClose)<a name="line.2265"></a>
<span class="sourceLineNo">2266</span> throws IOException {<a name="line.2266"></a>
<span class="sourceLineNo">2267</span> final List&lt;HStoreFile&gt; filesToRemove = new ArrayList&lt;&gt;(compactedfiles.size());<a name="line.2267"></a>
<span class="sourceLineNo">2268</span> final List&lt;Long&gt; storeFileSizes = new ArrayList&lt;&gt;(compactedfiles.size());<a name="line.2268"></a>
<span class="sourceLineNo">2269</span> for (final HStoreFile file : compactedfiles) {<a name="line.2269"></a>
<span class="sourceLineNo">2270</span> synchronized (file) {<a name="line.2270"></a>
<span class="sourceLineNo">2271</span> try {<a name="line.2271"></a>
<span class="sourceLineNo">2272</span> StoreFileReader r = file.getReader();<a name="line.2272"></a>
<span class="sourceLineNo">2273</span> if (r == null) {<a name="line.2273"></a>
<span class="sourceLineNo">2274</span> LOG.debug("The file {} was closed but still not archived", file);<a name="line.2274"></a>
<span class="sourceLineNo">2275</span> // HACK: Temporarily re-open the reader so we can get the size of the file. Ideally,<a name="line.2275"></a>
<span class="sourceLineNo">2276</span> // we should know the size of an HStoreFile without having to ask the HStoreFileReader<a name="line.2276"></a>
<span class="sourceLineNo">2277</span> // for that.<a name="line.2277"></a>
<span class="sourceLineNo">2278</span> long length = getStoreFileSize(file);<a name="line.2278"></a>
<span class="sourceLineNo">2279</span> filesToRemove.add(file);<a name="line.2279"></a>
<span class="sourceLineNo">2280</span> storeFileSizes.add(length);<a name="line.2280"></a>
<span class="sourceLineNo">2281</span> continue;<a name="line.2281"></a>
<span class="sourceLineNo">2282</span> }<a name="line.2282"></a>
<span class="sourceLineNo">2283</span><a name="line.2283"></a>
<span class="sourceLineNo">2284</span> if (file.isCompactedAway() &amp;&amp; !file.isReferencedInReads()) {<a name="line.2284"></a>
<span class="sourceLineNo">2285</span> // Even if deleting fails we need not bother as any new scanners won't be<a name="line.2285"></a>
<span class="sourceLineNo">2286</span> // able to use the compacted file as the status is already compactedAway<a name="line.2286"></a>
<span class="sourceLineNo">2287</span> LOG.trace("Closing and archiving the file {}", file);<a name="line.2287"></a>
<span class="sourceLineNo">2288</span> // Copy the file size before closing the reader<a name="line.2288"></a>
<span class="sourceLineNo">2289</span> final long length = r.length();<a name="line.2289"></a>
<span class="sourceLineNo">2290</span> r.close(evictOnClose);<a name="line.2290"></a>
<span class="sourceLineNo">2291</span> // Just close and return<a name="line.2291"></a>
<span class="sourceLineNo">2292</span> filesToRemove.add(file);<a name="line.2292"></a>
<span class="sourceLineNo">2293</span> // Only add the length if we successfully added the file to `filesToRemove`<a name="line.2293"></a>
<span class="sourceLineNo">2294</span> storeFileSizes.add(length);<a name="line.2294"></a>
<span class="sourceLineNo">2295</span> } else {<a name="line.2295"></a>
<span class="sourceLineNo">2296</span> LOG.info("Can't archive compacted file " + file.getPath()<a name="line.2296"></a>
<span class="sourceLineNo">2297</span> + " because of either isCompactedAway=" + file.isCompactedAway()<a name="line.2297"></a>
<span class="sourceLineNo">2298</span> + " or file has reference, isReferencedInReads=" + file.isReferencedInReads()<a name="line.2298"></a>
<span class="sourceLineNo">2299</span> + ", refCount=" + r.getRefCount() + ", skipping for now.");<a name="line.2299"></a>
<span class="sourceLineNo">2300</span> }<a name="line.2300"></a>
<span class="sourceLineNo">2301</span> } catch (Exception e) {<a name="line.2301"></a>
<span class="sourceLineNo">2302</span> LOG.error("Exception while trying to close the compacted store file {}", file.getPath(),<a name="line.2302"></a>
<span class="sourceLineNo">2303</span> e);<a name="line.2303"></a>
<span class="sourceLineNo">2304</span> }<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 (this.isPrimaryReplicaStore()) {<a name="line.2307"></a>
<span class="sourceLineNo">2308</span> // Only the primary region is allowed to move the file to archive.<a name="line.2308"></a>
<span class="sourceLineNo">2309</span> // The secondary region does not move the files to archive. Any active reads from<a name="line.2309"></a>
<span class="sourceLineNo">2310</span> // the secondary region will still work because the file as such has active readers on it.<a name="line.2310"></a>
<span class="sourceLineNo">2311</span> if (!filesToRemove.isEmpty()) {<a name="line.2311"></a>
<span class="sourceLineNo">2312</span> LOG.debug("Moving the files {} to archive", filesToRemove);<a name="line.2312"></a>
<span class="sourceLineNo">2313</span> // Only if this is successful it has to be removed<a name="line.2313"></a>
<span class="sourceLineNo">2314</span> try {<a name="line.2314"></a>
<span class="sourceLineNo">2315</span> getRegionFileSystem().removeStoreFiles(this.getColumnFamilyDescriptor().getNameAsString(),<a name="line.2315"></a>
<span class="sourceLineNo">2316</span> filesToRemove);<a name="line.2316"></a>
<span class="sourceLineNo">2317</span> } catch (FailedArchiveException fae) {<a name="line.2317"></a>
<span class="sourceLineNo">2318</span> // Even if archiving some files failed, we still need to clear out any of the<a name="line.2318"></a>
<span class="sourceLineNo">2319</span> // files which were successfully archived. Otherwise we will receive a<a name="line.2319"></a>
<span class="sourceLineNo">2320</span> // FileNotFoundException when we attempt to re-archive them in the next go around.<a name="line.2320"></a>
<span class="sourceLineNo">2321</span> Collection&lt;Path&gt; failedFiles = fae.getFailedFiles();<a name="line.2321"></a>
<span class="sourceLineNo">2322</span> Iterator&lt;HStoreFile&gt; iter = filesToRemove.iterator();<a name="line.2322"></a>
<span class="sourceLineNo">2323</span> Iterator&lt;Long&gt; sizeIter = storeFileSizes.iterator();<a name="line.2323"></a>
<span class="sourceLineNo">2324</span> while (iter.hasNext()) {<a name="line.2324"></a>
<span class="sourceLineNo">2325</span> sizeIter.next();<a name="line.2325"></a>
<span class="sourceLineNo">2326</span> if (failedFiles.contains(iter.next().getPath())) {<a name="line.2326"></a>
<span class="sourceLineNo">2327</span> iter.remove();<a name="line.2327"></a>
<span class="sourceLineNo">2328</span> sizeIter.remove();<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> if (!filesToRemove.isEmpty()) {<a name="line.2331"></a>
<span class="sourceLineNo">2332</span> clearCompactedfiles(filesToRemove);<a name="line.2332"></a>
<span class="sourceLineNo">2333</span> }<a name="line.2333"></a>
<span class="sourceLineNo">2334</span> throw fae;<a name="line.2334"></a>
<span class="sourceLineNo">2335</span> }<a name="line.2335"></a>
<span class="sourceLineNo">2336</span> }<a name="line.2336"></a>
<span class="sourceLineNo">2337</span> }<a name="line.2337"></a>
<span class="sourceLineNo">2338</span> if (!filesToRemove.isEmpty()) {<a name="line.2338"></a>
<span class="sourceLineNo">2339</span> // Clear the compactedfiles from the store file manager<a name="line.2339"></a>
<span class="sourceLineNo">2340</span> clearCompactedfiles(filesToRemove);<a name="line.2340"></a>
<span class="sourceLineNo">2341</span> // Try to send report of this archival to the Master for updating quota usage faster<a name="line.2341"></a>
<span class="sourceLineNo">2342</span> reportArchivedFilesForQuota(filesToRemove, storeFileSizes);<a name="line.2342"></a>
<span class="sourceLineNo">2343</span> }<a name="line.2343"></a>
<span class="sourceLineNo">2344</span> }<a name="line.2344"></a>
<span class="sourceLineNo">2345</span><a name="line.2345"></a>
<span class="sourceLineNo">2346</span> /**<a name="line.2346"></a>
<span class="sourceLineNo">2347</span> * Computes the length of a store file without succumbing to any errors along the way. If an error<a name="line.2347"></a>
<span class="sourceLineNo">2348</span> * is encountered, the implementation returns {@code 0} instead of the actual size.<a name="line.2348"></a>
<span class="sourceLineNo">2349</span> * @param file The file to compute the size of.<a name="line.2349"></a>
<span class="sourceLineNo">2350</span> * @return The size in bytes of the provided {@code file}.<a name="line.2350"></a>
<span class="sourceLineNo">2351</span> */<a name="line.2351"></a>
<span class="sourceLineNo">2352</span> long getStoreFileSize(HStoreFile file) {<a name="line.2352"></a>
<span class="sourceLineNo">2353</span> long length = 0;<a name="line.2353"></a>
<span class="sourceLineNo">2354</span> try {<a name="line.2354"></a>
<span class="sourceLineNo">2355</span> file.initReader();<a name="line.2355"></a>
<span class="sourceLineNo">2356</span> length = file.getReader().length();<a name="line.2356"></a>
<span class="sourceLineNo">2357</span> } catch (IOException e) {<a name="line.2357"></a>
<span class="sourceLineNo">2358</span> LOG.trace("Failed to open reader when trying to compute store file size for {}, ignoring",<a name="line.2358"></a>
<span class="sourceLineNo">2359</span> file, e);<a name="line.2359"></a>
<span class="sourceLineNo">2360</span> } finally {<a name="line.2360"></a>
<span class="sourceLineNo">2361</span> try {<a name="line.2361"></a>
<span class="sourceLineNo">2362</span> file.closeStoreFile(<a name="line.2362"></a>
<span class="sourceLineNo">2363</span> file.getCacheConf() != null ? file.getCacheConf().shouldEvictOnClose() : true);<a name="line.2363"></a>
<span class="sourceLineNo">2364</span> } catch (IOException e) {<a name="line.2364"></a>
<span class="sourceLineNo">2365</span> LOG.trace("Failed to close reader after computing store file size for {}, ignoring", file,<a name="line.2365"></a>
<span class="sourceLineNo">2366</span> e);<a name="line.2366"></a>
<span class="sourceLineNo">2367</span> }<a name="line.2367"></a>
<span class="sourceLineNo">2368</span> }<a name="line.2368"></a>
<span class="sourceLineNo">2369</span> return length;<a name="line.2369"></a>
<span class="sourceLineNo">2370</span> }<a name="line.2370"></a>
<span class="sourceLineNo">2371</span><a name="line.2371"></a>
<span class="sourceLineNo">2372</span> public Long preFlushSeqIDEstimation() {<a name="line.2372"></a>
<span class="sourceLineNo">2373</span> return memstore.preFlushSeqIDEstimation();<a name="line.2373"></a>
<span class="sourceLineNo">2374</span> }<a name="line.2374"></a>
<span class="sourceLineNo">2375</span><a name="line.2375"></a>
<span class="sourceLineNo">2376</span> @Override<a name="line.2376"></a>
<span class="sourceLineNo">2377</span> public boolean isSloppyMemStore() {<a name="line.2377"></a>
<span class="sourceLineNo">2378</span> return this.memstore.isSloppy();<a name="line.2378"></a>
<span class="sourceLineNo">2379</span> }<a name="line.2379"></a>
<span class="sourceLineNo">2380</span><a name="line.2380"></a>
<span class="sourceLineNo">2381</span> private void clearCompactedfiles(List&lt;HStoreFile&gt; filesToRemove) throws IOException {<a name="line.2381"></a>
<span class="sourceLineNo">2382</span> LOG.trace("Clearing the compacted file {} from this store", filesToRemove);<a name="line.2382"></a>
<span class="sourceLineNo">2383</span> storeEngine.removeCompactedFiles(filesToRemove);<a name="line.2383"></a>
<span class="sourceLineNo">2384</span> }<a name="line.2384"></a>
<span class="sourceLineNo">2385</span><a name="line.2385"></a>
<span class="sourceLineNo">2386</span> void reportArchivedFilesForQuota(List&lt;? extends StoreFile&gt; archivedFiles, List&lt;Long&gt; fileSizes) {<a name="line.2386"></a>
<span class="sourceLineNo">2387</span> // Sanity check from the caller<a name="line.2387"></a>
<span class="sourceLineNo">2388</span> if (archivedFiles.size() != fileSizes.size()) {<a name="line.2388"></a>
<span class="sourceLineNo">2389</span> throw new RuntimeException("Coding error: should never see lists of varying size");<a name="line.2389"></a>
<span class="sourceLineNo">2390</span> }<a name="line.2390"></a>
<span class="sourceLineNo">2391</span> RegionServerServices rss = this.region.getRegionServerServices();<a name="line.2391"></a>
<span class="sourceLineNo">2392</span> if (rss == null) {<a name="line.2392"></a>
<span class="sourceLineNo">2393</span> return;<a name="line.2393"></a>
<span class="sourceLineNo">2394</span> }<a name="line.2394"></a>
<span class="sourceLineNo">2395</span> List&lt;Entry&lt;String, Long&gt;&gt; filesWithSizes = new ArrayList&lt;&gt;(archivedFiles.size());<a name="line.2395"></a>
<span class="sourceLineNo">2396</span> Iterator&lt;Long&gt; fileSizeIter = fileSizes.iterator();<a name="line.2396"></a>
<span class="sourceLineNo">2397</span> for (StoreFile storeFile : archivedFiles) {<a name="line.2397"></a>
<span class="sourceLineNo">2398</span> final long fileSize = fileSizeIter.next();<a name="line.2398"></a>
<span class="sourceLineNo">2399</span> if (storeFile.isHFile() &amp;&amp; fileSize != 0) {<a name="line.2399"></a>
<span class="sourceLineNo">2400</span> filesWithSizes.add(Maps.immutableEntry(storeFile.getPath().getName(), fileSize));<a name="line.2400"></a>
<span class="sourceLineNo">2401</span> }<a name="line.2401"></a>
<span class="sourceLineNo">2402</span> }<a name="line.2402"></a>
<span class="sourceLineNo">2403</span> if (LOG.isTraceEnabled()) {<a name="line.2403"></a>
<span class="sourceLineNo">2404</span> LOG.trace("Files archived: " + archivedFiles + ", reporting the following to the Master: "<a name="line.2404"></a>
<span class="sourceLineNo">2405</span> + filesWithSizes);<a name="line.2405"></a>
<span class="sourceLineNo">2406</span> }<a name="line.2406"></a>
<span class="sourceLineNo">2407</span> boolean success = rss.reportFileArchivalForQuotas(getTableName(), filesWithSizes);<a name="line.2407"></a>
<span class="sourceLineNo">2408</span> if (!success) {<a name="line.2408"></a>
<span class="sourceLineNo">2409</span> LOG.warn("Failed to report archival of files: " + filesWithSizes);<a name="line.2409"></a>
<span class="sourceLineNo">2410</span> }<a name="line.2410"></a>
<span class="sourceLineNo">2411</span> }<a name="line.2411"></a>
<span class="sourceLineNo">2412</span><a name="line.2412"></a>
<span class="sourceLineNo">2413</span> @Override<a name="line.2413"></a>
<span class="sourceLineNo">2414</span> public int getCurrentParallelPutCount() {<a name="line.2414"></a>
<span class="sourceLineNo">2415</span> return currentParallelPutCount.get();<a name="line.2415"></a>
<span class="sourceLineNo">2416</span> }<a name="line.2416"></a>
<span class="sourceLineNo">2417</span><a name="line.2417"></a>
<span class="sourceLineNo">2418</span> public int getStoreRefCount() {<a name="line.2418"></a>
<span class="sourceLineNo">2419</span> return this.storeEngine.getStoreFileManager().getStoreFiles().stream()<a name="line.2419"></a>
<span class="sourceLineNo">2420</span> .filter(sf -&gt; sf.getReader() != null).filter(HStoreFile::isHFile)<a name="line.2420"></a>
<span class="sourceLineNo">2421</span> .mapToInt(HStoreFile::getRefCount).sum();<a name="line.2421"></a>
<span class="sourceLineNo">2422</span> }<a name="line.2422"></a>
<span class="sourceLineNo">2423</span><a name="line.2423"></a>
<span class="sourceLineNo">2424</span> /** Returns get maximum ref count of storeFile among all compacted HStore Files for the HStore */<a name="line.2424"></a>
<span class="sourceLineNo">2425</span> public int getMaxCompactedStoreFileRefCount() {<a name="line.2425"></a>
<span class="sourceLineNo">2426</span> OptionalInt maxCompactedStoreFileRefCount = this.storeEngine.getStoreFileManager()<a name="line.2426"></a>
<span class="sourceLineNo">2427</span> .getCompactedfiles().stream().filter(sf -&gt; sf.getReader() != null).filter(HStoreFile::isHFile)<a name="line.2427"></a>
<span class="sourceLineNo">2428</span> .mapToInt(HStoreFile::getRefCount).max();<a name="line.2428"></a>
<span class="sourceLineNo">2429</span> return maxCompactedStoreFileRefCount.isPresent() ? maxCompactedStoreFileRefCount.getAsInt() : 0;<a name="line.2429"></a>
<span class="sourceLineNo">2430</span> }<a name="line.2430"></a>
<span class="sourceLineNo">2431</span><a name="line.2431"></a>
<span class="sourceLineNo">2432</span> @Override<a name="line.2432"></a>
<span class="sourceLineNo">2433</span> public long getMemstoreOnlyRowReadsCount() {<a name="line.2433"></a>
<span class="sourceLineNo">2434</span> return memstoreOnlyRowReadsCount.sum();<a name="line.2434"></a>
<span class="sourceLineNo">2435</span> }<a name="line.2435"></a>
<span class="sourceLineNo">2436</span><a name="line.2436"></a>
<span class="sourceLineNo">2437</span> @Override<a name="line.2437"></a>
<span class="sourceLineNo">2438</span> public long getMixedRowReadsCount() {<a name="line.2438"></a>
<span class="sourceLineNo">2439</span> return mixedRowReadsCount.sum();<a name="line.2439"></a>
<span class="sourceLineNo">2440</span> }<a name="line.2440"></a>
<span class="sourceLineNo">2441</span><a name="line.2441"></a>
<span class="sourceLineNo">2442</span> @Override<a name="line.2442"></a>
<span class="sourceLineNo">2443</span> public Configuration getReadOnlyConfiguration() {<a name="line.2443"></a>
<span class="sourceLineNo">2444</span> return new ReadOnlyConfiguration(this.conf);<a name="line.2444"></a>
<span class="sourceLineNo">2445</span> }<a name="line.2445"></a>
<span class="sourceLineNo">2446</span><a name="line.2446"></a>
<span class="sourceLineNo">2447</span> void updateMetricsStore(boolean memstoreRead) {<a name="line.2447"></a>
<span class="sourceLineNo">2448</span> if (memstoreRead) {<a name="line.2448"></a>
<span class="sourceLineNo">2449</span> memstoreOnlyRowReadsCount.increment();<a name="line.2449"></a>
<span class="sourceLineNo">2450</span> } else {<a name="line.2450"></a>
<span class="sourceLineNo">2451</span> mixedRowReadsCount.increment();<a name="line.2451"></a>
<span class="sourceLineNo">2452</span> }<a name="line.2452"></a>
<span class="sourceLineNo">2453</span> }<a name="line.2453"></a>
<span class="sourceLineNo">2454</span><a name="line.2454"></a>
<span class="sourceLineNo">2455</span> /**<a name="line.2455"></a>
<span class="sourceLineNo">2456</span> * Return the storefiles which are currently being written to. Mainly used by<a name="line.2456"></a>
<span class="sourceLineNo">2457</span> * {@link BrokenStoreFileCleaner} to prevent deleting the these files as they are not present in<a name="line.2457"></a>
<span class="sourceLineNo">2458</span> * SFT yet.<a name="line.2458"></a>
<span class="sourceLineNo">2459</span> */<a name="line.2459"></a>
<span class="sourceLineNo">2460</span> public Set&lt;Path&gt; getStoreFilesBeingWritten() {<a name="line.2460"></a>
<span class="sourceLineNo">2461</span> return storeFileWriterCreationTrackers.stream().flatMap(t -&gt; t.get().stream())<a name="line.2461"></a>
<span class="sourceLineNo">2462</span> .collect(Collectors.toSet());<a name="line.2462"></a>
<span class="sourceLineNo">2463</span> }<a name="line.2463"></a>
<span class="sourceLineNo">2464</span><a name="line.2464"></a>
<span class="sourceLineNo">2465</span> @Override<a name="line.2465"></a>
<span class="sourceLineNo">2466</span> public long getBloomFilterRequestsCount() {<a name="line.2466"></a>
<span class="sourceLineNo">2467</span> return storeEngine.getBloomFilterMetrics().getRequestsCount();<a name="line.2467"></a>
<span class="sourceLineNo">2468</span> }<a name="line.2468"></a>
<span class="sourceLineNo">2469</span><a name="line.2469"></a>
<span class="sourceLineNo">2470</span> @Override<a name="line.2470"></a>
<span class="sourceLineNo">2471</span> public long getBloomFilterNegativeResultsCount() {<a name="line.2471"></a>
<span class="sourceLineNo">2472</span> return storeEngine.getBloomFilterMetrics().getNegativeResultsCount();<a name="line.2472"></a>
<span class="sourceLineNo">2473</span> }<a name="line.2473"></a>
<span class="sourceLineNo">2474</span><a name="line.2474"></a>
<span class="sourceLineNo">2475</span> @Override<a name="line.2475"></a>
<span class="sourceLineNo">2476</span> public long getBloomFilterEligibleRequestsCount() {<a name="line.2476"></a>
<span class="sourceLineNo">2477</span> return storeEngine.getBloomFilterMetrics().getEligibleRequestsCount();<a name="line.2477"></a>
<span class="sourceLineNo">2478</span> }<a name="line.2478"></a>
<span class="sourceLineNo">2479</span>}<a name="line.2479"></a>
</pre>
</div>
</body>
</html>