gaoran10 opened a new pull request #14870:
URL: https://github.com/apache/pulsar/pull/14870
Fixes #14864
### Motivation
If the producer enables batch, the message will add to the batch container
first, when the broker state is not `ready`, there is no subsequent logic to
send messages in the batch container.
Before PR #14185 there is a timer task to call the method
`batchMessageContainer` to send messages in the batch container. The PR #14185
optimize batch flush logic, remove the timer task, add a scheduled task after
adding messages.
**Some Codes**
Code block in method `serializeAndSendMessage`
```
boolean isBatchFull = batchMessageContainer.add(msg, callback);
lastSendFuture = callback.getFuture();
payload.release();
if (isBatchFull) {
batchMessageAndSend(false);
} else {
maybeScheduleBatchFlushTask();
}
```
If the producer state is not ready, the batch flush task will not be
scheduled.
```
private void maybeScheduleBatchFlushTask() {
if (this.batchFlushTask != null || getState() != State.Ready) {
log.info("xxxx [{}] MaybeScheduleBatchFlushTask state: {}", topic,
getState());
return;
}
scheduleBatchFlushTask(conf.getBatchingMaxPublishDelayMicros());
}
```
### Modifications
Call method `batchMessageAndSend` to make sure messages in the batch
container execute send process after producer re-connect.
### Verifying this change
Add new unit test.
### Does this pull request potentially affect one of the following parts:
*If `yes` was chosen, please highlight the changes*
- Dependencies (does it add or upgrade a dependency): (no)
- The public API: (no)
- The schema: (no)
- The default values of configurations: (no)
- The wire protocol: (no)
- The rest endpoints: (no)
- The admin cli options: (no)
- Anything that affects deployment: (no)
### Documentation
Check the box below or label this PR directly (if you have committer
privilege).
Need to update docs?
- [ ] `doc-required`
(If you need help on updating docs, create a doc issue)
- [x] `no-need-doc`
(Please explain why)
- [ ] `doc`
(If this PR contains doc changes)
--
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]