瀏覽代碼

svn merge -c 1305632 from trunk for HDFS-2413. Add an API DistributedFileSystem.isInSafeMode() and change DistributedFileSystem to @InterfaceAudience.LimitedPrivate.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.23@1305633 13f79535-47bb-0310-9956-ffa450edef68
Tsz-wo Sze 13 年之前
父節點
當前提交
28c307519a

+ 4 - 0
hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

@@ -58,6 +58,10 @@ Release 0.23.3 - UNRELEASED
     HDFS-2941. Add an administrative command to download a copy of the fsimage
     HDFS-2941. Add an administrative command to download a copy of the fsimage
     from the NN. (atm)
     from the NN. (atm)
 
 
+    HDFS-2413. Add an API DistributedFileSystem.isInSafeMode() and change
+    DistributedFileSystem to @InterfaceAudience.LimitedPrivate.
+    (harsh via szetszwo)
+
   IMPROVEMENTS
   IMPROVEMENTS
 
 
     HDFS-2018. Move all journal stream management code into one place.
     HDFS-2018. Move all journal stream management code into one place.

+ 13 - 2
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DistributedFileSystem.java

@@ -51,6 +51,7 @@ import org.apache.hadoop.hdfs.protocol.DirectoryListing;
 import org.apache.hadoop.hdfs.protocol.ExtendedBlock;
 import org.apache.hadoop.hdfs.protocol.ExtendedBlock;
 import org.apache.hadoop.hdfs.protocol.HdfsConstants;
 import org.apache.hadoop.hdfs.protocol.HdfsConstants;
 import org.apache.hadoop.hdfs.protocol.HdfsConstants.DatanodeReportType;
 import org.apache.hadoop.hdfs.protocol.HdfsConstants.DatanodeReportType;
+import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction;
 import org.apache.hadoop.hdfs.protocol.HdfsConstants.UpgradeAction;
 import org.apache.hadoop.hdfs.protocol.HdfsConstants.UpgradeAction;
 import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
 import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
 import org.apache.hadoop.hdfs.protocol.HdfsLocatedFileStatus;
 import org.apache.hadoop.hdfs.protocol.HdfsLocatedFileStatus;
@@ -71,8 +72,8 @@ import org.apache.hadoop.util.Progressable;
  * DistributedFileSystem.
  * DistributedFileSystem.
  *
  *
  *****************************************************************/
  *****************************************************************/
-@InterfaceAudience.Private
-@InterfaceStability.Evolving
+@InterfaceAudience.LimitedPrivate({ "MapReduce", "HBase" })
+@InterfaceStability.Unstable
 public class DistributedFileSystem extends FileSystem {
 public class DistributedFileSystem extends FileSystem {
   private Path workingDir;
   private Path workingDir;
   private URI uri;
   private URI uri;
@@ -854,4 +855,14 @@ public class DistributedFileSystem extends FileSystem {
       return super.getCanonicalServiceName();
       return super.getCanonicalServiceName();
     }
     }
   }
   }
+
+  /**
+   * Utility function that returns if the NameNode is in safemode or not.
+   *
+   * @return true if NameNode is in safemode, false otherwise.
+   * @throws IOException when there is an issue communicating with the NameNode
+   */
+  public boolean isInSafeMode() throws IOException {
+    return setSafeMode(SafeModeAction.SAFEMODE_GET);
+  }
 }
 }

+ 2 - 2
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java

@@ -59,7 +59,7 @@ import org.apache.hadoop.util.StringUtils;
 import org.apache.hadoop.util.ToolRunner;
 import org.apache.hadoop.util.ToolRunner;
 
 
 /**
 /**
- * This class provides some DFS administrative access.
+ * This class provides some DFS administrative access shell commands.
  */
  */
 @InterfaceAudience.Private
 @InterfaceAudience.Private
 public class DFSAdmin extends FsShell {
 public class DFSAdmin extends FsShell {
@@ -396,7 +396,7 @@ public class DFSAdmin extends FsShell {
         } catch (java.lang.InterruptedException e) {
         } catch (java.lang.InterruptedException e) {
           throw new IOException("Wait Interrupted");
           throw new IOException("Wait Interrupted");
         }
         }
-        inSafeMode = dfs.setSafeMode(action);
+        inSafeMode = dfs.isInSafeMode();
       }
       }
     }
     }
 
 

+ 15 - 0
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSafeMode.java

@@ -357,4 +357,19 @@ public class TestSafeMode {
     assertEquals("", cluster.getNamesystem().getSafemode());
     assertEquals("", cluster.getNamesystem().getSafemode());
   }
   }
 
 
+  /*
+   * Tests some utility methods that surround the SafeMode's state.
+   * @throws IOException when there's an issue connecting to the test DFS.
+   */
+  public void testSafeModeUtils() throws IOException {
+    dfs = (DistributedFileSystem)cluster.getFileSystem();
+
+    // Enter safemode.
+    dfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
+    assertTrue("State was expected to be in safemode.", dfs.isInSafeMode());
+
+    // Exit safemode.
+    dfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
+    assertFalse("State was expected to be out of safemode.", dfs.isInSafeMode());
+  }
 }
 }