synchronized void becomeCandidate(long newCurrentTerm) throws StorageException {
        long currentTerm = store.getCurrentTerm();

        checkArgument(currentTerm < newCurrentTerm, "currentTerm:%s newCurrentTerm:%s", currentTerm, newCurrentTerm);
        checkState(commands.isEmpty(), "commands:%s", commands);
        checkState(role == Role.FOLLOWER, "invalid transition from %s -> %s", role, Role.CANDIDATE);

        logRoleChange(newCurrentTerm, role, Role.CANDIDATE);

        stopHeartbeatTimeout();

        store.setCurrentTerm(newCurrentTerm);

        role = Role.CANDIDATE;

        setLeader(null);

        nextToApplyLogIndex = -1;
        serverData.clear();

        votedServers.clear();
        votedServers.put(self, true);
        store.setVotedFor(newCurrentTerm, self);

        scheduleNextElectionTimeout();
    }
synchronized void becomeCandidate ( long newCurrentTerm ) throws StorageException { long currentTerm = store . getCurrentTerm ( ) ; checkArgument ( currentTerm < newCurrentTerm , "currentTerm:%s newCurrentTerm:%s" , currentTerm , newCurrentTerm ) ; checkState ( commands . isEmpty ( ) , "commands:%s" , commands ) ; checkState ( role == Role . FOLLOWER , "invalid transition from %s -> %s" , role , Role . CANDIDATE ) ; logRoleChange ( newCurrentTerm , role , Role . CANDIDATE ) ; stopHeartbeatTimeout ( ) ; store . setCurrentTerm ( newCurrentTerm ) ; role = Role . CANDIDATE ; setLeader ( null ) ; nextToApplyLogIndex = - 1 ; serverData . clear ( ) ; votedServers . clear ( ) ; votedServers . put ( self , true ) ; store . setVotedFor ( newCurrentTerm , self ) ; scheduleNextElectionTimeout ( ) ; }
Transition this server from {@link Role#FOLLOWER} to {@link Role#CANDIDATE}.
<p/>
<strong>This method is package-private for testing
reasons only!</strong> It should <strong>never</strong>
be called in a non-test context!

@param newCurrentTerm new election term for this {@code RaftAlgorithm} instance