public void abort(RuntimeException exception) {
        if (!finalState.compareAndSet(null, FinalState.ABORTED))
            throw new IllegalStateException("Batch has already been completed in final state " + finalState.get());

        log.trace("Aborting batch for partition {}", topicPartition, exception);
        completeFutureAndFireCallbacks(ProduceResponse.INVALID_OFFSET, RecordBatch.NO_TIMESTAMP, index -> exception);
    }
Abort the batch and complete the future and callbacks.

@param exception The exception to use to complete the future and awaiting callbacks.
clients/src/main/java/org/apache/kafka/clients/producer/internals/ProducerBatch.java