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()) { while (!server.isStopped()) {
long now = EnvironmentEdgeManager.currentTime(); long now = EnvironmentEdgeManager.currentTime();
checkLowReplication(now); checkLowReplication(now);
if (!rollLog.get()) { boolean rollLogLocal;
synchronized (rollLog) {
rollLogLocal = rollLog.get();
rollLog.set(false);
}
if (!rollLogLocal) {
boolean periodic = false; boolean periodic = false;
for (RollController controller : wals.values()) { for (RollController controller : wals.values()) {
if (controller.needsPeriodicRoll(now)) { if (controller.needsPeriodicRoll(now)) {
@ -154,11 +159,10 @@ public class LogRoller extends HasThread {
if (!periodic) { if (!periodic) {
synchronized (rollLog) { synchronized (rollLog) {
try { try {
if (!rollLog.get()) {
rollLog.wait(this.threadWakeFrequency); rollLog.wait(this.threadWakeFrequency);
}
} catch (InterruptedException e) { } catch (InterruptedException e) {
// Fall through // Fall through
LOG.info("LogRoller interrupted ", e);
} }
} }
continue; continue;
@ -198,14 +202,10 @@ public class LogRoller extends HasThread {
final String msg = "Failed rolling WAL; aborting to recover edits!"; final String msg = "Failed rolling WAL; aborting to recover edits!";
LOG.error(msg, ex); LOG.error(msg, ex);
server.abort(msg, ex); server.abort(msg, ex);
} finally {
try {
rollLog.set(false);
} finally { } finally {
rollLock.unlock(); rollLock.unlock();
} }
} }
}
LOG.info("LogRoller exiting."); LOG.info("LogRoller exiting.");
} }
@ -266,8 +266,9 @@ public class LogRoller extends HasThread {
public byte[][] rollWal(long now) throws IOException { public byte[][] rollWal(long now) throws IOException {
this.lastRollTime = now; 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); this.rollRequest.set(false);
byte[][] regionsToFlush = wal.rollWriter(true);
return regionsToFlush; return regionsToFlush;
} }