private void runElection() { NodeID myNodeID = getLocalNodeID(); NodeID winner = ServerID.NULL_ID; int count = 0; // Only new L2 if the DB was empty (no previous state) and the current state is START (as in // before any elections // concluded) boolean isNew = state == START_STATE && clusterStatePersistor.getInitialState() == null; while (getActiveNodeID().isNull()) { if (++count > 1) { logger.info( "Rerunning election since node " + winner + " never declared itself as ACTIVE !"); } debugInfo("Running election - isNew: " + isNew); winner = electionMgr.runElection(myNodeID, isNew, weightsFactory); if (winner == myNodeID) { debugInfo("Won Election, moving to active state. myNodeID/winner=" + myNodeID); moveToActiveState(); } else { electionMgr.reset(null); // Election is lost, but we wait for the active node to declare itself as winner. If this // doesn't happen in a // finite time we restart the election. This is to prevent some weird cases where two nodes // might end up // thinking the other one is the winner. // @see MNK-518 debugInfo("Lost election, waiting for winner to declare as active, winner=" + winner); waitUntilActiveNodeIDNotNull(electionMgr.getElectionTime()); } } }