saintstack commented on a change in pull request #378: HBASE-22684 The log 
rolling request maybe canceled immediately in Log…
URL: https://github.com/apache/hbase/pull/378#discussion_r303223556
 
 

 ##########
 File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java
 ##########
 @@ -155,54 +145,57 @@ private void abort(String reason, Throwable cause) {
   @Override
   public void run() {
     while (running) {
+      boolean periodic = false;
       long now = System.currentTimeMillis();
       checkLowReplication(now);
-      boolean periodic = false;
-      if (!rollLog.get()) {
-        periodic = (now - this.lastrolltime) > this.rollperiod;
-        if (!periodic) {
-          synchronized (rollLog) {
+      periodic = (now - this.lastrolltime) > this.rollPeriod;
+      if (periodic) {
+        // Time for periodic roll, fall through
+        LOG.debug("Wal roll period {} ms elapsed", this.rollPeriod);
+      } else {
+        synchronized (this) {
+          if (walNeedsRoll.values().stream().anyMatch(Boolean::booleanValue)) {
+            // WAL roll requested, fall through
+            LOG.debug("WAL roll requested");
+          } else {
             try {
-              if (!rollLog.get()) {
-                rollLog.wait(this.threadWakeFrequency);
-              }
+              wait(this.threadWakeFrequency);
             } catch (InterruptedException e) {
-              // Fall through
+              // restore the interrupt state
+              Thread.currentThread().interrupt();
             }
+            // goto the beginning to check whether again whether we should 
fall through to roll
+            // several WALs, and also check whether we should quit.
+            continue;
           }
-          continue;
         }
-        // Time for periodic roll
-        LOG.debug("Wal roll period {} ms elapsed", this.rollperiod);
-      } else {
-        LOG.debug("WAL roll requested");
       }
-      rollLock.lock(); // FindBugs UL_UNRELEASED_LOCK_EXCEPTION_PATH
       try {
-        this.lastrolltime = now;
+        this.lastrolltime = System.currentTimeMillis();
         for (Iterator<Entry<WAL, Boolean>> iter = 
walNeedsRoll.entrySet().iterator(); iter
             .hasNext();) {
           Entry<WAL, Boolean> entry = iter.next();
-          final WAL wal = entry.getKey();
-          // Force the roll if the logroll.period is elapsed or if a roll was 
requested.
-          // The returned value is an array of actual region names.
+          WAL wal = entry.getKey();
+          // reset the flag in front to avoid missing roll request before we 
return from rollWriter.
+          walNeedsRoll.put(wal, Boolean.FALSE);
 
 Review comment:
   Ok we change the map though not synchronized on 'this' (Yeah it is a 
concurrent map...) Should this be a putIfAbsent?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to