@Override
    public void truncateOldEntries(long startOffset) {
        NavigableMap<Long, T> lesserValues = history.headMap(startOffset, true);
        while (lesserValues.size() > 1) {
            // Poll and ignore the entry to remove the first entry
            lesserValues.pollFirstEntry();
        }
    }
A implementation for {@code LogHistory} which uses a red-black tree to store values sorted by offset.
raft/src/main/java/org/apache/kafka/raft/internals/TreeMapLogHistory.java