shibd commented on PR #17318:
URL: https://github.com/apache/pulsar/pull/17318#issuecomment-1251213167
> It looks like a race condition here. Is it possible to introduce a lock or
use the same thread for messageReceived and redeliverUnacknowledgedMessages to
resolve the issue?
Seem cannot judge the consumer epoch before offer to the incoming queue.
Because, when the incoming queue has messages and the user invoke
`redeliverUnacknowledgedMessages` at this time, these invalid epoch message
also will return to the user.
It looks like the consumer epoch should be judged before returning the
message to the user.
However, even so, in extreme cases, we cannot avoid the problem described
below.
> @codelipenghui because, if check the epoch before polling the message from
the receiver queue, the user invoke redeliverUnacknowledgedMessages and the
client checks the message epoch at the same time, the invalid epoch also can
offer to the queue. user also can receive the smaller epoch message
Because the user may call the `receive` and
`redeliverUnacknowledgedMessages` methods from multiple threads, in this case,
user still may be receive old epoch messages. (TIP: this is not a good user
example, but it may exist)
```java
while(true) {
msg = consumer.receive();
// This message may be of an invalid epoch.
if(needCummtiveAck) {
try {
consumer.cummtiveAck(msg);
} catch() {
new Thread(() - > {consumer.redeliverUnacknowledgedMessages}).start;
}
}
}
```
--
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]