Browse Source

HDFS-15185. StartupProgress reports edits segments until the entire startup completes. Contributed by Konstantin V Shvachko.

(cherry picked from commit 6f84269bcd5cdb08ca68b2d8276f66d34a2a7a0d)
Konstantin V Shvachko 5 years ago
parent
commit
cd0525054d

+ 1 - 1
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;
     }
   }

+ 11 - 0
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);
   }
 }