Package org.apache.pulsar.broker.service
Class PendingAcksMap
java.lang.Object
org.apache.pulsar.broker.service.PendingAcksMap
A thread-safe map to store pending acks in the consumer.
The locking solution is used for the draining hashes solution
to ensure that there's a consistent view of the pending acks. This is needed in the DrainingHashesTracker
to ensure that the reference counts are consistent at all times.
Calling forEachAndClose will ensure that no more entries can be added,
therefore no other thread cannot send out entries while the forEachAndClose is being called.
remove is also locked to ensure that there aren't races in the removal of entries while forEachAndClose is
running.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCallback interface for handling the addition of pending acknowledgments.static interfaceCallback interface for processing pending acknowledgments.static interfaceCallback interface for handling the removal of pending acknowledgments. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddPendingAckIfAllowed(long ledgerId, long entryId, int batchSize, int stickyKeyHash) Add a pending ack to the map if it's allowed to send a message with the given sticky key hash.booleancontains(long ledgerId, long entryId) Check if the map contains a pending ack for the given ledger ID and entry ID.voidforEach(PendingAcksMap.PendingAcksConsumer processor) Iterate over all the pending acks and process them using the given processor.voidIterate over all the pending acks and close the map so that no more entries can be added.it.unimi.dsi.fastutil.ints.IntIntPairget(long ledgerId, long entryId) Get the pending ack for the given ledger ID and entry ID.booleanremove(long ledgerId, long entryId) Remove the pending ack for the given ledger ID and entry ID.booleanremove(long ledgerId, long entryId, int batchSize, int stickyKeyHash) Remove the pending ack for the given ledger ID, entry ID, batch size, and sticky key hash.voidremoveAllUpTo(long markDeleteLedgerId, long markDeleteEntryId) Remove all pending acks up to the given ledger ID and entry ID.longsize()Get the size of the pending acks map.
-
Method Details
-
addPendingAckIfAllowed
public boolean addPendingAckIfAllowed(long ledgerId, long entryId, int batchSize, int stickyKeyHash) Add a pending ack to the map if it's allowed to send a message with the given sticky key hash. If this method returns false, it means that the pending ack was not added, and it's not allowed to send a message. In that case, the caller should not send a message and skip the entry. The sending could be disallowed if the sticky key hash is blocked in the Key_Shared subscription.- Parameters:
ledgerId- the ledger IDentryId- the entry IDbatchSize- the batch sizestickyKeyHash- the sticky key hash- Returns:
- true if the pending ack was added, and it's allowed to send a message, false otherwise
-
size
public long size()Get the size of the pending acks map.- Returns:
- the size of the pending acks map
-
forEach
Iterate over all the pending acks and process them using the given processor.- Parameters:
processor- the processor to handle each pending ack
-
forEachAndClose
Iterate over all the pending acks and close the map so that no more entries can be added. All entries are removed.- Parameters:
processor- the processor to handle each pending ack
-
contains
public boolean contains(long ledgerId, long entryId) Check if the map contains a pending ack for the given ledger ID and entry ID.- Parameters:
ledgerId- the ledger IDentryId- the entry ID- Returns:
- true if the map contains the pending ack, false otherwise
-
get
public it.unimi.dsi.fastutil.ints.IntIntPair get(long ledgerId, long entryId) Get the pending ack for the given ledger ID and entry ID.- Parameters:
ledgerId- the ledger IDentryId- the entry ID- Returns:
- the pending ack, or null if not found
-
remove
public boolean remove(long ledgerId, long entryId, int batchSize, int stickyKeyHash) Remove the pending ack for the given ledger ID, entry ID, batch size, and sticky key hash.- Parameters:
ledgerId- the ledger IDentryId- the entry IDbatchSize- the batch sizestickyKeyHash- the sticky key hash- Returns:
- true if the pending ack was removed, false otherwise
-
remove
public boolean remove(long ledgerId, long entryId) Remove the pending ack for the given ledger ID and entry ID.- Parameters:
ledgerId- the ledger IDentryId- the entry ID- Returns:
- true if the pending ack was removed, false otherwise
-
removeAllUpTo
public void removeAllUpTo(long markDeleteLedgerId, long markDeleteEntryId) Remove all pending acks up to the given ledger ID and entry ID.- Parameters:
markDeleteLedgerId- the ledger ID up to which to remove pending acksmarkDeleteEntryId- the entry ID up to which to remove pending acks
-