From 6f84269bcd5cdb08ca68b2d8276f66d34a2a7a0d Mon Sep 17 00:00:00 2001 From: Konstantin V Shvachko Date: Fri, 21 Feb 2020 10:51:14 -0800 Subject: [PATCH] HDFS-15185. StartupProgress reports edits segments until the entire startup completes. Contributed by Konstantin V Shvachko. --- .../namenode/startupprogress/StartupProgress.java | 2 +- .../namenode/startupprogress/TestStartupProgress.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/startupprogress/StartupProgress.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/startupprogress/StartupProgress.java index b8244a156a4..6249a84e7f9 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/startupprogress/StartupProgress.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/startupprogress/StartupProgress.java @@ -218,7 +218,7 @@ public class StartupProgress { * @param total long to set */ public void setTotal(Phase phase, Step step, long total) { - if (!isComplete()) { + if (!isComplete(phase)) { lazyInitStep(phase, step).total = total; } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/startupprogress/TestStartupProgress.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/startupprogress/TestStartupProgress.java index c01844d63a7..8c0aa0ca2fb 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/startupprogress/TestStartupProgress.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/startupprogress/TestStartupProgress.java @@ -33,6 +33,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; +import org.apache.hadoop.hdfs.server.namenode.startupprogress.StartupProgress.Counter; import org.junit.Before; import org.junit.Test; @@ -457,5 +458,15 @@ public class TestStartupProgress { assertEquals(800L, view.getTotal(LOADING_FSIMAGE, loadingFsImageDelegationKeys)); assertEquals(10000L, view.getTotal(LOADING_EDITS, loadingEditsFile)); + + // Try adding another step to the completed phase + // Check the step is not added and the total is not updated + Step step2 = new Step("file_2", 7000L); + startupProgress.setTotal(LOADING_EDITS, step2, 2000L); + view = startupProgress.createView(); + assertEquals(view.getTotal(LOADING_EDITS, step2), 0); + Counter counter = startupProgress.getCounter(Phase.LOADING_EDITS, step2); + counter.increment(); + assertEquals(view.getCount(LOADING_EDITS, step2), 0); } }