diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt index 925af24d93..fecb9c8c82 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt @@ -49,3 +49,5 @@ HDFS-2625. TestDfsOverAvroRpc failing after introduction of HeartbeatResponse ty HDFS-2627. Determine DN's view of which NN is active based on heartbeat responses (todd) HDFS-2634. Standby needs to ingest latest edit logs before transitioning to active (todd) + +HDFS-2671. NN should throw StandbyException in response to RPCs in STANDBY state (todd) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/BackupNode.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/BackupNode.java index 381bf7b5be..b84d4eb34a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/BackupNode.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/BackupNode.java @@ -43,6 +43,7 @@ import org.apache.hadoop.hdfs.server.protocol.NamenodeRegistration; import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo; import org.apache.hadoop.ipc.RPC; +import org.apache.hadoop.ipc.StandbyException; import org.apache.hadoop.net.NetUtils; import com.google.protobuf.BlockingService; @@ -397,11 +398,11 @@ String getClusterId() { @Override // NameNode protected void checkOperation(OperationCategory op) - throws UnsupportedActionException { + throws StandbyException { if (OperationCategory.JOURNAL != op) { String msg = "Operation category " + op + " is not supported at the BackupNode"; - throw new UnsupportedActionException(msg); + throw new StandbyException(msg); } } 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 fca815fdea..25cbb2e08b 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 @@ -54,6 +54,7 @@ import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocol; import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols; import org.apache.hadoop.hdfs.server.protocol.NamenodeRegistration; +import org.apache.hadoop.ipc.StandbyException; import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; import org.apache.hadoop.net.NetUtils; import org.apache.hadoop.security.RefreshUserMappingsProtocol; @@ -910,7 +911,7 @@ synchronized void transitionToStandby() throws ServiceFailedException { /** Check if an operation of given category is allowed */ protected synchronized void checkOperation(final OperationCategory op) - throws UnsupportedActionException { + throws StandbyException { state.checkOperation(haContext, op); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/ActiveState.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/ActiveState.java index e00df208d7..f893cc2883 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/ActiveState.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/ActiveState.java @@ -37,8 +37,7 @@ public ActiveState() { } @Override - public void checkOperation(HAContext context, OperationCategory op) - throws UnsupportedActionException { + public void checkOperation(HAContext context, OperationCategory op) { return; // Other than journal all operations are allowed in active state } 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 6ee516c4ca..d3ff252cbc 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,6 +21,7 @@ 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; /** * Namenode base state to implement state machine pattern. @@ -89,12 +90,8 @@ public void setState(HAContext context, HAState s) throws ServiceFailedException * @throws UnsupportedActionException if a given type of operation is not * supported in this state. */ - public void checkOperation(final HAContext context, final OperationCategory op) - throws UnsupportedActionException { - String msg = "Operation category " + op + " is not supported in state " - + context.getState(); - throw new UnsupportedActionException(msg); - } + public abstract void checkOperation(final HAContext context, final OperationCategory op) + throws StandbyException; @Override public String toString() { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/StandbyState.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/StandbyState.java index a329934f58..aec86eae91 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/StandbyState.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/StandbyState.java @@ -22,6 +22,8 @@ import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.ha.ServiceFailedException; import org.apache.hadoop.hdfs.server.namenode.NameNode; +import org.apache.hadoop.hdfs.server.namenode.NameNode.OperationCategory; +import org.apache.hadoop.ipc.StandbyException; /** * Namenode standby state. In this state the namenode acts as warm standby and @@ -66,5 +68,13 @@ public void exitState(HAContext context) throws ServiceFailedException { throw new ServiceFailedException("Failed to stop standby services", e); } } + + @Override + public void checkOperation(HAContext context, OperationCategory op) + throws StandbyException { + String msg = "Operation category " + op + " is not supported in state " + + context.getState(); + throw new StandbyException(msg); + } }