Class SharePartition
java.lang.Object
kafka.server.share.SharePartition
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 Summary
Modifier and TypeMethodDescriptionacknowledge(String memberId, List<org.apache.kafka.server.share.acknowledge.ShareAcknowledgementBatch> acknowledgementBatches) Acknowledge the fetched records for the share partition.org.apache.kafka.server.share.fetch.ShareAcquiredRecordsacquire(String memberId, org.apache.kafka.clients.consumer.internals.ShareAcquireMode shareAcquireMode, int batchSize, int maxFetchRecords, long fetchOffset, org.apache.kafka.server.storage.log.FetchPartitionData fetchPartitionData, org.apache.kafka.server.storage.log.FetchIsolation isolationLevel) Acquire the fetched records for the share partition.booleanmaybeAcquireFetchLock(org.apache.kafka.common.Uuid fetchId) Prior to fetching records from the leader, the fetch lock is acquired to ensure that the same share partition is not fetched concurrently by multiple clients.May initialize the share partition by reading the state from the persister.longThe next fetch offset is used to determine the next offset that should be fetched from the leader.releaseAcquiredRecords(String memberId) Release the acquired records for the share partition.
-
Method Details
-
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.
-
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
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.
-
maybeAcquireFetchLock
public boolean maybeAcquireFetchLock(org.apache.kafka.common.Uuid fetchId) Prior to fetching records from the leader, the fetch lock is acquired to ensure that the same share partition is not fetched concurrently by multiple clients. The fetch lock is released once the records are fetched and acquired.- Parameters:
fetchId- - the caller's id that is trying to acquire the fetch lock.- Returns:
- A boolean which indicates whether the fetch lock is acquired.
-