From 87c036efb39ff45caa15a9dfd51e0cb27d120118 Mon Sep 17 00:00:00 2001 From: huhaiyang Date: Fri, 28 Jul 2023 15:15:00 +0800 Subject: [PATCH] HDFS-17116. RBF: Update invoke millisecond time as monotonicNow() in RouterSafemodeService (#5876). Contributed by Haiyang Hu. Reviewed-by: hfutatzhanghb <1036798979@qq.com> Reviewed-by: Shilun Fan Signed-off-by: He Xiaoqiao --- .../federation/router/RouterSafemodeService.java | 13 ++++++------- .../server/federation/store/StateStoreService.java | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterSafemodeService.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterSafemodeService.java index 23ce4fc18b..ce9e1a64c5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterSafemodeService.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterSafemodeService.java @@ -17,13 +17,12 @@ */ package org.apache.hadoop.hdfs.server.federation.router; -import static org.apache.hadoop.util.Time.now; +import static org.apache.hadoop.util.Time.monotonicNow; import java.util.concurrent.TimeUnit; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hdfs.server.federation.store.StateStoreService; -import org.apache.hadoop.util.Time; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -73,7 +72,7 @@ public class RouterSafemodeService extends PeriodicService { private long startupTime; /** The time the Router enters safe mode in milliseconds. */ - private long enterSafeModeTime = now(); + private long enterSafeModeTime = monotonicNow(); /** @@ -107,7 +106,7 @@ void setManualSafeMode(boolean mode) { */ private void enter() { LOG.info("Entering safe mode"); - enterSafeModeTime = now(); + enterSafeModeTime = monotonicNow(); safeMode = true; router.updateRouterState(RouterServiceState.SAFEMODE); } @@ -117,7 +116,7 @@ private void enter() { */ private void leave() { // Cache recently updated, leave safemode - long timeInSafemode = now() - enterSafeModeTime; + long timeInSafemode = monotonicNow() - enterSafeModeTime; LOG.info("Leaving safe mode after {} milliseconds", timeInSafemode); RouterMetrics routerMetrics = router.getRouterMetrics(); if (routerMetrics == null) { @@ -151,7 +150,7 @@ protected void serviceInit(Configuration conf) throws Exception { LOG.info("Enter safe mode after {} ms without reaching the State Store", this.staleInterval); - this.startupTime = Time.now(); + this.startupTime = monotonicNow(); // Initializing the RPC server in safe mode, it will disable it later enter(); @@ -161,7 +160,7 @@ protected void serviceInit(Configuration conf) throws Exception { @Override public void periodicInvoke() { - long now = Time.now(); + long now = monotonicNow(); long delta = now - startupTime; if (delta < startupInterval) { LOG.info("Delaying safemode exit for {} milliseconds...", diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/StateStoreService.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/StateStoreService.java index eaa55efe59..ce460a87c8 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/StateStoreService.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/StateStoreService.java @@ -435,7 +435,7 @@ public void refreshCaches(boolean force) { } if (success) { // Uses local time, not driver time. - this.cacheLastUpdateTime = Time.now(); + this.cacheLastUpdateTime = Time.monotonicNow(); } }