public void maybeUpdateNextBatchExpiryTime(ProducerBatch batch) {
        if (batch.createdMs + deliveryTimeoutMs  > 0) {
            // the non-negative check is to guard us against potential overflow due to setting
            // a large value for deliveryTimeoutMs
            nextBatchExpiryTimeMs = Math.min(nextBatchExpiryTimeMs, batch.createdMs + deliveryTimeoutMs);
        } else {
            log.warn("Skipping next batch expiry time update due to addition overflow: "
                + "batch.createMs={}, deliveryTimeoutMs={}", batch.createdMs, deliveryTimeoutMs);
        }
    }
Try to append to a ProducerBatch.

 If it is full, we return null and a new batch is created. We also close the batch for record appends to free up
 resources like compression buffers. The batch will be fully closed (ie. the record batch headers will be written
 and memory records built) in one of the following cases (whichever comes first): right before send,
 if it is expired, or when the producer is closed.
clients/src/main/java/org/apache/kafka/clients/producer/internals/RecordAccumulator.java