Skip to content

Conversation

@merlimat
Copy link
Contributor

Motivation

Previous merge of #165 at cd2d16e had minor conflicts with other PRs that were merged in between.

@merlimat merlimat added this to the 1.17 milestone Feb 26, 2017
@agarman
Copy link

agarman commented Feb 26, 2017

I was just opening an issue too. :-)

@rdhabalia rdhabalia merged commit 9fde15b into apache:master Feb 26, 2017
sijie added a commit to sijie/pulsar that referenced this pull request Mar 4, 2018
hangc0276 pushed a commit to hangc0276/pulsar that referenced this pull request May 26, 2021
Fixes apache#247

The original implementation of message publishing cannot guarantee that a topic partition's pending writes are completed in order. This PR is to fix the issue by refactoring the handler for Produce requests.

The basic steps of handling a single partition's produce request are:

Get PersistentTopic from topic manager;
Convert Kafka's MemoryRecords to Pulsar's ByteBuf;
Call PersistentTopic#publishMessages to write ByteBuf to BK asynchronously.
This PR adds a PendingProduce class to compose pending step 1 and 2 to a CompletableFuture, then add the PendingProduce object to a queue (PendingProduceQueue) which is associated with the partition name in a map named pendingProduceQueueMap. When the step 1 and 2 are completed, the queue will try to remove all ready PendingProduce objects in the head and call PersistentTopic#publishMessages. We use synchronized keyword to make the remove operation thread safe.

Therefore, the first two steps can be executed in parallel, but the third step is executed in order.

In addition, this PR fixes the current message order test by using different batch size. In the original test, all messages are batched to a single batch, so the disorder never happens because there's only one batch.


* Refactor handleProduceRequest to fix message disorder issue

* Fix existed message order test

* Synchronize PendingProduce#publishMessages

* Test message order with different batch.size config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants