private void clearProducerIds() {
        producers.clear();
        producerIdCount = 0;
    }
This method checks whether there is a late transaction in a thread safe manner.
storage/src/main/java/org/apache/kafka/storage/internals/log/ProducerStateManager.java