virajjasani commented on a change in pull request #3235:
URL: https://github.com/apache/hadoop/pull/3235#discussion_r693776368



##########
File path: 
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestEditLogTailer.java
##########
@@ -429,19 +432,29 @@ public void 
testStandbyTriggersLogRollsWhenTailInProgressEdits()
       waitForStandbyToCatchUpWithInProgressEdits(standby, activeTxId,
           standbyCatchupWaitTime);
 
+      long curTime = standby.getNamesystem().getEditLogTailer().getTimer()
+          .monotonicNow();
+      long inSufficientTimeForLogRoll = logRollPeriodMs / 3;
+      final FakeTimer testTimer =
+          new FakeTimer(curTime + inSufficientTimeForLogRoll);
+      standby.getNamesystem().getEditLogTailer().setTimerForTest(testTimer);
+      Thread.sleep(2000);
+
       for (int i = DIRS_TO_MAKE / 2; i < DIRS_TO_MAKE; i++) {
         NameNodeAdapter.mkdirs(active, getDirPath(i),
             new PermissionStatus("test", "test",
             new FsPermission((short)00755)), true);
       }
 
-      boolean exceptionThrown = false;
       try {
         checkForLogRoll(active, origTxId, noLogRollWaitTime);
+        fail("Expected to timeout");
       } catch (TimeoutException e) {
-        exceptionThrown = true;
+        // expected
       }
-      assertTrue(exceptionThrown);
+
+      long sufficientTimeForLogRoll = logRollPeriodMs * 3;

Review comment:
       We multiply by 3 to advance timer.monotonicNow() by `logRollPeriodMs * 
3` which would be `15` here, and that is quite sufficient for log roll as per 
this equation in EditLogTailer: 
   
   ```
     /**
      * @return true if the configured log roll period has elapsed.
      */
     private boolean tooLongSinceLastLoad() {
       return logRollPeriodMs >= 0 && 
         (timer.monotonicNow() - lastRollTimeMs) > logRollPeriodMs;
     }
   ```
   
   With `logRollPeriodMs / 3` worth of duration, `tooLongSinceLastLoad()` 
returns false whereas with `logRollPeriodMs * 3` duration, 
`tooLongSinceLastLoad()` will return true.
   e.g 
   logRollPeriodMs = 5 sec;
   With logRollPeriodMs/3, timer.monotonicNow() = lastRollTimeMs + 5/3 = 
lastRollTimeMs + 1;
   So, timer.monotonicNow() - lastRollTimeMs = 1;
   And hence, `(timer.monotonicNow() - lastRollTimeMs) > logRollPeriodMs` is 
false (1<5).
   
   Now with logRollPeriodMs*3, timer.monotonicNow() = lastRollTimeMs + 5*3 = 
lastRollTimeMs + 15;
   So, timer.monotonicNow() - lastRollTimeMs = 15;
   And hence, `(timer.monotonicNow() - lastRollTimeMs) > logRollPeriodMs` is 
true (15>5).




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to