public Optional<VoterSet> removeVoter(ReplicaKey voterKey) {
        VoterNode oldVoter = voters.get(voterKey.id());
        if (oldVoter != null &&
            Objects.equals(oldVoter.voterKey(), voterKey) &&
            voters.size() > 1
        ) {
            HashMap<Integer, VoterNode> newVoters = new HashMap<>(voters);
            newVoters.remove(voterKey.id());

            return Optional.of(new VoterSet(newVoters));
        }

        return Optional.empty();
    }
Remove a voter from the voter set.

This object is immutable. A new voter set is returned if the voter was removed.

A voter can be removed from the voter set if its id and directory id match and there
are more than one voter in the set of voters.

@param voterKey the voter key
@return a new voter set if the voter was removed, otherwise {@code Optional.empty()}
raft/src/main/java/org/apache/kafka/raft/internals/VoterSet.java