Class AbstractProtobufWALReader
java.lang.Object
org.apache.hadoop.hbase.regionserver.wal.AbstractProtobufWALReader
- All Implemented Interfaces:
Closeable
,AutoCloseable
,AbstractFSWALProvider.Initializer
- Direct Known Subclasses:
ProtobufWALStreamReader
,ProtobufWALTailingReader
@Private
public abstract class AbstractProtobufWALReader
extends Object
implements AbstractFSWALProvider.Initializer, Closeable
Base class for reading protobuf based wal reader
-
Field Summary
Modifier and TypeFieldDescriptionprotected WALCellCodec.ByteStringUncompressor
protected Codec.Decoder
protected String
protected CompressionContext
protected org.apache.hadoop.conf.Configuration
protected Decryptor
(package private) static final int
protected long
protected org.apache.hadoop.fs.FileSystem
protected boolean
protected boolean
protected boolean
protected org.apache.hadoop.fs.FSDataInputStream
private static final org.slf4j.Logger
protected org.apache.hadoop.fs.Path
static final byte[]
static final byte[]
protected org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.WALTrailer
protected boolean
protected int
protected Compression.Algorithm
(package private) static final String
Configuration name of WAL Trailer's warning size.protected long
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
protected final IOException
protected abstract InputStream
getCellCodecInputStream
(org.apache.hadoop.fs.FSDataInputStream stream) Get or create the input stream used by cell decoder.private WALCellCodec
getCodec
(org.apache.hadoop.conf.Configuration conf, String cellCodecClsName, CompressionContext compressionContext) Returns the cell codec classnamelong
protected final String
Returns names of the accepted writer classesvoid
init
(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path, org.apache.hadoop.conf.Configuration conf, long startPosition) A method to initialize a WAL reader.private void
initCompression
(org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.WALHeader header) private void
initDecryptor
(org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.WALHeader header) protected final void
initWALCellCodec
(org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.WALHeader header, InputStream inputStream) protected final boolean
isWALTrailer
(long startPosition) This is used to determine whether we have already reached the WALTrailer.protected final Pair<org.apache.hadoop.fs.FSDataInputStream,
org.apache.hadoop.fs.FileStatus> open()
private Pair<org.apache.hadoop.fs.FSDataInputStream,
org.apache.hadoop.fs.FileStatus> protected final boolean
reachWALEditsStopOffset
(long pos) protected final org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.WALHeader
readHeader
(org.apache.hadoop.fs.FSDataInputStream stream) protected final void
readTrailer
(org.apache.hadoop.fs.FSDataInputStream stream, org.apache.hadoop.fs.FileStatus stat) private boolean
setTrailerIfPresent
(org.apache.hadoop.fs.FSDataInputStream stream) To check whether a trailer is present in a WAL, it seeks to position (fileLength - PB_WAL_COMPLETE_MAGIC.size() - Bytes.SIZEOF_INT).protected abstract void
skipTo
(long position) Skip to the given position.long
-
Field Details
-
LOG
-
PB_WAL_MAGIC
-
PB_WAL_COMPLETE_MAGIC
-
WAL_TRAILER_WARN_SIZE
Configuration name of WAL Trailer's warning size. If a waltrailer's size is greater than the configured size, providers should log a warning. e.g. this is used with Protobuf reader/writer.- See Also:
-
DEFAULT_WAL_TRAILER_WARN_SIZE
- See Also:
-
WRITER_CLS_NAMES
-
conf
-
fs
-
path
-
fileLength
-
inputStream
-
compressionCtx
-
hasCompression
-
hasTagCompression
-
hasValueCompression
-
valueCompressionType
-
cellDecoder
-
byteStringUncompressor
-
walEditsStopOffset
-
trailerPresent
-
trailer
-
trailerWarnSize
-
codecClsName
-
decryptor
-
-
Constructor Details
-
AbstractProtobufWALReader
public AbstractProtobufWALReader()
-
-
Method Details
-
getCellCodecInputStream
protected abstract InputStream getCellCodecInputStream(org.apache.hadoop.fs.FSDataInputStream stream) Get or create the input stream used by cell decoder. For implementing replication, we may need to limit the bytes we can read, so here we provide a method so subclasses can wrap the original input stream. -
skipTo
Skip to the given position.- Throws:
IOException
-
init
public void init(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path, org.apache.hadoop.conf.Configuration conf, long startPosition) throws IOException Description copied from interface:AbstractFSWALProvider.Initializer
A method to initialize a WAL reader.- Specified by:
init
in interfaceAbstractFSWALProvider.Initializer
startPosition
- the start position you want to read from, -1 means start reading from the first WAL entry. Notice that, the first entry is not started at position as we have several headers, so typically you should not pass 0 here.- Throws:
IOException
-
openArchivedWAL
private Pair<org.apache.hadoop.fs.FSDataInputStream,org.apache.hadoop.fs.FileStatus> openArchivedWAL() throws IOException- Throws:
IOException
-
open
protected final Pair<org.apache.hadoop.fs.FSDataInputStream,org.apache.hadoop.fs.FileStatus> open() throws IOException- Throws:
IOException
-
readHeader
protected final org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.WALHeader readHeader(org.apache.hadoop.fs.FSDataInputStream stream) throws IOException - Throws:
IOException
-
initDecryptor
private void initDecryptor(org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.WALHeader header) throws IOException - Throws:
IOException
-
initCompression
private void initCompression(org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.WALHeader header) throws IOException - Throws:
IOException
-
getCodec
private WALCellCodec getCodec(org.apache.hadoop.conf.Configuration conf, String cellCodecClsName, CompressionContext compressionContext) throws IOException - Throws:
IOException
-
initWALCellCodec
protected final void initWALCellCodec(org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.WALHeader header, InputStream inputStream) throws IOException - Throws:
IOException
-
readTrailer
protected final void readTrailer(org.apache.hadoop.fs.FSDataInputStream stream, org.apache.hadoop.fs.FileStatus stat) throws IOException - Throws:
IOException
-
setTrailerIfPresent
private boolean setTrailerIfPresent(org.apache.hadoop.fs.FSDataInputStream stream) throws IOException To check whether a trailer is present in a WAL, it seeks to position (fileLength - PB_WAL_COMPLETE_MAGIC.size() - Bytes.SIZEOF_INT). It reads the int value to know the size of the trailer, and checks whether the trailer is present at the end or not by comparing the last PB_WAL_COMPLETE_MAGIC.size() bytes. In case trailer is not present, it returns false; otherwise, sets the trailer and sets this.walEditsStopOffset variable up to the point just before the trailer. The trailer is ignored in case:- fileLength is 0 or not correct (when file is under recovery, etc).
- the trailer size is negative.
- Returns:
- true if a valid trailer is present
- Throws:
IOException
-
reachWALEditsStopOffset
-
getWriterClsNames
Returns names of the accepted writer classes -
getCodecClsName
Returns the cell codec classname -
getPosition
- Throws:
IOException
-
trailerSize
-
getPositionQuietly
-
extractHiddenEof
-
isWALTrailer
This is used to determine whether we have already reached the WALTrailer. As the size and magic are at the end of the WAL file, it is possible that these two options are missing while writing, so we will consider there is no trailer. And when we actually reach the WALTrailer, we will try to decode it as WALKey and we will fail but the error could be varied as it is parsing WALTrailer actually.- Returns:
- whether this is a WALTrailer and we should throw EOF to upper layer the file is done
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-