hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject svn commit: r1338817 - in /hadoop/common/branches/HDFS-3042/hadoop-common-project/hadoop-common: dev-support/ src/main/java/org/apache/hadoop/ha/ src/test/java/org/apache/hadoop/ha/
Date Tue, 15 May 2012 18:16:50 GMT
Author: todd
Date: Tue May 15 18:16:49 2012
New Revision: 1338817

URL: http://svn.apache.org/viewvc?rev=1338817&view=rev
Log:
HDFS-3412. Fix findbugs warnings in auto-HA branch. Contributed by Todd Lipcon.

Modified:
    hadoop/common/branches/HDFS-3042/hadoop-common-project/hadoop-common/dev-support/findbugsExcludeFile.xml
    hadoop/common/branches/HDFS-3042/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ZKFailoverController.java
    hadoop/common/branches/HDFS-3042/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/MiniZKFCCluster.java
    hadoop/common/branches/HDFS-3042/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestZKFailoverController.java

Modified: hadoop/common/branches/HDFS-3042/hadoop-common-project/hadoop-common/dev-support/findbugsExcludeFile.xml
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-3042/hadoop-common-project/hadoop-common/dev-support/findbugsExcludeFile.xml?rev=1338817&r1=1338816&r2=1338817&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-3042/hadoop-common-project/hadoop-common/dev-support/findbugsExcludeFile.xml
(original)
+++ hadoop/common/branches/HDFS-3042/hadoop-common-project/hadoop-common/dev-support/findbugsExcludeFile.xml
Tue May 15 18:16:49 2012
@@ -290,5 +290,9 @@
       <!-- protobuf generated code -->
       <Class name="~org\.apache\.hadoop\.ha\.proto\.HAServiceProtocolProtos.*"/>
     </Match>
+    <Match>
+      <!-- protobuf generated code -->
+      <Class name="~org\.apache\.hadoop\.ha\.proto\.ZKFCProtocolProtos.*"/>
+    </Match>
 
  </FindBugsFilter>

Modified: hadoop/common/branches/HDFS-3042/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ZKFailoverController.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-3042/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ZKFailoverController.java?rev=1338817&r1=1338816&r2=1338817&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-3042/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ZKFailoverController.java
(original)
+++ hadoop/common/branches/HDFS-3042/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ZKFailoverController.java
Tue May 15 18:16:49 2012
@@ -44,7 +44,6 @@ import org.apache.hadoop.security.Securi
 import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.hadoop.security.authorize.PolicyProvider;
 import org.apache.hadoop.util.StringUtils;
-import org.apache.hadoop.util.Tool;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.hadoop.util.ToolRunner;
@@ -56,7 +55,7 @@ import com.google.common.base.Throwables
 import com.google.common.util.concurrent.ThreadFactoryBuilder;
 
 @InterfaceAudience.LimitedPrivate("HDFS")
-public abstract class ZKFailoverController implements Tool {
+public abstract class ZKFailoverController {
 
   static final Log LOG = LogFactory.getLog(ZKFailoverController.class);
   
@@ -93,15 +92,14 @@ public abstract class ZKFailoverControll
   /** Cannot connect to ZooKeeper */
   static final int ERR_CODE_NO_ZK = 6;
   
-  private Configuration conf;
+  protected Configuration conf;
   private String zkQuorum;
+  protected final HAServiceTarget localTarget;
 
   private HealthMonitor healthMonitor;
   private ActiveStandbyElector elector;
   protected ZKFCRpcServer rpcServer;
 
-  private HAServiceTarget localTarget;
-
   private State lastHealthState = State.INITIALIZING;
 
   /** Set if a fatal error occurs */
@@ -123,15 +121,13 @@ public abstract class ZKFailoverControll
   private ActiveAttemptRecord lastActiveAttemptRecord;
   private Object activeAttemptRecordLock = new Object();
 
-  @Override
-  public void setConf(Configuration conf) {
+  protected ZKFailoverController(Configuration conf, HAServiceTarget localTarget) {
+    this.localTarget = localTarget;
     this.conf = conf;
-    localTarget = getLocalTarget();
   }
   
 
   protected abstract byte[] targetToData(HAServiceTarget target);
-  protected abstract HAServiceTarget getLocalTarget();
   protected abstract HAServiceTarget dataToTarget(byte[] data);
   protected abstract void loginAsFCUser() throws IOException;
   protected abstract void checkRpcAdminAccess()
@@ -147,12 +143,10 @@ public abstract class ZKFailoverControll
    */
   protected abstract String getScopeInsideParentNode();
 
-  @Override
-  public Configuration getConf() {
-    return conf;
+  public HAServiceTarget getLocalTarget() {
+    return localTarget;
   }
-
-  @Override
+  
   public int run(final String[] args) throws Exception {
     if (!localTarget.isAutoFailoverEnabled()) {
       LOG.fatal("Automatic failover is not enabled for " + localTarget + "." +
@@ -792,9 +786,15 @@ public abstract class ZKFailoverControll
    * by the HealthMonitor.
    */
   @VisibleForTesting
-  State getLastHealthState() {
+  synchronized State getLastHealthState() {
     return lastHealthState;
   }
+
+  private synchronized void setLastHealthState(HealthMonitor.State newState) {
+    LOG.info("Local service " + localTarget +
+        " entered state: " + newState);
+    lastHealthState = newState;
+  }
   
   @VisibleForTesting
   ActiveStandbyElector getElectorForTests() {
@@ -836,7 +836,9 @@ public abstract class ZKFailoverControll
     
     @Override
     public String toString() {
-      return "Elector callbacks for " + localTarget;
+      synchronized (ZKFailoverController.this) {
+        return "Elector callbacks for " + localTarget;
+      }
     }
   }
   
@@ -846,9 +848,7 @@ public abstract class ZKFailoverControll
   class HealthCallbacks implements HealthMonitor.Callback {
     @Override
     public void enteredState(HealthMonitor.State newState) {
-      LOG.info("Local service " + localTarget +
-          " entered state: " + newState);
-      lastHealthState = newState;
+      setLastHealthState(newState);
       recheckElectability();
     }
   }

Modified: hadoop/common/branches/HDFS-3042/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/MiniZKFCCluster.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-3042/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/MiniZKFCCluster.java?rev=1338817&r1=1338816&r2=1338817&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-3042/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/MiniZKFCCluster.java
(original)
+++ hadoop/common/branches/HDFS-3042/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/MiniZKFCCluster.java
Tue May 15 18:16:49 2012
@@ -253,8 +253,7 @@ public class MiniZKFCCluster {
 
     public DummyZKFCThread(TestContext ctx, DummyHAService svc) {
       super(ctx);
-      this.zkfc = new DummyZKFC(svc);
-      zkfc.setConf(conf);
+      this.zkfc = new DummyZKFC(conf, svc);
     }
 
     @Override
@@ -276,7 +275,8 @@ public class MiniZKFCCluster {
       SCOPED_PARENT_ZNODE + "/" + ActiveStandbyElector.LOCK_FILENAME;
     private final DummyHAService localTarget;
     
-    public DummyZKFC(DummyHAService localTarget) {
+    public DummyZKFC(Configuration conf, DummyHAService localTarget) {
+      super(conf, localTarget);
       this.localTarget = localTarget;
     }
 
@@ -292,11 +292,6 @@ public class MiniZKFCCluster {
     }
 
     @Override
-    protected HAServiceTarget getLocalTarget() {
-      return localTarget;
-    }
-
-    @Override
     protected void loginAsFCUser() throws IOException {
     }
 

Modified: hadoop/common/branches/HDFS-3042/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestZKFailoverController.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-3042/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestZKFailoverController.java?rev=1338817&r1=1338816&r2=1338817&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-3042/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestZKFailoverController.java
(original)
+++ hadoop/common/branches/HDFS-3042/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestZKFailoverController.java
Tue May 15 18:16:49 2012
@@ -112,13 +112,12 @@ public class TestZKFailoverController ex
   public void testFormatOneClusterLeavesOtherClustersAlone() throws Exception {
     DummyHAService svc = cluster.getService(1);
 
-    DummyZKFC zkfcInOtherCluster = new DummyZKFC(cluster.getService(1)) {
+    DummyZKFC zkfcInOtherCluster = new DummyZKFC(conf, cluster.getService(1)) {
       @Override
       protected String getScopeInsideParentNode() {
         return "other-scope";
       }
     };
-    zkfcInOtherCluster.setConf(conf);
     
     // Run without formatting the base dir,
     // should barf
@@ -580,8 +579,7 @@ public class TestZKFailoverController ex
   }
 
   private int runFC(DummyHAService target, String ... args) throws Exception {
-    DummyZKFC zkfc = new DummyZKFC(target);
-    zkfc.setConf(conf);
+    DummyZKFC zkfc = new DummyZKFC(conf, target);
     return zkfc.run(args);
   }
 



Mime
View raw message