hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [26/51] [partial] hbase-site git commit: Published site at 82d554e3783372cc6b05489452c815b57c06f6cd.
Date Sat, 03 Jun 2017 14:59:54 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/c9d35424/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFile.FileInfo.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFile.FileInfo.html b/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFile.FileInfo.html
index b6c2fe3..1765903 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFile.FileInfo.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFile.FileInfo.html
@@ -60,892 +60,917 @@
 <span class="sourceLineNo">052</span>import org.apache.hadoop.hbase.classification.InterfaceAudience;<a name="line.52"></a>
 <span class="sourceLineNo">053</span>import org.apache.hadoop.hbase.fs.HFileSystem;<a name="line.53"></a>
 <span class="sourceLineNo">054</span>import org.apache.hadoop.hbase.io.FSDataInputStreamWrapper;<a name="line.54"></a>
-<span class="sourceLineNo">055</span>import org.apache.hadoop.hbase.io.compress.Compression;<a name="line.55"></a>
-<span class="sourceLineNo">056</span>import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;<a name="line.56"></a>
-<span class="sourceLineNo">057</span>import org.apache.hadoop.hbase.protobuf.ProtobufMagic;<a name="line.57"></a>
-<span class="sourceLineNo">058</span>import org.apache.hadoop.hbase.regionserver.CellSink;<a name="line.58"></a>
-<span class="sourceLineNo">059</span>import org.apache.hadoop.hbase.regionserver.ShipperListener;<a name="line.59"></a>
-<span class="sourceLineNo">060</span>import org.apache.hadoop.hbase.shaded.com.google.protobuf.UnsafeByteOperations;<a name="line.60"></a>
-<span class="sourceLineNo">061</span>import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;<a name="line.61"></a>
-<span class="sourceLineNo">062</span>import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos;<a name="line.62"></a>
-<span class="sourceLineNo">063</span>import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.BytesBytesPair;<a name="line.63"></a>
-<span class="sourceLineNo">064</span>import org.apache.hadoop.hbase.shaded.protobuf.generated.HFileProtos;<a name="line.64"></a>
-<span class="sourceLineNo">065</span>import org.apache.hadoop.hbase.util.BloomFilterWriter;<a name="line.65"></a>
-<span class="sourceLineNo">066</span>import org.apache.hadoop.hbase.util.Bytes;<a name="line.66"></a>
-<span class="sourceLineNo">067</span>import org.apache.hadoop.hbase.util.FSUtils;<a name="line.67"></a>
-<span class="sourceLineNo">068</span>import org.apache.hadoop.io.Writable;<a name="line.68"></a>
-<span class="sourceLineNo">069</span><a name="line.69"></a>
-<span class="sourceLineNo">070</span>import com.google.common.annotations.VisibleForTesting;<a name="line.70"></a>
-<span class="sourceLineNo">071</span>import com.google.common.base.Preconditions;<a name="line.71"></a>
-<span class="sourceLineNo">072</span><a name="line.72"></a>
-<span class="sourceLineNo">073</span>/**<a name="line.73"></a>
-<span class="sourceLineNo">074</span> * File format for hbase.<a name="line.74"></a>
-<span class="sourceLineNo">075</span> * A file of sorted key/value pairs. Both keys and values are byte arrays.<a name="line.75"></a>
-<span class="sourceLineNo">076</span> * &lt;p&gt;<a name="line.76"></a>
-<span class="sourceLineNo">077</span> * The memory footprint of a HFile includes the following (below is taken from the<a name="line.77"></a>
-<span class="sourceLineNo">078</span> * &lt;a<a name="line.78"></a>
-<span class="sourceLineNo">079</span> * href=https://issues.apache.org/jira/browse/HADOOP-3315&gt;TFile&lt;/a&gt; documentation<a name="line.79"></a>
-<span class="sourceLineNo">080</span> * but applies also to HFile):<a name="line.80"></a>
-<span class="sourceLineNo">081</span> * &lt;ul&gt;<a name="line.81"></a>
-<span class="sourceLineNo">082</span> * &lt;li&gt;Some constant overhead of reading or writing a compressed block.<a name="line.82"></a>
+<span class="sourceLineNo">055</span>import org.apache.hadoop.hbase.io.MetricsIO;<a name="line.55"></a>
+<span class="sourceLineNo">056</span>import org.apache.hadoop.hbase.io.MetricsIOWrapperImpl;<a name="line.56"></a>
+<span class="sourceLineNo">057</span>import org.apache.hadoop.hbase.io.compress.Compression;<a name="line.57"></a>
+<span class="sourceLineNo">058</span>import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;<a name="line.58"></a>
+<span class="sourceLineNo">059</span>import org.apache.hadoop.hbase.protobuf.ProtobufMagic;<a name="line.59"></a>
+<span class="sourceLineNo">060</span>import org.apache.hadoop.hbase.regionserver.CellSink;<a name="line.60"></a>
+<span class="sourceLineNo">061</span>import org.apache.hadoop.hbase.regionserver.ShipperListener;<a name="line.61"></a>
+<span class="sourceLineNo">062</span>import org.apache.hadoop.hbase.shaded.com.google.protobuf.UnsafeByteOperations;<a name="line.62"></a>
+<span class="sourceLineNo">063</span>import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;<a name="line.63"></a>
+<span class="sourceLineNo">064</span>import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos;<a name="line.64"></a>
+<span class="sourceLineNo">065</span>import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.BytesBytesPair;<a name="line.65"></a>
+<span class="sourceLineNo">066</span>import org.apache.hadoop.hbase.shaded.protobuf.generated.HFileProtos;<a name="line.66"></a>
+<span class="sourceLineNo">067</span>import org.apache.hadoop.hbase.util.BloomFilterWriter;<a name="line.67"></a>
+<span class="sourceLineNo">068</span>import org.apache.hadoop.hbase.util.Bytes;<a name="line.68"></a>
+<span class="sourceLineNo">069</span>import org.apache.hadoop.hbase.util.FSUtils;<a name="line.69"></a>
+<span class="sourceLineNo">070</span>import org.apache.hadoop.io.Writable;<a name="line.70"></a>
+<span class="sourceLineNo">071</span><a name="line.71"></a>
+<span class="sourceLineNo">072</span>import com.google.common.annotations.VisibleForTesting;<a name="line.72"></a>
+<span class="sourceLineNo">073</span>import com.google.common.base.Preconditions;<a name="line.73"></a>
+<span class="sourceLineNo">074</span><a name="line.74"></a>
+<span class="sourceLineNo">075</span>/**<a name="line.75"></a>
+<span class="sourceLineNo">076</span> * File format for hbase.<a name="line.76"></a>
+<span class="sourceLineNo">077</span> * A file of sorted key/value pairs. Both keys and values are byte arrays.<a name="line.77"></a>
+<span class="sourceLineNo">078</span> * &lt;p&gt;<a name="line.78"></a>
+<span class="sourceLineNo">079</span> * The memory footprint of a HFile includes the following (below is taken from the<a name="line.79"></a>
+<span class="sourceLineNo">080</span> * &lt;a<a name="line.80"></a>
+<span class="sourceLineNo">081</span> * href=https://issues.apache.org/jira/browse/HADOOP-3315&gt;TFile&lt;/a&gt; documentation<a name="line.81"></a>
+<span class="sourceLineNo">082</span> * but applies also to HFile):<a name="line.82"></a>
 <span class="sourceLineNo">083</span> * &lt;ul&gt;<a name="line.83"></a>
-<span class="sourceLineNo">084</span> * &lt;li&gt;Each compressed block requires one compression/decompression codec for<a name="line.84"></a>
-<span class="sourceLineNo">085</span> * I/O.<a name="line.85"></a>
-<span class="sourceLineNo">086</span> * &lt;li&gt;Temporary space to buffer the key.<a name="line.86"></a>
-<span class="sourceLineNo">087</span> * &lt;li&gt;Temporary space to buffer the value.<a name="line.87"></a>
-<span class="sourceLineNo">088</span> * &lt;/ul&gt;<a name="line.88"></a>
-<span class="sourceLineNo">089</span> * &lt;li&gt;HFile index, which is proportional to the total number of Data Blocks.<a name="line.89"></a>
-<span class="sourceLineNo">090</span> * The total amount of memory needed to hold the index can be estimated as<a name="line.90"></a>
-<span class="sourceLineNo">091</span> * (56+AvgKeySize)*NumBlocks.<a name="line.91"></a>
-<span class="sourceLineNo">092</span> * &lt;/ul&gt;<a name="line.92"></a>
-<span class="sourceLineNo">093</span> * Suggestions on performance optimization.<a name="line.93"></a>
-<span class="sourceLineNo">094</span> * &lt;ul&gt;<a name="line.94"></a>
-<span class="sourceLineNo">095</span> * &lt;li&gt;Minimum block size. We recommend a setting of minimum block size between<a name="line.95"></a>
-<span class="sourceLineNo">096</span> * 8KB to 1MB for general usage. Larger block size is preferred if files are<a name="line.96"></a>
-<span class="sourceLineNo">097</span> * primarily for sequential access. However, it would lead to inefficient random<a name="line.97"></a>
-<span class="sourceLineNo">098</span> * access (because there are more data to decompress). Smaller blocks are good<a name="line.98"></a>
-<span class="sourceLineNo">099</span> * for random access, but require more memory to hold the block index, and may<a name="line.99"></a>
-<span class="sourceLineNo">100</span> * be slower to create (because we must flush the compressor stream at the<a name="line.100"></a>
-<span class="sourceLineNo">101</span> * conclusion of each data block, which leads to an FS I/O flush). Further, due<a name="line.101"></a>
-<span class="sourceLineNo">102</span> * to the internal caching in Compression codec, the smallest possible block<a name="line.102"></a>
-<span class="sourceLineNo">103</span> * size would be around 20KB-30KB.<a name="line.103"></a>
-<span class="sourceLineNo">104</span> * &lt;li&gt;The current implementation does not offer true multi-threading for<a name="line.104"></a>
-<span class="sourceLineNo">105</span> * reading. The implementation uses FSDataInputStream seek()+read(), which is<a name="line.105"></a>
-<span class="sourceLineNo">106</span> * shown to be much faster than positioned-read call in single thread mode.<a name="line.106"></a>
-<span class="sourceLineNo">107</span> * However, it also means that if multiple threads attempt to access the same<a name="line.107"></a>
-<span class="sourceLineNo">108</span> * HFile (using multiple scanners) simultaneously, the actual I/O is carried out<a name="line.108"></a>
-<span class="sourceLineNo">109</span> * sequentially even if they access different DFS blocks (Reexamine! pread seems<a name="line.109"></a>
-<span class="sourceLineNo">110</span> * to be 10% faster than seek+read in my testing -- stack).<a name="line.110"></a>
-<span class="sourceLineNo">111</span> * &lt;li&gt;Compression codec. Use "none" if the data is not very compressable (by<a name="line.111"></a>
-<span class="sourceLineNo">112</span> * compressable, I mean a compression ratio at least 2:1). Generally, use "lzo"<a name="line.112"></a>
-<span class="sourceLineNo">113</span> * as the starting point for experimenting. "gz" overs slightly better<a name="line.113"></a>
-<span class="sourceLineNo">114</span> * compression ratio over "lzo" but requires 4x CPU to compress and 2x CPU to<a name="line.114"></a>
-<span class="sourceLineNo">115</span> * decompress, comparing to "lzo".<a name="line.115"></a>
-<span class="sourceLineNo">116</span> * &lt;/ul&gt;<a name="line.116"></a>
-<span class="sourceLineNo">117</span> *<a name="line.117"></a>
-<span class="sourceLineNo">118</span> * For more on the background behind HFile, see &lt;a<a name="line.118"></a>
-<span class="sourceLineNo">119</span> * href=https://issues.apache.org/jira/browse/HBASE-61&gt;HBASE-61&lt;/a&gt;.<a name="line.119"></a>
-<span class="sourceLineNo">120</span> * &lt;p&gt;<a name="line.120"></a>
-<span class="sourceLineNo">121</span> * File is made of data blocks followed by meta data blocks (if any), a fileinfo<a name="line.121"></a>
-<span class="sourceLineNo">122</span> * block, data block index, meta data block index, and a fixed size trailer<a name="line.122"></a>
-<span class="sourceLineNo">123</span> * which records the offsets at which file changes content type.<a name="line.123"></a>
-<span class="sourceLineNo">124</span> * &lt;pre&gt;&amp;lt;data blocks&amp;gt;&amp;lt;meta blocks&amp;gt;&amp;lt;fileinfo&amp;gt;&amp;lt;<a name="line.124"></a>
-<span class="sourceLineNo">125</span> * data index&amp;gt;&amp;lt;meta index&amp;gt;&amp;lt;trailer&amp;gt;&lt;/pre&gt;<a name="line.125"></a>
-<span class="sourceLineNo">126</span> * Each block has a bit of magic at its start.  Block are comprised of<a name="line.126"></a>
-<span class="sourceLineNo">127</span> * key/values.  In data blocks, they are both byte arrays.  Metadata blocks are<a name="line.127"></a>
-<span class="sourceLineNo">128</span> * a String key and a byte array value.  An empty file looks like this:<a name="line.128"></a>
-<span class="sourceLineNo">129</span> * &lt;pre&gt;&amp;lt;fileinfo&amp;gt;&amp;lt;trailer&amp;gt;&lt;/pre&gt;.  That is, there are not data nor meta<a name="line.129"></a>
-<span class="sourceLineNo">130</span> * blocks present.<a name="line.130"></a>
-<span class="sourceLineNo">131</span> * &lt;p&gt;<a name="line.131"></a>
-<span class="sourceLineNo">132</span> * TODO: Do scanners need to be able to take a start and end row?<a name="line.132"></a>
-<span class="sourceLineNo">133</span> * TODO: Should BlockIndex know the name of its file?  Should it have a Path<a name="line.133"></a>
-<span class="sourceLineNo">134</span> * that points at its file say for the case where an index lives apart from<a name="line.134"></a>
-<span class="sourceLineNo">135</span> * an HFile instance?<a name="line.135"></a>
-<span class="sourceLineNo">136</span> */<a name="line.136"></a>
-<span class="sourceLineNo">137</span>@InterfaceAudience.Private<a name="line.137"></a>
-<span class="sourceLineNo">138</span>public class HFile {<a name="line.138"></a>
-<span class="sourceLineNo">139</span>  // LOG is being used in HFileBlock and CheckSumUtil<a name="line.139"></a>
-<span class="sourceLineNo">140</span>  static final Log LOG = LogFactory.getLog(HFile.class);<a name="line.140"></a>
-<span class="sourceLineNo">141</span><a name="line.141"></a>
-<span class="sourceLineNo">142</span>  /**<a name="line.142"></a>
-<span class="sourceLineNo">143</span>   * Maximum length of key in HFile.<a name="line.143"></a>
-<span class="sourceLineNo">144</span>   */<a name="line.144"></a>
-<span class="sourceLineNo">145</span>  public final static int MAXIMUM_KEY_LENGTH = Integer.MAX_VALUE;<a name="line.145"></a>
-<span class="sourceLineNo">146</span><a name="line.146"></a>
-<span class="sourceLineNo">147</span>  /**<a name="line.147"></a>
-<span class="sourceLineNo">148</span>   * Default compression: none.<a name="line.148"></a>
-<span class="sourceLineNo">149</span>   */<a name="line.149"></a>
-<span class="sourceLineNo">150</span>  public final static Compression.Algorithm DEFAULT_COMPRESSION_ALGORITHM =<a name="line.150"></a>
-<span class="sourceLineNo">151</span>    Compression.Algorithm.NONE;<a name="line.151"></a>
-<span class="sourceLineNo">152</span><a name="line.152"></a>
-<span class="sourceLineNo">153</span>  /** Minimum supported HFile format version */<a name="line.153"></a>
-<span class="sourceLineNo">154</span>  public static final int MIN_FORMAT_VERSION = 2;<a name="line.154"></a>
-<span class="sourceLineNo">155</span><a name="line.155"></a>
-<span class="sourceLineNo">156</span>  /** Maximum supported HFile format version<a name="line.156"></a>
-<span class="sourceLineNo">157</span>   */<a name="line.157"></a>
-<span class="sourceLineNo">158</span>  public static final int MAX_FORMAT_VERSION = 3;<a name="line.158"></a>
-<span class="sourceLineNo">159</span><a name="line.159"></a>
-<span class="sourceLineNo">160</span>  /**<a name="line.160"></a>
-<span class="sourceLineNo">161</span>   * Minimum HFile format version with support for persisting cell tags<a name="line.161"></a>
-<span class="sourceLineNo">162</span>   */<a name="line.162"></a>
-<span class="sourceLineNo">163</span>  public static final int MIN_FORMAT_VERSION_WITH_TAGS = 3;<a name="line.163"></a>
-<span class="sourceLineNo">164</span><a name="line.164"></a>
-<span class="sourceLineNo">165</span>  /** Default compression name: none. */<a name="line.165"></a>
-<span class="sourceLineNo">166</span>  public final static String DEFAULT_COMPRESSION =<a name="line.166"></a>
-<span class="sourceLineNo">167</span>    DEFAULT_COMPRESSION_ALGORITHM.getName();<a name="line.167"></a>
-<span class="sourceLineNo">168</span><a name="line.168"></a>
-<span class="sourceLineNo">169</span>  /** Meta data block name for bloom filter bits. */<a name="line.169"></a>
-<span class="sourceLineNo">170</span>  public static final String BLOOM_FILTER_DATA_KEY = "BLOOM_FILTER_DATA";<a name="line.170"></a>
-<span class="sourceLineNo">171</span><a name="line.171"></a>
-<span class="sourceLineNo">172</span>  /**<a name="line.172"></a>
-<span class="sourceLineNo">173</span>   * We assume that HFile path ends with<a name="line.173"></a>
-<span class="sourceLineNo">174</span>   * ROOT_DIR/TABLE_NAME/REGION_NAME/CF_NAME/HFILE, so it has at least this<a name="line.174"></a>
-<span class="sourceLineNo">175</span>   * many levels of nesting. This is needed for identifying table and CF name<a name="line.175"></a>
-<span class="sourceLineNo">176</span>   * from an HFile path.<a name="line.176"></a>
-<span class="sourceLineNo">177</span>   */<a name="line.177"></a>
-<span class="sourceLineNo">178</span>  public final static int MIN_NUM_HFILE_PATH_LEVELS = 5;<a name="line.178"></a>
-<span class="sourceLineNo">179</span><a name="line.179"></a>
-<span class="sourceLineNo">180</span>  /**<a name="line.180"></a>
-<span class="sourceLineNo">181</span>   * The number of bytes per checksum.<a name="line.181"></a>
-<span class="sourceLineNo">182</span>   */<a name="line.182"></a>
-<span class="sourceLineNo">183</span>  public static final int DEFAULT_BYTES_PER_CHECKSUM = 16 * 1024;<a name="line.183"></a>
-<span class="sourceLineNo">184</span><a name="line.184"></a>
-<span class="sourceLineNo">185</span>  // For measuring number of checksum failures<a name="line.185"></a>
-<span class="sourceLineNo">186</span>  static final LongAdder CHECKSUM_FAILURES = new LongAdder();<a name="line.186"></a>
-<span class="sourceLineNo">187</span><a name="line.187"></a>
-<span class="sourceLineNo">188</span>  // For tests. Gets incremented when we read a block whether from HDFS or from Cache.<a name="line.188"></a>
-<span class="sourceLineNo">189</span>  public static final LongAdder DATABLOCK_READ_COUNT = new LongAdder();<a name="line.189"></a>
-<span class="sourceLineNo">190</span><a name="line.190"></a>
-<span class="sourceLineNo">191</span>  /**<a name="line.191"></a>
-<span class="sourceLineNo">192</span>   * Number of checksum verification failures. It also<a name="line.192"></a>
-<span class="sourceLineNo">193</span>   * clears the counter.<a name="line.193"></a>
-<span class="sourceLineNo">194</span>   */<a name="line.194"></a>
-<span class="sourceLineNo">195</span>  public static final long getChecksumFailuresCount() {<a name="line.195"></a>
-<span class="sourceLineNo">196</span>    return CHECKSUM_FAILURES.sumThenReset();<a name="line.196"></a>
-<span class="sourceLineNo">197</span>  }<a name="line.197"></a>
-<span class="sourceLineNo">198</span><a name="line.198"></a>
-<span class="sourceLineNo">199</span>  /** API required to write an {@link HFile} */<a name="line.199"></a>
-<span class="sourceLineNo">200</span>  public interface Writer extends Closeable, CellSink, ShipperListener {<a name="line.200"></a>
-<span class="sourceLineNo">201</span>    /** Max memstore (mvcc) timestamp in FileInfo */<a name="line.201"></a>
-<span class="sourceLineNo">202</span>    public static final byte [] MAX_MEMSTORE_TS_KEY = Bytes.toBytes("MAX_MEMSTORE_TS_KEY");<a name="line.202"></a>
+<span class="sourceLineNo">084</span> * &lt;li&gt;Some constant overhead of reading or writing a compressed block.<a name="line.84"></a>
+<span class="sourceLineNo">085</span> * &lt;ul&gt;<a name="line.85"></a>
+<span class="sourceLineNo">086</span> * &lt;li&gt;Each compressed block requires one compression/decompression codec for<a name="line.86"></a>
+<span class="sourceLineNo">087</span> * I/O.<a name="line.87"></a>
+<span class="sourceLineNo">088</span> * &lt;li&gt;Temporary space to buffer the key.<a name="line.88"></a>
+<span class="sourceLineNo">089</span> * &lt;li&gt;Temporary space to buffer the value.<a name="line.89"></a>
+<span class="sourceLineNo">090</span> * &lt;/ul&gt;<a name="line.90"></a>
+<span class="sourceLineNo">091</span> * &lt;li&gt;HFile index, which is proportional to the total number of Data Blocks.<a name="line.91"></a>
+<span class="sourceLineNo">092</span> * The total amount of memory needed to hold the index can be estimated as<a name="line.92"></a>
+<span class="sourceLineNo">093</span> * (56+AvgKeySize)*NumBlocks.<a name="line.93"></a>
+<span class="sourceLineNo">094</span> * &lt;/ul&gt;<a name="line.94"></a>
+<span class="sourceLineNo">095</span> * Suggestions on performance optimization.<a name="line.95"></a>
+<span class="sourceLineNo">096</span> * &lt;ul&gt;<a name="line.96"></a>
+<span class="sourceLineNo">097</span> * &lt;li&gt;Minimum block size. We recommend a setting of minimum block size between<a name="line.97"></a>
+<span class="sourceLineNo">098</span> * 8KB to 1MB for general usage. Larger block size is preferred if files are<a name="line.98"></a>
+<span class="sourceLineNo">099</span> * primarily for sequential access. However, it would lead to inefficient random<a name="line.99"></a>
+<span class="sourceLineNo">100</span> * access (because there are more data to decompress). Smaller blocks are good<a name="line.100"></a>
+<span class="sourceLineNo">101</span> * for random access, but require more memory to hold the block index, and may<a name="line.101"></a>
+<span class="sourceLineNo">102</span> * be slower to create (because we must flush the compressor stream at the<a name="line.102"></a>
+<span class="sourceLineNo">103</span> * conclusion of each data block, which leads to an FS I/O flush). Further, due<a name="line.103"></a>
+<span class="sourceLineNo">104</span> * to the internal caching in Compression codec, the smallest possible block<a name="line.104"></a>
+<span class="sourceLineNo">105</span> * size would be around 20KB-30KB.<a name="line.105"></a>
+<span class="sourceLineNo">106</span> * &lt;li&gt;The current implementation does not offer true multi-threading for<a name="line.106"></a>
+<span class="sourceLineNo">107</span> * reading. The implementation uses FSDataInputStream seek()+read(), which is<a name="line.107"></a>
+<span class="sourceLineNo">108</span> * shown to be much faster than positioned-read call in single thread mode.<a name="line.108"></a>
+<span class="sourceLineNo">109</span> * However, it also means that if multiple threads attempt to access the same<a name="line.109"></a>
+<span class="sourceLineNo">110</span> * HFile (using multiple scanners) simultaneously, the actual I/O is carried out<a name="line.110"></a>
+<span class="sourceLineNo">111</span> * sequentially even if they access different DFS blocks (Reexamine! pread seems<a name="line.111"></a>
+<span class="sourceLineNo">112</span> * to be 10% faster than seek+read in my testing -- stack).<a name="line.112"></a>
+<span class="sourceLineNo">113</span> * &lt;li&gt;Compression codec. Use "none" if the data is not very compressable (by<a name="line.113"></a>
+<span class="sourceLineNo">114</span> * compressable, I mean a compression ratio at least 2:1). Generally, use "lzo"<a name="line.114"></a>
+<span class="sourceLineNo">115</span> * as the starting point for experimenting. "gz" overs slightly better<a name="line.115"></a>
+<span class="sourceLineNo">116</span> * compression ratio over "lzo" but requires 4x CPU to compress and 2x CPU to<a name="line.116"></a>
+<span class="sourceLineNo">117</span> * decompress, comparing to "lzo".<a name="line.117"></a>
+<span class="sourceLineNo">118</span> * &lt;/ul&gt;<a name="line.118"></a>
+<span class="sourceLineNo">119</span> *<a name="line.119"></a>
+<span class="sourceLineNo">120</span> * For more on the background behind HFile, see &lt;a<a name="line.120"></a>
+<span class="sourceLineNo">121</span> * href=https://issues.apache.org/jira/browse/HBASE-61&gt;HBASE-61&lt;/a&gt;.<a name="line.121"></a>
+<span class="sourceLineNo">122</span> * &lt;p&gt;<a name="line.122"></a>
+<span class="sourceLineNo">123</span> * File is made of data blocks followed by meta data blocks (if any), a fileinfo<a name="line.123"></a>
+<span class="sourceLineNo">124</span> * block, data block index, meta data block index, and a fixed size trailer<a name="line.124"></a>
+<span class="sourceLineNo">125</span> * which records the offsets at which file changes content type.<a name="line.125"></a>
+<span class="sourceLineNo">126</span> * &lt;pre&gt;&amp;lt;data blocks&amp;gt;&amp;lt;meta blocks&amp;gt;&amp;lt;fileinfo&amp;gt;&amp;lt;<a name="line.126"></a>
+<span class="sourceLineNo">127</span> * data index&amp;gt;&amp;lt;meta index&amp;gt;&amp;lt;trailer&amp;gt;&lt;/pre&gt;<a name="line.127"></a>
+<span class="sourceLineNo">128</span> * Each block has a bit of magic at its start.  Block are comprised of<a name="line.128"></a>
+<span class="sourceLineNo">129</span> * key/values.  In data blocks, they are both byte arrays.  Metadata blocks are<a name="line.129"></a>
+<span class="sourceLineNo">130</span> * a String key and a byte array value.  An empty file looks like this:<a name="line.130"></a>
+<span class="sourceLineNo">131</span> * &lt;pre&gt;&amp;lt;fileinfo&amp;gt;&amp;lt;trailer&amp;gt;&lt;/pre&gt;.  That is, there are not data nor meta<a name="line.131"></a>
+<span class="sourceLineNo">132</span> * blocks present.<a name="line.132"></a>
+<span class="sourceLineNo">133</span> * &lt;p&gt;<a name="line.133"></a>
+<span class="sourceLineNo">134</span> * TODO: Do scanners need to be able to take a start and end row?<a name="line.134"></a>
+<span class="sourceLineNo">135</span> * TODO: Should BlockIndex know the name of its file?  Should it have a Path<a name="line.135"></a>
+<span class="sourceLineNo">136</span> * that points at its file say for the case where an index lives apart from<a name="line.136"></a>
+<span class="sourceLineNo">137</span> * an HFile instance?<a name="line.137"></a>
+<span class="sourceLineNo">138</span> */<a name="line.138"></a>
+<span class="sourceLineNo">139</span>@InterfaceAudience.Private<a name="line.139"></a>
+<span class="sourceLineNo">140</span>public class HFile {<a name="line.140"></a>
+<span class="sourceLineNo">141</span>  // LOG is being used in HFileBlock and CheckSumUtil<a name="line.141"></a>
+<span class="sourceLineNo">142</span>  static final Log LOG = LogFactory.getLog(HFile.class);<a name="line.142"></a>
+<span class="sourceLineNo">143</span><a name="line.143"></a>
+<span class="sourceLineNo">144</span>  /**<a name="line.144"></a>
+<span class="sourceLineNo">145</span>   * Maximum length of key in HFile.<a name="line.145"></a>
+<span class="sourceLineNo">146</span>   */<a name="line.146"></a>
+<span class="sourceLineNo">147</span>  public final static int MAXIMUM_KEY_LENGTH = Integer.MAX_VALUE;<a name="line.147"></a>
+<span class="sourceLineNo">148</span><a name="line.148"></a>
+<span class="sourceLineNo">149</span>  /**<a name="line.149"></a>
+<span class="sourceLineNo">150</span>   * Default compression: none.<a name="line.150"></a>
+<span class="sourceLineNo">151</span>   */<a name="line.151"></a>
+<span class="sourceLineNo">152</span>  public final static Compression.Algorithm DEFAULT_COMPRESSION_ALGORITHM =<a name="line.152"></a>
+<span class="sourceLineNo">153</span>    Compression.Algorithm.NONE;<a name="line.153"></a>
+<span class="sourceLineNo">154</span><a name="line.154"></a>
+<span class="sourceLineNo">155</span>  /** Minimum supported HFile format version */<a name="line.155"></a>
+<span class="sourceLineNo">156</span>  public static final int MIN_FORMAT_VERSION = 2;<a name="line.156"></a>
+<span class="sourceLineNo">157</span><a name="line.157"></a>
+<span class="sourceLineNo">158</span>  /** Maximum supported HFile format version<a name="line.158"></a>
+<span class="sourceLineNo">159</span>   */<a name="line.159"></a>
+<span class="sourceLineNo">160</span>  public static final int MAX_FORMAT_VERSION = 3;<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>   * Minimum HFile format version with support for persisting cell tags<a name="line.163"></a>
+<span class="sourceLineNo">164</span>   */<a name="line.164"></a>
+<span class="sourceLineNo">165</span>  public static final int MIN_FORMAT_VERSION_WITH_TAGS = 3;<a name="line.165"></a>
+<span class="sourceLineNo">166</span><a name="line.166"></a>
+<span class="sourceLineNo">167</span>  /** Default compression name: none. */<a name="line.167"></a>
+<span class="sourceLineNo">168</span>  public final static String DEFAULT_COMPRESSION =<a name="line.168"></a>
+<span class="sourceLineNo">169</span>    DEFAULT_COMPRESSION_ALGORITHM.getName();<a name="line.169"></a>
+<span class="sourceLineNo">170</span><a name="line.170"></a>
+<span class="sourceLineNo">171</span>  /** Meta data block name for bloom filter bits. */<a name="line.171"></a>
+<span class="sourceLineNo">172</span>  public static final String BLOOM_FILTER_DATA_KEY = "BLOOM_FILTER_DATA";<a name="line.172"></a>
+<span class="sourceLineNo">173</span><a name="line.173"></a>
+<span class="sourceLineNo">174</span>  /**<a name="line.174"></a>
+<span class="sourceLineNo">175</span>   * We assume that HFile path ends with<a name="line.175"></a>
+<span class="sourceLineNo">176</span>   * ROOT_DIR/TABLE_NAME/REGION_NAME/CF_NAME/HFILE, so it has at least this<a name="line.176"></a>
+<span class="sourceLineNo">177</span>   * many levels of nesting. This is needed for identifying table and CF name<a name="line.177"></a>
+<span class="sourceLineNo">178</span>   * from an HFile path.<a name="line.178"></a>
+<span class="sourceLineNo">179</span>   */<a name="line.179"></a>
+<span class="sourceLineNo">180</span>  public final static int MIN_NUM_HFILE_PATH_LEVELS = 5;<a name="line.180"></a>
+<span class="sourceLineNo">181</span><a name="line.181"></a>
+<span class="sourceLineNo">182</span>  /**<a name="line.182"></a>
+<span class="sourceLineNo">183</span>   * The number of bytes per checksum.<a name="line.183"></a>
+<span class="sourceLineNo">184</span>   */<a name="line.184"></a>
+<span class="sourceLineNo">185</span>  public static final int DEFAULT_BYTES_PER_CHECKSUM = 16 * 1024;<a name="line.185"></a>
+<span class="sourceLineNo">186</span><a name="line.186"></a>
+<span class="sourceLineNo">187</span>  // For measuring number of checksum failures<a name="line.187"></a>
+<span class="sourceLineNo">188</span>  static final LongAdder CHECKSUM_FAILURES = new LongAdder();<a name="line.188"></a>
+<span class="sourceLineNo">189</span><a name="line.189"></a>
+<span class="sourceLineNo">190</span>  // For tests. Gets incremented when we read a block whether from HDFS or from Cache.<a name="line.190"></a>
+<span class="sourceLineNo">191</span>  public static final LongAdder DATABLOCK_READ_COUNT = new LongAdder();<a name="line.191"></a>
+<span class="sourceLineNo">192</span><a name="line.192"></a>
+<span class="sourceLineNo">193</span>  /** Static instance for the metrics so that HFileReaders access the same instance */<a name="line.193"></a>
+<span class="sourceLineNo">194</span>  static final MetricsIO metrics = new MetricsIO(new MetricsIOWrapperImpl());<a name="line.194"></a>
+<span class="sourceLineNo">195</span><a name="line.195"></a>
+<span class="sourceLineNo">196</span>  /**<a name="line.196"></a>
+<span class="sourceLineNo">197</span>   * Number of checksum verification failures. It also<a name="line.197"></a>
+<span class="sourceLineNo">198</span>   * clears the counter.<a name="line.198"></a>
+<span class="sourceLineNo">199</span>   */<a name="line.199"></a>
+<span class="sourceLineNo">200</span>  public static final long getAndResetChecksumFailuresCount() {<a name="line.200"></a>
+<span class="sourceLineNo">201</span>    return CHECKSUM_FAILURES.sumThenReset();<a name="line.201"></a>
+<span class="sourceLineNo">202</span>  }<a name="line.202"></a>
 <span class="sourceLineNo">203</span><a name="line.203"></a>
-<span class="sourceLineNo">204</span>    /** Add an element to the file info map. */<a name="line.204"></a>
-<span class="sourceLineNo">205</span>    void appendFileInfo(byte[] key, byte[] value) throws IOException;<a name="line.205"></a>
-<span class="sourceLineNo">206</span><a name="line.206"></a>
-<span class="sourceLineNo">207</span>    /** @return the path to this {@link HFile} */<a name="line.207"></a>
-<span class="sourceLineNo">208</span>    Path getPath();<a name="line.208"></a>
-<span class="sourceLineNo">209</span><a name="line.209"></a>
-<span class="sourceLineNo">210</span>    /**<a name="line.210"></a>
-<span class="sourceLineNo">211</span>     * Adds an inline block writer such as a multi-level block index writer or<a name="line.211"></a>
-<span class="sourceLineNo">212</span>     * a compound Bloom filter writer.<a name="line.212"></a>
-<span class="sourceLineNo">213</span>     */<a name="line.213"></a>
-<span class="sourceLineNo">214</span>    void addInlineBlockWriter(InlineBlockWriter bloomWriter);<a name="line.214"></a>
-<span class="sourceLineNo">215</span><a name="line.215"></a>
-<span class="sourceLineNo">216</span>    // The below three methods take Writables.  We'd like to undo Writables but undoing the below would be pretty<a name="line.216"></a>
-<span class="sourceLineNo">217</span>    // painful.  Could take a byte [] or a Message but we want to be backward compatible around hfiles so would need<a name="line.217"></a>
-<span class="sourceLineNo">218</span>    // to map between Message and Writable or byte [] and current Writable serialization.  This would be a bit of work<a name="line.218"></a>
-<span class="sourceLineNo">219</span>    // to little gain.  Thats my thinking at moment.  St.Ack 20121129<a name="line.219"></a>
-<span class="sourceLineNo">220</span><a name="line.220"></a>
-<span class="sourceLineNo">221</span>    void appendMetaBlock(String bloomFilterMetaKey, Writable metaWriter);<a name="line.221"></a>
-<span class="sourceLineNo">222</span><a name="line.222"></a>
-<span class="sourceLineNo">223</span>    /**<a name="line.223"></a>
-<span class="sourceLineNo">224</span>     * Store general Bloom filter in the file. This does not deal with Bloom filter<a name="line.224"></a>
-<span class="sourceLineNo">225</span>     * internals but is necessary, since Bloom filters are stored differently<a name="line.225"></a>
-<span class="sourceLineNo">226</span>     * in HFile version 1 and version 2.<a name="line.226"></a>
-<span class="sourceLineNo">227</span>     */<a name="line.227"></a>
-<span class="sourceLineNo">228</span>    void addGeneralBloomFilter(BloomFilterWriter bfw);<a name="line.228"></a>
-<span class="sourceLineNo">229</span><a name="line.229"></a>
-<span class="sourceLineNo">230</span>    /**<a name="line.230"></a>
-<span class="sourceLineNo">231</span>     * Store delete family Bloom filter in the file, which is only supported in<a name="line.231"></a>
-<span class="sourceLineNo">232</span>     * HFile V2.<a name="line.232"></a>
-<span class="sourceLineNo">233</span>     */<a name="line.233"></a>
-<span class="sourceLineNo">234</span>    void addDeleteFamilyBloomFilter(BloomFilterWriter bfw) throws IOException;<a name="line.234"></a>
-<span class="sourceLineNo">235</span><a name="line.235"></a>
-<span class="sourceLineNo">236</span>    /**<a name="line.236"></a>
-<span class="sourceLineNo">237</span>     * Return the file context for the HFile this writer belongs to<a name="line.237"></a>
+<span class="sourceLineNo">204</span>  /**<a name="line.204"></a>
+<span class="sourceLineNo">205</span>   * Number of checksum verification failures. It also<a name="line.205"></a>
+<span class="sourceLineNo">206</span>   * clears the counter.<a name="line.206"></a>
+<span class="sourceLineNo">207</span>   */<a name="line.207"></a>
+<span class="sourceLineNo">208</span>  public static final long getChecksumFailuresCount() {<a name="line.208"></a>
+<span class="sourceLineNo">209</span>    return CHECKSUM_FAILURES.sum();<a name="line.209"></a>
+<span class="sourceLineNo">210</span>  }<a name="line.210"></a>
+<span class="sourceLineNo">211</span><a name="line.211"></a>
+<span class="sourceLineNo">212</span>  public static final void updateReadLatency(long latencyMillis, boolean pread) {<a name="line.212"></a>
+<span class="sourceLineNo">213</span>    if (pread) {<a name="line.213"></a>
+<span class="sourceLineNo">214</span>      metrics.updateFsPreadTime(latencyMillis);<a name="line.214"></a>
+<span class="sourceLineNo">215</span>    } else {<a name="line.215"></a>
+<span class="sourceLineNo">216</span>      metrics.updateFsReadTime(latencyMillis);<a name="line.216"></a>
+<span class="sourceLineNo">217</span>    }<a name="line.217"></a>
+<span class="sourceLineNo">218</span>  }<a name="line.218"></a>
+<span class="sourceLineNo">219</span><a name="line.219"></a>
+<span class="sourceLineNo">220</span>  public static final void updateWriteLatency(long latencyMillis) {<a name="line.220"></a>
+<span class="sourceLineNo">221</span>    metrics.updateFsWriteTime(latencyMillis);<a name="line.221"></a>
+<span class="sourceLineNo">222</span>  }<a name="line.222"></a>
+<span class="sourceLineNo">223</span><a name="line.223"></a>
+<span class="sourceLineNo">224</span>  /** API required to write an {@link HFile} */<a name="line.224"></a>
+<span class="sourceLineNo">225</span>  public interface Writer extends Closeable, CellSink, ShipperListener {<a name="line.225"></a>
+<span class="sourceLineNo">226</span>    /** Max memstore (mvcc) timestamp in FileInfo */<a name="line.226"></a>
+<span class="sourceLineNo">227</span>    public static final byte [] MAX_MEMSTORE_TS_KEY = Bytes.toBytes("MAX_MEMSTORE_TS_KEY");<a name="line.227"></a>
+<span class="sourceLineNo">228</span><a name="line.228"></a>
+<span class="sourceLineNo">229</span>    /** Add an element to the file info map. */<a name="line.229"></a>
+<span class="sourceLineNo">230</span>    void appendFileInfo(byte[] key, byte[] value) throws IOException;<a name="line.230"></a>
+<span class="sourceLineNo">231</span><a name="line.231"></a>
+<span class="sourceLineNo">232</span>    /** @return the path to this {@link HFile} */<a name="line.232"></a>
+<span class="sourceLineNo">233</span>    Path getPath();<a name="line.233"></a>
+<span class="sourceLineNo">234</span><a name="line.234"></a>
+<span class="sourceLineNo">235</span>    /**<a name="line.235"></a>
+<span class="sourceLineNo">236</span>     * Adds an inline block writer such as a multi-level block index writer or<a name="line.236"></a>
+<span class="sourceLineNo">237</span>     * a compound Bloom filter writer.<a name="line.237"></a>
 <span class="sourceLineNo">238</span>     */<a name="line.238"></a>
-<span class="sourceLineNo">239</span>    HFileContext getFileContext();<a name="line.239"></a>
-<span class="sourceLineNo">240</span>  }<a name="line.240"></a>
-<span class="sourceLineNo">241</span><a name="line.241"></a>
-<span class="sourceLineNo">242</span>  /**<a name="line.242"></a>
-<span class="sourceLineNo">243</span>   * This variety of ways to construct writers is used throughout the code, and<a name="line.243"></a>
-<span class="sourceLineNo">244</span>   * we want to be able to swap writer implementations.<a name="line.244"></a>
-<span class="sourceLineNo">245</span>   */<a name="line.245"></a>
-<span class="sourceLineNo">246</span>  public static class WriterFactory {<a name="line.246"></a>
-<span class="sourceLineNo">247</span>    protected final Configuration conf;<a name="line.247"></a>
-<span class="sourceLineNo">248</span>    protected final CacheConfig cacheConf;<a name="line.248"></a>
-<span class="sourceLineNo">249</span>    protected FileSystem fs;<a name="line.249"></a>
-<span class="sourceLineNo">250</span>    protected Path path;<a name="line.250"></a>
-<span class="sourceLineNo">251</span>    protected FSDataOutputStream ostream;<a name="line.251"></a>
-<span class="sourceLineNo">252</span>    protected CellComparator comparator =<a name="line.252"></a>
-<span class="sourceLineNo">253</span>        CellComparator.COMPARATOR;<a name="line.253"></a>
-<span class="sourceLineNo">254</span>    protected InetSocketAddress[] favoredNodes;<a name="line.254"></a>
-<span class="sourceLineNo">255</span>    private HFileContext fileContext;<a name="line.255"></a>
-<span class="sourceLineNo">256</span>    protected boolean shouldDropBehind = false;<a name="line.256"></a>
-<span class="sourceLineNo">257</span><a name="line.257"></a>
-<span class="sourceLineNo">258</span>    WriterFactory(Configuration conf, CacheConfig cacheConf) {<a name="line.258"></a>
-<span class="sourceLineNo">259</span>      this.conf = conf;<a name="line.259"></a>
-<span class="sourceLineNo">260</span>      this.cacheConf = cacheConf;<a name="line.260"></a>
-<span class="sourceLineNo">261</span>    }<a name="line.261"></a>
-<span class="sourceLineNo">262</span><a name="line.262"></a>
-<span class="sourceLineNo">263</span>    public WriterFactory withPath(FileSystem fs, Path path) {<a name="line.263"></a>
-<span class="sourceLineNo">264</span>      Preconditions.checkNotNull(fs);<a name="line.264"></a>
-<span class="sourceLineNo">265</span>      Preconditions.checkNotNull(path);<a name="line.265"></a>
-<span class="sourceLineNo">266</span>      this.fs = fs;<a name="line.266"></a>
-<span class="sourceLineNo">267</span>      this.path = path;<a name="line.267"></a>
-<span class="sourceLineNo">268</span>      return this;<a name="line.268"></a>
-<span class="sourceLineNo">269</span>    }<a name="line.269"></a>
-<span class="sourceLineNo">270</span><a name="line.270"></a>
-<span class="sourceLineNo">271</span>    public WriterFactory withOutputStream(FSDataOutputStream ostream) {<a name="line.271"></a>
-<span class="sourceLineNo">272</span>      Preconditions.checkNotNull(ostream);<a name="line.272"></a>
-<span class="sourceLineNo">273</span>      this.ostream = ostream;<a name="line.273"></a>
-<span class="sourceLineNo">274</span>      return this;<a name="line.274"></a>
-<span class="sourceLineNo">275</span>    }<a name="line.275"></a>
-<span class="sourceLineNo">276</span><a name="line.276"></a>
-<span class="sourceLineNo">277</span>    public WriterFactory withComparator(CellComparator comparator) {<a name="line.277"></a>
-<span class="sourceLineNo">278</span>      Preconditions.checkNotNull(comparator);<a name="line.278"></a>
-<span class="sourceLineNo">279</span>      this.comparator = comparator;<a name="line.279"></a>
-<span class="sourceLineNo">280</span>      return this;<a name="line.280"></a>
-<span class="sourceLineNo">281</span>    }<a name="line.281"></a>
+<span class="sourceLineNo">239</span>    void addInlineBlockWriter(InlineBlockWriter bloomWriter);<a name="line.239"></a>
+<span class="sourceLineNo">240</span><a name="line.240"></a>
+<span class="sourceLineNo">241</span>    // The below three methods take Writables.  We'd like to undo Writables but undoing the below would be pretty<a name="line.241"></a>
+<span class="sourceLineNo">242</span>    // painful.  Could take a byte [] or a Message but we want to be backward compatible around hfiles so would need<a name="line.242"></a>
+<span class="sourceLineNo">243</span>    // to map between Message and Writable or byte [] and current Writable serialization.  This would be a bit of work<a name="line.243"></a>
+<span class="sourceLineNo">244</span>    // to little gain.  Thats my thinking at moment.  St.Ack 20121129<a name="line.244"></a>
+<span class="sourceLineNo">245</span><a name="line.245"></a>
+<span class="sourceLineNo">246</span>    void appendMetaBlock(String bloomFilterMetaKey, Writable metaWriter);<a name="line.246"></a>
+<span class="sourceLineNo">247</span><a name="line.247"></a>
+<span class="sourceLineNo">248</span>    /**<a name="line.248"></a>
+<span class="sourceLineNo">249</span>     * Store general Bloom filter in the file. This does not deal with Bloom filter<a name="line.249"></a>
+<span class="sourceLineNo">250</span>     * internals but is necessary, since Bloom filters are stored differently<a name="line.250"></a>
+<span class="sourceLineNo">251</span>     * in HFile version 1 and version 2.<a name="line.251"></a>
+<span class="sourceLineNo">252</span>     */<a name="line.252"></a>
+<span class="sourceLineNo">253</span>    void addGeneralBloomFilter(BloomFilterWriter bfw);<a name="line.253"></a>
+<span class="sourceLineNo">254</span><a name="line.254"></a>
+<span class="sourceLineNo">255</span>    /**<a name="line.255"></a>
+<span class="sourceLineNo">256</span>     * Store delete family Bloom filter in the file, which is only supported in<a name="line.256"></a>
+<span class="sourceLineNo">257</span>     * HFile V2.<a name="line.257"></a>
+<span class="sourceLineNo">258</span>     */<a name="line.258"></a>
+<span class="sourceLineNo">259</span>    void addDeleteFamilyBloomFilter(BloomFilterWriter bfw) throws IOException;<a name="line.259"></a>
+<span class="sourceLineNo">260</span><a name="line.260"></a>
+<span class="sourceLineNo">261</span>    /**<a name="line.261"></a>
+<span class="sourceLineNo">262</span>     * Return the file context for the HFile this writer belongs to<a name="line.262"></a>
+<span class="sourceLineNo">263</span>     */<a name="line.263"></a>
+<span class="sourceLineNo">264</span>    HFileContext getFileContext();<a name="line.264"></a>
+<span class="sourceLineNo">265</span>  }<a name="line.265"></a>
+<span class="sourceLineNo">266</span><a name="line.266"></a>
+<span class="sourceLineNo">267</span>  /**<a name="line.267"></a>
+<span class="sourceLineNo">268</span>   * This variety of ways to construct writers is used throughout the code, and<a name="line.268"></a>
+<span class="sourceLineNo">269</span>   * we want to be able to swap writer implementations.<a name="line.269"></a>
+<span class="sourceLineNo">270</span>   */<a name="line.270"></a>
+<span class="sourceLineNo">271</span>  public static class WriterFactory {<a name="line.271"></a>
+<span class="sourceLineNo">272</span>    protected final Configuration conf;<a name="line.272"></a>
+<span class="sourceLineNo">273</span>    protected final CacheConfig cacheConf;<a name="line.273"></a>
+<span class="sourceLineNo">274</span>    protected FileSystem fs;<a name="line.274"></a>
+<span class="sourceLineNo">275</span>    protected Path path;<a name="line.275"></a>
+<span class="sourceLineNo">276</span>    protected FSDataOutputStream ostream;<a name="line.276"></a>
+<span class="sourceLineNo">277</span>    protected CellComparator comparator =<a name="line.277"></a>
+<span class="sourceLineNo">278</span>        CellComparator.COMPARATOR;<a name="line.278"></a>
+<span class="sourceLineNo">279</span>    protected InetSocketAddress[] favoredNodes;<a name="line.279"></a>
+<span class="sourceLineNo">280</span>    private HFileContext fileContext;<a name="line.280"></a>
+<span class="sourceLineNo">281</span>    protected boolean shouldDropBehind = false;<a name="line.281"></a>
 <span class="sourceLineNo">282</span><a name="line.282"></a>
-<span class="sourceLineNo">283</span>    public WriterFactory withFavoredNodes(InetSocketAddress[] favoredNodes) {<a name="line.283"></a>
-<span class="sourceLineNo">284</span>      // Deliberately not checking for null here.<a name="line.284"></a>
-<span class="sourceLineNo">285</span>      this.favoredNodes = favoredNodes;<a name="line.285"></a>
-<span class="sourceLineNo">286</span>      return this;<a name="line.286"></a>
-<span class="sourceLineNo">287</span>    }<a name="line.287"></a>
-<span class="sourceLineNo">288</span><a name="line.288"></a>
-<span class="sourceLineNo">289</span>    public WriterFactory withFileContext(HFileContext fileContext) {<a name="line.289"></a>
-<span class="sourceLineNo">290</span>      this.fileContext = fileContext;<a name="line.290"></a>
-<span class="sourceLineNo">291</span>      return this;<a name="line.291"></a>
-<span class="sourceLineNo">292</span>    }<a name="line.292"></a>
-<span class="sourceLineNo">293</span><a name="line.293"></a>
-<span class="sourceLineNo">294</span>    public WriterFactory withShouldDropCacheBehind(boolean shouldDropBehind) {<a name="line.294"></a>
-<span class="sourceLineNo">295</span>      this.shouldDropBehind = shouldDropBehind;<a name="line.295"></a>
-<span class="sourceLineNo">296</span>      return this;<a name="line.296"></a>
-<span class="sourceLineNo">297</span>    }<a name="line.297"></a>
-<span class="sourceLineNo">298</span><a name="line.298"></a>
-<span class="sourceLineNo">299</span><a name="line.299"></a>
-<span class="sourceLineNo">300</span>    public Writer create() throws IOException {<a name="line.300"></a>
-<span class="sourceLineNo">301</span>      if ((path != null ? 1 : 0) + (ostream != null ? 1 : 0) != 1) {<a name="line.301"></a>
-<span class="sourceLineNo">302</span>        throw new AssertionError("Please specify exactly one of " +<a name="line.302"></a>
-<span class="sourceLineNo">303</span>            "filesystem/path or path");<a name="line.303"></a>
-<span class="sourceLineNo">304</span>      }<a name="line.304"></a>
-<span class="sourceLineNo">305</span>      if (path != null) {<a name="line.305"></a>
-<span class="sourceLineNo">306</span>        ostream = HFileWriterImpl.createOutputStream(conf, fs, path, favoredNodes);<a name="line.306"></a>
-<span class="sourceLineNo">307</span>        try {<a name="line.307"></a>
-<span class="sourceLineNo">308</span>          ostream.setDropBehind(shouldDropBehind &amp;&amp; cacheConf.shouldDropBehindCompaction());<a name="line.308"></a>
-<span class="sourceLineNo">309</span>        } catch (UnsupportedOperationException uoe) {<a name="line.309"></a>
-<span class="sourceLineNo">310</span>          if (LOG.isTraceEnabled()) LOG.trace("Unable to set drop behind on " + path, uoe);<a name="line.310"></a>
-<span class="sourceLineNo">311</span>          else if (LOG.isDebugEnabled()) LOG.debug("Unable to set drop behind on " + path);<a name="line.311"></a>
-<span class="sourceLineNo">312</span>        }<a name="line.312"></a>
-<span class="sourceLineNo">313</span>      }<a name="line.313"></a>
-<span class="sourceLineNo">314</span>      return new HFileWriterImpl(conf, cacheConf, path, ostream, comparator, fileContext);<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><a name="line.317"></a>
-<span class="sourceLineNo">318</span>  /** The configuration key for HFile version to use for new files */<a name="line.318"></a>
-<span class="sourceLineNo">319</span>  public static final String FORMAT_VERSION_KEY = "hfile.format.version";<a name="line.319"></a>
-<span class="sourceLineNo">320</span><a name="line.320"></a>
-<span class="sourceLineNo">321</span>  public static int getFormatVersion(Configuration conf) {<a name="line.321"></a>
-<span class="sourceLineNo">322</span>    int version = conf.getInt(FORMAT_VERSION_KEY, MAX_FORMAT_VERSION);<a name="line.322"></a>
-<span class="sourceLineNo">323</span>    checkFormatVersion(version);<a name="line.323"></a>
-<span class="sourceLineNo">324</span>    return version;<a name="line.324"></a>
-<span class="sourceLineNo">325</span>  }<a name="line.325"></a>
-<span class="sourceLineNo">326</span><a name="line.326"></a>
-<span class="sourceLineNo">327</span>  /**<a name="line.327"></a>
-<span class="sourceLineNo">328</span>   * Returns the factory to be used to create {@link HFile} writers.<a name="line.328"></a>
-<span class="sourceLineNo">329</span>   * Disables block cache access for all writers created through the<a name="line.329"></a>
-<span class="sourceLineNo">330</span>   * returned factory.<a name="line.330"></a>
-<span class="sourceLineNo">331</span>   */<a name="line.331"></a>
-<span class="sourceLineNo">332</span>  public static final WriterFactory getWriterFactoryNoCache(Configuration<a name="line.332"></a>
-<span class="sourceLineNo">333</span>       conf) {<a name="line.333"></a>
-<span class="sourceLineNo">334</span>    Configuration tempConf = new Configuration(conf);<a name="line.334"></a>
-<span class="sourceLineNo">335</span>    tempConf.setFloat(HConstants.HFILE_BLOCK_CACHE_SIZE_KEY, 0.0f);<a name="line.335"></a>
-<span class="sourceLineNo">336</span>    return HFile.getWriterFactory(conf, new CacheConfig(tempConf));<a name="line.336"></a>
-<span class="sourceLineNo">337</span>  }<a name="line.337"></a>
-<span class="sourceLineNo">338</span><a name="line.338"></a>
-<span class="sourceLineNo">339</span>  /**<a name="line.339"></a>
-<span class="sourceLineNo">340</span>   * Returns the factory to be used to create {@link HFile} writers<a name="line.340"></a>
-<span class="sourceLineNo">341</span>   */<a name="line.341"></a>
-<span class="sourceLineNo">342</span>  public static final WriterFactory getWriterFactory(Configuration conf,<a name="line.342"></a>
-<span class="sourceLineNo">343</span>      CacheConfig cacheConf) {<a name="line.343"></a>
-<span class="sourceLineNo">344</span>    int version = getFormatVersion(conf);<a name="line.344"></a>
-<span class="sourceLineNo">345</span>    switch (version) {<a name="line.345"></a>
-<span class="sourceLineNo">346</span>    case 2:<a name="line.346"></a>
-<span class="sourceLineNo">347</span>      throw new IllegalArgumentException("This should never happen. " +<a name="line.347"></a>
-<span class="sourceLineNo">348</span>        "Did you change hfile.format.version to read v2? This version of the software writes v3" +<a name="line.348"></a>
-<span class="sourceLineNo">349</span>        " hfiles only (but it can read v2 files without having to update hfile.format.version " +<a name="line.349"></a>
-<span class="sourceLineNo">350</span>        "in hbase-site.xml)");<a name="line.350"></a>
-<span class="sourceLineNo">351</span>    case 3:<a name="line.351"></a>
-<span class="sourceLineNo">352</span>      return new HFile.WriterFactory(conf, cacheConf);<a name="line.352"></a>
-<span class="sourceLineNo">353</span>    default:<a name="line.353"></a>
-<span class="sourceLineNo">354</span>      throw new IllegalArgumentException("Cannot create writer for HFile " +<a name="line.354"></a>
-<span class="sourceLineNo">355</span>          "format version " + version);<a name="line.355"></a>
-<span class="sourceLineNo">356</span>    }<a name="line.356"></a>
-<span class="sourceLineNo">357</span>  }<a name="line.357"></a>
-<span class="sourceLineNo">358</span><a name="line.358"></a>
-<span class="sourceLineNo">359</span>  /**<a name="line.359"></a>
-<span class="sourceLineNo">360</span>   * An abstraction used by the block index.<a name="line.360"></a>
-<span class="sourceLineNo">361</span>   * Implementations will check cache for any asked-for block and return cached block if found.<a name="line.361"></a>
-<span class="sourceLineNo">362</span>   * Otherwise, after reading from fs, will try and put block into cache before returning.<a name="line.362"></a>
-<span class="sourceLineNo">363</span>   */<a name="line.363"></a>
-<span class="sourceLineNo">364</span>  public interface CachingBlockReader {<a name="line.364"></a>
-<span class="sourceLineNo">365</span>    /**<a name="line.365"></a>
-<span class="sourceLineNo">366</span>     * Read in a file block.<a name="line.366"></a>
-<span class="sourceLineNo">367</span>     * @param offset offset to read.<a name="line.367"></a>
-<span class="sourceLineNo">368</span>     * @param onDiskBlockSize size of the block<a name="line.368"></a>
-<span class="sourceLineNo">369</span>     * @param cacheBlock<a name="line.369"></a>
-<span class="sourceLineNo">370</span>     * @param pread<a name="line.370"></a>
-<span class="sourceLineNo">371</span>     * @param isCompaction is this block being read as part of a compaction<a name="line.371"></a>
-<span class="sourceLineNo">372</span>     * @param expectedBlockType the block type we are expecting to read with this read operation,<a name="line.372"></a>
-<span class="sourceLineNo">373</span>     *  or null to read whatever block type is available and avoid checking (that might reduce<a name="line.373"></a>
-<span class="sourceLineNo">374</span>     *  caching efficiency of encoded data blocks)<a name="line.374"></a>
-<span class="sourceLineNo">375</span>     * @param expectedDataBlockEncoding the data block encoding the caller is expecting data blocks<a name="line.375"></a>
-<span class="sourceLineNo">376</span>     *  to be in, or null to not perform this check and return the block irrespective of the<a name="line.376"></a>
-<span class="sourceLineNo">377</span>     *  encoding. This check only applies to data blocks and can be set to null when the caller is<a name="line.377"></a>
-<span class="sourceLineNo">378</span>     *  expecting to read a non-data block and has set expectedBlockType accordingly.<a name="line.378"></a>
-<span class="sourceLineNo">379</span>     * @return Block wrapped in a ByteBuffer.<a name="line.379"></a>
-<span class="sourceLineNo">380</span>     * @throws IOException<a name="line.380"></a>
-<span class="sourceLineNo">381</span>     */<a name="line.381"></a>
-<span class="sourceLineNo">382</span>    HFileBlock readBlock(long offset, long onDiskBlockSize,<a name="line.382"></a>
-<span class="sourceLineNo">383</span>        boolean cacheBlock, final boolean pread, final boolean isCompaction,<a name="line.383"></a>
-<span class="sourceLineNo">384</span>        final boolean updateCacheMetrics, BlockType expectedBlockType,<a name="line.384"></a>
-<span class="sourceLineNo">385</span>        DataBlockEncoding expectedDataBlockEncoding)<a name="line.385"></a>
-<span class="sourceLineNo">386</span>        throws IOException;<a name="line.386"></a>
-<span class="sourceLineNo">387</span><a name="line.387"></a>
-<span class="sourceLineNo">388</span>    /**<a name="line.388"></a>
-<span class="sourceLineNo">389</span>     * Return the given block back to the cache, if it was obtained from cache.<a name="line.389"></a>
-<span class="sourceLineNo">390</span>     * @param block Block to be returned.<a name="line.390"></a>
-<span class="sourceLineNo">391</span>     */<a name="line.391"></a>
-<span class="sourceLineNo">392</span>    void returnBlock(HFileBlock block);<a name="line.392"></a>
-<span class="sourceLineNo">393</span>  }<a name="line.393"></a>
-<span class="sourceLineNo">394</span><a name="line.394"></a>
-<span class="sourceLineNo">395</span>  /** An interface used by clients to open and iterate an {@link HFile}. */<a name="line.395"></a>
-<span class="sourceLineNo">396</span>  public interface Reader extends Closeable, CachingBlockReader {<a name="line.396"></a>
-<span class="sourceLineNo">397</span>    /**<a name="line.397"></a>
-<span class="sourceLineNo">398</span>     * Returns this reader's "name". Usually the last component of the path.<a name="line.398"></a>
-<span class="sourceLineNo">399</span>     * Needs to be constant as the file is being moved to support caching on<a name="line.399"></a>
-<span class="sourceLineNo">400</span>     * write.<a name="line.400"></a>
-<span class="sourceLineNo">401</span>     */<a name="line.401"></a>
-<span class="sourceLineNo">402</span>    String getName();<a name="line.402"></a>
-<span class="sourceLineNo">403</span><a name="line.403"></a>
-<span class="sourceLineNo">404</span>    CellComparator getComparator();<a name="line.404"></a>
-<span class="sourceLineNo">405</span><a name="line.405"></a>
-<span class="sourceLineNo">406</span>    HFileScanner getScanner(boolean cacheBlocks, final boolean pread, final boolean isCompaction);<a name="line.406"></a>
-<span class="sourceLineNo">407</span><a name="line.407"></a>
-<span class="sourceLineNo">408</span>    HFileBlock getMetaBlock(String metaBlockName, boolean cacheBlock) throws IOException;<a name="line.408"></a>
-<span class="sourceLineNo">409</span><a name="line.409"></a>
-<span class="sourceLineNo">410</span>    Map&lt;byte[], byte[]&gt; loadFileInfo() throws IOException;<a name="line.410"></a>
-<span class="sourceLineNo">411</span><a name="line.411"></a>
-<span class="sourceLineNo">412</span>    Cell getLastKey();<a name="line.412"></a>
-<span class="sourceLineNo">413</span><a name="line.413"></a>
-<span class="sourceLineNo">414</span>    Cell midkey() throws IOException;<a name="line.414"></a>
-<span class="sourceLineNo">415</span><a name="line.415"></a>
-<span class="sourceLineNo">416</span>    long length();<a name="line.416"></a>
-<span class="sourceLineNo">417</span><a name="line.417"></a>
-<span class="sourceLineNo">418</span>    long getEntries();<a name="line.418"></a>
+<span class="sourceLineNo">283</span>    WriterFactory(Configuration conf, CacheConfig cacheConf) {<a name="line.283"></a>
+<span class="sourceLineNo">284</span>      this.conf = conf;<a name="line.284"></a>
+<span class="sourceLineNo">285</span>      this.cacheConf = cacheConf;<a name="line.285"></a>
+<span class="sourceLineNo">286</span>    }<a name="line.286"></a>
+<span class="sourceLineNo">287</span><a name="line.287"></a>
+<span class="sourceLineNo">288</span>    public WriterFactory withPath(FileSystem fs, Path path) {<a name="line.288"></a>
+<span class="sourceLineNo">289</span>      Preconditions.checkNotNull(fs);<a name="line.289"></a>
+<span class="sourceLineNo">290</span>      Preconditions.checkNotNull(path);<a name="line.290"></a>
+<span class="sourceLineNo">291</span>      this.fs = fs;<a name="line.291"></a>
+<span class="sourceLineNo">292</span>      this.path = path;<a name="line.292"></a>
+<span class="sourceLineNo">293</span>      return this;<a name="line.293"></a>
+<span class="sourceLineNo">294</span>    }<a name="line.294"></a>
+<span class="sourceLineNo">295</span><a name="line.295"></a>
+<span class="sourceLineNo">296</span>    public WriterFactory withOutputStream(FSDataOutputStream ostream) {<a name="line.296"></a>
+<span class="sourceLineNo">297</span>      Preconditions.checkNotNull(ostream);<a name="line.297"></a>
+<span class="sourceLineNo">298</span>      this.ostream = ostream;<a name="line.298"></a>
+<span class="sourceLineNo">299</span>      return this;<a name="line.299"></a>
+<span class="sourceLineNo">300</span>    }<a name="line.300"></a>
+<span class="sourceLineNo">301</span><a name="line.301"></a>
+<span class="sourceLineNo">302</span>    public WriterFactory withComparator(CellComparator comparator) {<a name="line.302"></a>
+<span class="sourceLineNo">303</span>      Preconditions.checkNotNull(comparator);<a name="line.303"></a>
+<span class="sourceLineNo">304</span>      this.comparator = comparator;<a name="line.304"></a>
+<span class="sourceLineNo">305</span>      return this;<a name="line.305"></a>
+<span class="sourceLineNo">306</span>    }<a name="line.306"></a>
+<span class="sourceLineNo">307</span><a name="line.307"></a>
+<span class="sourceLineNo">308</span>    public WriterFactory withFavoredNodes(InetSocketAddress[] favoredNodes) {<a name="line.308"></a>
+<span class="sourceLineNo">309</span>      // Deliberately not checking for null here.<a name="line.309"></a>
+<span class="sourceLineNo">310</span>      this.favoredNodes = favoredNodes;<a name="line.310"></a>
+<span class="sourceLineNo">311</span>      return this;<a name="line.311"></a>
+<span class="sourceLineNo">312</span>    }<a name="line.312"></a>
+<span class="sourceLineNo">313</span><a name="line.313"></a>
+<span class="sourceLineNo">314</span>    public WriterFactory withFileContext(HFileContext fileContext) {<a name="line.314"></a>
+<span class="sourceLineNo">315</span>      this.fileContext = fileContext;<a name="line.315"></a>
+<span class="sourceLineNo">316</span>      return this;<a name="line.316"></a>
+<span class="sourceLineNo">317</span>    }<a name="line.317"></a>
+<span class="sourceLineNo">318</span><a name="line.318"></a>
+<span class="sourceLineNo">319</span>    public WriterFactory withShouldDropCacheBehind(boolean shouldDropBehind) {<a name="line.319"></a>
+<span class="sourceLineNo">320</span>      this.shouldDropBehind = shouldDropBehind;<a name="line.320"></a>
+<span class="sourceLineNo">321</span>      return this;<a name="line.321"></a>
+<span class="sourceLineNo">322</span>    }<a name="line.322"></a>
+<span class="sourceLineNo">323</span><a name="line.323"></a>
+<span class="sourceLineNo">324</span><a name="line.324"></a>
+<span class="sourceLineNo">325</span>    public Writer create() throws IOException {<a name="line.325"></a>
+<span class="sourceLineNo">326</span>      if ((path != null ? 1 : 0) + (ostream != null ? 1 : 0) != 1) {<a name="line.326"></a>
+<span class="sourceLineNo">327</span>        throw new AssertionError("Please specify exactly one of " +<a name="line.327"></a>
+<span class="sourceLineNo">328</span>            "filesystem/path or path");<a name="line.328"></a>
+<span class="sourceLineNo">329</span>      }<a name="line.329"></a>
+<span class="sourceLineNo">330</span>      if (path != null) {<a name="line.330"></a>
+<span class="sourceLineNo">331</span>        ostream = HFileWriterImpl.createOutputStream(conf, fs, path, favoredNodes);<a name="line.331"></a>
+<span class="sourceLineNo">332</span>        try {<a name="line.332"></a>
+<span class="sourceLineNo">333</span>          ostream.setDropBehind(shouldDropBehind &amp;&amp; cacheConf.shouldDropBehindCompaction());<a name="line.333"></a>
+<span class="sourceLineNo">334</span>        } catch (UnsupportedOperationException uoe) {<a name="line.334"></a>
+<span class="sourceLineNo">335</span>          if (LOG.isTraceEnabled()) LOG.trace("Unable to set drop behind on " + path, uoe);<a name="line.335"></a>
+<span class="sourceLineNo">336</span>          else if (LOG.isDebugEnabled()) LOG.debug("Unable to set drop behind on " + path);<a name="line.336"></a>
+<span class="sourceLineNo">337</span>        }<a name="line.337"></a>
+<span class="sourceLineNo">338</span>      }<a name="line.338"></a>
+<span class="sourceLineNo">339</span>      return new HFileWriterImpl(conf, cacheConf, path, ostream, comparator, fileContext);<a name="line.339"></a>
+<span class="sourceLineNo">340</span>    }<a name="line.340"></a>
+<span class="sourceLineNo">341</span>  }<a name="line.341"></a>
+<span class="sourceLineNo">342</span><a name="line.342"></a>
+<span class="sourceLineNo">343</span>  /** The configuration key for HFile version to use for new files */<a name="line.343"></a>
+<span class="sourceLineNo">344</span>  public static final String FORMAT_VERSION_KEY = "hfile.format.version";<a name="line.344"></a>
+<span class="sourceLineNo">345</span><a name="line.345"></a>
+<span class="sourceLineNo">346</span>  public static int getFormatVersion(Configuration conf) {<a name="line.346"></a>
+<span class="sourceLineNo">347</span>    int version = conf.getInt(FORMAT_VERSION_KEY, MAX_FORMAT_VERSION);<a name="line.347"></a>
+<span class="sourceLineNo">348</span>    checkFormatVersion(version);<a name="line.348"></a>
+<span class="sourceLineNo">349</span>    return version;<a name="line.349"></a>
+<span class="sourceLineNo">350</span>  }<a name="line.350"></a>
+<span class="sourceLineNo">351</span><a name="line.351"></a>
+<span class="sourceLineNo">352</span>  /**<a name="line.352"></a>
+<span class="sourceLineNo">353</span>   * Returns the factory to be used to create {@link HFile} writers.<a name="line.353"></a>
+<span class="sourceLineNo">354</span>   * Disables block cache access for all writers created through the<a name="line.354"></a>
+<span class="sourceLineNo">355</span>   * returned factory.<a name="line.355"></a>
+<span class="sourceLineNo">356</span>   */<a name="line.356"></a>
+<span class="sourceLineNo">357</span>  public static final WriterFactory getWriterFactoryNoCache(Configuration<a name="line.357"></a>
+<span class="sourceLineNo">358</span>       conf) {<a name="line.358"></a>
+<span class="sourceLineNo">359</span>    Configuration tempConf = new Configuration(conf);<a name="line.359"></a>
+<span class="sourceLineNo">360</span>    tempConf.setFloat(HConstants.HFILE_BLOCK_CACHE_SIZE_KEY, 0.0f);<a name="line.360"></a>
+<span class="sourceLineNo">361</span>    return HFile.getWriterFactory(conf, new CacheConfig(tempConf));<a name="line.361"></a>
+<span class="sourceLineNo">362</span>  }<a name="line.362"></a>
+<span class="sourceLineNo">363</span><a name="line.363"></a>
+<span class="sourceLineNo">364</span>  /**<a name="line.364"></a>
+<span class="sourceLineNo">365</span>   * Returns the factory to be used to create {@link HFile} writers<a name="line.365"></a>
+<span class="sourceLineNo">366</span>   */<a name="line.366"></a>
+<span class="sourceLineNo">367</span>  public static final WriterFactory getWriterFactory(Configuration conf,<a name="line.367"></a>
+<span class="sourceLineNo">368</span>      CacheConfig cacheConf) {<a name="line.368"></a>
+<span class="sourceLineNo">369</span>    int version = getFormatVersion(conf);<a name="line.369"></a>
+<span class="sourceLineNo">370</span>    switch (version) {<a name="line.370"></a>
+<span class="sourceLineNo">371</span>    case 2:<a name="line.371"></a>
+<span class="sourceLineNo">372</span>      throw new IllegalArgumentException("This should never happen. " +<a name="line.372"></a>
+<span class="sourceLineNo">373</span>        "Did you change hfile.format.version to read v2? This version of the software writes v3" +<a name="line.373"></a>
+<span class="sourceLineNo">374</span>        " hfiles only (but it can read v2 files without having to update hfile.format.version " +<a name="line.374"></a>
+<span class="sourceLineNo">375</span>        "in hbase-site.xml)");<a name="line.375"></a>
+<span class="sourceLineNo">376</span>    case 3:<a name="line.376"></a>
+<span class="sourceLineNo">377</span>      return new HFile.WriterFactory(conf, cacheConf);<a name="line.377"></a>
+<span class="sourceLineNo">378</span>    default:<a name="line.378"></a>
+<span class="sourceLineNo">379</span>      throw new IllegalArgumentException("Cannot create writer for HFile " +<a name="line.379"></a>
+<span class="sourceLineNo">380</span>          "format version " + version);<a name="line.380"></a>
+<span class="sourceLineNo">381</span>    }<a name="line.381"></a>
+<span class="sourceLineNo">382</span>  }<a name="line.382"></a>
+<span class="sourceLineNo">383</span><a name="line.383"></a>
+<span class="sourceLineNo">384</span>  /**<a name="line.384"></a>
+<span class="sourceLineNo">385</span>   * An abstraction used by the block index.<a name="line.385"></a>
+<span class="sourceLineNo">386</span>   * Implementations will check cache for any asked-for block and return cached block if found.<a name="line.386"></a>
+<span class="sourceLineNo">387</span>   * Otherwise, after reading from fs, will try and put block into cache before returning.<a name="line.387"></a>
+<span class="sourceLineNo">388</span>   */<a name="line.388"></a>
+<span class="sourceLineNo">389</span>  public interface CachingBlockReader {<a name="line.389"></a>
+<span class="sourceLineNo">390</span>    /**<a name="line.390"></a>
+<span class="sourceLineNo">391</span>     * Read in a file block.<a name="line.391"></a>
+<span class="sourceLineNo">392</span>     * @param offset offset to read.<a name="line.392"></a>
+<span class="sourceLineNo">393</span>     * @param onDiskBlockSize size of the block<a name="line.393"></a>
+<span class="sourceLineNo">394</span>     * @param cacheBlock<a name="line.394"></a>
+<span class="sourceLineNo">395</span>     * @param pread<a name="line.395"></a>
+<span class="sourceLineNo">396</span>     * @param isCompaction is this block being read as part of a compaction<a name="line.396"></a>
+<span class="sourceLineNo">397</span>     * @param expectedBlockType the block type we are expecting to read with this read operation,<a name="line.397"></a>
+<span class="sourceLineNo">398</span>     *  or null to read whatever block type is available and avoid checking (that might reduce<a name="line.398"></a>
+<span class="sourceLineNo">399</span>     *  caching efficiency of encoded data blocks)<a name="line.399"></a>
+<span class="sourceLineNo">400</span>     * @param expectedDataBlockEncoding the data block encoding the caller is expecting data blocks<a name="line.400"></a>
+<span class="sourceLineNo">401</span>     *  to be in, or null to not perform this check and return the block irrespective of the<a name="line.401"></a>
+<span class="sourceLineNo">402</span>     *  encoding. This check only applies to data blocks and can be set to null when the caller is<a name="line.402"></a>
+<span class="sourceLineNo">403</span>     *  expecting to read a non-data block and has set expectedBlockType accordingly.<a name="line.403"></a>
+<span class="sourceLineNo">404</span>     * @return Block wrapped in a ByteBuffer.<a name="line.404"></a>
+<span class="sourceLineNo">405</span>     * @throws IOException<a name="line.405"></a>
+<span class="sourceLineNo">406</span>     */<a name="line.406"></a>
+<span class="sourceLineNo">407</span>    HFileBlock readBlock(long offset, long onDiskBlockSize,<a name="line.407"></a>
+<span class="sourceLineNo">408</span>        boolean cacheBlock, final boolean pread, final boolean isCompaction,<a name="line.408"></a>
+<span class="sourceLineNo">409</span>        final boolean updateCacheMetrics, BlockType expectedBlockType,<a name="line.409"></a>
+<span class="sourceLineNo">410</span>        DataBlockEncoding expectedDataBlockEncoding)<a name="line.410"></a>
+<span class="sourceLineNo">411</span>        throws IOException;<a name="line.411"></a>
+<span class="sourceLineNo">412</span><a name="line.412"></a>
+<span class="sourceLineNo">413</span>    /**<a name="line.413"></a>
+<span class="sourceLineNo">414</span>     * Return the given block back to the cache, if it was obtained from cache.<a name="line.414"></a>
+<span class="sourceLineNo">415</span>     * @param block Block to be returned.<a name="line.415"></a>
+<span class="sourceLineNo">416</span>     */<a name="line.416"></a>
+<span class="sourceLineNo">417</span>    void returnBlock(HFileBlock block);<a name="line.417"></a>
+<span class="sourceLineNo">418</span>  }<a name="line.418"></a>
 <span class="sourceLineNo">419</span><a name="line.419"></a>
-<span class="sourceLineNo">420</span>    Cell getFirstKey();<a name="line.420"></a>
-<span class="sourceLineNo">421</span><a name="line.421"></a>
-<span class="sourceLineNo">422</span>    long indexSize();<a name="line.422"></a>
-<span class="sourceLineNo">423</span><a name="line.423"></a>
-<span class="sourceLineNo">424</span>    byte[] getFirstRowKey();<a name="line.424"></a>
-<span class="sourceLineNo">425</span><a name="line.425"></a>
-<span class="sourceLineNo">426</span>    byte[] getLastRowKey();<a name="line.426"></a>
-<span class="sourceLineNo">427</span><a name="line.427"></a>
-<span class="sourceLineNo">428</span>    FixedFileTrailer getTrailer();<a name="line.428"></a>
-<span class="sourceLineNo">429</span><a name="line.429"></a>
-<span class="sourceLineNo">430</span>    HFileBlockIndex.BlockIndexReader getDataBlockIndexReader();<a name="line.430"></a>
-<span class="sourceLineNo">431</span><a name="line.431"></a>
-<span class="sourceLineNo">432</span>    HFileScanner getScanner(boolean cacheBlocks, boolean pread);<a name="line.432"></a>
-<span class="sourceLineNo">433</span><a name="line.433"></a>
-<span class="sourceLineNo">434</span>    Compression.Algorithm getCompressionAlgorithm();<a name="line.434"></a>
-<span class="sourceLineNo">435</span><a name="line.435"></a>
-<span class="sourceLineNo">436</span>    /**<a name="line.436"></a>
-<span class="sourceLineNo">437</span>     * Retrieves general Bloom filter metadata as appropriate for each<a name="line.437"></a>
-<span class="sourceLineNo">438</span>     * {@link HFile} version.<a name="line.438"></a>
-<span class="sourceLineNo">439</span>     * Knows nothing about how that metadata is structured.<a name="line.439"></a>
-<span class="sourceLineNo">440</span>     */<a name="line.440"></a>
-<span class="sourceLineNo">441</span>    DataInput getGeneralBloomFilterMetadata() throws IOException;<a name="line.441"></a>
+<span class="sourceLineNo">420</span>  /** An interface used by clients to open and iterate an {@link HFile}. */<a name="line.420"></a>
+<span class="sourceLineNo">421</span>  public interface Reader extends Closeable, CachingBlockReader {<a name="line.421"></a>
+<span class="sourceLineNo">422</span>    /**<a name="line.422"></a>
+<span class="sourceLineNo">423</span>     * Returns this reader's "name". Usually the last component of the path.<a name="line.423"></a>
+<span class="sourceLineNo">424</span>     * Needs to be constant as the file is being moved to support caching on<a name="line.424"></a>
+<span class="sourceLineNo">425</span>     * write.<a name="line.425"></a>
+<span class="sourceLineNo">426</span>     */<a name="line.426"></a>
+<span class="sourceLineNo">427</span>    String getName();<a name="line.427"></a>
+<span class="sourceLineNo">428</span><a name="line.428"></a>
+<span class="sourceLineNo">429</span>    CellComparator getComparator();<a name="line.429"></a>
+<span class="sourceLineNo">430</span><a name="line.430"></a>
+<span class="sourceLineNo">431</span>    HFileScanner getScanner(boolean cacheBlocks, final boolean pread, final boolean isCompaction);<a name="line.431"></a>
+<span class="sourceLineNo">432</span><a name="line.432"></a>
+<span class="sourceLineNo">433</span>    HFileBlock getMetaBlock(String metaBlockName, boolean cacheBlock) throws IOException;<a name="line.433"></a>
+<span class="sourceLineNo">434</span><a name="line.434"></a>
+<span class="sourceLineNo">435</span>    Map&lt;byte[], byte[]&gt; loadFileInfo() throws IOException;<a name="line.435"></a>
+<span class="sourceLineNo">436</span><a name="line.436"></a>
+<span class="sourceLineNo">437</span>    Cell getLastKey();<a name="line.437"></a>
+<span class="sourceLineNo">438</span><a name="line.438"></a>
+<span class="sourceLineNo">439</span>    Cell midkey() throws IOException;<a name="line.439"></a>
+<span class="sourceLineNo">440</span><a name="line.440"></a>
+<span class="sourceLineNo">441</span>    long length();<a name="line.441"></a>
 <span class="sourceLineNo">442</span><a name="line.442"></a>
-<span class="sourceLineNo">443</span>    /**<a name="line.443"></a>
-<span class="sourceLineNo">444</span>     * Retrieves delete family Bloom filter metadata as appropriate for each<a name="line.444"></a>
-<span class="sourceLineNo">445</span>     * {@link HFile}  version.<a name="line.445"></a>
-<span class="sourceLineNo">446</span>     * Knows nothing about how that metadata is structured.<a name="line.446"></a>
-<span class="sourceLineNo">447</span>     */<a name="line.447"></a>
-<span class="sourceLineNo">448</span>    DataInput getDeleteBloomFilterMetadata() throws IOException;<a name="line.448"></a>
-<span class="sourceLineNo">449</span><a name="line.449"></a>
-<span class="sourceLineNo">450</span>    Path getPath();<a name="line.450"></a>
-<span class="sourceLineNo">451</span><a name="line.451"></a>
-<span class="sourceLineNo">452</span>    /** Close method with optional evictOnClose */<a name="line.452"></a>
-<span class="sourceLineNo">453</span>    void close(boolean evictOnClose) throws IOException;<a name="line.453"></a>
+<span class="sourceLineNo">443</span>    long getEntries();<a name="line.443"></a>
+<span class="sourceLineNo">444</span><a name="line.444"></a>
+<span class="sourceLineNo">445</span>    Cell getFirstKey();<a name="line.445"></a>
+<span class="sourceLineNo">446</span><a name="line.446"></a>
+<span class="sourceLineNo">447</span>    long indexSize();<a name="line.447"></a>
+<span class="sourceLineNo">448</span><a name="line.448"></a>
+<span class="sourceLineNo">449</span>    byte[] getFirstRowKey();<a name="line.449"></a>
+<span class="sourceLineNo">450</span><a name="line.450"></a>
+<span class="sourceLineNo">451</span>    byte[] getLastRowKey();<a name="line.451"></a>
+<span class="sourceLineNo">452</span><a name="line.452"></a>
+<span class="sourceLineNo">453</span>    FixedFileTrailer getTrailer();<a name="line.453"></a>
 <span class="sourceLineNo">454</span><a name="line.454"></a>
-<span class="sourceLineNo">455</span>    DataBlockEncoding getDataBlockEncoding();<a name="line.455"></a>
+<span class="sourceLineNo">455</span>    HFileBlockIndex.BlockIndexReader getDataBlockIndexReader();<a name="line.455"></a>
 <span class="sourceLineNo">456</span><a name="line.456"></a>
-<span class="sourceLineNo">457</span>    boolean hasMVCCInfo();<a name="line.457"></a>
+<span class="sourceLineNo">457</span>    HFileScanner getScanner(boolean cacheBlocks, boolean pread);<a name="line.457"></a>
 <span class="sourceLineNo">458</span><a name="line.458"></a>
-<span class="sourceLineNo">459</span>    /**<a name="line.459"></a>
-<span class="sourceLineNo">460</span>     * Return the file context of the HFile this reader belongs to<a name="line.460"></a>
-<span class="sourceLineNo">461</span>     */<a name="line.461"></a>
-<span class="sourceLineNo">462</span>    HFileContext getFileContext();<a name="line.462"></a>
-<span class="sourceLineNo">463</span><a name="line.463"></a>
-<span class="sourceLineNo">464</span>    boolean isPrimaryReplicaReader();<a name="line.464"></a>
-<span class="sourceLineNo">465</span><a name="line.465"></a>
-<span class="sourceLineNo">466</span>    boolean shouldIncludeMemstoreTS();<a name="line.466"></a>
+<span class="sourceLineNo">459</span>    Compression.Algorithm getCompressionAlgorithm();<a name="line.459"></a>
+<span class="sourceLineNo">460</span><a name="line.460"></a>
+<span class="sourceLineNo">461</span>    /**<a name="line.461"></a>
+<span class="sourceLineNo">462</span>     * Retrieves general Bloom filter metadata as appropriate for each<a name="line.462"></a>
+<span class="sourceLineNo">463</span>     * {@link HFile} version.<a name="line.463"></a>
+<span class="sourceLineNo">464</span>     * Knows nothing about how that metadata is structured.<a name="line.464"></a>
+<span class="sourceLineNo">465</span>     */<a name="line.465"></a>
+<span class="sourceLineNo">466</span>    DataInput getGeneralBloomFilterMetadata() throws IOException;<a name="line.466"></a>
 <span class="sourceLineNo">467</span><a name="line.467"></a>
-<span class="sourceLineNo">468</span>    boolean isDecodeMemstoreTS();<a name="line.468"></a>
-<span class="sourceLineNo">469</span><a name="line.469"></a>
-<span class="sourceLineNo">470</span>    DataBlockEncoding getEffectiveEncodingInCache(boolean isCompaction);<a name="line.470"></a>
-<span class="sourceLineNo">471</span><a name="line.471"></a>
-<span class="sourceLineNo">472</span>    @VisibleForTesting<a name="line.472"></a>
-<span class="sourceLineNo">473</span>    HFileBlock.FSReader getUncachedBlockReader();<a name="line.473"></a>
+<span class="sourceLineNo">468</span>    /**<a name="line.468"></a>
+<span class="sourceLineNo">469</span>     * Retrieves delete family Bloom filter metadata as appropriate for each<a name="line.469"></a>
+<span class="sourceLineNo">470</span>     * {@link HFile}  version.<a name="line.470"></a>
+<span class="sourceLineNo">471</span>     * Knows nothing about how that metadata is structured.<a name="line.471"></a>
+<span class="sourceLineNo">472</span>     */<a name="line.472"></a>
+<span class="sourceLineNo">473</span>    DataInput getDeleteBloomFilterMetadata() throws IOException;<a name="line.473"></a>
 <span class="sourceLineNo">474</span><a name="line.474"></a>
-<span class="sourceLineNo">475</span>    @VisibleForTesting<a name="line.475"></a>
-<span class="sourceLineNo">476</span>    boolean prefetchComplete();<a name="line.476"></a>
-<span class="sourceLineNo">477</span>  }<a name="line.477"></a>
-<span class="sourceLineNo">478</span><a name="line.478"></a>
-<span class="sourceLineNo">479</span>  /**<a name="line.479"></a>
-<span class="sourceLineNo">480</span>   * Method returns the reader given the specified arguments.<a name="line.480"></a>
-<span class="sourceLineNo">481</span>   * TODO This is a bad abstraction.  See HBASE-6635.<a name="line.481"></a>
-<span class="sourceLineNo">482</span>   *<a name="line.482"></a>
-<span class="sourceLineNo">483</span>   * @param path hfile's path<a name="line.483"></a>
-<span class="sourceLineNo">484</span>   * @param fsdis stream of path's file<a name="line.484"></a>
-<span class="sourceLineNo">485</span>   * @param size max size of the trailer.<a name="line.485"></a>
-<span class="sourceLineNo">486</span>   * @param cacheConf Cache configuation values, cannot be null.<a name="line.486"></a>
-<span class="sourceLineNo">487</span>   * @param hfs<a name="line.487"></a>
-<span class="sourceLineNo">488</span>   * @param primaryReplicaReader true if this is a reader for primary replica<a name="line.488"></a>
-<span class="sourceLineNo">489</span>   * @return an appropriate instance of HFileReader<a name="line.489"></a>
-<span class="sourceLineNo">490</span>   * @throws IOException If file is invalid, will throw CorruptHFileException flavored IOException<a name="line.490"></a>
-<span class="sourceLineNo">491</span>   */<a name="line.491"></a>
-<span class="sourceLineNo">492</span>  @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="SF_SWITCH_FALLTHROUGH",<a name="line.492"></a>
-<span class="sourceLineNo">493</span>      justification="Intentional")<a name="line.493"></a>
-<span class="sourceLineNo">494</span>  private static Reader pickReaderVersion(Path path, FSDataInputStreamWrapper fsdis, long size,<a name="line.494"></a>
-<span class="sourceLineNo">495</span>      CacheConfig cacheConf, HFileSystem hfs, boolean primaryReplicaReader, Configuration conf)<a name="line.495"></a>
-<span class="sourceLineNo">496</span>      throws IOException {<a name="line.496"></a>
-<span class="sourceLineNo">497</span>    FixedFileTrailer trailer = null;<a name="line.497"></a>
-<span class="sourceLineNo">498</span>    try {<a name="line.498"></a>
-<span class="sourceLineNo">499</span>      boolean isHBaseChecksum = fsdis.shouldUseHBaseChecksum();<a name="line.499"></a>
-<span class="sourceLineNo">500</span>      assert !isHBaseChecksum; // Initially we must read with FS checksum.<a name="line.500"></a>
-<span class="sourceLineNo">501</span>      trailer = FixedFileTrailer.readFromStream(fsdis.getStream(isHBaseChecksum), size);<a name="line.501"></a>
-<span class="sourceLineNo">502</span>      switch (trailer.getMajorVersion()) {<a name="line.502"></a>
-<span class="sourceLineNo">503</span>        case 2:<a name="line.503"></a>
-<span class="sourceLineNo">504</span>          LOG.debug("Opening HFile v2 with v3 reader");<a name="line.504"></a>
-<span class="sourceLineNo">505</span>          // Fall through. FindBugs: SF_SWITCH_FALLTHROUGH<a name="line.505"></a>
-<span class="sourceLineNo">506</span>        case 3:<a name="line.506"></a>
-<span class="sourceLineNo">507</span>          return new HFileReaderImpl(path, trailer, fsdis, size, cacheConf, hfs,<a name="line.507"></a>
-<span class="sourceLineNo">508</span>              primaryReplicaReader, conf);<a name="line.508"></a>
-<span class="sourceLineNo">509</span>        default:<a name="line.509"></a>
-<span class="sourceLineNo">510</span>          throw new IllegalArgumentException("Invalid HFile version " + trailer.getMajorVersion());<a name="line.510"></a>
-<span class="sourceLineNo">511</span>      }<a name="line.511"></a>
-<span class="sourceLineNo">512</span>    } catch (Throwable t) {<a name="line.512"></a>
-<span class="sourceLineNo">513</span>      IOUtils.closeQuietly(fsdis);<a name="line.513"></a>
-<span class="sourceLineNo">514</span>      throw new CorruptHFileException("Problem reading HFile Trailer from file " + path, t);<a name="line.514"></a>
-<span class="sourceLineNo">515</span>    }<a name="line.515"></a>
-<span class="sourceLineNo">516</span>  }<a name="line.516"></a>
-<span class="sourceLineNo">517</span><a name="line.517"></a>
-<span class="sourceLineNo">518</span>  /**<a name="line.518"></a>
-<span class="sourceLineNo">519</span>   * @param fs A file system<a name="line.519"></a>
-<span class="sourceLineNo">520</span>   * @param path Path to HFile<a name="line.520"></a>
-<span class="sourceLineNo">521</span>   * @param fsdis a stream of path's file<a name="line.521"></a>
-<span class="sourceLineNo">522</span>   * @param size max size of the trailer.<a name="line.522"></a>
-<span class="sourceLineNo">523</span>   * @param cacheConf Cache configuration for hfile's contents<a name="line.523"></a>
-<span class="sourceLineNo">524</span>   * @param primaryReplicaReader true if this is a reader for primary replica<a name="line.524"></a>
-<span class="sourceLineNo">525</span>   * @param conf Configuration<a name="line.525"></a>
-<span class="sourceLineNo">526</span>   * @return A version specific Hfile Reader<a name="line.526"></a>
-<span class="sourceLineNo">527</span>   * @throws IOException If file is invalid, will thr

<TRUNCATED>

Mime
View raw message