private synchronized OptionalLong nextExpectedOffset() {
            if (lastSent != null) {
                OptionalLong lastSentOffset = lastSent.lastOffset();
                if (lastSentOffset.isPresent()) {
                    return OptionalLong.of(lastSentOffset.getAsLong() + 1);
                } else {
                    return OptionalLong.empty();
                }
            } else {
                return OptionalLong.of(nextOffset);
            }
        }
Get the next expected offset, which might be larger than the last acked
offset if there are inflight batches which have not been acked yet.
Note that when fetching from disk, we may not know the last offset of
inflight data until it has been processed by the state machine. In this case,
we delay sending additional data until the state machine has read to the
end and the last offset is determined.
raft/src/main/java/org/apache/kafka/raft/KafkaRaftClient.java