Class SharePartition

java.lang.Object
kafka.server.share.SharePartition

public class SharePartition extends Object
The SharePartition is used to track the state of a partition that is shared between multiple consumers. The class maintains the state of the records that have been fetched from the leader and are in-flight.
  • Method Details

    • maybeInitialize

      public CompletableFuture<Void> maybeInitialize()
      May initialize the share partition by reading the state from the persister. The share partition is initialized only if the state is in the EMPTY state. If the share partition is in ACTIVE state, the method completes the future successfully. For other states, the method completes the future with exception, which might be re-triable.
      Returns:
      The method returns a future which is completed when the share partition is initialized or completes with an exception if the share partition is in non-initializable state.
    • nextFetchOffset

      public long nextFetchOffset()
      The next fetch offset is used to determine the next offset that should be fetched from the leader. The offset should be the next offset after the last fetched batch but there could be batches/ offsets that are either released by acknowledge API or lock timed out hence the next fetch offset might be different from the last batch next offset. Hence, method checks if the next fetch offset should be recomputed else returns the last computed next fetch offset.
      Returns:
      The next fetch offset that should be fetched from the leader.
    • acquire

      public org.apache.kafka.server.share.fetch.ShareAcquiredRecords acquire(String memberId, int maxFetchRecords, org.apache.kafka.server.storage.log.FetchPartitionData fetchPartitionData)
      Acquire the fetched records for the share partition. The acquired records are added to the in-flight records and the next fetch offset is updated to the next offset that should be fetched from the leader.
      Parameters:
      memberId - The member id of the client that is fetching the record.
      maxFetchRecords - The maximum number of records that should be acquired, this is a soft limit and the method might acquire more records than the maxFetchRecords, if the records are already part of the same fetch batch.
      fetchPartitionData - The fetched records for the share partition.
      Returns:
      The acquired records for the share partition.
    • acknowledge

      public CompletableFuture<Void> acknowledge(String memberId, List<org.apache.kafka.server.share.acknowledge.ShareAcknowledgementBatch> acknowledgementBatches)
      Acknowledge the fetched records for the share partition. The accepted batches are removed from the in-flight records once persisted. The next fetch offset is updated to the next offset that should be fetched from the leader, if required.
      Parameters:
      memberId - The member id of the client that is fetching the record.
      acknowledgementBatches - The acknowledgement batch list for the share partition.
      Returns:
      A future which is completed when the records are acknowledged.
    • releaseAcquiredRecords

      public CompletableFuture<Void> releaseAcquiredRecords(String memberId)
      Release the acquired records for the share partition. The next fetch offset is updated to the next offset that should be fetched from the leader.
      Parameters:
      memberId - The member id of the client whose records shall be released.
      Returns:
      A future which is completed when the records are released.