zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f..@apache.org
Subject svn commit: r1605380 - in /zookeeper/trunk: ./ src/java/main/org/apache/zookeeper/server/quorum/ src/java/test/org/apache/zookeeper/test/
Date Wed, 25 Jun 2014 13:04:28 GMT
Author: fpj
Date: Wed Jun 25 13:04:27 2014
New Revision: 1605380

URL: http://svn.apache.org/r1605380
Log:
ZOOKEEPER-1870. flakey test in StandaloneDisabledTest.startSingleServerTest (Helen Hastings
via fpj)

Modified:
    zookeeper/trunk/CHANGES.txt
    zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java
    zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java
    zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
    zookeeper/trunk/src/java/test/org/apache/zookeeper/test/CnxManagerTest.java
    zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLETest.java

Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1605380&r1=1605379&r2=1605380&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Wed Jun 25 13:04:27 2014
@@ -667,6 +667,9 @@ BUGFIXES:
   ZOOKEEPER-1699. Leader should timeout and give up leadership when losing
   quorum of last proposed configuration (Alexander Shraer via michim)
 
+  ZOOKEEPER-1870. flakey test in StandaloneDisabledTest.startSingleServerTest 
+  (Helen Hastings via fpj)
+
 IMPROVEMENTS:
 
   ZOOKEEPER-1170. Fix compiler (eclipse) warnings: unused imports,

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java?rev=1605380&r1=1605379&r2=1605380&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java
(original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java
Wed Jun 25 13:04:27 2014
@@ -277,6 +277,7 @@ public class FastLeaderElection implemen
                                            LOG.info("restarting leader election");
                                            self.shuttingDownLE = true;
                                            self.getElectionAlg().shutdown();
+                                           break;
                                        }
                                    }           
                                } catch (IOException e) {                         
@@ -573,6 +574,8 @@ public class FastLeaderElection implemen
     volatile boolean stop;
     public void shutdown(){
         stop = true;
+        proposedLeader = -1;
+        proposedZxid = -1;
         LOG.debug("Shutting down connection manager");
         manager.halt();
         LOG.debug("Shutting down messenger");
@@ -713,7 +716,7 @@ public class FastLeaderElection implemen
         proposedEpoch = epoch;
     }
 
-    synchronized Vote getVote(){
+    synchronized public Vote getVote(){
         return new Vote(proposedLeader, proposedZxid, proposedEpoch);
     }
 

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java?rev=1605380&r1=1605379&r2=1605380&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java
(original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java
Wed Jun 25 13:04:27 2014
@@ -457,6 +457,12 @@ public class QuorumCnxManager {
         LOG.debug("Halting listener");
         listener.halt();
         
+        // Wait for the listener to terminate.
+        try {
+            listener.join();
+        } catch (InterruptedException ex) {
+            LOG.warn("Got interrupted before joining the listener", ex);
+        }
         softHalt();
     }
    
@@ -551,22 +557,19 @@ public class QuorumCnxManager {
                         numRetries = 0;
                     }
                 } catch (IOException e) {
-                    if ( !shutdown ) {
-                        LOG.error("Exception while listening", e);
+                    if (shutdown) {
+                        break;
                     }
+                    LOG.error("Exception while listening", e);
                     numRetries++;
                     try {
                         ss.close();
                         Thread.sleep(1000);
                     } catch (IOException ie) {
-                        if ( !shutdown ) {
-                            LOG.error("Error closing server socket", ie);
-                        }
+                        LOG.error("Error closing server socket", ie);
                     } catch (InterruptedException ie) {
-                        if ( !shutdown ) {
-                            LOG.error("Interrupted while sleeping. " +
-                                "Ignoring exception", ie);
-                        }
+                        LOG.error("Interrupted while sleeping. " +
+                            "Ignoring exception", ie);
                     }
                 }
             }
@@ -576,9 +579,17 @@ public class QuorumCnxManager {
                         + "I won't be able to participate in leader "
                         + "election any longer: "
                         + self.getElectionAddress());
+            } else if (ss != null) {
+                // Clean up for shutdown.
+                try {
+                    ss.close();
+                } catch (IOException ie) {
+                    // Don't log an error for shutdown.
+                    LOG.debug("Error closing server socket", ie);
+                }
             }
         }
-        
+
         /**
          * Halts this listener thread.
          */

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java?rev=1605380&r1=1605379&r2=1605380&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java Wed Jun
25 13:04:27 2014
@@ -1269,6 +1269,7 @@ public class QuorumPeer extends ZooKeepe
         if (qvOLD == null || !qvOLD.equals(qvNEW)) {
             LOG.warn("Restarting Leader Election");
             getElectionAlg().shutdown();
+            shuttingDownLE = false;
             startLeaderElection();
         }           
     }

Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/CnxManagerTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/CnxManagerTest.java?rev=1605380&r1=1605379&r2=1605380&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/CnxManagerTest.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/CnxManagerTest.java Wed Jun 25
13:04:27 2014
@@ -173,7 +173,8 @@ public class CnxManagerTest extends ZKTe
             if(thread.failed)
                 Assert.fail("Did not receive expected message");
         }
-
+        cnxManager.halt();
+        Assert.assertFalse(cnxManager.listener.isAlive());
     }
 
     @Test
@@ -206,7 +207,8 @@ public class CnxManagerTest extends ZKTe
         long end = System.currentTimeMillis();
 
         if((end - begin) > 6000) Assert.fail("Waited more than necessary");
-
+        cnxManager.halt();
+        Assert.assertFalse(cnxManager.listener.isAlive());
     }
 
     /**
@@ -269,6 +271,7 @@ public class CnxManagerTest extends ZKTe
         }
         peer.shutdown();
         cnxManager.halt();
+        Assert.assertFalse(cnxManager.listener.isAlive());
     }
 
     /*
@@ -295,6 +298,8 @@ public class CnxManagerTest extends ZKTe
         cnxManager.receiveConnection(sock);
         long end = System.currentTimeMillis();
         if((end - begin) > ((peer.getSyncLimit() * peer.getTickTime()) + 500)) Assert.fail("Waited
more than necessary");
+        cnxManager.halt();
+        Assert.assertFalse(cnxManager.listener.isAlive());
     }
 
     /*

Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLETest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLETest.java?rev=1605380&r1=1605379&r2=1605380&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLETest.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLETest.java Wed Jun 25 13:04:27
2014
@@ -162,7 +162,11 @@ public class FLETest extends ZKTestCase 
                         LOG.info("I'm the leader: " + i);
                         if (lc < this.totalRounds) {
                             LOG.info("Leader " + i + " dying");
-                            ((FastLeaderElection) peer.getElectionAlg()).shutdown();
+                            FastLeaderElection election =
+                                (FastLeaderElection) peer.getElectionAlg();
+                            election.shutdown();
+                            // Make sure the vote is reset to -1 after shutdown.
+                            Assert.assertEquals(-1, election.getVote().getId());
                             LOG.info("Leader " + i + " dead");
                             
                             break;



Mime
View raw message