HDFS-16623. Avoid IllegalArgumentException in LifelineSender (#4409)

* HDFS-16623. Avoid IllegalArgumentException in LifelineSender

Co-authored-by: zengqiang.xu <zengqiang.xu@shopee.com>
This commit is contained in:
xuzq 2022-06-11 03:00:56 +08:00 committed by GitHub
parent 7f5a34dfaa
commit af5003a473
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -1345,7 +1345,8 @@ long getHeartbeatWaitTime() {
} }
long getLifelineWaitTime() { long getLifelineWaitTime() {
return nextLifelineTime - monotonicNow(); long waitTime = nextLifelineTime - monotonicNow();
return waitTime > 0 ? waitTime : 0;
} }
@VisibleForTesting @VisibleForTesting

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.hdfs.server.datanode; package org.apache.hadoop.hdfs.server.datanode;
import org.apache.hadoop.util.Time;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.apache.hadoop.hdfs.server.datanode.BPServiceActor.Scheduler; import org.apache.hadoop.hdfs.server.datanode.BPServiceActor.Scheduler;
@ -204,6 +205,18 @@ public void testScheduleLifeline() {
} }
} }
@Test
public void testScheduleLifelineScheduleTime() {
Scheduler mockScheduler = spy(new Scheduler(
HEARTBEAT_INTERVAL_MS, LIFELINE_INTERVAL_MS,
BLOCK_REPORT_INTERVAL_MS, OUTLIER_REPORT_INTERVAL_MS));
long now = Time.monotonicNow();
mockScheduler.scheduleNextLifeline(now);
long mockMonotonicNow = now + LIFELINE_INTERVAL_MS * 2;
doReturn(mockMonotonicNow).when(mockScheduler).monotonicNow();
assertTrue(mockScheduler.getLifelineWaitTime() >= 0);
}
@Test @Test
public void testOutlierReportScheduling() { public void testOutlierReportScheduling() {
for (final long now : getTimestamps()) { for (final long now : getTimestamps()) {