Class PendingAcksMap

java.lang.Object
org.apache.pulsar.broker.service.PendingAcksMap

public class PendingAcksMap extends Object
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 Classes
    Modifier and Type
    Class
    Description
    static interface 
    Callback interface for handling the addition of pending acknowledgments.
    static interface 
    Callback interface for processing pending acknowledgments.
    static interface 
    Callback interface for handling the removal of pending acknowledgments.
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    boolean
    contains(long ledgerId, long entryId)
    Check if the map contains a pending ack for the given ledger ID and entry ID.
    void
    Iterate over all the pending acks and process them using the given processor.
    void
    Iterate over all the pending acks and close the map so that no more entries can be added.
    it.unimi.dsi.fastutil.ints.IntIntPair
    get(long ledgerId, long entryId)
    Get the pending ack for the given ledger ID and entry ID.
    boolean
    remove(long ledgerId, long entryId)
    Remove the pending ack for the given ledger ID and entry ID.
    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.
    void
    removeAllUpTo(long markDeleteLedgerId, long markDeleteEntryId)
    Remove all pending acks up to the given ledger ID and entry ID.
    long
    Get the size of the pending acks map.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 ID
      entryId - the entry ID
      batchSize - the batch size
      stickyKeyHash - 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

      public void forEach(PendingAcksMap.PendingAcksConsumer processor)
      Iterate over all the pending acks and process them using the given processor.
      Parameters:
      processor - the processor to handle each pending ack
    • forEachAndClose

      public void forEachAndClose(PendingAcksMap.PendingAcksConsumer processor)
      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 ID
      entryId - 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 ID
      entryId - 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 ID
      entryId - the entry ID
      batchSize - the batch size
      stickyKeyHash - 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 ID
      entryId - 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 acks
      markDeleteEntryId - the entry ID up to which to remove pending acks