Browse Source

HADOOP-7970. HAServiceProtocol methods must throw IOException.Contributed by Hari Mankude.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-1623@1230351 13f79535-47bb-0310-9956-ffa450edef68
Suresh Srinivas 13 năm trước cách đây
mục cha
commit
09e5af76f3

+ 3 - 0
hadoop-common-project/hadoop-common/CHANGES.HDFS-1623.txt

@@ -28,3 +28,6 @@ HADOOP-7932. Make client connection retries on socket time outs configurable.
 HADOOP-7924. 
FailoverController for client-based configuration (eli)
 
 HADOOP-7961. Move HA fencing to common. (eli)
+
+HADOOP-7970. HAServiceProtocol methods must throw IOException.
+(Hari Mankude via suresh).

+ 6 - 1
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/FailoverController.java

@@ -17,6 +17,8 @@
  */
 package org.apache.hadoop.ha;
 
+import java.io.IOException;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -51,7 +53,7 @@ public class FailoverController {
     HAServiceState toSvcState;
     try {
       toSvcState = toSvc.getServiceState();
-    } catch (Exception e) {
+    } catch (IOException e) {
       String msg = "Unable to get service state for " + toSvcName;
       LOG.error(msg, e);
       throw new FailoverFailedException(msg, e);
@@ -65,6 +67,9 @@ public class FailoverController {
     } catch (HealthCheckFailedException hce) {
       throw new FailoverFailedException(
           "Can't failover to an unhealthy service", hce);
+    } catch (IOException e) {
+      throw new FailoverFailedException(
+          "Got an io exception", e);
     }
     // TODO(HA): ask toSvc if it's capable. Eg not in SM.
   }

+ 18 - 4
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAServiceProtocol.java

@@ -21,6 +21,8 @@ import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
 import org.apache.hadoop.ipc.VersionedProtocol;
 
+import java.io.IOException;
+
 /**
  * Protocol interface that provides High Availability related primitives to
  * monitor and fail-over the service.
@@ -69,8 +71,11 @@ public interface HAServiceProtocol extends VersionedProtocol {
    * 
    * @throws HealthCheckFailedException
    *           if the health check of a service fails.
+   * @throws IOException
+   *           if other errors happen
    */
-  public void monitorHealth() throws HealthCheckFailedException;
+  public void monitorHealth() throws HealthCheckFailedException,
+                                     IOException;
 
   /**
    * Request service to transition to active state. No operation, if the
@@ -78,8 +83,11 @@ public interface HAServiceProtocol extends VersionedProtocol {
    * 
    * @throws ServiceFailedException
    *           if transition from standby to active fails.
+   * @throws IOException
+   *           if other errors happen
    */
-  public void transitionToActive() throws ServiceFailedException;
+  public void transitionToActive() throws ServiceFailedException,
+                                          IOException;
 
   /**
    * Request service to transition to standby state. No operation, if the
@@ -87,11 +95,17 @@ public interface HAServiceProtocol extends VersionedProtocol {
    * 
    * @throws ServiceFailedException
    *           if transition from active to standby fails.
+   * @throws IOException
+   *           if other errors happen
    */
-  public void transitionToStandby() throws ServiceFailedException;
+  public void transitionToStandby() throws ServiceFailedException,
+                                           IOException;
 
   /**
    * Return the current state of the service.
+   * 
+   * @throws IOException
+   *           if other errors happen
    */
-  public HAServiceState getServiceState();
+  public HAServiceState getServiceState() throws IOException;
 }

+ 3 - 1
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HealthCheckFailedException.java

@@ -17,6 +17,8 @@
  */
 package org.apache.hadoop.ha;
 
+import java.io.IOException;
+
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
 
@@ -25,7 +27,7 @@ import org.apache.hadoop.classification.InterfaceStability;
  */
 @InterfaceAudience.Public
 @InterfaceStability.Evolving
-public class HealthCheckFailedException extends Exception {
+public class HealthCheckFailedException extends IOException {
   private static final long serialVersionUID = 1L;
 
   public HealthCheckFailedException(final String message) {

+ 3 - 1
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ServiceFailedException.java

@@ -17,6 +17,8 @@
  */
 package org.apache.hadoop.ha;
 
+import java.io.IOException;
+
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
 
@@ -27,7 +29,7 @@ import org.apache.hadoop.classification.InterfaceStability;
  */
 @InterfaceAudience.Public
 @InterfaceStability.Evolving
-public class ServiceFailedException extends Exception {
+public class ServiceFailedException extends IOException {
   private static final long serialVersionUID = 1L;
 
   public ServiceFailedException(final String message) {

+ 0 - 3
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java

@@ -551,9 +551,6 @@ public class NameNode {
     } catch (HadoopIllegalArgumentException e) {
       this.stop();
       throw e;
-    } catch (ServiceFailedException e) {
-      this.stop();
-      throw new IOException("Service failed to start", e);
     }
   }