Browse Source

ZOOKEEPER-1870. flakey test in StandaloneDisabledTest.startSingleServerTest (Helen Hastings via fpj)

git-svn-id: https://svn.apache.org/repos/asf/zookeeper/trunk@1605380 13f79535-47bb-0310-9956-ffa450edef68
Flavio Paiva Junqueira 11 years ago
parent
commit
7e262c717d

+ 3 - 0
CHANGES.txt

@@ -667,6 +667,9 @@ BUGFIXES:
   ZOOKEEPER-1699. Leader should timeout and give up leadership when losing
   ZOOKEEPER-1699. Leader should timeout and give up leadership when losing
   quorum of last proposed configuration (Alexander Shraer via michim)
   quorum of last proposed configuration (Alexander Shraer via michim)
 
 
+  ZOOKEEPER-1870. flakey test in StandaloneDisabledTest.startSingleServerTest 
+  (Helen Hastings via fpj)
+
 IMPROVEMENTS:
 IMPROVEMENTS:
 
 
   ZOOKEEPER-1170. Fix compiler (eclipse) warnings: unused imports,
   ZOOKEEPER-1170. Fix compiler (eclipse) warnings: unused imports,

+ 4 - 1
src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java

@@ -277,6 +277,7 @@ public class FastLeaderElection implements Election {
                                            LOG.info("restarting leader election");
                                            LOG.info("restarting leader election");
                                            self.shuttingDownLE = true;
                                            self.shuttingDownLE = true;
                                            self.getElectionAlg().shutdown();
                                            self.getElectionAlg().shutdown();
+                                           break;
                                        }
                                        }
                                    }           
                                    }           
                                } catch (IOException e) {                         
                                } catch (IOException e) {                         
@@ -573,6 +574,8 @@ public class FastLeaderElection implements Election {
     volatile boolean stop;
     volatile boolean stop;
     public void shutdown(){
     public void shutdown(){
         stop = true;
         stop = true;
+        proposedLeader = -1;
+        proposedZxid = -1;
         LOG.debug("Shutting down connection manager");
         LOG.debug("Shutting down connection manager");
         manager.halt();
         manager.halt();
         LOG.debug("Shutting down messenger");
         LOG.debug("Shutting down messenger");
@@ -713,7 +716,7 @@ public class FastLeaderElection implements Election {
         proposedEpoch = epoch;
         proposedEpoch = epoch;
     }
     }
 
 
-    synchronized Vote getVote(){
+    synchronized public Vote getVote(){
         return new Vote(proposedLeader, proposedZxid, proposedEpoch);
         return new Vote(proposedLeader, proposedZxid, proposedEpoch);
     }
     }
 
 

+ 21 - 10
src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java

@@ -457,6 +457,12 @@ public class QuorumCnxManager {
         LOG.debug("Halting listener");
         LOG.debug("Halting listener");
         listener.halt();
         listener.halt();
         
         
+        // Wait for the listener to terminate.
+        try {
+            listener.join();
+        } catch (InterruptedException ex) {
+            LOG.warn("Got interrupted before joining the listener", ex);
+        }
         softHalt();
         softHalt();
     }
     }
    
    
@@ -551,22 +557,19 @@ public class QuorumCnxManager {
                         numRetries = 0;
                         numRetries = 0;
                     }
                     }
                 } catch (IOException e) {
                 } catch (IOException e) {
-                    if ( !shutdown ) {
-                        LOG.error("Exception while listening", e);
+                    if (shutdown) {
+                        break;
                     }
                     }
+                    LOG.error("Exception while listening", e);
                     numRetries++;
                     numRetries++;
                     try {
                     try {
                         ss.close();
                         ss.close();
                         Thread.sleep(1000);
                         Thread.sleep(1000);
                     } catch (IOException ie) {
                     } catch (IOException ie) {
-                        if ( !shutdown ) {
-                            LOG.error("Error closing server socket", ie);
-                        }
+                        LOG.error("Error closing server socket", ie);
                     } catch (InterruptedException 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 "
                         + "I won't be able to participate in leader "
                         + "election any longer: "
                         + "election any longer: "
                         + self.getElectionAddress());
                         + 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.
          * Halts this listener thread.
          */
          */

+ 1 - 0
src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java

@@ -1269,6 +1269,7 @@ public class QuorumPeer extends ZooKeeperThread implements QuorumStats.Provider
         if (qvOLD == null || !qvOLD.equals(qvNEW)) {
         if (qvOLD == null || !qvOLD.equals(qvNEW)) {
             LOG.warn("Restarting Leader Election");
             LOG.warn("Restarting Leader Election");
             getElectionAlg().shutdown();
             getElectionAlg().shutdown();
+            shuttingDownLE = false;
             startLeaderElection();
             startLeaderElection();
         }           
         }           
     }
     }

+ 7 - 2
src/java/test/org/apache/zookeeper/test/CnxManagerTest.java

@@ -173,7 +173,8 @@ public class CnxManagerTest extends ZKTestCase {
             if(thread.failed)
             if(thread.failed)
                 Assert.fail("Did not receive expected message");
                 Assert.fail("Did not receive expected message");
         }
         }
-
+        cnxManager.halt();
+        Assert.assertFalse(cnxManager.listener.isAlive());
     }
     }
 
 
     @Test
     @Test
@@ -206,7 +207,8 @@ public class CnxManagerTest extends ZKTestCase {
         long end = System.currentTimeMillis();
         long end = System.currentTimeMillis();
 
 
         if((end - begin) > 6000) Assert.fail("Waited more than necessary");
         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 ZKTestCase {
         }
         }
         peer.shutdown();
         peer.shutdown();
         cnxManager.halt();
         cnxManager.halt();
+        Assert.assertFalse(cnxManager.listener.isAlive());
     }
     }
 
 
     /*
     /*
@@ -295,6 +298,8 @@ public class CnxManagerTest extends ZKTestCase {
         cnxManager.receiveConnection(sock);
         cnxManager.receiveConnection(sock);
         long end = System.currentTimeMillis();
         long end = System.currentTimeMillis();
         if((end - begin) > ((peer.getSyncLimit() * peer.getTickTime()) + 500)) Assert.fail("Waited more than necessary");
         if((end - begin) > ((peer.getSyncLimit() * peer.getTickTime()) + 500)) Assert.fail("Waited more than necessary");
+        cnxManager.halt();
+        Assert.assertFalse(cnxManager.listener.isAlive());
     }
     }
 
 
     /*
     /*

+ 5 - 1
src/java/test/org/apache/zookeeper/test/FLETest.java

@@ -162,7 +162,11 @@ public class FLETest extends ZKTestCase {
                         LOG.info("I'm the leader: " + i);
                         LOG.info("I'm the leader: " + i);
                         if (lc < this.totalRounds) {
                         if (lc < this.totalRounds) {
                             LOG.info("Leader " + i + " dying");
                             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");
                             LOG.info("Leader " + i + " dead");
                             
                             
                             break;
                             break;