-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature - support seek() on Reader #4031
Feature - support seek() on Reader #4031
Conversation
@lovelle It looks good! |
BTW, I don't know if you have considered other test scenarios. I think your test is only calling a seek() to the beginning of a sequence of messages you sent right (i.e. equivalent to I'm asking this because in my test, only |
f333d36
to
80db9aa
Compare
@ConcurrencyPractitioner great suggestion! please take a look now, I've just add more tests according to what you said, please let me know what you think! Thanks 👍 Added test seeks in the middle of the sequence of messages using MessageId and works great ! |
cb61dbe
to
5f157a2
Compare
pulsar-broker/src/test/java/org/apache/pulsar/client/api/TopicReaderTest.java
Outdated
Show resolved
Hide resolved
pulsar-broker/src/test/java/org/apache/pulsar/client/api/TopicReaderTest.java
Outdated
Show resolved
Hide resolved
pulsar-broker/src/test/java/org/apache/pulsar/client/api/TopicReaderTest.java
Outdated
Show resolved
Hide resolved
@Test | ||
public void testReaderIsAbleToSeekWithMessageIdOnMiddleOfTopic() throws Exception { | ||
final String topicName = "persistent://my-property/my-ns/ReaderSeekWithMessageIdOnMiddleOfTopic"; | ||
final int numOfMessage = 100; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you numOfMessage as an argument to this test and try with edge cases like
numOfMessage = [1, 9, 100]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By this you mean having a generic method doing all the asserts and receiving by arguments all the parameters?
* the individual partitions. | ||
* | ||
* @param messageId the message id where to reposition the reader | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't the operation be renamed as reset
instead of seek
. I mean I would assume seek
to just find the message id but not change the state of subscription.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mm I don't agree here, imho keeping seek()
would be easier for the user understanding because of already existing seek on Consumer.
Also, what I think that is great of naming it seek()
is that it behaves exactly the same as seeking on a file e.g. Linux which a lot of people already know what is meant for.
public void flushAndClean() { | ||
flush(); | ||
lastCumulativeAck = (MessageIdImpl) MessageId.earliest; | ||
pendingIndividualAcks.clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't flush empty out pendingIndividualAcks
If yes then I would not create a new function - I would just add lastCumulativeAck = (MessageIdImpl) MessageId.earliest;
to the flush() function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, flush will empty pendingIndividualAcks
but that doesn't mean that when you call flush()
(do the effective redelivery of the message) also wants to lost track of lastCumulativeAck
.
I added flushAndClean()
because here we need to start over again and forget every message tracked, the same as when the constructor occurs.
Sorry, just one last test case. If |
5f157a2
to
0a5ea4c
Compare
Oh, so @lovelle
And this was the test output:
I think seek(long timestamp) in your code is also suffering from the same problems that I am. |
Yes, you are right, reset on ManagedCursorImpl tells moving the cursor to 3:4 position but after this I still receive [3:0..3:9]
I will keep debugging this to see if I find something. 👍 |
0a5ea4c
to
71f10d9
Compare
*Motivation* Trying to fix apache#3976 According to what was discussed in pull apache#3983 it would be an acceptable solution to add seek() command to Reader in order to reset a non durable cursor after Reader instance was build. *Modifications* - Bugfix reset() by timestamp on a non-durable consumer, previously the cached cursor was not present, therefore the state set by reset() was missed resulting in a reset() at the beginning of the cursor instead of a reset() at the expected position. - Copy seek() commands to Reader interface from Consumer interface. - Fix inconsistency with lastDequeuedMessage field after seek() command was performed successfully. - Fix consumer discarding messages on receive (after seek() command) due to messages being present on acknowledge grouping tacker.
- Add functional test to assert seek() with timestamp behaviour from Reader to reach the beginning of the topic. - Add functional test to assert seek() with timestamp behaviour from Reader to reach the middle of the topic. - Add functional test to assert seek() with MessageId behaviour from Reader to reach the middle of the topic.
71f10d9
to
12c8ab9
Compare
@ConcurrencyPractitioner the last mentioned missed test case is now solved and added, please take a look now 👍 @sijie @jai1 this pull is ready to be fully reviewed, thanks!. |
👍 I see now, you made some changes to ManagedLedgerImpl. I could see now why seek(long timestamp) was not working. Nice work! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
run java8 tests |
@jai1 can you please take a look again? |
ping @jai1 |
Motivation
Trying to fix #3976
According to what was discussed in pull #3983 it would be an acceptable solution
to add seek() command to Reader in order to reset a non durable cursor after
Reader instance was built.
Modifications
cached cursor was not present, therefore the state set by reset() was missed
resulting in a reset() at the beginning of the cursor instead of a reset()
at the expected position.
performed successfully.
messages being present on acknowledge grouping tacker.
Verifying this change