hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [06/51] [partial] hbase-site git commit: Published site at 82d554e3783372cc6b05489452c815b57c06f6cd.
Date Wed, 19 Apr 2017 15:02:32 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/6b4bae59/devapidocs/src-html/org/apache/hadoop/hbase/io/FSDataInputStreamWrapper.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/io/FSDataInputStreamWrapper.html b/devapidocs/src-html/org/apache/hadoop/hbase/io/FSDataInputStreamWrapper.html
index 43f337a..7415a30 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/io/FSDataInputStreamWrapper.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/io/FSDataInputStreamWrapper.html
@@ -25,209 +25,222 @@
 <span class="sourceLineNo">017</span> */<a name="line.17"></a>
 <span class="sourceLineNo">018</span>package org.apache.hadoop.hbase.io;<a name="line.18"></a>
 <span class="sourceLineNo">019</span><a name="line.19"></a>
-<span class="sourceLineNo">020</span>import java.io.IOException;<a name="line.20"></a>
-<span class="sourceLineNo">021</span><a name="line.21"></a>
-<span class="sourceLineNo">022</span>import org.apache.hadoop.fs.FSDataInputStream;<a name="line.22"></a>
-<span class="sourceLineNo">023</span>import org.apache.hadoop.fs.FileSystem;<a name="line.23"></a>
-<span class="sourceLineNo">024</span>import org.apache.hadoop.fs.Path;<a name="line.24"></a>
-<span class="sourceLineNo">025</span>import org.apache.hadoop.hbase.fs.HFileSystem;<a name="line.25"></a>
-<span class="sourceLineNo">026</span><a name="line.26"></a>
-<span class="sourceLineNo">027</span>import com.google.common.annotations.VisibleForTesting;<a name="line.27"></a>
-<span class="sourceLineNo">028</span><a name="line.28"></a>
-<span class="sourceLineNo">029</span>/**<a name="line.29"></a>
-<span class="sourceLineNo">030</span> * Wrapper for input stream(s) that takes care of the interaction of FS and HBase checksums,<a name="line.30"></a>
-<span class="sourceLineNo">031</span> * as well as closing streams. Initialization is not thread-safe, but normal operation is;<a name="line.31"></a>
-<span class="sourceLineNo">032</span> * see method comments.<a name="line.32"></a>
-<span class="sourceLineNo">033</span> */<a name="line.33"></a>
-<span class="sourceLineNo">034</span>public class FSDataInputStreamWrapper {<a name="line.34"></a>
-<span class="sourceLineNo">035</span>  private final HFileSystem hfs;<a name="line.35"></a>
-<span class="sourceLineNo">036</span>  private final Path path;<a name="line.36"></a>
-<span class="sourceLineNo">037</span>  private final FileLink link;<a name="line.37"></a>
-<span class="sourceLineNo">038</span>  private final boolean doCloseStreams;<a name="line.38"></a>
-<span class="sourceLineNo">039</span><a name="line.39"></a>
-<span class="sourceLineNo">040</span>  /** Two stream handles, one with and one without FS-level checksum.<a name="line.40"></a>
-<span class="sourceLineNo">041</span>   * HDFS checksum setting is on FS level, not single read level, so you have to keep two<a name="line.41"></a>
-<span class="sourceLineNo">042</span>   * FS objects and two handles open to interleave different reads freely, which is very sad.<a name="line.42"></a>
-<span class="sourceLineNo">043</span>   * This is what we do:<a name="line.43"></a>
-<span class="sourceLineNo">044</span>   * 1) First, we need to read the trailer of HFile to determine checksum parameters.<a name="line.44"></a>
-<span class="sourceLineNo">045</span>   *  We always use FS checksum to do that, so ctor opens {@link #stream}.<a name="line.45"></a>
-<span class="sourceLineNo">046</span>   * 2.1) After that, if HBase checksum is not used, we'd just always use {@link #stream};<a name="line.46"></a>
-<span class="sourceLineNo">047</span>   * 2.2) If HBase checksum can be used, we'll open {@link #streamNoFsChecksum},<a name="line.47"></a>
-<span class="sourceLineNo">048</span>   *  and close {@link #stream}. User MUST call prepareForBlockReader for that to happen;<a name="line.48"></a>
-<span class="sourceLineNo">049</span>   *  if they don't, (2.1) will be the default.<a name="line.49"></a>
-<span class="sourceLineNo">050</span>   * 3) The users can call {@link #shouldUseHBaseChecksum()}, and pass its result to<a name="line.50"></a>
-<span class="sourceLineNo">051</span>   *  {@link #getStream(boolean)} to get stream (if Java had out/pointer params we could<a name="line.51"></a>
-<span class="sourceLineNo">052</span>   *  return both in one call). This stream is guaranteed to be set.<a name="line.52"></a>
-<span class="sourceLineNo">053</span>   * 4) The first time HBase checksum fails, one would call {@link #fallbackToFsChecksum(int)}.<a name="line.53"></a>
-<span class="sourceLineNo">054</span>   * That will take lock, and open {@link #stream}. While this is going on, others will<a name="line.54"></a>
-<span class="sourceLineNo">055</span>   * continue to use the old stream; if they also want to fall back, they'll also call<a name="line.55"></a>
-<span class="sourceLineNo">056</span>   * {@link #fallbackToFsChecksum(int)}, and block until {@link #stream} is set.<a name="line.56"></a>
-<span class="sourceLineNo">057</span>   * 5) After some number of checksumOk() calls, we will go back to using HBase checksum.<a name="line.57"></a>
-<span class="sourceLineNo">058</span>   * We will have 2 handles; however we presume checksums fail so rarely that we don't care.<a name="line.58"></a>
-<span class="sourceLineNo">059</span>   */<a name="line.59"></a>
-<span class="sourceLineNo">060</span>  private volatile FSDataInputStream stream = null;<a name="line.60"></a>
-<span class="sourceLineNo">061</span>  private volatile FSDataInputStream streamNoFsChecksum = null;<a name="line.61"></a>
-<span class="sourceLineNo">062</span>  private Object streamNoFsChecksumFirstCreateLock = new Object();<a name="line.62"></a>
-<span class="sourceLineNo">063</span><a name="line.63"></a>
-<span class="sourceLineNo">064</span>  // The configuration states that we should validate hbase checksums<a name="line.64"></a>
-<span class="sourceLineNo">065</span>  private boolean useHBaseChecksumConfigured;<a name="line.65"></a>
-<span class="sourceLineNo">066</span><a name="line.66"></a>
-<span class="sourceLineNo">067</span>  // Record the current state of this reader with respect to<a name="line.67"></a>
-<span class="sourceLineNo">068</span>  // validating checkums in HBase. This is originally set the same<a name="line.68"></a>
-<span class="sourceLineNo">069</span>  // value as useHBaseChecksumConfigured, but can change state as and when<a name="line.69"></a>
-<span class="sourceLineNo">070</span>  // we encounter checksum verification failures.<a name="line.70"></a>
-<span class="sourceLineNo">071</span>  private volatile boolean useHBaseChecksum;<a name="line.71"></a>
+<span class="sourceLineNo">020</span>import java.io.Closeable;<a name="line.20"></a>
+<span class="sourceLineNo">021</span>import java.io.IOException;<a name="line.21"></a>
+<span class="sourceLineNo">022</span><a name="line.22"></a>
+<span class="sourceLineNo">023</span>import org.apache.commons.io.IOUtils;<a name="line.23"></a>
+<span class="sourceLineNo">024</span>import org.apache.hadoop.fs.FSDataInputStream;<a name="line.24"></a>
+<span class="sourceLineNo">025</span>import org.apache.hadoop.fs.FileSystem;<a name="line.25"></a>
+<span class="sourceLineNo">026</span>import org.apache.hadoop.fs.Path;<a name="line.26"></a>
+<span class="sourceLineNo">027</span>import org.apache.hadoop.hbase.classification.InterfaceAudience;<a name="line.27"></a>
+<span class="sourceLineNo">028</span>import org.apache.hadoop.hbase.fs.HFileSystem;<a name="line.28"></a>
+<span class="sourceLineNo">029</span><a name="line.29"></a>
+<span class="sourceLineNo">030</span>import com.google.common.annotations.VisibleForTesting;<a name="line.30"></a>
+<span class="sourceLineNo">031</span><a name="line.31"></a>
+<span class="sourceLineNo">032</span>/**<a name="line.32"></a>
+<span class="sourceLineNo">033</span> * Wrapper for input stream(s) that takes care of the interaction of FS and HBase checksums,<a name="line.33"></a>
+<span class="sourceLineNo">034</span> * as well as closing streams. Initialization is not thread-safe, but normal operation is;<a name="line.34"></a>
+<span class="sourceLineNo">035</span> * see method comments.<a name="line.35"></a>
+<span class="sourceLineNo">036</span> */<a name="line.36"></a>
+<span class="sourceLineNo">037</span>@InterfaceAudience.Private<a name="line.37"></a>
+<span class="sourceLineNo">038</span>public class FSDataInputStreamWrapper implements Closeable {<a name="line.38"></a>
+<span class="sourceLineNo">039</span>  private final HFileSystem hfs;<a name="line.39"></a>
+<span class="sourceLineNo">040</span>  private final Path path;<a name="line.40"></a>
+<span class="sourceLineNo">041</span>  private final FileLink link;<a name="line.41"></a>
+<span class="sourceLineNo">042</span>  private final boolean doCloseStreams;<a name="line.42"></a>
+<span class="sourceLineNo">043</span>  private final boolean dropBehind;<a name="line.43"></a>
+<span class="sourceLineNo">044</span>  private final long readahead;<a name="line.44"></a>
+<span class="sourceLineNo">045</span><a name="line.45"></a>
+<span class="sourceLineNo">046</span>  /** Two stream handles, one with and one without FS-level checksum.<a name="line.46"></a>
+<span class="sourceLineNo">047</span>   * HDFS checksum setting is on FS level, not single read level, so you have to keep two<a name="line.47"></a>
+<span class="sourceLineNo">048</span>   * FS objects and two handles open to interleave different reads freely, which is very sad.<a name="line.48"></a>
+<span class="sourceLineNo">049</span>   * This is what we do:<a name="line.49"></a>
+<span class="sourceLineNo">050</span>   * 1) First, we need to read the trailer of HFile to determine checksum parameters.<a name="line.50"></a>
+<span class="sourceLineNo">051</span>   *  We always use FS checksum to do that, so ctor opens {@link #stream}.<a name="line.51"></a>
+<span class="sourceLineNo">052</span>   * 2.1) After that, if HBase checksum is not used, we'd just always use {@link #stream};<a name="line.52"></a>
+<span class="sourceLineNo">053</span>   * 2.2) If HBase checksum can be used, we'll open {@link #streamNoFsChecksum},<a name="line.53"></a>
+<span class="sourceLineNo">054</span>   *  and close {@link #stream}. User MUST call prepareForBlockReader for that to happen;<a name="line.54"></a>
+<span class="sourceLineNo">055</span>   *  if they don't, (2.1) will be the default.<a name="line.55"></a>
+<span class="sourceLineNo">056</span>   * 3) The users can call {@link #shouldUseHBaseChecksum()}, and pass its result to<a name="line.56"></a>
+<span class="sourceLineNo">057</span>   *  {@link #getStream(boolean)} to get stream (if Java had out/pointer params we could<a name="line.57"></a>
+<span class="sourceLineNo">058</span>   *  return both in one call). This stream is guaranteed to be set.<a name="line.58"></a>
+<span class="sourceLineNo">059</span>   * 4) The first time HBase checksum fails, one would call {@link #fallbackToFsChecksum(int)}.<a name="line.59"></a>
+<span class="sourceLineNo">060</span>   * That will take lock, and open {@link #stream}. While this is going on, others will<a name="line.60"></a>
+<span class="sourceLineNo">061</span>   * continue to use the old stream; if they also want to fall back, they'll also call<a name="line.61"></a>
+<span class="sourceLineNo">062</span>   * {@link #fallbackToFsChecksum(int)}, and block until {@link #stream} is set.<a name="line.62"></a>
+<span class="sourceLineNo">063</span>   * 5) After some number of checksumOk() calls, we will go back to using HBase checksum.<a name="line.63"></a>
+<span class="sourceLineNo">064</span>   * We will have 2 handles; however we presume checksums fail so rarely that we don't care.<a name="line.64"></a>
+<span class="sourceLineNo">065</span>   */<a name="line.65"></a>
+<span class="sourceLineNo">066</span>  private volatile FSDataInputStream stream = null;<a name="line.66"></a>
+<span class="sourceLineNo">067</span>  private volatile FSDataInputStream streamNoFsChecksum = null;<a name="line.67"></a>
+<span class="sourceLineNo">068</span>  private Object streamNoFsChecksumFirstCreateLock = new Object();<a name="line.68"></a>
+<span class="sourceLineNo">069</span><a name="line.69"></a>
+<span class="sourceLineNo">070</span>  // The configuration states that we should validate hbase checksums<a name="line.70"></a>
+<span class="sourceLineNo">071</span>  private boolean useHBaseChecksumConfigured;<a name="line.71"></a>
 <span class="sourceLineNo">072</span><a name="line.72"></a>
-<span class="sourceLineNo">073</span>  // In the case of a checksum failure, do these many succeeding<a name="line.73"></a>
-<span class="sourceLineNo">074</span>  // reads without hbase checksum verification.<a name="line.74"></a>
-<span class="sourceLineNo">075</span>  private volatile int hbaseChecksumOffCount = -1;<a name="line.75"></a>
-<span class="sourceLineNo">076</span><a name="line.76"></a>
-<span class="sourceLineNo">077</span>  public FSDataInputStreamWrapper(FileSystem fs, Path path) throws IOException {<a name="line.77"></a>
-<span class="sourceLineNo">078</span>    this(fs, null, path, false);<a name="line.78"></a>
-<span class="sourceLineNo">079</span>  }<a name="line.79"></a>
-<span class="sourceLineNo">080</span><a name="line.80"></a>
-<span class="sourceLineNo">081</span>  public FSDataInputStreamWrapper(FileSystem fs, Path path, boolean dropBehind) throws IOException {<a name="line.81"></a>
-<span class="sourceLineNo">082</span>    this(fs, null, path, dropBehind);<a name="line.82"></a>
-<span class="sourceLineNo">083</span>  }<a name="line.83"></a>
-<span class="sourceLineNo">084</span><a name="line.84"></a>
-<span class="sourceLineNo">085</span>  public FSDataInputStreamWrapper(FileSystem fs, FileLink link) throws IOException {<a name="line.85"></a>
-<span class="sourceLineNo">086</span>    this(fs, link, null, false);<a name="line.86"></a>
-<span class="sourceLineNo">087</span>  }<a name="line.87"></a>
-<span class="sourceLineNo">088</span>  public FSDataInputStreamWrapper(FileSystem fs, FileLink link,<a name="line.88"></a>
-<span class="sourceLineNo">089</span>                                  boolean dropBehind) throws IOException {<a name="line.89"></a>
-<span class="sourceLineNo">090</span>    this(fs, link, null, dropBehind);<a name="line.90"></a>
-<span class="sourceLineNo">091</span>  }<a name="line.91"></a>
-<span class="sourceLineNo">092</span><a name="line.92"></a>
-<span class="sourceLineNo">093</span>  private FSDataInputStreamWrapper(FileSystem fs, FileLink link,<a name="line.93"></a>
-<span class="sourceLineNo">094</span>                                   Path path, boolean dropBehind) throws IOException {<a name="line.94"></a>
-<span class="sourceLineNo">095</span>    assert (path == null) != (link == null);<a name="line.95"></a>
-<span class="sourceLineNo">096</span>    this.path = path;<a name="line.96"></a>
-<span class="sourceLineNo">097</span>    this.link = link;<a name="line.97"></a>
-<span class="sourceLineNo">098</span>    this.doCloseStreams = true;<a name="line.98"></a>
-<span class="sourceLineNo">099</span>    // If the fs is not an instance of HFileSystem, then create an instance of HFileSystem<a name="line.99"></a>
-<span class="sourceLineNo">100</span>    // that wraps over the specified fs. In this case, we will not be able to avoid<a name="line.100"></a>
-<span class="sourceLineNo">101</span>    // checksumming inside the filesystem.<a name="line.101"></a>
-<span class="sourceLineNo">102</span>    this.hfs = (fs instanceof HFileSystem) ? (HFileSystem)fs : new HFileSystem(fs);<a name="line.102"></a>
-<span class="sourceLineNo">103</span><a name="line.103"></a>
-<span class="sourceLineNo">104</span>    // Initially we are going to read the tail block. Open the reader w/FS checksum.<a name="line.104"></a>
-<span class="sourceLineNo">105</span>    this.useHBaseChecksumConfigured = this.useHBaseChecksum = false;<a name="line.105"></a>
-<span class="sourceLineNo">106</span>    this.stream = (link != null) ? link.open(hfs) : hfs.open(path);<a name="line.106"></a>
-<span class="sourceLineNo">107</span>    try {<a name="line.107"></a>
-<span class="sourceLineNo">108</span>      this.stream.setDropBehind(dropBehind);<a name="line.108"></a>
-<span class="sourceLineNo">109</span>    } catch (Exception e) {<a name="line.109"></a>
-<span class="sourceLineNo">110</span>      // Skipped.<a name="line.110"></a>
-<span class="sourceLineNo">111</span>    }<a name="line.111"></a>
-<span class="sourceLineNo">112</span>  }<a name="line.112"></a>
-<span class="sourceLineNo">113</span><a name="line.113"></a>
+<span class="sourceLineNo">073</span>  // Record the current state of this reader with respect to<a name="line.73"></a>
+<span class="sourceLineNo">074</span>  // validating checkums in HBase. This is originally set the same<a name="line.74"></a>
+<span class="sourceLineNo">075</span>  // value as useHBaseChecksumConfigured, but can change state as and when<a name="line.75"></a>
+<span class="sourceLineNo">076</span>  // we encounter checksum verification failures.<a name="line.76"></a>
+<span class="sourceLineNo">077</span>  private volatile boolean useHBaseChecksum;<a name="line.77"></a>
+<span class="sourceLineNo">078</span><a name="line.78"></a>
+<span class="sourceLineNo">079</span>  // In the case of a checksum failure, do these many succeeding<a name="line.79"></a>
+<span class="sourceLineNo">080</span>  // reads without hbase checksum verification.<a name="line.80"></a>
+<span class="sourceLineNo">081</span>  private volatile int hbaseChecksumOffCount = -1;<a name="line.81"></a>
+<span class="sourceLineNo">082</span><a name="line.82"></a>
+<span class="sourceLineNo">083</span>  public FSDataInputStreamWrapper(FileSystem fs, Path path) throws IOException {<a name="line.83"></a>
+<span class="sourceLineNo">084</span>    this(fs, path, false, -1L);<a name="line.84"></a>
+<span class="sourceLineNo">085</span>  }<a name="line.85"></a>
+<span class="sourceLineNo">086</span><a name="line.86"></a>
+<span class="sourceLineNo">087</span>  public FSDataInputStreamWrapper(FileSystem fs, Path path, boolean dropBehind, long readahead) throws IOException {<a name="line.87"></a>
+<span class="sourceLineNo">088</span>    this(fs, null, path, dropBehind, readahead);<a name="line.88"></a>
+<span class="sourceLineNo">089</span>  }<a name="line.89"></a>
+<span class="sourceLineNo">090</span><a name="line.90"></a>
+<span class="sourceLineNo">091</span>  public FSDataInputStreamWrapper(FileSystem fs, FileLink link,<a name="line.91"></a>
+<span class="sourceLineNo">092</span>                                  boolean dropBehind, long readahead) throws IOException {<a name="line.92"></a>
+<span class="sourceLineNo">093</span>    this(fs, link, null, dropBehind, readahead);<a name="line.93"></a>
+<span class="sourceLineNo">094</span>  }<a name="line.94"></a>
+<span class="sourceLineNo">095</span><a name="line.95"></a>
+<span class="sourceLineNo">096</span>  private FSDataInputStreamWrapper(FileSystem fs, FileLink link, Path path, boolean dropBehind,<a name="line.96"></a>
+<span class="sourceLineNo">097</span>      long readahead) throws IOException {<a name="line.97"></a>
+<span class="sourceLineNo">098</span>    assert (path == null) != (link == null);<a name="line.98"></a>
+<span class="sourceLineNo">099</span>    this.path = path;<a name="line.99"></a>
+<span class="sourceLineNo">100</span>    this.link = link;<a name="line.100"></a>
+<span class="sourceLineNo">101</span>    this.doCloseStreams = true;<a name="line.101"></a>
+<span class="sourceLineNo">102</span>    this.dropBehind = dropBehind;<a name="line.102"></a>
+<span class="sourceLineNo">103</span>    this.readahead = readahead;<a name="line.103"></a>
+<span class="sourceLineNo">104</span>    // If the fs is not an instance of HFileSystem, then create an instance of HFileSystem<a name="line.104"></a>
+<span class="sourceLineNo">105</span>    // that wraps over the specified fs. In this case, we will not be able to avoid<a name="line.105"></a>
+<span class="sourceLineNo">106</span>    // checksumming inside the filesystem.<a name="line.106"></a>
+<span class="sourceLineNo">107</span>    this.hfs = (fs instanceof HFileSystem) ? (HFileSystem) fs : new HFileSystem(fs);<a name="line.107"></a>
+<span class="sourceLineNo">108</span><a name="line.108"></a>
+<span class="sourceLineNo">109</span>    // Initially we are going to read the tail block. Open the reader w/FS checksum.<a name="line.109"></a>
+<span class="sourceLineNo">110</span>    this.useHBaseChecksumConfigured = this.useHBaseChecksum = false;<a name="line.110"></a>
+<span class="sourceLineNo">111</span>    this.stream = (link != null) ? link.open(hfs) : hfs.open(path);<a name="line.111"></a>
+<span class="sourceLineNo">112</span>    setStreamOptions(stream);<a name="line.112"></a>
+<span class="sourceLineNo">113</span>  }<a name="line.113"></a>
 <span class="sourceLineNo">114</span><a name="line.114"></a>
-<span class="sourceLineNo">115</span>  /**<a name="line.115"></a>
-<span class="sourceLineNo">116</span>   * Prepares the streams for block reader. NOT THREAD SAFE. Must be called once, after any<a name="line.116"></a>
-<span class="sourceLineNo">117</span>   * reads finish and before any other reads start (what happens in reality is we read the<a name="line.117"></a>
-<span class="sourceLineNo">118</span>   * tail, then call this based on what's in the tail, then read blocks).<a name="line.118"></a>
-<span class="sourceLineNo">119</span>   * @param forceNoHBaseChecksum Force not using HBase checksum.<a name="line.119"></a>
-<span class="sourceLineNo">120</span>   */<a name="line.120"></a>
-<span class="sourceLineNo">121</span>  public void prepareForBlockReader(boolean forceNoHBaseChecksum) throws IOException {<a name="line.121"></a>
-<span class="sourceLineNo">122</span>    if (hfs == null) return;<a name="line.122"></a>
-<span class="sourceLineNo">123</span>    assert this.stream != null &amp;&amp; !this.useHBaseChecksumConfigured;<a name="line.123"></a>
-<span class="sourceLineNo">124</span>    boolean useHBaseChecksum =<a name="line.124"></a>
-<span class="sourceLineNo">125</span>        !forceNoHBaseChecksum &amp;&amp; hfs.useHBaseChecksum() &amp;&amp; (hfs.getNoChecksumFs() != hfs);<a name="line.125"></a>
-<span class="sourceLineNo">126</span><a name="line.126"></a>
-<span class="sourceLineNo">127</span>    if (useHBaseChecksum) {<a name="line.127"></a>
-<span class="sourceLineNo">128</span>      FileSystem fsNc = hfs.getNoChecksumFs();<a name="line.128"></a>
-<span class="sourceLineNo">129</span>      this.streamNoFsChecksum = (link != null) ? link.open(fsNc) : fsNc.open(path);<a name="line.129"></a>
-<span class="sourceLineNo">130</span>      this.useHBaseChecksumConfigured = this.useHBaseChecksum = useHBaseChecksum;<a name="line.130"></a>
-<span class="sourceLineNo">131</span>      // Close the checksum stream; we will reopen it if we get an HBase checksum failure.<a name="line.131"></a>
-<span class="sourceLineNo">132</span>      this.stream.close();<a name="line.132"></a>
-<span class="sourceLineNo">133</span>      this.stream = null;<a name="line.133"></a>
-<span class="sourceLineNo">134</span>    }<a name="line.134"></a>
-<span class="sourceLineNo">135</span>  }<a name="line.135"></a>
-<span class="sourceLineNo">136</span><a name="line.136"></a>
-<span class="sourceLineNo">137</span>  /** For use in tests. */<a name="line.137"></a>
-<span class="sourceLineNo">138</span>  @VisibleForTesting<a name="line.138"></a>
-<span class="sourceLineNo">139</span>  public FSDataInputStreamWrapper(FSDataInputStream fsdis) {<a name="line.139"></a>
-<span class="sourceLineNo">140</span>    this(fsdis, fsdis);<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>  /** For use in tests. */<a name="line.143"></a>
-<span class="sourceLineNo">144</span>  @VisibleForTesting<a name="line.144"></a>
-<span class="sourceLineNo">145</span>  public FSDataInputStreamWrapper(FSDataInputStream fsdis, FSDataInputStream noChecksum) {<a name="line.145"></a>
-<span class="sourceLineNo">146</span>    doCloseStreams = false;<a name="line.146"></a>
-<span class="sourceLineNo">147</span>    stream = fsdis;<a name="line.147"></a>
-<span class="sourceLineNo">148</span>    streamNoFsChecksum = noChecksum;<a name="line.148"></a>
-<span class="sourceLineNo">149</span>    path = null;<a name="line.149"></a>
-<span class="sourceLineNo">150</span>    link = null;<a name="line.150"></a>
-<span class="sourceLineNo">151</span>    hfs = null;<a name="line.151"></a>
-<span class="sourceLineNo">152</span>    useHBaseChecksumConfigured = useHBaseChecksum = false;<a name="line.152"></a>
-<span class="sourceLineNo">153</span>  }<a name="line.153"></a>
-<span class="sourceLineNo">154</span><a name="line.154"></a>
-<span class="sourceLineNo">155</span>  /**<a name="line.155"></a>
-<span class="sourceLineNo">156</span>   * @return Whether we are presently using HBase checksum.<a name="line.156"></a>
-<span class="sourceLineNo">157</span>   */<a name="line.157"></a>
-<span class="sourceLineNo">158</span>  public boolean shouldUseHBaseChecksum() {<a name="line.158"></a>
-<span class="sourceLineNo">159</span>    return this.useHBaseChecksum;<a name="line.159"></a>
-<span class="sourceLineNo">160</span>  }<a name="line.160"></a>
-<span class="sourceLineNo">161</span><a name="line.161"></a>
-<span class="sourceLineNo">162</span>  /**<a name="line.162"></a>
-<span class="sourceLineNo">163</span>   * Get the stream to use. Thread-safe.<a name="line.163"></a>
-<span class="sourceLineNo">164</span>   * @param useHBaseChecksum must be the value that shouldUseHBaseChecksum has returned<a name="line.164"></a>
-<span class="sourceLineNo">165</span>   *  at some point in the past, otherwise the result is undefined.<a name="line.165"></a>
-<span class="sourceLineNo">166</span>   */<a name="line.166"></a>
-<span class="sourceLineNo">167</span>  public FSDataInputStream getStream(boolean useHBaseChecksum) {<a name="line.167"></a>
-<span class="sourceLineNo">168</span>    return useHBaseChecksum ? this.streamNoFsChecksum : this.stream;<a name="line.168"></a>
-<span class="sourceLineNo">169</span>  }<a name="line.169"></a>
-<span class="sourceLineNo">170</span><a name="line.170"></a>
-<span class="sourceLineNo">171</span>  /**<a name="line.171"></a>
-<span class="sourceLineNo">172</span>   * Read from non-checksum stream failed, fall back to FS checksum. Thread-safe.<a name="line.172"></a>
-<span class="sourceLineNo">173</span>   * @param offCount For how many checksumOk calls to turn off the HBase checksum.<a name="line.173"></a>
-<span class="sourceLineNo">174</span>   */<a name="line.174"></a>
-<span class="sourceLineNo">175</span>  public FSDataInputStream fallbackToFsChecksum(int offCount) throws IOException {<a name="line.175"></a>
-<span class="sourceLineNo">176</span>    // checksumOffCount is speculative, but let's try to reset it less.<a name="line.176"></a>
-<span class="sourceLineNo">177</span>    boolean partOfConvoy = false;<a name="line.177"></a>
-<span class="sourceLineNo">178</span>    if (this.stream == null) {<a name="line.178"></a>
-<span class="sourceLineNo">179</span>      synchronized (streamNoFsChecksumFirstCreateLock) {<a name="line.179"></a>
-<span class="sourceLineNo">180</span>        partOfConvoy = (this.stream != null);<a name="line.180"></a>
-<span class="sourceLineNo">181</span>        if (!partOfConvoy) {<a name="line.181"></a>
-<span class="sourceLineNo">182</span>          this.stream = (link != null) ? link.open(hfs) : hfs.open(path);<a name="line.182"></a>
-<span class="sourceLineNo">183</span>        }<a name="line.183"></a>
-<span class="sourceLineNo">184</span>      }<a name="line.184"></a>
-<span class="sourceLineNo">185</span>    }<a name="line.185"></a>
-<span class="sourceLineNo">186</span>    if (!partOfConvoy) {<a name="line.186"></a>
-<span class="sourceLineNo">187</span>      this.useHBaseChecksum = false;<a name="line.187"></a>
-<span class="sourceLineNo">188</span>      this.hbaseChecksumOffCount = offCount;<a name="line.188"></a>
-<span class="sourceLineNo">189</span>    }<a name="line.189"></a>
-<span class="sourceLineNo">190</span>    return this.stream;<a name="line.190"></a>
-<span class="sourceLineNo">191</span>  }<a name="line.191"></a>
-<span class="sourceLineNo">192</span><a name="line.192"></a>
-<span class="sourceLineNo">193</span>  /** Report that checksum was ok, so we may ponder going back to HBase checksum. */<a name="line.193"></a>
-<span class="sourceLineNo">194</span>  public void checksumOk() {<a name="line.194"></a>
-<span class="sourceLineNo">195</span>    if (this.useHBaseChecksumConfigured &amp;&amp; !this.useHBaseChecksum<a name="line.195"></a>
-<span class="sourceLineNo">196</span>        &amp;&amp; (this.hbaseChecksumOffCount-- &lt; 0)) {<a name="line.196"></a>
-<span class="sourceLineNo">197</span>      // The stream we need is already open (because we were using HBase checksum in the past).<a name="line.197"></a>
-<span class="sourceLineNo">198</span>      assert this.streamNoFsChecksum != null;<a name="line.198"></a>
-<span class="sourceLineNo">199</span>      this.useHBaseChecksum = true;<a name="line.199"></a>
-<span class="sourceLineNo">200</span>    }<a name="line.200"></a>
-<span class="sourceLineNo">201</span>  }<a name="line.201"></a>
-<span class="sourceLineNo">202</span><a name="line.202"></a>
-<span class="sourceLineNo">203</span>  /** Close stream(s) if necessary. */<a name="line.203"></a>
-<span class="sourceLineNo">204</span>  public void close() throws IOException {<a name="line.204"></a>
-<span class="sourceLineNo">205</span>    if (!doCloseStreams) return;<a name="line.205"></a>
-<span class="sourceLineNo">206</span>    try {<a name="line.206"></a>
-<span class="sourceLineNo">207</span>      if (stream != streamNoFsChecksum &amp;&amp; streamNoFsChecksum != null) {<a name="line.207"></a>
-<span class="sourceLineNo">208</span>        streamNoFsChecksum.close();<a name="line.208"></a>
-<span class="sourceLineNo">209</span>        streamNoFsChecksum = null;<a name="line.209"></a>
-<span class="sourceLineNo">210</span>      }<a name="line.210"></a>
-<span class="sourceLineNo">211</span>    } finally {<a name="line.211"></a>
-<span class="sourceLineNo">212</span>      if (stream != null) {<a name="line.212"></a>
-<span class="sourceLineNo">213</span>        stream.close();<a name="line.213"></a>
-<span class="sourceLineNo">214</span>        stream = null;<a name="line.214"></a>
-<span class="sourceLineNo">215</span>      }<a name="line.215"></a>
-<span class="sourceLineNo">216</span>    }<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>  public HFileSystem getHfs() {<a name="line.219"></a>
-<span class="sourceLineNo">220</span>    return this.hfs;<a name="line.220"></a>
-<span class="sourceLineNo">221</span>  }<a name="line.221"></a>
-<span class="sourceLineNo">222</span>}<a name="line.222"></a>
+<span class="sourceLineNo">115</span>  private void setStreamOptions(FSDataInputStream in) {<a name="line.115"></a>
+<span class="sourceLineNo">116</span>    try {<a name="line.116"></a>
+<span class="sourceLineNo">117</span>      this.stream.setDropBehind(dropBehind);<a name="line.117"></a>
+<span class="sourceLineNo">118</span>    } catch (Exception e) {<a name="line.118"></a>
+<span class="sourceLineNo">119</span>      // Skipped.<a name="line.119"></a>
+<span class="sourceLineNo">120</span>    }<a name="line.120"></a>
+<span class="sourceLineNo">121</span>    if (readahead &gt;= 0) {<a name="line.121"></a>
+<span class="sourceLineNo">122</span>      try {<a name="line.122"></a>
+<span class="sourceLineNo">123</span>        this.stream.setReadahead(readahead);<a name="line.123"></a>
+<span class="sourceLineNo">124</span>      } catch (Exception e) {<a name="line.124"></a>
+<span class="sourceLineNo">125</span>        // Skipped.<a name="line.125"></a>
+<span class="sourceLineNo">126</span>      }<a name="line.126"></a>
+<span class="sourceLineNo">127</span>    }<a name="line.127"></a>
+<span class="sourceLineNo">128</span>  }<a name="line.128"></a>
+<span class="sourceLineNo">129</span><a name="line.129"></a>
+<span class="sourceLineNo">130</span>  /**<a name="line.130"></a>
+<span class="sourceLineNo">131</span>   * Prepares the streams for block reader. NOT THREAD SAFE. Must be called once, after any<a name="line.131"></a>
+<span class="sourceLineNo">132</span>   * reads finish and before any other reads start (what happens in reality is we read the<a name="line.132"></a>
+<span class="sourceLineNo">133</span>   * tail, then call this based on what's in the tail, then read blocks).<a name="line.133"></a>
+<span class="sourceLineNo">134</span>   * @param forceNoHBaseChecksum Force not using HBase checksum.<a name="line.134"></a>
+<span class="sourceLineNo">135</span>   */<a name="line.135"></a>
+<span class="sourceLineNo">136</span>  public void prepareForBlockReader(boolean forceNoHBaseChecksum) throws IOException {<a name="line.136"></a>
+<span class="sourceLineNo">137</span>    if (hfs == null) return;<a name="line.137"></a>
+<span class="sourceLineNo">138</span>    assert this.stream != null &amp;&amp; !this.useHBaseChecksumConfigured;<a name="line.138"></a>
+<span class="sourceLineNo">139</span>    boolean useHBaseChecksum =<a name="line.139"></a>
+<span class="sourceLineNo">140</span>        !forceNoHBaseChecksum &amp;&amp; hfs.useHBaseChecksum() &amp;&amp; (hfs.getNoChecksumFs() != hfs);<a name="line.140"></a>
+<span class="sourceLineNo">141</span><a name="line.141"></a>
+<span class="sourceLineNo">142</span>    if (useHBaseChecksum) {<a name="line.142"></a>
+<span class="sourceLineNo">143</span>      FileSystem fsNc = hfs.getNoChecksumFs();<a name="line.143"></a>
+<span class="sourceLineNo">144</span>      this.streamNoFsChecksum = (link != null) ? link.open(fsNc) : fsNc.open(path);<a name="line.144"></a>
+<span class="sourceLineNo">145</span>      setStreamOptions(streamNoFsChecksum);<a name="line.145"></a>
+<span class="sourceLineNo">146</span>      this.useHBaseChecksumConfigured = this.useHBaseChecksum = useHBaseChecksum;<a name="line.146"></a>
+<span class="sourceLineNo">147</span>      // Close the checksum stream; we will reopen it if we get an HBase checksum failure.<a name="line.147"></a>
+<span class="sourceLineNo">148</span>      this.stream.close();<a name="line.148"></a>
+<span class="sourceLineNo">149</span>      this.stream = null;<a name="line.149"></a>
+<span class="sourceLineNo">150</span>    }<a name="line.150"></a>
+<span class="sourceLineNo">151</span>  }<a name="line.151"></a>
+<span class="sourceLineNo">152</span><a name="line.152"></a>
+<span class="sourceLineNo">153</span>  /** For use in tests. */<a name="line.153"></a>
+<span class="sourceLineNo">154</span>  @VisibleForTesting<a name="line.154"></a>
+<span class="sourceLineNo">155</span>  public FSDataInputStreamWrapper(FSDataInputStream fsdis) {<a name="line.155"></a>
+<span class="sourceLineNo">156</span>    this(fsdis, fsdis);<a name="line.156"></a>
+<span class="sourceLineNo">157</span>  }<a name="line.157"></a>
+<span class="sourceLineNo">158</span><a name="line.158"></a>
+<span class="sourceLineNo">159</span>  /** For use in tests. */<a name="line.159"></a>
+<span class="sourceLineNo">160</span>  @VisibleForTesting<a name="line.160"></a>
+<span class="sourceLineNo">161</span>  public FSDataInputStreamWrapper(FSDataInputStream fsdis, FSDataInputStream noChecksum) {<a name="line.161"></a>
+<span class="sourceLineNo">162</span>    doCloseStreams = false;<a name="line.162"></a>
+<span class="sourceLineNo">163</span>    stream = fsdis;<a name="line.163"></a>
+<span class="sourceLineNo">164</span>    streamNoFsChecksum = noChecksum;<a name="line.164"></a>
+<span class="sourceLineNo">165</span>    path = null;<a name="line.165"></a>
+<span class="sourceLineNo">166</span>    link = null;<a name="line.166"></a>
+<span class="sourceLineNo">167</span>    hfs = null;<a name="line.167"></a>
+<span class="sourceLineNo">168</span>    useHBaseChecksumConfigured = useHBaseChecksum = false;<a name="line.168"></a>
+<span class="sourceLineNo">169</span>    dropBehind = false;<a name="line.169"></a>
+<span class="sourceLineNo">170</span>    readahead = 0;<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>  /**<a name="line.173"></a>
+<span class="sourceLineNo">174</span>   * @return Whether we are presently using HBase checksum.<a name="line.174"></a>
+<span class="sourceLineNo">175</span>   */<a name="line.175"></a>
+<span class="sourceLineNo">176</span>  public boolean shouldUseHBaseChecksum() {<a name="line.176"></a>
+<span class="sourceLineNo">177</span>    return this.useHBaseChecksum;<a name="line.177"></a>
+<span class="sourceLineNo">178</span>  }<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>   * Get the stream to use. Thread-safe.<a name="line.181"></a>
+<span class="sourceLineNo">182</span>   * @param useHBaseChecksum must be the value that shouldUseHBaseChecksum has returned<a name="line.182"></a>
+<span class="sourceLineNo">183</span>   *  at some point in the past, otherwise the result is undefined.<a name="line.183"></a>
+<span class="sourceLineNo">184</span>   */<a name="line.184"></a>
+<span class="sourceLineNo">185</span>  public FSDataInputStream getStream(boolean useHBaseChecksum) {<a name="line.185"></a>
+<span class="sourceLineNo">186</span>    return useHBaseChecksum ? this.streamNoFsChecksum : this.stream;<a name="line.186"></a>
+<span class="sourceLineNo">187</span>  }<a name="line.187"></a>
+<span class="sourceLineNo">188</span><a name="line.188"></a>
+<span class="sourceLineNo">189</span>  /**<a name="line.189"></a>
+<span class="sourceLineNo">190</span>   * Read from non-checksum stream failed, fall back to FS checksum. Thread-safe.<a name="line.190"></a>
+<span class="sourceLineNo">191</span>   * @param offCount For how many checksumOk calls to turn off the HBase checksum.<a name="line.191"></a>
+<span class="sourceLineNo">192</span>   */<a name="line.192"></a>
+<span class="sourceLineNo">193</span>  public FSDataInputStream fallbackToFsChecksum(int offCount) throws IOException {<a name="line.193"></a>
+<span class="sourceLineNo">194</span>    // checksumOffCount is speculative, but let's try to reset it less.<a name="line.194"></a>
+<span class="sourceLineNo">195</span>    boolean partOfConvoy = false;<a name="line.195"></a>
+<span class="sourceLineNo">196</span>    if (this.stream == null) {<a name="line.196"></a>
+<span class="sourceLineNo">197</span>      synchronized (streamNoFsChecksumFirstCreateLock) {<a name="line.197"></a>
+<span class="sourceLineNo">198</span>        partOfConvoy = (this.stream != null);<a name="line.198"></a>
+<span class="sourceLineNo">199</span>        if (!partOfConvoy) {<a name="line.199"></a>
+<span class="sourceLineNo">200</span>          this.stream = (link != null) ? link.open(hfs) : hfs.open(path);<a name="line.200"></a>
+<span class="sourceLineNo">201</span>        }<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>    if (!partOfConvoy) {<a name="line.204"></a>
+<span class="sourceLineNo">205</span>      this.useHBaseChecksum = false;<a name="line.205"></a>
+<span class="sourceLineNo">206</span>      this.hbaseChecksumOffCount = offCount;<a name="line.206"></a>
+<span class="sourceLineNo">207</span>    }<a name="line.207"></a>
+<span class="sourceLineNo">208</span>    return this.stream;<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>  /** Report that checksum was ok, so we may ponder going back to HBase checksum. */<a name="line.211"></a>
+<span class="sourceLineNo">212</span>  public void checksumOk() {<a name="line.212"></a>
+<span class="sourceLineNo">213</span>    if (this.useHBaseChecksumConfigured &amp;&amp; !this.useHBaseChecksum<a name="line.213"></a>
+<span class="sourceLineNo">214</span>        &amp;&amp; (this.hbaseChecksumOffCount-- &lt; 0)) {<a name="line.214"></a>
+<span class="sourceLineNo">215</span>      // The stream we need is already open (because we were using HBase checksum in the past).<a name="line.215"></a>
+<span class="sourceLineNo">216</span>      assert this.streamNoFsChecksum != null;<a name="line.216"></a>
+<span class="sourceLineNo">217</span>      this.useHBaseChecksum = true;<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><a name="line.220"></a>
+<span class="sourceLineNo">221</span>  /** Close stream(s) if necessary. */<a name="line.221"></a>
+<span class="sourceLineNo">222</span>  @Override<a name="line.222"></a>
+<span class="sourceLineNo">223</span>  public void close() {<a name="line.223"></a>
+<span class="sourceLineNo">224</span>    if (!doCloseStreams) {<a name="line.224"></a>
+<span class="sourceLineNo">225</span>      return;<a name="line.225"></a>
+<span class="sourceLineNo">226</span>    }<a name="line.226"></a>
+<span class="sourceLineNo">227</span>    // we do not care about the close exception as it is for reading, no data loss issue.<a name="line.227"></a>
+<span class="sourceLineNo">228</span>    IOUtils.closeQuietly(streamNoFsChecksum);<a name="line.228"></a>
+<span class="sourceLineNo">229</span>    IOUtils.closeQuietly(stream);<a name="line.229"></a>
+<span class="sourceLineNo">230</span>  }<a name="line.230"></a>
+<span class="sourceLineNo">231</span><a name="line.231"></a>
+<span class="sourceLineNo">232</span>  public HFileSystem getHfs() {<a name="line.232"></a>
+<span class="sourceLineNo">233</span>    return this.hfs;<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>
 
 
 


Mime
View raw message