http://git-wip-us.apache.org/repos/asf/hbase-site/blob/f8d69509/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/wal/ProtobufLogReader.WALHdrResult.html
----------------------------------------------------------------------
diff --git 
a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/wal/ProtobufLogReader.WALHdrResult.html
 
b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/wal/ProtobufLogReader.WALHdrResult.html
index 98a2d4e..38d4804 100644
--- 
a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/wal/ProtobufLogReader.WALHdrResult.html
+++ 
b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/wal/ProtobufLogReader.WALHdrResult.html
@@ -99,328 +99,329 @@
 <span class="sourceLineNo">091</span>  private static List&lt;String&gt; 
writerClsNames = new ArrayList&lt;String&gt;();<a name="line.91"></a>
 <span class="sourceLineNo">092</span>  static {<a name="line.92"></a>
 <span class="sourceLineNo">093</span>    
writerClsNames.add(ProtobufLogWriter.class.getSimpleName());<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>  // cell codec classname<a 
name="line.96"></a>
-<span class="sourceLineNo">097</span>  private String codecClsName = null;<a 
name="line.97"></a>
-<span class="sourceLineNo">098</span><a name="line.98"></a>
-<span class="sourceLineNo">099</span>  enum WALHdrResult {<a 
name="line.99"></a>
-<span class="sourceLineNo">100</span>    EOF,                   // stream is 
at EOF when method starts<a name="line.100"></a>
-<span class="sourceLineNo">101</span>    SUCCESS,<a name="line.101"></a>
-<span class="sourceLineNo">102</span>    UNKNOWN_WRITER_CLS     // name of 
writer class isn't recognized<a name="line.102"></a>
-<span class="sourceLineNo">103</span>  }<a name="line.103"></a>
-<span class="sourceLineNo">104</span>  <a name="line.104"></a>
-<span class="sourceLineNo">105</span>  // context for WALHdr carrying 
information such as Cell Codec classname<a name="line.105"></a>
-<span class="sourceLineNo">106</span>  static class WALHdrContext {<a 
name="line.106"></a>
-<span class="sourceLineNo">107</span>    WALHdrResult result;<a 
name="line.107"></a>
-<span class="sourceLineNo">108</span>    String cellCodecClsName;<a 
name="line.108"></a>
-<span class="sourceLineNo">109</span>    <a name="line.109"></a>
-<span class="sourceLineNo">110</span>    WALHdrContext(WALHdrResult result, 
String cellCodecClsName) {<a name="line.110"></a>
-<span class="sourceLineNo">111</span>      this.result = result;<a 
name="line.111"></a>
-<span class="sourceLineNo">112</span>      this.cellCodecClsName = 
cellCodecClsName;<a name="line.112"></a>
-<span class="sourceLineNo">113</span>    }<a name="line.113"></a>
-<span class="sourceLineNo">114</span>    WALHdrResult getResult() {<a 
name="line.114"></a>
-<span class="sourceLineNo">115</span>      return result;<a 
name="line.115"></a>
-<span class="sourceLineNo">116</span>    }<a name="line.116"></a>
-<span class="sourceLineNo">117</span>    String getCellCodecClsName() {<a 
name="line.117"></a>
-<span class="sourceLineNo">118</span>      return cellCodecClsName;<a 
name="line.118"></a>
-<span class="sourceLineNo">119</span>    }<a name="line.119"></a>
-<span class="sourceLineNo">120</span>  }<a name="line.120"></a>
-<span class="sourceLineNo">121</span><a name="line.121"></a>
-<span class="sourceLineNo">122</span>  public ProtobufLogReader() {<a 
name="line.122"></a>
-<span class="sourceLineNo">123</span>    super();<a name="line.123"></a>
-<span class="sourceLineNo">124</span>  }<a name="line.124"></a>
-<span class="sourceLineNo">125</span><a name="line.125"></a>
-<span class="sourceLineNo">126</span>  @Override<a name="line.126"></a>
-<span class="sourceLineNo">127</span>  public void close() throws IOException 
{<a name="line.127"></a>
-<span class="sourceLineNo">128</span>    if (this.inputStream != null) {<a 
name="line.128"></a>
-<span class="sourceLineNo">129</span>      this.inputStream.close();<a 
name="line.129"></a>
-<span class="sourceLineNo">130</span>      this.inputStream = null;<a 
name="line.130"></a>
-<span class="sourceLineNo">131</span>    }<a name="line.131"></a>
-<span class="sourceLineNo">132</span>  }<a name="line.132"></a>
-<span class="sourceLineNo">133</span><a name="line.133"></a>
-<span class="sourceLineNo">134</span>  @Override<a name="line.134"></a>
-<span class="sourceLineNo">135</span>  public long getPosition() throws 
IOException {<a name="line.135"></a>
-<span class="sourceLineNo">136</span>    return inputStream.getPos();<a 
name="line.136"></a>
-<span class="sourceLineNo">137</span>  }<a name="line.137"></a>
-<span class="sourceLineNo">138</span><a name="line.138"></a>
-<span class="sourceLineNo">139</span>  @Override<a name="line.139"></a>
-<span class="sourceLineNo">140</span>  public void reset() throws IOException 
{<a name="line.140"></a>
-<span class="sourceLineNo">141</span>    String clsName = initInternal(null, 
false);<a name="line.141"></a>
-<span class="sourceLineNo">142</span>    initAfterCompression(clsName); // We 
need a new decoder (at least).<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>  @Override<a name="line.145"></a>
-<span class="sourceLineNo">146</span>  public void init(FileSystem fs, Path 
path, Configuration conf, FSDataInputStream stream)<a name="line.146"></a>
-<span class="sourceLineNo">147</span>      throws IOException {<a 
name="line.147"></a>
-<span class="sourceLineNo">148</span>    this.trailerWarnSize = 
conf.getInt(WAL_TRAILER_WARN_SIZE, DEFAULT_WAL_TRAILER_WARN_SIZE);<a 
name="line.148"></a>
-<span class="sourceLineNo">149</span>    super.init(fs, path, conf, stream);<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>  @Override<a name="line.152"></a>
-<span class="sourceLineNo">153</span>  protected String 
initReader(FSDataInputStream stream) throws IOException {<a name="line.153"></a>
-<span class="sourceLineNo">154</span>    return initInternal(stream, true);<a 
name="line.154"></a>
-<span class="sourceLineNo">155</span>  }<a name="line.155"></a>
-<span class="sourceLineNo">156</span><a name="line.156"></a>
-<span class="sourceLineNo">157</span>  /*<a name="line.157"></a>
-<span class="sourceLineNo">158</span>   * Returns names of the accepted writer 
classes<a name="line.158"></a>
-<span class="sourceLineNo">159</span>   */<a name="line.159"></a>
-<span class="sourceLineNo">160</span>  public List&lt;String&gt; 
getWriterClsNames() {<a name="line.160"></a>
-<span class="sourceLineNo">161</span>    return writerClsNames;<a 
name="line.161"></a>
-<span class="sourceLineNo">162</span>  }<a name="line.162"></a>
-<span class="sourceLineNo">163</span>  <a name="line.163"></a>
-<span class="sourceLineNo">164</span>  /*<a name="line.164"></a>
-<span class="sourceLineNo">165</span>   * Returns the cell codec classname<a 
name="line.165"></a>
-<span class="sourceLineNo">166</span>   */<a name="line.166"></a>
-<span class="sourceLineNo">167</span>  public String getCodecClsName() {<a 
name="line.167"></a>
-<span class="sourceLineNo">168</span>      return codecClsName;<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>  protected WALHdrContext 
readHeader(Builder builder, FSDataInputStream stream)<a name="line.171"></a>
-<span class="sourceLineNo">172</span>      throws IOException {<a 
name="line.172"></a>
-<span class="sourceLineNo">173</span>     boolean res = 
builder.mergeDelimitedFrom(stream);<a name="line.173"></a>
-<span class="sourceLineNo">174</span>     if (!res) return new 
WALHdrContext(WALHdrResult.EOF, null);<a name="line.174"></a>
-<span class="sourceLineNo">175</span>     if (builder.hasWriterClsName() 
&amp;&amp;<a name="line.175"></a>
-<span class="sourceLineNo">176</span>         
!getWriterClsNames().contains(builder.getWriterClsName())) {<a 
name="line.176"></a>
-<span class="sourceLineNo">177</span>       return new 
WALHdrContext(WALHdrResult.UNKNOWN_WRITER_CLS, null);<a name="line.177"></a>
-<span class="sourceLineNo">178</span>     }<a name="line.178"></a>
-<span class="sourceLineNo">179</span>     String clsName = null;<a 
name="line.179"></a>
-<span class="sourceLineNo">180</span>     if (builder.hasCellCodecClsName()) 
{<a name="line.180"></a>
-<span class="sourceLineNo">181</span>       clsName = 
builder.getCellCodecClsName();<a name="line.181"></a>
-<span class="sourceLineNo">182</span>     }<a name="line.182"></a>
-<span class="sourceLineNo">183</span>     return new 
WALHdrContext(WALHdrResult.SUCCESS, clsName);<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>  private String 
initInternal(FSDataInputStream stream, boolean isFirst)<a name="line.186"></a>
-<span class="sourceLineNo">187</span>      throws IOException {<a 
name="line.187"></a>
-<span class="sourceLineNo">188</span>    close();<a name="line.188"></a>
-<span class="sourceLineNo">189</span>    long expectedPos = 
PB_WAL_MAGIC.length;<a name="line.189"></a>
-<span class="sourceLineNo">190</span>    if (stream == null) {<a 
name="line.190"></a>
-<span class="sourceLineNo">191</span>      stream = fs.open(path);<a 
name="line.191"></a>
-<span class="sourceLineNo">192</span>      stream.seek(expectedPos);<a 
name="line.192"></a>
-<span class="sourceLineNo">193</span>    }<a name="line.193"></a>
-<span class="sourceLineNo">194</span>    if (stream.getPos() != expectedPos) 
{<a name="line.194"></a>
-<span class="sourceLineNo">195</span>      throw new IOException("The stream 
is at invalid position: " + stream.getPos());<a name="line.195"></a>
-<span class="sourceLineNo">196</span>    }<a name="line.196"></a>
-<span class="sourceLineNo">197</span>    // Initialize metadata or, when we 
reset, just skip the header.<a name="line.197"></a>
-<span class="sourceLineNo">198</span>    WALProtos.WALHeader.Builder builder = 
WALProtos.WALHeader.newBuilder();<a name="line.198"></a>
-<span class="sourceLineNo">199</span>    WALHdrContext hdrCtxt = 
readHeader(builder, stream);<a name="line.199"></a>
-<span class="sourceLineNo">200</span>    WALHdrResult walHdrRes = 
hdrCtxt.getResult();<a name="line.200"></a>
-<span class="sourceLineNo">201</span>    if (walHdrRes == WALHdrResult.EOF) 
{<a name="line.201"></a>
-<span class="sourceLineNo">202</span>      throw new EOFException("Couldn't 
read WAL PB header");<a name="line.202"></a>
-<span class="sourceLineNo">203</span>    }<a name="line.203"></a>
-<span class="sourceLineNo">204</span>    if (walHdrRes == 
WALHdrResult.UNKNOWN_WRITER_CLS) {<a name="line.204"></a>
-<span class="sourceLineNo">205</span>      throw new IOException("Got unknown 
writer class: " + builder.getWriterClsName());<a name="line.205"></a>
-<span class="sourceLineNo">206</span>    }<a name="line.206"></a>
-<span class="sourceLineNo">207</span>    if (isFirst) {<a name="line.207"></a>
-<span class="sourceLineNo">208</span>      WALProtos.WALHeader header = 
builder.build();<a name="line.208"></a>
-<span class="sourceLineNo">209</span>      this.hasCompression = 
header.hasHasCompression() &amp;&amp; header.getHasCompression();<a 
name="line.209"></a>
-<span class="sourceLineNo">210</span>      this.hasTagCompression = 
header.hasHasTagCompression() &amp;&amp; header.getHasTagCompression();<a 
name="line.210"></a>
-<span class="sourceLineNo">211</span>    }<a name="line.211"></a>
-<span class="sourceLineNo">212</span>    this.inputStream = stream;<a 
name="line.212"></a>
-<span class="sourceLineNo">213</span>    this.walEditsStopOffset = 
this.fileLength;<a name="line.213"></a>
-<span class="sourceLineNo">214</span>    long currentPosition = 
stream.getPos();<a name="line.214"></a>
-<span class="sourceLineNo">215</span>    trailerPresent = 
setTrailerIfPresent();<a name="line.215"></a>
-<span class="sourceLineNo">216</span>    this.seekOnFs(currentPosition);<a 
name="line.216"></a>
-<span class="sourceLineNo">217</span>    if (LOG.isTraceEnabled()) {<a 
name="line.217"></a>
-<span class="sourceLineNo">218</span>      LOG.trace("After reading the 
trailer: walEditsStopOffset: " + this.walEditsStopOffset<a name="line.218"></a>
-<span class="sourceLineNo">219</span>          + ", fileLength: " + 
this.fileLength + ", " + "trailerPresent: " + trailerPresent);<a 
name="line.219"></a>
-<span class="sourceLineNo">220</span>    }<a name="line.220"></a>
-<span class="sourceLineNo">221</span>    <a name="line.221"></a>
-<span class="sourceLineNo">222</span>    codecClsName = 
hdrCtxt.getCellCodecClsName();<a name="line.222"></a>
-<span class="sourceLineNo">223</span>    <a name="line.223"></a>
-<span class="sourceLineNo">224</span>    return 
hdrCtxt.getCellCodecClsName();<a name="line.224"></a>
-<span class="sourceLineNo">225</span>  }<a name="line.225"></a>
-<span class="sourceLineNo">226</span><a name="line.226"></a>
-<span class="sourceLineNo">227</span>  /**<a name="line.227"></a>
-<span class="sourceLineNo">228</span>   * To check whether a trailer is 
present in a WAL, it seeks to position (fileLength -<a name="line.228"></a>
-<span class="sourceLineNo">229</span>   * PB_WAL_COMPLETE_MAGIC.size() - 
Bytes.SIZEOF_INT). It reads the int value to know the size of<a 
name="line.229"></a>
-<span class="sourceLineNo">230</span>   * the trailer, and checks whether the 
trailer is present at the end or not by comparing the last<a 
name="line.230"></a>
-<span class="sourceLineNo">231</span>   * PB_WAL_COMPLETE_MAGIC.size() bytes. 
In case trailer is not present, it returns false;<a name="line.231"></a>
-<span class="sourceLineNo">232</span>   * otherwise, sets the trailer and sets 
this.walEditsStopOffset variable up to the point just<a name="line.232"></a>
-<span class="sourceLineNo">233</span>   * before the trailer.<a 
name="line.233"></a>
-<span class="sourceLineNo">234</span>   * &lt;ul&gt;<a name="line.234"></a>
-<span class="sourceLineNo">235</span>   * The trailer is ignored in case:<a 
name="line.235"></a>
-<span class="sourceLineNo">236</span>   * &lt;li&gt;fileLength is 0 or not 
correct (when file is under recovery, etc).<a name="line.236"></a>
-<span class="sourceLineNo">237</span>   * &lt;li&gt;the trailer size is 
negative.<a name="line.237"></a>
-<span class="sourceLineNo">238</span>   * &lt;/ul&gt;<a name="line.238"></a>
-<span class="sourceLineNo">239</span>   * &lt;p&gt;<a name="line.239"></a>
-<span class="sourceLineNo">240</span>   * In case the trailer size &gt; 
this.trailerMaxSize, it is read after a WARN message.<a name="line.240"></a>
-<span class="sourceLineNo">241</span>   * @return true if a valid trailer is 
present<a name="line.241"></a>
-<span class="sourceLineNo">242</span>   * @throws IOException<a 
name="line.242"></a>
-<span class="sourceLineNo">243</span>   */<a name="line.243"></a>
-<span class="sourceLineNo">244</span>  private boolean setTrailerIfPresent() 
{<a name="line.244"></a>
-<span class="sourceLineNo">245</span>    try {<a name="line.245"></a>
-<span class="sourceLineNo">246</span>      long trailerSizeOffset = 
this.fileLength - (PB_WAL_COMPLETE_MAGIC.length + Bytes.SIZEOF_INT);<a 
name="line.246"></a>
-<span class="sourceLineNo">247</span>      if (trailerSizeOffset &lt;= 0) 
return false;// no trailer possible.<a name="line.247"></a>
-<span class="sourceLineNo">248</span>      this.seekOnFs(trailerSizeOffset);<a 
name="line.248"></a>
-<span class="sourceLineNo">249</span>      // read the int as trailer size.<a 
name="line.249"></a>
-<span class="sourceLineNo">250</span>      int trailerSize = 
this.inputStream.readInt();<a name="line.250"></a>
-<span class="sourceLineNo">251</span>      ByteBuffer buf = 
ByteBuffer.allocate(ProtobufLogReader.PB_WAL_COMPLETE_MAGIC.length);<a 
name="line.251"></a>
-<span class="sourceLineNo">252</span>      
this.inputStream.readFully(buf.array(), buf.arrayOffset(), buf.capacity());<a 
name="line.252"></a>
-<span class="sourceLineNo">253</span>      if (!Arrays.equals(buf.array(), 
PB_WAL_COMPLETE_MAGIC)) {<a name="line.253"></a>
-<span class="sourceLineNo">254</span>        LOG.trace("No trailer found.");<a 
name="line.254"></a>
-<span class="sourceLineNo">255</span>        return false;<a 
name="line.255"></a>
-<span class="sourceLineNo">256</span>      }<a name="line.256"></a>
-<span class="sourceLineNo">257</span>      if (trailerSize &lt; 0) {<a 
name="line.257"></a>
-<span class="sourceLineNo">258</span>        LOG.warn("Invalid trailer Size " 
+ trailerSize + ", ignoring the trailer");<a name="line.258"></a>
-<span class="sourceLineNo">259</span>        return false;<a 
name="line.259"></a>
-<span class="sourceLineNo">260</span>      } else if (trailerSize &gt; 
this.trailerWarnSize) {<a name="line.260"></a>
-<span class="sourceLineNo">261</span>        // continue reading after warning 
the user.<a name="line.261"></a>
-<span class="sourceLineNo">262</span>        LOG.warn("Please investigate 
WALTrailer usage. Trailer size &gt; maximum configured size : "<a 
name="line.262"></a>
-<span class="sourceLineNo">263</span>          + trailerSize + " &gt; " + 
this.trailerWarnSize);<a name="line.263"></a>
-<span class="sourceLineNo">264</span>      }<a name="line.264"></a>
-<span class="sourceLineNo">265</span>      // seek to the position where 
trailer starts.<a name="line.265"></a>
-<span class="sourceLineNo">266</span>      long positionOfTrailer = 
trailerSizeOffset - trailerSize;<a name="line.266"></a>
-<span class="sourceLineNo">267</span>      this.seekOnFs(positionOfTrailer);<a 
name="line.267"></a>
-<span class="sourceLineNo">268</span>      // read the trailer.<a 
name="line.268"></a>
-<span class="sourceLineNo">269</span>      buf = 
ByteBuffer.allocate(trailerSize);// for trailer.<a name="line.269"></a>
-<span class="sourceLineNo">270</span>      
this.inputStream.readFully(buf.array(), buf.arrayOffset(), buf.capacity());<a 
name="line.270"></a>
-<span class="sourceLineNo">271</span>      trailer = 
WALTrailer.parseFrom(buf.array());<a name="line.271"></a>
-<span class="sourceLineNo">272</span>      this.walEditsStopOffset = 
positionOfTrailer;<a name="line.272"></a>
-<span class="sourceLineNo">273</span>      return true;<a name="line.273"></a>
-<span class="sourceLineNo">274</span>    } catch (IOException ioe) {<a 
name="line.274"></a>
-<span class="sourceLineNo">275</span>      LOG.warn("Got IOE while reading the 
trailer. Continuing as if no trailer is present.", ioe);<a name="line.275"></a>
-<span class="sourceLineNo">276</span>    }<a name="line.276"></a>
-<span class="sourceLineNo">277</span>    return false;<a name="line.277"></a>
-<span class="sourceLineNo">278</span>  }<a name="line.278"></a>
-<span class="sourceLineNo">279</span><a name="line.279"></a>
-<span class="sourceLineNo">280</span>  protected WALCellCodec 
getCodec(Configuration conf, String cellCodecClsName,<a name="line.280"></a>
-<span class="sourceLineNo">281</span>      CompressionContext 
compressionContext) throws IOException {<a name="line.281"></a>
-<span class="sourceLineNo">282</span>    return WALCellCodec.create(conf, 
cellCodecClsName, compressionContext);<a name="line.282"></a>
-<span class="sourceLineNo">283</span>  }<a name="line.283"></a>
-<span class="sourceLineNo">284</span><a name="line.284"></a>
-<span class="sourceLineNo">285</span>  @Override<a name="line.285"></a>
-<span class="sourceLineNo">286</span>  protected void initAfterCompression() 
throws IOException {<a name="line.286"></a>
-<span class="sourceLineNo">287</span>    initAfterCompression(null);<a 
name="line.287"></a>
-<span class="sourceLineNo">288</span>  }<a name="line.288"></a>
-<span class="sourceLineNo">289</span>  <a name="line.289"></a>
-<span class="sourceLineNo">290</span>  @Override<a name="line.290"></a>
-<span class="sourceLineNo">291</span>  protected void 
initAfterCompression(String cellCodecClsName) throws IOException {<a 
name="line.291"></a>
-<span class="sourceLineNo">292</span>    WALCellCodec codec = 
getCodec(this.conf, cellCodecClsName, this.compressionContext);<a 
name="line.292"></a>
-<span class="sourceLineNo">293</span>    this.cellDecoder = 
codec.getDecoder(this.inputStream);<a name="line.293"></a>
-<span class="sourceLineNo">294</span>    if (this.hasCompression) {<a 
name="line.294"></a>
-<span class="sourceLineNo">295</span>      this.byteStringUncompressor = 
codec.getByteStringUncompressor();<a name="line.295"></a>
-<span class="sourceLineNo">296</span>    }<a name="line.296"></a>
-<span class="sourceLineNo">297</span>  }<a name="line.297"></a>
-<span class="sourceLineNo">298</span><a name="line.298"></a>
-<span class="sourceLineNo">299</span>  @Override<a name="line.299"></a>
-<span class="sourceLineNo">300</span>  protected boolean hasCompression() {<a 
name="line.300"></a>
-<span class="sourceLineNo">301</span>    return this.hasCompression;<a 
name="line.301"></a>
-<span class="sourceLineNo">302</span>  }<a name="line.302"></a>
-<span class="sourceLineNo">303</span><a name="line.303"></a>
-<span class="sourceLineNo">304</span>  @Override<a name="line.304"></a>
-<span class="sourceLineNo">305</span>  protected boolean hasTagCompression() 
{<a name="line.305"></a>
-<span class="sourceLineNo">306</span>    return this.hasTagCompression;<a 
name="line.306"></a>
-<span class="sourceLineNo">307</span>  }<a name="line.307"></a>
-<span class="sourceLineNo">308</span><a name="line.308"></a>
-<span class="sourceLineNo">309</span>  @Override<a name="line.309"></a>
-<span class="sourceLineNo">310</span>  protected boolean readNext(Entry entry) 
throws IOException {<a name="line.310"></a>
-<span class="sourceLineNo">311</span>    while (true) {<a name="line.311"></a>
-<span class="sourceLineNo">312</span>      // OriginalPosition might be &lt; 0 
on local fs; if so, it is useless to us.<a name="line.312"></a>
-<span class="sourceLineNo">313</span>      long originalPosition = 
this.inputStream.getPos();<a name="line.313"></a>
-<span class="sourceLineNo">314</span>      if (trailerPresent &amp;&amp; 
originalPosition &gt; 0 &amp;&amp; originalPosition == this.walEditsStopOffset) 
{<a name="line.314"></a>
-<span class="sourceLineNo">315</span>        return false;<a 
name="line.315"></a>
-<span class="sourceLineNo">316</span>      }<a name="line.316"></a>
-<span class="sourceLineNo">317</span>      WALKey.Builder builder = 
WALKey.newBuilder();<a name="line.317"></a>
-<span class="sourceLineNo">318</span>      long size = 0;<a 
name="line.318"></a>
-<span class="sourceLineNo">319</span>      try {<a name="line.319"></a>
-<span class="sourceLineNo">320</span>        long available = -1;<a 
name="line.320"></a>
-<span class="sourceLineNo">321</span>        try {<a name="line.321"></a>
-<span class="sourceLineNo">322</span>          int firstByte = 
this.inputStream.read();<a name="line.322"></a>
-<span class="sourceLineNo">323</span>          if (firstByte == -1) {<a 
name="line.323"></a>
-<span class="sourceLineNo">324</span>            throw new EOFException("First 
byte is negative");<a name="line.324"></a>
-<span class="sourceLineNo">325</span>          }<a name="line.325"></a>
-<span class="sourceLineNo">326</span>          size = 
CodedInputStream.readRawVarint32(firstByte, this.inputStream);<a 
name="line.326"></a>
-<span class="sourceLineNo">327</span>          // available may be &lt; 0 on 
local fs for instance.  If so, can't depend on it.<a name="line.327"></a>
-<span class="sourceLineNo">328</span>          available = 
this.inputStream.available();<a name="line.328"></a>
-<span class="sourceLineNo">329</span>          if (available &gt; 0 &amp;&amp; 
available &lt; size) {<a name="line.329"></a>
-<span class="sourceLineNo">330</span>            throw new 
EOFException("Available stream not enough for edit, " +<a name="line.330"></a>
-<span class="sourceLineNo">331</span>                "inputStream.available()= 
" + this.inputStream.available() + ", " +<a name="line.331"></a>
-<span class="sourceLineNo">332</span>                "entry size= " + size);<a 
name="line.332"></a>
-<span class="sourceLineNo">333</span>          }<a name="line.333"></a>
-<span class="sourceLineNo">334</span>          ProtobufUtil.mergeFrom(builder, 
new LimitInputStream(this.inputStream, size),<a name="line.334"></a>
-<span class="sourceLineNo">335</span>            (int)size);<a 
name="line.335"></a>
-<span class="sourceLineNo">336</span>        } catch 
(InvalidProtocolBufferException ipbe) {<a name="line.336"></a>
-<span class="sourceLineNo">337</span>          throw (EOFException) new 
EOFException("Invalid PB, EOF? Ignoring; originalPosition=" +<a 
name="line.337"></a>
-<span class="sourceLineNo">338</span>            originalPosition + ", 
currentPosition=" + this.inputStream.getPos() +<a name="line.338"></a>
-<span class="sourceLineNo">339</span>            ", messageSize=" + size + ", 
currentAvailable=" + available).initCause(ipbe);<a name="line.339"></a>
-<span class="sourceLineNo">340</span>        }<a name="line.340"></a>
-<span class="sourceLineNo">341</span>        if (!builder.isInitialized()) {<a 
name="line.341"></a>
-<span class="sourceLineNo">342</span>          // TODO: not clear if we should 
try to recover from corrupt PB that looks semi-legit.<a name="line.342"></a>
-<span class="sourceLineNo">343</span>          //       If we can get the KV 
count, we could, theoretically, try to get next record.<a name="line.343"></a>
-<span class="sourceLineNo">344</span>          throw new EOFException("Partial 
PB while reading WAL, " +<a name="line.344"></a>
-<span class="sourceLineNo">345</span>              "probably an unexpected 
EOF, ignoring");<a name="line.345"></a>
-<span class="sourceLineNo">346</span>        }<a name="line.346"></a>
-<span class="sourceLineNo">347</span>        WALKey walKey = 
builder.build();<a name="line.347"></a>
-<span class="sourceLineNo">348</span>        
entry.getKey().readFieldsFromPb(walKey, this.byteStringUncompressor);<a 
name="line.348"></a>
-<span class="sourceLineNo">349</span>        if (!walKey.hasFollowingKvCount() 
|| 0 == walKey.getFollowingKvCount()) {<a name="line.349"></a>
-<span class="sourceLineNo">350</span>          LOG.trace("WALKey has no KVs 
that follow it; trying the next one");<a name="line.350"></a>
-<span class="sourceLineNo">351</span>          continue;<a name="line.351"></a>
-<span class="sourceLineNo">352</span>        }<a name="line.352"></a>
-<span class="sourceLineNo">353</span>        int expectedCells = 
walKey.getFollowingKvCount();<a name="line.353"></a>
-<span class="sourceLineNo">354</span>        long posBefore = 
this.inputStream.getPos();<a name="line.354"></a>
-<span class="sourceLineNo">355</span>        try {<a name="line.355"></a>
-<span class="sourceLineNo">356</span>          int actualCells = 
entry.getEdit().readFromCells(cellDecoder, expectedCells);<a 
name="line.356"></a>
-<span class="sourceLineNo">357</span>          if (expectedCells != 
actualCells) {<a name="line.357"></a>
-<span class="sourceLineNo">358</span>            throw new EOFException("Only 
read " + actualCells); // other info added in catch<a name="line.358"></a>
-<span class="sourceLineNo">359</span>          }<a name="line.359"></a>
-<span class="sourceLineNo">360</span>        } catch (Exception ex) {<a 
name="line.360"></a>
-<span class="sourceLineNo">361</span>          String posAfterStr = 
"&lt;unknown&gt;";<a name="line.361"></a>
-<span class="sourceLineNo">362</span>          try {<a name="line.362"></a>
-<span class="sourceLineNo">363</span>            posAfterStr = 
this.inputStream.getPos() + "";<a name="line.363"></a>
-<span class="sourceLineNo">364</span>          } catch (Throwable t) {<a 
name="line.364"></a>
-<span class="sourceLineNo">365</span>            LOG.trace("Error getting pos 
for error message - ignoring", t);<a name="line.365"></a>
-<span class="sourceLineNo">366</span>          }<a name="line.366"></a>
-<span class="sourceLineNo">367</span>          String message = " while 
reading " + expectedCells + " WAL KVs; started reading at "<a 
name="line.367"></a>
-<span class="sourceLineNo">368</span>              + posBefore + " and read up 
to " + posAfterStr;<a name="line.368"></a>
-<span class="sourceLineNo">369</span>          IOException realEofEx = 
extractHiddenEof(ex);<a name="line.369"></a>
-<span class="sourceLineNo">370</span>          throw (EOFException) new 
EOFException("EOF " + message).<a name="line.370"></a>
-<span class="sourceLineNo">371</span>              initCause(realEofEx != null 
? realEofEx : ex);<a name="line.371"></a>
-<span class="sourceLineNo">372</span>        }<a name="line.372"></a>
-<span class="sourceLineNo">373</span>        if (trailerPresent &amp;&amp; 
this.inputStream.getPos() &gt; this.walEditsStopOffset) {<a name="line.373"></a>
-<span class="sourceLineNo">374</span>          LOG.error("Read WALTrailer 
while reading WALEdits. wal: " + this.path<a name="line.374"></a>
-<span class="sourceLineNo">375</span>              + ", inputStream.getPos(): 
" + this.inputStream.getPos() + ", walEditsStopOffset: "<a name="line.375"></a>
-<span class="sourceLineNo">376</span>              + 
this.walEditsStopOffset);<a name="line.376"></a>
-<span class="sourceLineNo">377</span>          throw new EOFException("Read 
WALTrailer while reading WALEdits");<a name="line.377"></a>
-<span class="sourceLineNo">378</span>        }<a name="line.378"></a>
-<span class="sourceLineNo">379</span>      } catch (EOFException eof) {<a 
name="line.379"></a>
-<span class="sourceLineNo">380</span>        LOG.trace("Encountered a 
malformed edit, seeking back to last good position in file", eof);<a 
name="line.380"></a>
-<span class="sourceLineNo">381</span>        // If originalPosition is &lt; 0, 
it is rubbish and we cannot use it (probably local fs)<a name="line.381"></a>
-<span class="sourceLineNo">382</span>        if (originalPosition &lt; 0) 
throw eof;<a name="line.382"></a>
-<span class="sourceLineNo">383</span>        // Else restore our position to 
original location in hope that next time through we will<a name="line.383"></a>
-<span class="sourceLineNo">384</span>        // read successfully.<a 
name="line.384"></a>
-<span class="sourceLineNo">385</span>        seekOnFs(originalPosition);<a 
name="line.385"></a>
-<span class="sourceLineNo">386</span>        return false;<a 
name="line.386"></a>
-<span class="sourceLineNo">387</span>      }<a name="line.387"></a>
-<span class="sourceLineNo">388</span>      return true;<a name="line.388"></a>
-<span class="sourceLineNo">389</span>    }<a name="line.389"></a>
-<span class="sourceLineNo">390</span>  }<a name="line.390"></a>
-<span class="sourceLineNo">391</span><a name="line.391"></a>
-<span class="sourceLineNo">392</span>  private IOException 
extractHiddenEof(Exception ex) {<a name="line.392"></a>
-<span class="sourceLineNo">393</span>    // There are two problems we are 
dealing with here. Hadoop stream throws generic exception<a name="line.393"></a>
-<span class="sourceLineNo">394</span>    // for EOF, not EOFException; and 
scanner further hides it inside RuntimeException.<a name="line.394"></a>
-<span class="sourceLineNo">395</span>    IOException ioEx = null;<a 
name="line.395"></a>
-<span class="sourceLineNo">396</span>    if (ex instanceof EOFException) {<a 
name="line.396"></a>
-<span class="sourceLineNo">397</span>      return (EOFException)ex;<a 
name="line.397"></a>
-<span class="sourceLineNo">398</span>    } else if (ex instanceof IOException) 
{<a name="line.398"></a>
-<span class="sourceLineNo">399</span>      ioEx = (IOException)ex;<a 
name="line.399"></a>
-<span class="sourceLineNo">400</span>    } else if (ex instanceof 
RuntimeException<a name="line.400"></a>
-<span class="sourceLineNo">401</span>        &amp;&amp; ex.getCause() != null 
&amp;&amp; ex.getCause() instanceof IOException) {<a name="line.401"></a>
-<span class="sourceLineNo">402</span>      ioEx = 
(IOException)ex.getCause();<a name="line.402"></a>
-<span class="sourceLineNo">403</span>    }<a name="line.403"></a>
-<span class="sourceLineNo">404</span>    if (ioEx != null) {<a 
name="line.404"></a>
-<span class="sourceLineNo">405</span>      if 
(ioEx.getMessage().contains("EOF")) return ioEx;<a name="line.405"></a>
-<span class="sourceLineNo">406</span>      return null;<a name="line.406"></a>
-<span class="sourceLineNo">407</span>    }<a name="line.407"></a>
-<span class="sourceLineNo">408</span>    return null;<a name="line.408"></a>
-<span class="sourceLineNo">409</span>  }<a name="line.409"></a>
-<span class="sourceLineNo">410</span><a name="line.410"></a>
-<span class="sourceLineNo">411</span>  @Override<a name="line.411"></a>
-<span class="sourceLineNo">412</span>  protected void seekOnFs(long pos) 
throws IOException {<a name="line.412"></a>
-<span class="sourceLineNo">413</span>    this.inputStream.seek(pos);<a 
name="line.413"></a>
-<span class="sourceLineNo">414</span>  }<a name="line.414"></a>
-<span class="sourceLineNo">415</span>}<a name="line.415"></a>
+<span class="sourceLineNo">094</span>    
writerClsNames.add(AsyncProtobufLogWriter.class.getSimpleName());<a 
name="line.94"></a>
+<span class="sourceLineNo">095</span>  }<a name="line.95"></a>
+<span class="sourceLineNo">096</span>  <a name="line.96"></a>
+<span class="sourceLineNo">097</span>  // cell codec classname<a 
name="line.97"></a>
+<span class="sourceLineNo">098</span>  private String codecClsName = null;<a 
name="line.98"></a>
+<span class="sourceLineNo">099</span><a name="line.99"></a>
+<span class="sourceLineNo">100</span>  enum WALHdrResult {<a 
name="line.100"></a>
+<span class="sourceLineNo">101</span>    EOF,                   // stream is 
at EOF when method starts<a name="line.101"></a>
+<span class="sourceLineNo">102</span>    SUCCESS,<a name="line.102"></a>
+<span class="sourceLineNo">103</span>    UNKNOWN_WRITER_CLS     // name of 
writer class isn't recognized<a name="line.103"></a>
+<span class="sourceLineNo">104</span>  }<a name="line.104"></a>
+<span class="sourceLineNo">105</span>  <a name="line.105"></a>
+<span class="sourceLineNo">106</span>  // context for WALHdr carrying 
information such as Cell Codec classname<a name="line.106"></a>
+<span class="sourceLineNo">107</span>  static class WALHdrContext {<a 
name="line.107"></a>
+<span class="sourceLineNo">108</span>    WALHdrResult result;<a 
name="line.108"></a>
+<span class="sourceLineNo">109</span>    String cellCodecClsName;<a 
name="line.109"></a>
+<span class="sourceLineNo">110</span>    <a name="line.110"></a>
+<span class="sourceLineNo">111</span>    WALHdrContext(WALHdrResult result, 
String cellCodecClsName) {<a name="line.111"></a>
+<span class="sourceLineNo">112</span>      this.result = result;<a 
name="line.112"></a>
+<span class="sourceLineNo">113</span>      this.cellCodecClsName = 
cellCodecClsName;<a name="line.113"></a>
+<span class="sourceLineNo">114</span>    }<a name="line.114"></a>
+<span class="sourceLineNo">115</span>    WALHdrResult getResult() {<a 
name="line.115"></a>
+<span class="sourceLineNo">116</span>      return result;<a 
name="line.116"></a>
+<span class="sourceLineNo">117</span>    }<a name="line.117"></a>
+<span class="sourceLineNo">118</span>    String getCellCodecClsName() {<a 
name="line.118"></a>
+<span class="sourceLineNo">119</span>      return cellCodecClsName;<a 
name="line.119"></a>
+<span class="sourceLineNo">120</span>    }<a name="line.120"></a>
+<span class="sourceLineNo">121</span>  }<a name="line.121"></a>
+<span class="sourceLineNo">122</span><a name="line.122"></a>
+<span class="sourceLineNo">123</span>  public ProtobufLogReader() {<a 
name="line.123"></a>
+<span class="sourceLineNo">124</span>    super();<a name="line.124"></a>
+<span class="sourceLineNo">125</span>  }<a name="line.125"></a>
+<span class="sourceLineNo">126</span><a name="line.126"></a>
+<span class="sourceLineNo">127</span>  @Override<a name="line.127"></a>
+<span class="sourceLineNo">128</span>  public void close() throws IOException 
{<a name="line.128"></a>
+<span class="sourceLineNo">129</span>    if (this.inputStream != null) {<a 
name="line.129"></a>
+<span class="sourceLineNo">130</span>      this.inputStream.close();<a 
name="line.130"></a>
+<span class="sourceLineNo">131</span>      this.inputStream = null;<a 
name="line.131"></a>
+<span class="sourceLineNo">132</span>    }<a name="line.132"></a>
+<span class="sourceLineNo">133</span>  }<a name="line.133"></a>
+<span class="sourceLineNo">134</span><a name="line.134"></a>
+<span class="sourceLineNo">135</span>  @Override<a name="line.135"></a>
+<span class="sourceLineNo">136</span>  public long getPosition() throws 
IOException {<a name="line.136"></a>
+<span class="sourceLineNo">137</span>    return inputStream.getPos();<a 
name="line.137"></a>
+<span class="sourceLineNo">138</span>  }<a name="line.138"></a>
+<span class="sourceLineNo">139</span><a name="line.139"></a>
+<span class="sourceLineNo">140</span>  @Override<a name="line.140"></a>
+<span class="sourceLineNo">141</span>  public void reset() throws IOException 
{<a name="line.141"></a>
+<span class="sourceLineNo">142</span>    String clsName = initInternal(null, 
false);<a name="line.142"></a>
+<span class="sourceLineNo">143</span>    initAfterCompression(clsName); // We 
need a new decoder (at least).<a name="line.143"></a>
+<span class="sourceLineNo">144</span>  }<a name="line.144"></a>
+<span class="sourceLineNo">145</span><a name="line.145"></a>
+<span class="sourceLineNo">146</span>  @Override<a name="line.146"></a>
+<span class="sourceLineNo">147</span>  public void init(FileSystem fs, Path 
path, Configuration conf, FSDataInputStream stream)<a name="line.147"></a>
+<span class="sourceLineNo">148</span>      throws IOException {<a 
name="line.148"></a>
+<span class="sourceLineNo">149</span>    this.trailerWarnSize = 
conf.getInt(WAL_TRAILER_WARN_SIZE, DEFAULT_WAL_TRAILER_WARN_SIZE);<a 
name="line.149"></a>
+<span class="sourceLineNo">150</span>    super.init(fs, path, conf, stream);<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>  @Override<a name="line.153"></a>
+<span class="sourceLineNo">154</span>  protected String 
initReader(FSDataInputStream stream) throws IOException {<a name="line.154"></a>
+<span class="sourceLineNo">155</span>    return initInternal(stream, true);<a 
name="line.155"></a>
+<span class="sourceLineNo">156</span>  }<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>   * Returns names of the accepted writer 
classes<a name="line.159"></a>
+<span class="sourceLineNo">160</span>   */<a name="line.160"></a>
+<span class="sourceLineNo">161</span>  public List&lt;String&gt; 
getWriterClsNames() {<a name="line.161"></a>
+<span class="sourceLineNo">162</span>    return writerClsNames;<a 
name="line.162"></a>
+<span class="sourceLineNo">163</span>  }<a name="line.163"></a>
+<span class="sourceLineNo">164</span>  <a name="line.164"></a>
+<span class="sourceLineNo">165</span>  /*<a name="line.165"></a>
+<span class="sourceLineNo">166</span>   * Returns the cell codec classname<a 
name="line.166"></a>
+<span class="sourceLineNo">167</span>   */<a name="line.167"></a>
+<span class="sourceLineNo">168</span>  public String getCodecClsName() {<a 
name="line.168"></a>
+<span class="sourceLineNo">169</span>      return codecClsName;<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>  protected WALHdrContext 
readHeader(Builder builder, FSDataInputStream stream)<a name="line.172"></a>
+<span class="sourceLineNo">173</span>      throws IOException {<a 
name="line.173"></a>
+<span class="sourceLineNo">174</span>     boolean res = 
builder.mergeDelimitedFrom(stream);<a name="line.174"></a>
+<span class="sourceLineNo">175</span>     if (!res) return new 
WALHdrContext(WALHdrResult.EOF, null);<a name="line.175"></a>
+<span class="sourceLineNo">176</span>     if (builder.hasWriterClsName() 
&amp;&amp;<a name="line.176"></a>
+<span class="sourceLineNo">177</span>         
!getWriterClsNames().contains(builder.getWriterClsName())) {<a 
name="line.177"></a>
+<span class="sourceLineNo">178</span>       return new 
WALHdrContext(WALHdrResult.UNKNOWN_WRITER_CLS, null);<a name="line.178"></a>
+<span class="sourceLineNo">179</span>     }<a name="line.179"></a>
+<span class="sourceLineNo">180</span>     String clsName = null;<a 
name="line.180"></a>
+<span class="sourceLineNo">181</span>     if (builder.hasCellCodecClsName()) 
{<a name="line.181"></a>
+<span class="sourceLineNo">182</span>       clsName = 
builder.getCellCodecClsName();<a name="line.182"></a>
+<span class="sourceLineNo">183</span>     }<a name="line.183"></a>
+<span class="sourceLineNo">184</span>     return new 
WALHdrContext(WALHdrResult.SUCCESS, clsName);<a name="line.184"></a>
+<span class="sourceLineNo">185</span>  }<a name="line.185"></a>
+<span class="sourceLineNo">186</span><a name="line.186"></a>
+<span class="sourceLineNo">187</span>  private String 
initInternal(FSDataInputStream stream, boolean isFirst)<a name="line.187"></a>
+<span class="sourceLineNo">188</span>      throws IOException {<a 
name="line.188"></a>
+<span class="sourceLineNo">189</span>    close();<a name="line.189"></a>
+<span class="sourceLineNo">190</span>    long expectedPos = 
PB_WAL_MAGIC.length;<a name="line.190"></a>
+<span class="sourceLineNo">191</span>    if (stream == null) {<a 
name="line.191"></a>
+<span class="sourceLineNo">192</span>      stream = fs.open(path);<a 
name="line.192"></a>
+<span class="sourceLineNo">193</span>      stream.seek(expectedPos);<a 
name="line.193"></a>
+<span class="sourceLineNo">194</span>    }<a name="line.194"></a>
+<span class="sourceLineNo">195</span>    if (stream.getPos() != expectedPos) 
{<a name="line.195"></a>
+<span class="sourceLineNo">196</span>      throw new IOException("The stream 
is at invalid position: " + stream.getPos());<a name="line.196"></a>
+<span class="sourceLineNo">197</span>    }<a name="line.197"></a>
+<span class="sourceLineNo">198</span>    // Initialize metadata or, when we 
reset, just skip the header.<a name="line.198"></a>
+<span class="sourceLineNo">199</span>    WALProtos.WALHeader.Builder builder = 
WALProtos.WALHeader.newBuilder();<a name="line.199"></a>
+<span class="sourceLineNo">200</span>    WALHdrContext hdrCtxt = 
readHeader(builder, stream);<a name="line.200"></a>
+<span class="sourceLineNo">201</span>    WALHdrResult walHdrRes = 
hdrCtxt.getResult();<a name="line.201"></a>
+<span class="sourceLineNo">202</span>    if (walHdrRes == WALHdrResult.EOF) 
{<a name="line.202"></a>
+<span class="sourceLineNo">203</span>      throw new EOFException("Couldn't 
read WAL PB header");<a name="line.203"></a>
+<span class="sourceLineNo">204</span>    }<a name="line.204"></a>
+<span class="sourceLineNo">205</span>    if (walHdrRes == 
WALHdrResult.UNKNOWN_WRITER_CLS) {<a name="line.205"></a>
+<span class="sourceLineNo">206</span>      throw new IOException("Got unknown 
writer class: " + builder.getWriterClsName());<a name="line.206"></a>
+<span class="sourceLineNo">207</span>    }<a name="line.207"></a>
+<span class="sourceLineNo">208</span>    if (isFirst) {<a name="line.208"></a>
+<span class="sourceLineNo">209</span>      WALProtos.WALHeader header = 
builder.build();<a name="line.209"></a>
+<span class="sourceLineNo">210</span>      this.hasCompression = 
header.hasHasCompression() &amp;&amp; header.getHasCompression();<a 
name="line.210"></a>
+<span class="sourceLineNo">211</span>      this.hasTagCompression = 
header.hasHasTagCompression() &amp;&amp; header.getHasTagCompression();<a 
name="line.211"></a>
+<span class="sourceLineNo">212</span>    }<a name="line.212"></a>
+<span class="sourceLineNo">213</span>    this.inputStream = stream;<a 
name="line.213"></a>
+<span class="sourceLineNo">214</span>    this.walEditsStopOffset = 
this.fileLength;<a name="line.214"></a>
+<span class="sourceLineNo">215</span>    long currentPosition = 
stream.getPos();<a name="line.215"></a>
+<span class="sourceLineNo">216</span>    trailerPresent = 
setTrailerIfPresent();<a name="line.216"></a>
+<span class="sourceLineNo">217</span>    this.seekOnFs(currentPosition);<a 
name="line.217"></a>
+<span class="sourceLineNo">218</span>    if (LOG.isTraceEnabled()) {<a 
name="line.218"></a>
+<span class="sourceLineNo">219</span>      LOG.trace("After reading the 
trailer: walEditsStopOffset: " + this.walEditsStopOffset<a name="line.219"></a>
+<span class="sourceLineNo">220</span>          + ", fileLength: " + 
this.fileLength + ", " + "trailerPresent: " + trailerPresent);<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">223</span>    codecClsName = 
hdrCtxt.getCellCodecClsName();<a name="line.223"></a>
+<span class="sourceLineNo">224</span>    <a name="line.224"></a>
+<span class="sourceLineNo">225</span>    return 
hdrCtxt.getCellCodecClsName();<a name="line.225"></a>
+<span class="sourceLineNo">226</span>  }<a name="line.226"></a>
+<span class="sourceLineNo">227</span><a name="line.227"></a>
+<span class="sourceLineNo">228</span>  /**<a name="line.228"></a>
+<span class="sourceLineNo">229</span>   * To check whether a trailer is 
present in a WAL, it seeks to position (fileLength -<a name="line.229"></a>
+<span class="sourceLineNo">230</span>   * PB_WAL_COMPLETE_MAGIC.size() - 
Bytes.SIZEOF_INT). It reads the int value to know the size of<a 
name="line.230"></a>
+<span class="sourceLineNo">231</span>   * the trailer, and checks whether the 
trailer is present at the end or not by comparing the last<a 
name="line.231"></a>
+<span class="sourceLineNo">232</span>   * PB_WAL_COMPLETE_MAGIC.size() bytes. 
In case trailer is not present, it returns false;<a name="line.232"></a>
+<span class="sourceLineNo">233</span>   * otherwise, sets the trailer and sets 
this.walEditsStopOffset variable up to the point just<a name="line.233"></a>
+<span class="sourceLineNo">234</span>   * before the trailer.<a 
name="line.234"></a>
+<span class="sourceLineNo">235</span>   * &lt;ul&gt;<a name="line.235"></a>
+<span class="sourceLineNo">236</span>   * The trailer is ignored in case:<a 
name="line.236"></a>
+<span class="sourceLineNo">237</span>   * &lt;li&gt;fileLength is 0 or not 
correct (when file is under recovery, etc).<a name="line.237"></a>
+<span class="sourceLineNo">238</span>   * &lt;li&gt;the trailer size is 
negative.<a name="line.238"></a>
+<span class="sourceLineNo">239</span>   * &lt;/ul&gt;<a name="line.239"></a>
+<span class="sourceLineNo">240</span>   * &lt;p&gt;<a name="line.240"></a>
+<span class="sourceLineNo">241</span>   * In case the trailer size &gt; 
this.trailerMaxSize, it is read after a WARN message.<a name="line.241"></a>
+<span class="sourceLineNo">242</span>   * @return true if a valid trailer is 
present<a name="line.242"></a>
+<span class="sourceLineNo">243</span>   * @throws IOException<a 
name="line.243"></a>
+<span class="sourceLineNo">244</span>   */<a name="line.244"></a>
+<span class="sourceLineNo">245</span>  private boolean setTrailerIfPresent() 
{<a name="line.245"></a>
+<span class="sourceLineNo">246</span>    try {<a name="line.246"></a>
+<span class="sourceLineNo">247</span>      long trailerSizeOffset = 
this.fileLength - (PB_WAL_COMPLETE_MAGIC.length + Bytes.SIZEOF_INT);<a 
name="line.247"></a>
+<span class="sourceLineNo">248</span>      if (trailerSizeOffset &lt;= 0) 
return false;// no trailer possible.<a name="line.248"></a>
+<span class="sourceLineNo">249</span>      this.seekOnFs(trailerSizeOffset);<a 
name="line.249"></a>
+<span class="sourceLineNo">250</span>      // read the int as trailer size.<a 
name="line.250"></a>
+<span class="sourceLineNo">251</span>      int trailerSize = 
this.inputStream.readInt();<a name="line.251"></a>
+<span class="sourceLineNo">252</span>      ByteBuffer buf = 
ByteBuffer.allocate(ProtobufLogReader.PB_WAL_COMPLETE_MAGIC.length);<a 
name="line.252"></a>
+<span class="sourceLineNo">253</span>      
this.inputStream.readFully(buf.array(), buf.arrayOffset(), buf.capacity());<a 
name="line.253"></a>
+<span class="sourceLineNo">254</span>      if (!Arrays.equals(buf.array(), 
PB_WAL_COMPLETE_MAGIC)) {<a name="line.254"></a>
+<span class="sourceLineNo">255</span>        LOG.trace("No trailer found.");<a 
name="line.255"></a>
+<span class="sourceLineNo">256</span>        return false;<a 
name="line.256"></a>
+<span class="sourceLineNo">257</span>      }<a name="line.257"></a>
+<span class="sourceLineNo">258</span>      if (trailerSize &lt; 0) {<a 
name="line.258"></a>
+<span class="sourceLineNo">259</span>        LOG.warn("Invalid trailer Size " 
+ trailerSize + ", ignoring the trailer");<a name="line.259"></a>
+<span class="sourceLineNo">260</span>        return false;<a 
name="line.260"></a>
+<span class="sourceLineNo">261</span>      } else if (trailerSize &gt; 
this.trailerWarnSize) {<a name="line.261"></a>
+<span class="sourceLineNo">262</span>        // continue reading after warning 
the user.<a name="line.262"></a>
+<span class="sourceLineNo">263</span>        LOG.warn("Please investigate 
WALTrailer usage. Trailer size &gt; maximum configured size : "<a 
name="line.263"></a>
+<span class="sourceLineNo">264</span>          + trailerSize + " &gt; " + 
this.trailerWarnSize);<a name="line.264"></a>
+<span class="sourceLineNo">265</span>      }<a name="line.265"></a>
+<span class="sourceLineNo">266</span>      // seek to the position where 
trailer starts.<a name="line.266"></a>
+<span class="sourceLineNo">267</span>      long positionOfTrailer = 
trailerSizeOffset - trailerSize;<a name="line.267"></a>
+<span class="sourceLineNo">268</span>      this.seekOnFs(positionOfTrailer);<a 
name="line.268"></a>
+<span class="sourceLineNo">269</span>      // read the trailer.<a 
name="line.269"></a>
+<span class="sourceLineNo">270</span>      buf = 
ByteBuffer.allocate(trailerSize);// for trailer.<a name="line.270"></a>
+<span class="sourceLineNo">271</span>      
this.inputStream.readFully(buf.array(), buf.arrayOffset(), buf.capacity());<a 
name="line.271"></a>
+<span class="sourceLineNo">272</span>      trailer = 
WALTrailer.parseFrom(buf.array());<a name="line.272"></a>
+<span class="sourceLineNo">273</span>      this.walEditsStopOffset = 
positionOfTrailer;<a name="line.273"></a>
+<span class="sourceLineNo">274</span>      return true;<a name="line.274"></a>
+<span class="sourceLineNo">275</span>    } catch (IOException ioe) {<a 
name="line.275"></a>
+<span class="sourceLineNo">276</span>      LOG.warn("Got IOE while reading the 
trailer. Continuing as if no trailer is present.", ioe);<a name="line.276"></a>
+<span class="sourceLineNo">277</span>    }<a name="line.277"></a>
+<span class="sourceLineNo">278</span>    return false;<a name="line.278"></a>
+<span class="sourceLineNo">279</span>  }<a name="line.279"></a>
+<span class="sourceLineNo">280</span><a name="line.280"></a>
+<span class="sourceLineNo">281</span>  protected WALCellCodec 
getCodec(Configuration conf, String cellCodecClsName,<a name="line.281"></a>
+<span class="sourceLineNo">282</span>      CompressionContext 
compressionContext) throws IOException {<a name="line.282"></a>
+<span class="sourceLineNo">283</span>    return WALCellCodec.create(conf, 
cellCodecClsName, compressionContext);<a name="line.283"></a>
+<span class="sourceLineNo">284</span>  }<a name="line.284"></a>
+<span class="sourceLineNo">285</span><a name="line.285"></a>
+<span class="sourceLineNo">286</span>  @Override<a name="line.286"></a>
+<span class="sourceLineNo">287</span>  protected void initAfterCompression() 
throws IOException {<a name="line.287"></a>
+<span class="sourceLineNo">288</span>    initAfterCompression(null);<a 
name="line.288"></a>
+<span class="sourceLineNo">289</span>  }<a name="line.289"></a>
+<span class="sourceLineNo">290</span>  <a name="line.290"></a>
+<span class="sourceLineNo">291</span>  @Override<a name="line.291"></a>
+<span class="sourceLineNo">292</span>  protected void 
initAfterCompression(String cellCodecClsName) throws IOException {<a 
name="line.292"></a>
+<span class="sourceLineNo">293</span>    WALCellCodec codec = 
getCodec(this.conf, cellCodecClsName, this.compressionContext);<a 
name="line.293"></a>
+<span class="sourceLineNo">294</span>    this.cellDecoder = 
codec.getDecoder(this.inputStream);<a name="line.294"></a>
+<span class="sourceLineNo">295</span>    if (this.hasCompression) {<a 
name="line.295"></a>
+<span class="sourceLineNo">296</span>      this.byteStringUncompressor = 
codec.getByteStringUncompressor();<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>  @Override<a name="line.300"></a>
+<span class="sourceLineNo">301</span>  protected boolean hasCompression() {<a 
name="line.301"></a>
+<span class="sourceLineNo">302</span>    return this.hasCompression;<a 
name="line.302"></a>
+<span class="sourceLineNo">303</span>  }<a name="line.303"></a>
+<span class="sourceLineNo">304</span><a name="line.304"></a>
+<span class="sourceLineNo">305</span>  @Override<a name="line.305"></a>
+<span class="sourceLineNo">306</span>  protected boolean hasTagCompression() 
{<a name="line.306"></a>
+<span class="sourceLineNo">307</span>    return this.hasTagCompression;<a 
name="line.307"></a>
+<span class="sourceLineNo">308</span>  }<a name="line.308"></a>
+<span class="sourceLineNo">309</span><a name="line.309"></a>
+<span class="sourceLineNo">310</span>  @Override<a name="line.310"></a>
+<span class="sourceLineNo">311</span>  protected boolean readNext(Entry entry) 
throws IOException {<a name="line.311"></a>
+<span class="sourceLineNo">312</span>    while (true) {<a name="line.312"></a>
+<span class="sourceLineNo">313</span>      // OriginalPosition might be &lt; 0 
on local fs; if so, it is useless to us.<a name="line.313"></a>
+<span class="sourceLineNo">314</span>      long originalPosition = 
this.inputStream.getPos();<a name="line.314"></a>
+<span class="sourceLineNo">315</span>      if (trailerPresent &amp;&amp; 
originalPosition &gt; 0 &amp;&amp; originalPosition == this.walEditsStopOffset) 
{<a name="line.315"></a>
+<span class="sourceLineNo">316</span>        return false;<a 
name="line.316"></a>
+<span class="sourceLineNo">317</span>      }<a name="line.317"></a>
+<span class="sourceLineNo">318</span>      WALKey.Builder builder = 
WALKey.newBuilder();<a name="line.318"></a>
+<span class="sourceLineNo">319</span>      long size = 0;<a 
name="line.319"></a>
+<span class="sourceLineNo">320</span>      try {<a name="line.320"></a>
+<span class="sourceLineNo">321</span>        long available = -1;<a 
name="line.321"></a>
+<span class="sourceLineNo">322</span>        try {<a name="line.322"></a>
+<span class="sourceLineNo">323</span>          int firstByte = 
this.inputStream.read();<a name="line.323"></a>
+<span class="sourceLineNo">324</span>          if (firstByte == -1) {<a 
name="line.324"></a>
+<span class="sourceLineNo">325</span>            throw new EOFException("First 
byte is negative");<a name="line.325"></a>
+<span class="sourceLineNo">326</span>          }<a name="line.326"></a>
+<span class="sourceLineNo">327</span>          size = 
CodedInputStream.readRawVarint32(firstByte, this.inputStream);<a 
name="line.327"></a>
+<span class="sourceLineNo">328</span>          // available may be &lt; 0 on 
local fs for instance.  If so, can't depend on it.<a name="line.328"></a>
+<span class="sourceLineNo">329</span>          available = 
this.inputStream.available();<a name="line.329"></a>
+<span class="sourceLineNo">330</span>          if (available &gt; 0 &amp;&amp; 
available &lt; size) {<a name="line.330"></a>
+<span class="sourceLineNo">331</span>            throw new 
EOFException("Available stream not enough for edit, " +<a name="line.331"></a>
+<span class="sourceLineNo">332</span>                "inputStream.available()= 
" + this.inputStream.available() + ", " +<a name="line.332"></a>
+<span class="sourceLineNo">333</span>                "entry size= " + size);<a 
name="line.333"></a>
+<span class="sourceLineNo">334</span>          }<a name="line.334"></a>
+<span class="sourceLineNo">335</span>          ProtobufUtil.mergeFrom(builder, 
new LimitInputStream(this.inputStream, size),<a name="line.335"></a>
+<span class="sourceLineNo">336</span>            (int)size);<a 
name="line.336"></a>
+<span class="sourceLineNo">337</span>        } catch 
(InvalidProtocolBufferException ipbe) {<a name="line.337"></a>
+<span class="sourceLineNo">338</span>          throw (EOFException) new 
EOFException("Invalid PB, EOF? Ignoring; originalPosition=" +<a 
name="line.338"></a>
+<span class="sourceLineNo">339</span>            originalPosition + ", 
currentPosition=" + this.inputStream.getPos() +<a name="line.339"></a>
+<span class="sourceLineNo">340</span>            ", messageSize=" + size + ", 
currentAvailable=" + available).initCause(ipbe);<a name="line.340"></a>
+<span class="sourceLineNo">341</span>        }<a name="line.341"></a>
+<span class="sourceLineNo">342</span>        if (!builder.isInitialized()) {<a 
name="line.342"></a>
+<span class="sourceLineNo">343</span>          // TODO: not clear if we should 
try to recover from corrupt PB that looks semi-legit.<a name="line.343"></a>
+<span class="sourceLineNo">344</span>          //       If we can get the KV 
count, we could, theoretically, try to get next record.<a name="line.344"></a>
+<span class="sourceLineNo">345</span>          throw new EOFException("Partial 
PB while reading WAL, " +<a name="line.345"></a>
+<span class="sourceLineNo">346</span>              "probably an unexpected 
EOF, ignoring");<a name="line.346"></a>
+<span class="sourceLineNo">347</span>        }<a name="line.347"></a>
+<span class="sourceLineNo">348</span>        WALKey walKey = 
builder.build();<a name="line.348"></a>
+<span class="sourceLineNo">349</span>        
entry.getKey().readFieldsFromPb(walKey, this.byteStringUncompressor);<a 
name="line.349"></a>
+<span class="sourceLineNo">350</span>        if (!walKey.hasFollowingKvCount() 
|| 0 == walKey.getFollowingKvCount()) {<a name="line.350"></a>
+<span class="sourceLineNo">351</span>          LOG.trace("WALKey has no KVs 
that follow it; trying the next one");<a name="line.351"></a>
+<span class="sourceLineNo">352</span>          continue;<a name="line.352"></a>
+<span class="sourceLineNo">353</span>        }<a name="line.353"></a>
+<span class="sourceLineNo">354</span>        int expectedCells = 
walKey.getFollowingKvCount();<a name="line.354"></a>
+<span class="sourceLineNo">355</span>        long posBefore = 
this.inputStream.getPos();<a name="line.355"></a>
+<span class="sourceLineNo">356</span>        try {<a name="line.356"></a>
+<span class="sourceLineNo">357</span>          int actualCells = 
entry.getEdit().readFromCells(cellDecoder, expectedCells);<a 
name="line.357"></a>
+<span class="sourceLineNo">358</span>          if (expectedCells != 
actualCells) {<a name="line.358"></a>
+<span class="sourceLineNo">359</span>            throw new EOFException("Only 
read " + actualCells); // other info added in catch<a name="line.359"></a>
+<span class="sourceLineNo">360</span>          }<a name="line.360"></a>
+<span class="sourceLineNo">361</span>        } catch (Exception ex) {<a 
name="line.361"></a>
+<span class="sourceLineNo">362</span>          String posAfterStr = 
"&lt;unknown&gt;";<a name="line.362"></a>
+<span class="sourceLineNo">363</span>          try {<a name="line.363"></a>
+<span class="sourceLineNo">364</span>            posAfterStr = 
this.inputStream.getPos() + "";<a name="line.364"></a>
+<span class="sourceLineNo">365</span>          } catch (Throwable t) {<a 
name="line.365"></a>
+<span class="sourceLineNo">366</span>            LOG.trace("Error getting pos 
for error message - ignoring", t);<a name="line.366"></a>
+<span class="sourceLineNo">367</span>          }<a name="line.367"></a>
+<span class="sourceLineNo">368</span>          String message = " while 
reading " + expectedCells + " WAL KVs; started reading at "<a 
name="line.368"></a>
+<span class="sourceLineNo">369</span>              + posBefore + " and read up 
to " + posAfterStr;<a name="line.369"></a>
+<span class="sourceLineNo">370</span>          IOException realEofEx = 
extractHiddenEof(ex);<a name="line.370"></a>
+<span class="sourceLineNo">371</span>          throw (EOFException) new 
EOFException("EOF " + message).<a name="line.371"></a>
+<span class="sourceLineNo">372</span>              initCause(realEofEx != null 
? realEofEx : ex);<a name="line.372"></a>
+<span class="sourceLineNo">373</span>        }<a name="line.373"></a>
+<span class="sourceLineNo">374</span>        if (trailerPresent &amp;&amp; 
this.inputStream.getPos() &gt; this.walEditsStopOffset) {<a name="line.374"></a>
+<span class="sourceLineNo">375</span>          LOG.error("Read WALTrailer 
while reading WALEdits. wal: " + this.path<a name="line.375"></a>
+<span class="sourceLineNo">376</span>              + ", inputStream.getPos(): 
" + this.inputStream.getPos() + ", walEditsStopOffset: "<a name="line.376"></a>
+<span class="sourceLineNo">377</span>              + 
this.walEditsStopOffset);<a name="line.377"></a>
+<span class="sourceLineNo">378</span>          throw new EOFException("Read 
WALTrailer while reading WALEdits");<a name="line.378"></a>
+<span class="sourceLineNo">379</span>        }<a name="line.379"></a>
+<span class="sourceLineNo">380</span>      } catch (EOFException eof) {<a 
name="line.380"></a>
+<span class="sourceLineNo">381</span>        LOG.trace("Encountered a 
malformed edit, seeking back to last good position in file", eof);<a 
name="line.381"></a>
+<span class="sourceLineNo">382</span>        // If originalPosition is &lt; 0, 
it is rubbish and we cannot use it (probably local fs)<a name="line.382"></a>
+<span class="sourceLineNo">383</span>        if (originalPosition &lt; 0) 
throw eof;<a name="line.383"></a>
+<span class="sourceLineNo">384</span>        // Else restore our position to 
original location in hope that next time through we will<a name="line.384"></a>
+<span class="sourceLineNo">385</span>        // read successfully.<a 
name="line.385"></a>
+<span class="sourceLineNo">386</span>        seekOnFs(originalPosition);<a 
name="line.386"></a>
+<span class="sourceLineNo">387</span>        return false;<a 
name="line.387"></a>
+<span class="sourceLineNo">388</span>      }<a name="line.388"></a>
+<span class="sourceLineNo">389</span>      return true;<a name="line.389"></a>
+<span class="sourceLineNo">390</span>    }<a name="line.390"></a>
+<span class="sourceLineNo">391</span>  }<a name="line.391"></a>
+<span class="sourceLineNo">392</span><a name="line.392"></a>
+<span class="sourceLineNo">393</span>  private IOException 
extractHiddenEof(Exception ex) {<a name="line.393"></a>
+<span class="sourceLineNo">394</span>    // There are two problems we are 
dealing with here. Hadoop stream throws generic exception<a name="line.394"></a>
+<span class="sourceLineNo">395</span>    // for EOF, not EOFException; and 
scanner further hides it inside RuntimeException.<a name="line.395"></a>
+<span class="sourceLineNo">396</span>    IOException ioEx = null;<a 
name="line.396"></a>
+<span class="sourceLineNo">397</span>    if (ex instanceof EOFException) {<a 
name="line.397"></a>
+<span class="sourceLineNo">398</span>      return (EOFException)ex;<a 
name="line.398"></a>
+<span class="sourceLineNo">399</span>    } else if (ex instanceof IOException) 
{<a name="line.399"></a>
+<span class="sourceLineNo">400</span>      ioEx = (IOException)ex;<a 
name="line.400"></a>
+<span class="sourceLineNo">401</span>    } else if (ex instanceof 
RuntimeException<a name="line.401"></a>
+<span class="sourceLineNo">402</span>        &amp;&amp; ex.getCause() != null 
&amp;&amp; ex.getCause() instanceof IOException) {<a name="line.402"></a>
+<span class="sourceLineNo">403</span>      ioEx = 
(IOException)ex.getCause();<a name="line.403"></a>
+<span class="sourceLineNo">404</span>    }<a name="line.404"></a>
+<span class="sourceLineNo">405</span>    if (ioEx != null) {<a 
name="line.405"></a>
+<span class="sourceLineNo">406</span>      if 
(ioEx.getMessage().contains("EOF")) return ioEx;<a name="line.406"></a>
+<span class="sourceLineNo">407</span>      return null;<a name="line.407"></a>
+<span class="sourceLineNo">408</span>    }<a name="line.408"></a>
+<span class="sourceLineNo">409</span>    return null;<a name="line.409"></a>
+<span class="sourceLineNo">410</span>  }<a name="line.410"></a>
+<span class="sourceLineNo">411</span><a name="line.411"></a>
+<span class="sourceLineNo">412</span>  @Override<a name="line.412"></a>
+<span class="sourceLineNo">413</span>  protected void seekOnFs(long pos) 
throws IOException {<a name="line.413"></a>
+<span class="sourceLineNo">414</span>    this.inputStream.seek(pos);<a 
name="line.414"></a>
+<span class="sourceLineNo">415</span>  }<a name="line.415"></a>
+<span class="sourceLineNo">416</span>}<a name="line.416"></a>
 
 
 

Reply via email to