Skip to content

Commit 7af6179

Browse files
authored
HBASE-28184 Tailing the WAL is very slow if there are multiple peers (#5503)
1 parent 027a119 commit 7af6179

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/WALEntryStream.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -460,17 +460,27 @@ private void dequeueCurrentLog() {
460460
* Returns whether the file is opened for writing.
461461
*/
462462
private Pair<WALTailingReader.State, Boolean> readNextEntryAndRecordReaderPosition() {
463-
// we must call this before actually reading from the reader, as this method will acquire the
464-
// rollWriteLock. This is very important, as we will enqueue the new WAL file in postLogRoll,
465-
// and before this happens, we could have already finished closing the previous WAL file. If we
466-
// do not acquire the rollWriteLock and return whether the current file is being written to, we
467-
// may finish reading the previous WAL file and start to read the next one, before it is
468-
// enqueued into the logQueue, thus lead to an empty logQueue and make the shipper think the
469-
// queue is already ended and quit. See HBASE-28114 and related issues for more details.
470-
// in the future, if we want to optimize the logic here, for example, do not call this method
471-
// every time, or do not acquire rollWriteLock in the implementation of this method, we need to
472-
// carefully review the optimized implementation
473-
OptionalLong fileLength = walFileLengthProvider.getLogFileSizeIfBeingWritten(currentPath);
463+
OptionalLong fileLength;
464+
if (logQueue.getQueueSize(walGroupId) > 1) {
465+
// if there are more than one files in queue, although it is possible that we are
466+
// still trying to write the trailer of the file and it is not closed yet, we can
467+
// make sure that we will not write any WAL entries to it any more, so it is safe
468+
// to just let the upper layer try to read the whole file without limit
469+
fileLength = OptionalLong.empty();
470+
} else {
471+
// if there is only one file in queue, check whether it is still being written to
472+
// we must call this before actually reading from the reader, as this method will acquire the
473+
// rollWriteLock. This is very important, as we will enqueue the new WAL file in postLogRoll,
474+
// and before this happens, we could have already finished closing the previous WAL file. If
475+
// we do not acquire the rollWriteLock and return whether the current file is being written
476+
// to, we may finish reading the previous WAL file and start to read the next one, before it
477+
// is enqueued into the logQueue, thus lead to an empty logQueue and make the shipper think
478+
// the queue is already ended and quit. See HBASE-28114 and related issues for more details.
479+
// in the future, if we want to optimize the logic here, for example, do not call this method
480+
// every time, or do not acquire rollWriteLock in the implementation of this method, we need
481+
// to carefully review the optimized implementation
482+
fileLength = walFileLengthProvider.getLogFileSizeIfBeingWritten(currentPath);
483+
}
474484
WALTailingReader.Result readResult = reader.next(fileLength.orElse(-1));
475485
long readerPos = readResult.getEntryEndPos();
476486
Entry readEntry = readResult.getEntry();

0 commit comments

Comments
 (0)