Jason918 opened a new issue #12234:
URL: https://github.com/apache/pulsar/issues/12234


   ## Motivation
   
   Currently we can reset the read position of a cursor by message id or 
timestamp. Since we formerly introduced index in broker metadata since 2.8.0, 
reset cursor by index is very helpful in other protocol handler (KoP or RoP).
   
   ## Goal
   
   Add seek by index feature for consumer.
   
   ## API Changes
   
   Add following interface in `org.apache.pulsar.client.api.Consumer`
   - void seekByIndex(long index)
   - CompletableFuture<Void> seekByIndexAsync(long index);
   
   Here is the docs for this new interface.
   Reset the subscription associated with this consumer to a specific message 
index.
   For example, giving the index of message in this topic is in range [A, B), 
where A <= B;
   - if seekByIndex(X), where X in range [A,B), message with index a is the 
next message consumer will receive.
   - if seekByIndex(X), where X < A, it's the same as 
Consumer#seek(MessageId.earliest). Reset the subscription on the earliest 
message available in the topic. 
   - if seekByIndex(X), where X >= B, it's the same as 
Consumer#seek(MessageId.latest). Reset the subscription on the latest message 
in the topic.
   
   Note: "org.apache.pulsar.common.intercept.AppendIndexMetadataInterceptor" 
must be added to "brokerEntryMetadataInterceptors" in broker configuration to 
enable index meta in broker.
   
   ## Implementation
   
   For client-broker communication, we can reuse the old CommandSeek, which is 
used for `seek(messageId)` and `seek(timestamp)`. Add an optional field "index" 
for this interface.
   
   In broker, the implementation for seek by index is basically the same as 
seek by timestamp. The key is to find the messageId with the giving index. A 
new class  PersistentMessageFinderByIndex is introduced to do this. The 
difference between PersistentMessageFinderByIndex and origin 
PersistentMessageFinder is that, PersistentMessageFinderByIndex use 
BrokerEntryMetadata#index of the searching message instead of 
BrokerEntryMetadata#brokerTimestamp. Once we find the messageId, we can reset 
the subscription with `PersistentSubscription#resetCursor`.
   
   ## Reject Alternatives
   
   No alternatives yet.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to