This is an automated email from the ASF dual-hosted git repository.

weichiu pushed a commit to branch branch-2
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-2 by this push:
     new db75ef2  HBASE-26050 Remove the reflection used in 
FSUtils.isInSafeMode (#3445)
db75ef2 is described below

commit db75ef265e78f3ec4b6d6e96475d8a53dfa44a2a
Author: Wei-Chiu Chuang <[email protected]>
AuthorDate: Thu Jul 1 23:19:03 2021 -0700

    HBASE-26050 Remove the reflection used in FSUtils.isInSafeMode (#3445)
    
    Signed-off-by: Michael Stack <[email protected]>
    Signed-off-by: Duo Zhang <[email protected]>
    Signed-off-by: Viraj Jasani <[email protected]>
    (cherry picked from commit 82c44b49f54d92e8635d35117d6ae47a92938e30)
---
 .../java/org/apache/hadoop/hbase/util/FSUtils.java | 23 +++++-----------------
 1 file changed, 5 insertions(+), 18 deletions(-)

diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java
index a0b68d3..60097a1 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java
@@ -18,6 +18,8 @@
  */
 package org.apache.hadoop.hbase.util;
 
+import static 
org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction.SAFEMODE_GET;
+
 import edu.umd.cs.findbugs.annotations.CheckForNull;
 import java.io.ByteArrayInputStream;
 import java.io.DataInputStream;
@@ -79,7 +81,6 @@ import org.apache.hadoop.hdfs.DFSClient;
 import org.apache.hadoop.hdfs.DFSHedgedReadMetrics;
 import org.apache.hadoop.hdfs.DFSUtil;
 import org.apache.hadoop.hdfs.DistributedFileSystem;
-import org.apache.hadoop.hdfs.protocol.HdfsConstants;
 import org.apache.hadoop.io.IOUtils;
 import org.apache.hadoop.ipc.RemoteException;
 import org.apache.hadoop.util.Progressable;
@@ -256,28 +257,14 @@ public final class FSUtils {
   }
 
   /**
-   * We use reflection because {@link DistributedFileSystem#setSafeMode(
-   * HdfsConstants.SafeModeAction action, boolean isChecked)} is not in hadoop 
1.1
+   * Inquire the Active NameNode's safe mode status.
    *
-   * @param dfs
+   * @param dfs A DistributedFileSystem object representing the underlying 
HDFS.
    * @return whether we're in safe mode
    * @throws IOException
    */
   private static boolean isInSafeMode(DistributedFileSystem dfs) throws 
IOException {
-    boolean inSafeMode = false;
-    try {
-      Method m = DistributedFileSystem.class.getMethod("setSafeMode", new 
Class<?> []{
-          org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction.class, 
boolean.class});
-      inSafeMode = (Boolean) m.invoke(dfs,
-        
org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction.SAFEMODE_GET, 
true);
-    } catch (Exception e) {
-      if (e instanceof IOException) throw (IOException) e;
-
-      // Check whether dfs is on safemode.
-      inSafeMode = dfs.setSafeMode(
-        
org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction.SAFEMODE_GET);
-    }
-    return inSafeMode;
+    return dfs.setSafeMode(SAFEMODE_GET, true);
   }
 
   /**

Reply via email to