Class ProducerPoolImpl

  • All Implemented Interfaces:
    AutoCloseable, ProducerPool

    @NotThreadSafe
    @Internal
    public class ProducerPoolImpl
    extends Object
    implements ProducerPool
    Manages a pool of FlinkKafkaInternalProducer instances for reuse in the KafkaWriter and keeps track of the used transactional ids.

    Reusing the producers is important for performance reasons. The producer initialization includes a few requests to the broker (e.g., ApiVersion), which can be avoided with reuse.

    Tracking the transactional ids in use can be a tricky because the KafkaCommitter is ultimately finishing the transactions. There are two major cases:

    • The committer is chained to the writer (common case): The KafkaCommittable contains the producer (in-memory transfer) and the producer is only returned to the producer pool upon completion by the committer. Thus, none of the producers in the pool have active transactions.
    • The committer is not chained: The KafkaCommittableSerializer will return the producer to this pool, but it still has an ongoing transaction. The producer will be "cloned" in the committer by using producer id and epoch. In this case, we rely on ProducerFencedException to test later if a producer in the pool is still in the transaction or not.

    This pool is not thread-safe and is only intended to be accessed from the writer, which owns it.