From ee3ee98ee5a4c34da7a4960b099686bdc1186a71 Mon Sep 17 00:00:00 2001 From: xuzq <15040255127@163.com> Date: Sat, 11 Jun 2022 03:00:56 +0800 Subject: [PATCH] HDFS-16623. Avoid IllegalArgumentException in LifelineSender (#4409) * HDFS-16623. Avoid IllegalArgumentException in LifelineSender Co-authored-by: zengqiang.xu (cherry picked from commit af5003a47311bad542964c42c1f776e4350446b9) --- .../hadoop/hdfs/server/datanode/BPServiceActor.java | 3 ++- .../datanode/TestBpServiceActorScheduler.java | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BPServiceActor.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BPServiceActor.java index 8a33e0baaa..d5e3cfd65c 100755 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BPServiceActor.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BPServiceActor.java @@ -1286,7 +1286,8 @@ long getHeartbeatWaitTime() { } long getLifelineWaitTime() { - return nextLifelineTime - monotonicNow(); + long waitTime = nextLifelineTime - monotonicNow(); + return waitTime > 0 ? waitTime : 0; } @VisibleForTesting diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBpServiceActorScheduler.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBpServiceActorScheduler.java index f8406ed7a3..166ae118f7 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBpServiceActorScheduler.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBpServiceActorScheduler.java @@ -18,6 +18,7 @@ package org.apache.hadoop.hdfs.server.datanode; +import org.apache.hadoop.util.Time; import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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 public void testOutlierReportScheduling() { for (final long now : getTimestamps()) {