2021-03-26 kafka生产者RecordAccumul

2021-03-26  本文已影响0人  CayChan

RecordAccumulator

This class acts as a queue that accumulates records into MemoryRecords instances to be sent to the server.
The accumulator uses a bounded amount of memory and append calls will block when that memory is exhausted, unless this behavior is explicitly disabled.
累加器,就是kafka的客户端缓存。所有send的ProducerRecord存放在这里,等待发送到远程Broker中。
缓存空间是一定的,缓存满了之后,新的ProducerRecord在send时会被阻塞。

缓存池

image.png

ConcurrentMap实际上是一个自定义的CopyOnWriteMap

/**
 * A callback and the associated FutureRecordMetadata argument to pass to it.
 */
final private static class Thunk {
    final Callback callback;
    //记录了record的相关信息,比如key、value、partition、exception等
    final FutureRecordMetadata future;

    public Thunk(Callback callback, FutureRecordMetadata future) {
        this.callback = callback;
        this.future = future;
    }
}
上一篇 下一篇

猜你喜欢

热点阅读