HBASE-26435 The log rolling request maybe canceled immediately in LogRoller due to a race (#3832)

Co-authored-by: Rushabh Shah <shahrs87@apache.org>
Signed-off-by: Reid Chan <reidchan@apache.org>
This commit is contained in:
Rushabh Shah 2022-03-03 04:49:07 -05:00 committed by GitHub
parent 5b26932415
commit f712a4ceb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 10 deletions

View File

@ -143,7 +143,12 @@ public class LogRoller extends HasThread {
while (!server.isStopped()) {
long now = EnvironmentEdgeManager.currentTime();
checkLowReplication(now);
if (!rollLog.get()) {
boolean rollLogLocal;
synchronized (rollLog) {
rollLogLocal = rollLog.get();
rollLog.set(false);
}
if (!rollLogLocal) {
boolean periodic = false;
for (RollController controller : wals.values()) {
if (controller.needsPeriodicRoll(now)) {
@ -154,11 +159,10 @@ public class LogRoller extends HasThread {
if (!periodic) {
synchronized (rollLog) {
try {
if (!rollLog.get()) {
rollLog.wait(this.threadWakeFrequency);
}
rollLog.wait(this.threadWakeFrequency);
} catch (InterruptedException e) {
// Fall through
LOG.info("LogRoller interrupted ", e);
}
}
continue;
@ -199,11 +203,7 @@ public class LogRoller extends HasThread {
LOG.error(msg, ex);
server.abort(msg, ex);
} finally {
try {
rollLog.set(false);
} finally {
rollLock.unlock();
}
rollLock.unlock();
}
}
LOG.info("LogRoller exiting.");
@ -266,8 +266,9 @@ public class LogRoller extends HasThread {
public byte[][] rollWal(long now) throws IOException {
this.lastRollTime = now;
byte[][] regionsToFlush = wal.rollWriter(true);
// reset the flag in front to avoid missing roll request before we return from rollWriter.
this.rollRequest.set(false);
byte[][] regionsToFlush = wal.rollWriter(true);
return regionsToFlush;
}