@InterfaceAudience.Private @InterfaceStability.Evolving class WALEntryStream extends Object implements Closeable
Path
, and continually
iterates through all the WAL WAL.Entry
in the queue. When it's done reading from a Path, it
dequeues it and starts reading from the next.Modifier and Type | Class and Description |
---|---|
static class |
WALEntryStream.HasNext |
Modifier and Type | Field and Description |
---|---|
private org.apache.hadoop.conf.Configuration |
conf |
private WAL.Entry |
currentEntry |
private org.apache.hadoop.fs.Path |
currentPath |
private long |
currentPositionOfEntry |
private long |
currentPositionOfReader |
private boolean |
eofAutoRecovery |
private org.apache.hadoop.fs.FileSystem |
fs |
private static org.slf4j.Logger |
LOG |
private ReplicationSourceLogQueue |
logQueue |
private MetricsSource |
metrics |
private WALTailingReader |
reader |
private WALTailingReader.State |
state |
private WALFileLengthProvider |
walFileLengthProvider |
private String |
walGroupId |
Constructor and Description |
---|
WALEntryStream(ReplicationSourceLogQueue logQueue,
org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.conf.Configuration conf,
long startPosition,
WALFileLengthProvider walFileLengthProvider,
MetricsSource metrics,
String walGroupId)
Create an entry stream over the given queue at the given start position
|
Modifier and Type | Method and Description |
---|---|
private boolean |
checkAllBytesParsed() |
void |
close() |
private void |
closeReader() |
private long |
currentTrailerSize() |
private void |
dequeueCurrentLog() |
org.apache.hadoop.fs.Path |
getCurrentPath()
Returns the
Path of the current WAL |
private org.apache.hadoop.fs.FileStatus |
getCurrentPathFileStatus() |
private String |
getCurrentPathStat() |
long |
getPosition()
Returns the position of the last Entry returned by next()
|
WALEntryStream.HasNext |
hasNext()
Try advance the stream if there is no entry yet.
|
private WALEntryStream.HasNext |
lastAttempt() |
WAL.Entry |
next()
Returns the next WAL entry in this stream and advance the stream.
|
WAL.Entry |
peek()
Returns the next WAL entry in this stream but does not advance.
|
private WALEntryStream.HasNext |
prepareReader() |
private Pair<WALTailingReader.State,Boolean> |
readNextEntryAndRecordReaderPosition()
Returns whether the file is opened for writing.
|
private void |
setCurrentPath(org.apache.hadoop.fs.Path path) |
private WALEntryStream.HasNext |
tryAdvanceEntry() |
private static final org.slf4j.Logger LOG
private WALTailingReader reader
private WALTailingReader.State state
private org.apache.hadoop.fs.Path currentPath
private WAL.Entry currentEntry
private long currentPositionOfEntry
private long currentPositionOfReader
private final ReplicationSourceLogQueue logQueue
private final String walGroupId
private final org.apache.hadoop.fs.FileSystem fs
private final org.apache.hadoop.conf.Configuration conf
private final WALFileLengthProvider walFileLengthProvider
private final MetricsSource metrics
private boolean eofAutoRecovery
public WALEntryStream(ReplicationSourceLogQueue logQueue, org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.conf.Configuration conf, long startPosition, WALFileLengthProvider walFileLengthProvider, MetricsSource metrics, String walGroupId)
logQueue
- the queue of WAL pathsconf
- the Configuration
to use to create WALStreamReader
for this streamstartPosition
- the position in the first WAL to start reading atwalFileLengthProvider
- provides the length of the WAL fileserverName
- the server name which all WALs belong tometrics
- the replication metricspublic WALEntryStream.HasNext hasNext()
WALEntryStream.HasNext
for more
details about the meanings of the return values.
You can call peek()
or next()
to get the actual WAL.Entry
if this method
returns WALEntryStream.HasNext.YES
.public WAL.Entry peek()
hasNext()
first before calling this method, and if you have already called
next()
to consume the current entry, you need to call hasNext()
again to
advance the stream before calling this method again, otherwise it will always return
null
The reason here is that, we need to use the return value of hasNext()
to tell upper
layer to retry or not, so we can not wrap the hasNext()
call inside peek()
or
next()
as they have their own return value.public WAL.Entry next()
IllegalStateException
if you do not call hasNext()
before calling this method.
Please see the javadoc of peek()
method to see why we need this.IllegalStateException
- Every time you want to call this method, please call
hasNext()
first, otherwise a
IllegalStateException
will be thrown.hasNext()
,
peek()
public void close()
close
in interface Closeable
close
in interface AutoCloseable
public long getPosition()
public org.apache.hadoop.fs.Path getCurrentPath()
Path
of the current WALprivate String getCurrentPathStat()
private void setCurrentPath(org.apache.hadoop.fs.Path path)
private WALEntryStream.HasNext prepareReader()
private WALEntryStream.HasNext lastAttempt()
private WALEntryStream.HasNext tryAdvanceEntry()
private org.apache.hadoop.fs.FileStatus getCurrentPathFileStatus() throws IOException
IOException
private boolean checkAllBytesParsed()
private void dequeueCurrentLog()
private Pair<WALTailingReader.State,Boolean> readNextEntryAndRecordReaderPosition()
private void closeReader()
private long currentTrailerSize()
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.