PIP-210: Retry producing on next partition if possible when a partition is not available
- Dominant language
- Java
- Stars
- 15.3k
- Forks
- 3.8k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 160
Description
### Motivation
When a topic is a partitioned topic and a partition is not available for producing messages, currently pulsar client will still try to produce messages on unavailable partitions, which it may not necessarily need to do in certain cases. Pulsar Client may simply pick up another partition and try producing in certain cases.
Partition Unavailable
There could be a plethora of reasons a partition can become unavailable. But the most prominent reason is partition is moving from one broker to another, and until every actor is in sync with which broker owns the partition, the partition will be unavailable for producing. Actors are producers, old broker, new broker.
### Goal
Produce uninterrupted as long as possible when a partition is down.
### API Changes
pulsar-client-api/src/main/java/org/apache/pulsar/client/api/ProducerBuilder.java
/**
* This config will ensure that If possible PartitionedProducer would attempt to produce message on
* another available partitions, If currently picked partition is not available for some reason.
* Next available partition will be chosen by the same routing policy as client is configured with.
* @param maxRetryOtherPartition
* How many partitions should be tried before bailing out
* @return the producer builder instance
*/
ProducerBuilder maxRetryOtherPartitions(int maxRetryOtherPartition);
### Implementation
**Client Behavior**
This is the typical produce code.
producer.sendAsync(payLoad.getBytes(StandardCharsets.UTF_8));
When send is called message is enqueued in a queue(called pending message queue) and the future is returned.
And future is only completed when the message is picked from the queue and sent to the broker asynchronously and ack is received asynchronously again. Max size of the pending message queue is controlled by producer config maxPendingMessages.
When pending message queue is full, the application will start getting publish failures. Pending message queue provide a cushion towards unavailable partitions. But again it has some limits.
**When another partitions can be picked**
When the message is not keyed. That means the message is not ordered based on a key.
When routing mode is round-robin, that means a message can be produced to any of the partitions. So If a partition is unavailable try and pick up another partition for producing, by using the same round-robin algorithm.
### Alternatives
_No response_
### Anything else?
My suggestion is to keep Router(RoundRobin) not dependent on whether a partition is available or not. Or batching is enabled or publish is happening under transaction.
Contributor guide
Research direction
Start with the maxRetryOtherPartitions API proposal in pulsar-client-api/src/main/java/org/apache/pulsar/client/api/ProducerBuilder.java, then trace the partitioned producer send path and round-robin routing behavior. Check how non-keyed messages and unavailable partitions are handled, including batching and transactions. Done means eligible sends retry available partitions according to the configured limit while preserving the stated routing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend-api-design, distributed-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100