int attemptsWhenLeaderLastChanged() {
        return attemptsWhenLeaderLastChanged;
    }
Abort the record builder and reset the state of the underlying buffer. This is used prior to aborting
the batch with {@link #abort(RuntimeException)} and ensures that no record previously appended can be
read. This is used in scenarios where we want to ensure a batch ultimately gets aborted, but in which
it is not safe to invoke the completion callbacks (e.g. because we are holding a lock, such as
when aborting batches in {@link RecordAccumulator}).
clients/src/main/java/org/apache/kafka/clients/producer/internals/ProducerBatch.java