hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From whe...@apache.org
Subject git commit: HDFS-7257. Add the time of last HA state transition to NN's /jmx page. Contributed by Charles Lamb.
Date Thu, 23 Oct 2014 23:53:05 GMT
Repository: hadoop
Updated Branches:
  refs/heads/trunk 828429dec -> 670879ef4


HDFS-7257. Add the time of last HA state transition to NN's /jmx page. Contributed by Charles
Lamb.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/670879ef
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/670879ef
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/670879ef

Branch: refs/heads/trunk
Commit: 670879ef414e704f48491805d9af1b0ac5bb4329
Parents: 828429d
Author: Haohui Mai <wheat9@apache.org>
Authored: Thu Oct 23 16:52:58 2014 -0700
Committer: Haohui Mai <wheat9@apache.org>
Committed: Thu Oct 23 16:52:58 2014 -0700

----------------------------------------------------------------------
 hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt        |  3 +++
 .../hadoop/hdfs/server/namenode/NameNode.java      |  5 +++++
 .../hdfs/server/namenode/NameNodeStatusMXBean.java |  7 +++++++
 .../hadoop/hdfs/server/namenode/ha/HAState.java    | 17 ++++++++++++++++-
 .../hdfs/server/namenode/ha/TestHAMetrics.java     | 13 +++++++++++++
 5 files changed, 44 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/670879ef/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
index c7dce00..d3da6d8 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
+++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
@@ -297,6 +297,9 @@ Release 2.7.0 - UNRELEASED
 
     HDFS-7222. Expose DataNode network errors as a metric. (Charles Lamb via wang)
 
+    HDFS-7257. Add the time of last HA state transition to NN's /jmx page.
+    (Charles Lamb via wheat9)
+
   OPTIMIZATIONS
 
   BUG FIXES

http://git-wip-us.apache.org/repos/asf/hadoop/blob/670879ef/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java
index 4e61f05..a71d158 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java
@@ -1619,6 +1619,11 @@ public class NameNode implements NameNodeStatusMXBean {
     return UserGroupInformation.isSecurityEnabled();
   }
 
+  @Override // NameNodeStatusMXBean
+  public long getLastHATransitionTime() {
+    return state.getLastHATransitionTime();
+  }
+
   /**
    * Shutdown the NN immediately in an ungraceful way. Used when it would be
    * unsafe for the NN to continue operating, e.g. during a failed HA state

http://git-wip-us.apache.org/repos/asf/hadoop/blob/670879ef/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeStatusMXBean.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeStatusMXBean.java
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeStatusMXBean.java
index f52407f..e3f712a 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeStatusMXBean.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeStatusMXBean.java
@@ -54,4 +54,11 @@ public interface NameNodeStatusMXBean {
    * @return true, if security is enabled.
    */
   public boolean isSecurityEnabled();
+
+  /**
+   * Gets the most recent HA transition time in milliseconds from the epoch.
+   *
+   * @return the most recent HA transition time in milliseconds from the epoch.
+   */
+  public long getLastHATransitionTime();
 }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/670879ef/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/HAState.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/HAState.java
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/HAState.java
index 34a5da2..f300710 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/HAState.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/HAState.java
@@ -21,8 +21,8 @@ import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState;
 import org.apache.hadoop.ha.ServiceFailedException;
 import org.apache.hadoop.hdfs.server.namenode.NameNode.OperationCategory;
-import org.apache.hadoop.hdfs.server.namenode.UnsupportedActionException;
 import org.apache.hadoop.ipc.StandbyException;
+import org.apache.hadoop.util.Time;
 
 /**
  * Namenode base state to implement state machine pattern.
@@ -30,6 +30,7 @@ import org.apache.hadoop.ipc.StandbyException;
 @InterfaceAudience.Private
 abstract public class HAState {
   protected final HAServiceState state;
+  private long lastHATransitionTime;
 
   /**
    * Constructor
@@ -61,12 +62,26 @@ abstract public class HAState {
       exitState(context);
       context.setState(s);
       s.enterState(context);
+      s.updateLastHATransitionTime();
     } finally {
       context.writeUnlock();
     }
   }
 
   /**
+   * Gets the most recent HA transition time in milliseconds from the epoch.
+   *
+   * @return the most recent HA transition time in milliseconds from the epoch.
+   */
+  public long getLastHATransitionTime() {
+    return lastHATransitionTime;
+  }
+
+  private void updateLastHATransitionTime() {
+    lastHATransitionTime = Time.now();
+  }
+
+  /**
    * Method to be overridden by subclasses to prepare to enter a state.
    * This method is called <em>without</em> the context being locked,
    * and after {@link #prepareToExitState(HAContext)} has been called

http://git-wip-us.apache.org/repos/asf/hadoop/blob/670879ef/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHAMetrics.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHAMetrics.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHAMetrics.java
index 1cd76f4..6f9fc6e 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHAMetrics.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHAMetrics.java
@@ -30,6 +30,10 @@ import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
 import org.apache.hadoop.io.IOUtils;
 import org.junit.Test;
 
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import java.lang.management.ManagementFactory;
+
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
@@ -62,6 +66,12 @@ public class TestHAMetrics {
       assertTrue(0 < nn1.getMillisSinceLastLoadedEdits());
 
       cluster.transitionToActive(0);
+      final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+      final ObjectName mxbeanName =
+          new ObjectName("Hadoop:service=NameNode,name=NameNodeStatus");
+      final Long ltt1 =
+          (Long) mbs.getAttribute(mxbeanName, "LastHATransitionTime");
+      assertTrue("lastHATransitionTime should be > 0", ltt1 > 0);
       
       assertEquals("active", nn0.getHAState());
       assertEquals(0, nn0.getMillisSinceLastLoadedEdits());
@@ -69,6 +79,9 @@ public class TestHAMetrics {
       assertTrue(0 < nn1.getMillisSinceLastLoadedEdits());
       
       cluster.transitionToStandby(0);
+      final Long ltt2 =
+          (Long) mbs.getAttribute(mxbeanName, "LastHATransitionTime");
+      assertTrue("lastHATransitionTime should be > " + ltt1, ltt2 > ltt1);
       cluster.transitionToActive(1);
       
       assertEquals("standby", nn0.getHAState());


Mime
View raw message