Skip to content

HBASE-27354 EOF thrown by WALEntryStream causes replication blocking #4756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,21 @@ private void dequeueCurrentLog() throws IOException {
* Returns whether the file is opened for writing.
*/
private boolean readNextEntryAndRecordReaderPosition() throws IOException {
long prePos = reader.getPosition();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a nice improvement that we can return earlier when there is no data can be read. But I do not get the point that why here if we try to read more data can lead to a problem? We could still hit EOFException when the remaining data is not enough for a whole entry?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing.
I haven't found out yet that we read an incomplete entry. EOFException is thrown by org.apache.hadoop.fs.FSDataInputStream#seek.
After reading the uncommitted data, we will reopen FSDataInputStream and seek back. If the position where seek back is the sync length, it may cause EOF. As the 3 copies of the hdfs block being written are inconsistent, even if we can read the data from a specific position in one copy, it may not be read in the other one.
It's not a big problem if it just throws EOF as we'll retry. The big problem is that if we have read some entries into the WALEntryBatch and increased the totalBufferUsed, and the totalBufferUsed is not subtracted after throwing EOF, all peers will eventually block completely.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a big problem if it just throws EOF as we'll retry. The big problem is that if we have read some entries into the WALEntryBatch and increased the totalBufferUsed, and the totalBufferUsed is not subtracted after throwing EOF, all peers will eventually block completely.

One of our customers seems to be consistently reaching this EOF problem, per below exception trace.

WARN org.apache.hadoop.hbase.regionserver.wal.ProtobufLogReader: Encountered a malformed edit, seeking back to last good position in file, from 31912404 to 31912265 java.io.EOFException: EOF while reading 106 WAL KVs; started reading at 31912338 and read up to 31912404 at org.apache.hadoop.hbase.regionserver.wal.ProtobufLogReader.readNext(ProtobufLogReader.java:397) at org.apache.hadoop.hbase.regionserver.wal.ReaderBase.next(ReaderBase.java:98) at org.apache.hadoop.hbase.regionserver.wal.ReaderBase.next(ReaderBase.java:86) at org.apache.hadoop.hbase.replication.regionserver.WALEntryStream.readNextEntryAndRecordReaderPosition(WALEntryStream.java:262) at org.apache.hadoop.hbase.replication.regionserver.WALEntryStream.tryAdvanceEntry(WALEntryStream.java:176) at org.apache.hadoop.hbase.replication.regionserver.WALEntryStream.hasNext(WALEntryStream.java:101)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I do not think the fix here is enough? We should decrease the totalBufferUsed when calling resetReader?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking the code, we have a special logic in ReplicationSourceWALReader for dealing with EOFException. Please see ReplicationSourceWALReader.handleEofException.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @wchevreuil for reviewing and sharing the case. This looks like it reads an incomplete entry?

Then I do not think the fix here is enough?

As @Apache9 said, this fix may not enough, it may not cover that reading incomplete entry caused by like RS down. I'm digging deeper into the root cause.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wchevreuil for the above stacktrace you mentioned, which version the cluster is running on?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI @apurtell

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of our customers seems to be consistently reaching this EOF problem, per below exception trace.

WARN org.apache.hadoop.hbase.regionserver.wal.ProtobufLogReader: Encountered a malformed edit, seeking back to last good position in file, from 31912404 to 31912265 java.io.EOFException: EOF while reading 106 WAL KVs; started reading at 31912338 and read up to 31912404 at org.apache.hadoop.hbase.regionserver.wal.ProtobufLogReader.readNext(ProtobufLogReader.java:397) at org.apache.hadoop.hbase.regionserver.wal.ReaderBase.next(ReaderBase.java:98) at org.apache.hadoop.hbase.regionserver.wal.ReaderBase.next(ReaderBase.java:86) at org.apache.hadoop.hbase.replication.regionserver.WALEntryStream.readNextEntryAndRecordReaderPosition(WALEntryStream.java:262) at org.apache.hadoop.hbase.replication.regionserver.WALEntryStream.tryAdvanceEntry(WALEntryStream.java:176) at org.apache.hadoop.hbase.replication.regionserver.WALEntryStream.hasNext(WALEntryStream.java:101)

@wchevreuil, this problem seems not throw EOFException in WALEntryStream.readNextEntryAndRecordReaderPosition, it may be another problem?

OptionalLong fileLength = walFileLengthProvider.getLogFileSizeIfBeingWritten(currentPath);
if (fileLength.isPresent() && prePos == fileLength.getAsLong()) {
LOG.debug("The provider tells us the valid length for {} is {}, we have advanced the end",
currentPath, fileLength.getAsLong());
return true;
}
Entry readEntry = reader.next();
long readerPos = reader.getPosition();
OptionalLong fileLength = walFileLengthProvider.getLogFileSizeIfBeingWritten(currentPath);
if (fileLength.isPresent() && readerPos > fileLength.getAsLong()) {
// See HBASE-14004, for AsyncFSWAL which uses fan-out, it is possible that we read uncommitted
// data, so we need to make sure that we do not read beyond the committed file length.
if (LOG.isDebugEnabled()) {
LOG.debug("The provider tells us the valid length for " + currentPath + " is "
+ fileLength.getAsLong() + ", but we have advanced to " + readerPos);
LOG.debug("The provider tells us the valid length for {} is {}, but we have advanced to {}",
currentPath, fileLength.getAsLong(), readerPos);
}
resetReader();
return true;
Expand Down