@Override
    public boolean canGrantVote(ReplicaKey candidateKey, boolean isLogUpToDate) {
        if (votedKey.id() == candidateKey.id()) {
            return !votedKey.directoryId().isPresent() || votedKey.directoryId().equals(candidateKey.directoryId());
        }

        log.debug(
            "Rejecting vote request from candidate ({}), already have voted for another " +
            "candidate ({}) in epoch {}",
            candidateKey,
            votedKey,
            epoch
        );

        return false;
    }
The "voted" state is for voters who have cast their vote for a specific candidate.

Once a vote has been cast, it is not possible for a voter to change its vote until a
new election is started. If the election timeout expires before a new leader is elected,
then the voter will become a candidate.
raft/src/main/java/org/apache/kafka/raft/VotedState.java