public final class BufferingPartitionDataBuilder extends Object
Used to consume incoming PushReplicationEvent
s for a given partition replica and
(eventually) to build a AppendRecordsRequestData.PartitionData
out of them. The partition data created this way
can then be sent with an AppendRecords request. When an incoming event can not be consumed,
the builder is expected to be used to build a AppendRecordsRequestData.PartitionData
to be sent, after which a
new builder should be created for the subsequent events for that partition replica.
In case of multiple PushReplicationEvent.Type.MEMORY_RECORDS
events, the buffered memory records can be
sent efficiently using a custom MultiBufferRecords
type. The records buffered for these
types of events can also be limited by the total memory consumed by them.
This class is not thread-safe. It expects that the same thread will be initializing it, sending push replication events to it, and building a partition data out of it.
Modifier and Type | Class and Description |
---|---|
static class |
BufferingPartitionDataBuilder.MultiMemoryRecords
A
MultiBufferRecords that can send the buffers of multiple memory records in a
single org.apache.kafka.common.network.Send . |
Modifier and Type | Method and Description |
---|---|
boolean |
addHighWatermarkUpdate(PushSession pushSession,
long highWatermark)
Updates the high watermark if the push session matches the initial push session
and the new high watermark has a higher value
|
boolean |
addLogStartOffsetUpdate(PushSession pushSession,
long logStartOffset)
Updates the log start offset if the push session matches the initial push session
and the new log start offset has a higher value
|
boolean |
addMemoryRecords(PushSession pushSession,
org.apache.kafka.common.record.MemoryRecords memoryRecords,
long appendOffset)
Enqueues a new set of memory records to the request if the push session matches the initial push session
and the size of the memory records doesn't bump the total bytes counter of the builder over its limit and
potentially update the high watermark of the builder.
|
List<org.apache.kafka.common.record.AbstractRecords> |
stopPushAndDiscardState(boolean sendEndSessionRequest)
Stops a push session for this partition replica.
|
public List<org.apache.kafka.common.record.AbstractRecords> stopPushAndDiscardState(boolean sendEndSessionRequest)
Stops a push session for this partition replica.
Whenever such an event is received, the builder will discard the data it has buffered, it will reset its internal state, and if sending an endSessionRequest is necessary it will mark that it has received such an event so that additional partition updates cannot be consumed. If sending an endSessionRequest isn't necessary, the caller is responsible for removing the partition data builder.
If such an event has already been consumed before, the builder will take care to update its internal state so that it doesn't omit sending a request to the follower to notify it about the ending of the replication session if any of the consumed events had required that.
public boolean addHighWatermarkUpdate(PushSession pushSession, long highWatermark)
public boolean addLogStartOffsetUpdate(PushSession pushSession, long logStartOffset)
public boolean addMemoryRecords(PushSession pushSession, org.apache.kafka.common.record.MemoryRecords memoryRecords, long appendOffset)