Skip to main content

producer_decision

Function producer_decision 

Source
pub fn producer_decision(
    entry: Option<ProducerEntryFacts>,
    retained: &[Option<RetainedSequenceRange>],
    producer_epoch: i16,
    base_sequence: i32,
    last_offset_delta: i32,
    log_empty: bool,
    trunk_rules: bool,
) -> ProducerDecision
Expand description

Classify an incoming batch against a producer’s tracked entry and the sequence ranges of the batches it retains.

This is Kafka’s UnifiedLog.analyzeAndValidateProducerState for a client append. It first looks the batch up among the retained batches (ProducerStateEntry.findDuplicateBatch): at the entry’s epoch, a batch whose base sequence and last sequence (base_sequence + last_offset_delta modulo 2^31) equal a retained batch’s is a duplicate of the first such batch. None slots never match. Only a batch that repeats no retained batch goes on to ProducerAppendInfo.checkProducerEpoch and checkSequence:

  • a producer with no entry can start at any sequence, except that under trunk_rules it must start at sequence 0 on a partition whose log is empty (log_empty) and is otherwise out of order;
  • a lower epoch is fenced;
  • a higher epoch must start at sequence 0 and is otherwise out of order;
  • the same epoch must continue at the last sequence plus one modulo 2^31 and is otherwise out of order.

The empty-log rule is Kafka trunk’s (KAFKA-15591, in ProducerAppendInfo.checkSequence); Kafka 4.3.1 does not have it. log_empty is Kafka’s ProducerStateManager.mapEndOffset() == 0: no record has ever been appended to the partition, so no producer state can have been lost, and trunk_rules says whether the host serves Kafka trunk’s behaviour.

The host supplies the retained batches at the entry’s epoch; a batch at any other epoch never matches them.