public void addAt(long offset, VoterSet voters) {
        Optional<LogHistory.Entry<VoterSet>> lastEntry = votersHistory.lastEntry();
        if (lastEntry.isPresent() && lastEntry.get().offset() >= 0) {
            // If the last voter set comes from the replicated log then the majorities must overlap.
            // This ignores the static voter set and the bootstrapped voter set since they come from
            // the configuration and the KRaft leader never guaranteed that they are the same across
            // all replicas.
            VoterSet lastVoterSet = lastEntry.get().value();
            if (!lastVoterSet.hasOverlappingMajority(voters)) {
                throw new IllegalArgumentException(
                    String.format(
                        "Last voter set %s doesn't have an overlapping majority with the new voter set %s",
                        lastVoterSet,
                        voters
                    )
                );
            }
        }

        votersHistory.addAt(offset, voters);
    }
@Test
    void testAddAt() {
        Map<Integer, VoterSet.VoterNode> voterMap = VoterSetTest.voterMap(IntStream.of(1, 2, 3), true);
        VoterSet staticVoterSet = VoterSet.fromMap(new HashMap<>(voterMap));
        VoterSetHistory votersHistory = new VoterSetHistory(staticVoterSet);

        assertThrows(
            IllegalArgumentException.class,
            () -> votersHistory.addAt(-2, VoterSet.fromMap(VoterSetTest.voterMap(IntStream.of(1, 2, 3), true)))
        );
        assertEquals(staticVoterSet, votersHistory.lastValue());

        voterMap.put(4, VoterSetTest.voterNode(4, true));
        VoterSet addedVoterSet = VoterSet.fromMap(new HashMap<>(voterMap));
        votersHistory.addAt(100, addedVoterSet);

        assertEquals(addedVoterSet, votersHistory.lastValue());
        assertEquals(Optional.empty(), votersHistory.valueAtOrBefore(99));
        assertEquals(Optional.of(addedVoterSet), votersHistory.valueAtOrBefore(100));

        voterMap.remove(4);
        VoterSet removedVoterSet = VoterSet.fromMap(new HashMap<>(voterMap));
        votersHistory.addAt(200, removedVoterSet);

        assertEquals(removedVoterSet, votersHistory.lastValue());
        assertEquals(Optional.empty(), votersHistory.valueAtOrBefore(99));
        assertEquals(Optional.of(addedVoterSet), votersHistory.valueAtOrBefore(199));
        assertEquals(Optional.of(removedVoterSet), votersHistory.valueAtOrBefore(200));
    }