You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 16, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Nov 16, 2026. It is now read-only.
[BUG] Offset in send callback is not continuous when batching is enabled #332
For what I mentioned before, the second bug is easy to fix, but the first bug needs some refactor because it's caused by race condition.
Let
Persist[i] be the time when message i was persisted;
Complete[i] be the time when callback (MessagePublishContext#completed) was invoked.
Assuming there're two messages/records 0 and 1, each record has only 1 message. Then we have
Persist[0] happens before Persist[1], which guarantees the messaging order.
Persist[0] happens before Complete[0].
Persist[1] happens before Complete[1].
So there're two possible timelines (current offset is the offset of latest message, it's LEO - 1 in Kafka):
Event
interceptor's index (current offset)
base offset
Persist[0]
0
Persist[1]
1
Complete[0]
1
1
Complete[1]
1
1
or
Event
interceptor's index (current offset)
base offset
Persist[0]
0
Complete[0]
0
0
Persist[1]
1
Complete[1]
1
1
We can see for the first case, the callback of message 0 retrieves the wrong current offset which belongs to message 1, because the interceptor has already updated twice.
Activity
jiazhai commentedon Jan 19, 2021
this is a little strange, how many entries(batched messages) are there in bk? it would be helpful to get the offset metadata from entry.
BewareMyPower commentedon Jan 19, 2021
It looks like there are two bugs:
PendingProduceQueuehas some problems, when I remove the queue and send synchronously, the offset will be continuous.BewareMyPower commentedon Jan 19, 2021
For what I mentioned before, the second bug is easy to fix, but the first bug needs some refactor because it's caused by race condition.
Let
Persist[i]be the time when messageiwas persisted;Complete[i]be the time when callback (MessagePublishContext#completed) was invoked.Assuming there're two messages/records 0 and 1, each record has only 1 message. Then we have
Persist[0]happens beforePersist[1], which guarantees the messaging order.Persist[0]happens beforeComplete[0].Persist[1]happens beforeComplete[1].So there're two possible timelines (current offset is the offset of latest message, it's
LEO - 1in Kafka):or
We can see for the first case, the callback of message 0 retrieves the wrong current offset which belongs to message 1, because the interceptor has already updated twice.
Fix wrong offset in send callback (#335)
BewareMyPower commentedon Jan 22, 2021
Another fix from pulsar side is WIP, see apache/pulsar#9257
BewareMyPower commentedon Jan 24, 2021
The fix of Kafka client's send callback needs:
BrokerEntryMetadatawell.PublishContext.PublishContext#setMetadataFromEntryDataAPI .BewareMyPower commentedon Apr 13, 2021
The
KafkaRequestHandlerTest#testProduceCallbackis flaky because this task is not completed but was closed accidentally before.From the error log, we can see the first message's offset is 5. It's caused by the race condition I mentioned before.
Use setMetadataFromEntryData API to retrieve offset (#443)