-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-8635: Skip client poll in Sender loop when no request is sent #7085
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
ddd2d3f
2da11bc
0cd3376
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -302,12 +302,22 @@ void runOnce() { | |
| transactionManager.transitionToFatalError( | ||
| new KafkaException("The client hasn't received acknowledgment for " + | ||
| "some previously sent messages and can no longer retry them. It isn't safe to continue.")); | ||
| } else if (transactionManager.hasInFlightTransactionalRequest() || maybeSendTransactionalRequest()) { | ||
| } else if (transactionManager.hasInFlightTransactionalRequest()) { | ||
| // as long as there are outstanding transactional requests, we simply wait for them to return | ||
| client.poll(retryBackoffMs, time.milliseconds()); | ||
| return; | ||
| } | ||
|
|
||
| maybeBeginFlush(); | ||
| TransactionManager.TxnRequestHandler nextRequestHandler = transactionManager.nextRequestHandler(accumulator.hasIncomplete()); | ||
| if (nextRequestHandler != null) { | ||
| if (maybeSendTransactionalRequest(nextRequestHandler)) { | ||
| client.poll(retryBackoffMs, time.milliseconds()); | ||
| } | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| // do not continue sending if the transaction manager is in a failed state or if there | ||
| // is no producer id (for the idempotent case). | ||
| if (transactionManager.hasFatalError() || !transactionManager.hasProducerId()) { | ||
|
|
@@ -412,7 +422,7 @@ private long sendProducerData(long now) { | |
| return pollTimeout; | ||
| } | ||
|
|
||
| private boolean maybeSendTransactionalRequest() { | ||
| private void maybeBeginFlush() { | ||
| if (transactionManager.isCompleting() && accumulator.hasIncomplete()) { | ||
| if (transactionManager.isAborting()) | ||
| accumulator.abortUndrainedBatches(new KafkaException("Failing batch since transaction was aborted")); | ||
|
|
@@ -423,11 +433,12 @@ private boolean maybeSendTransactionalRequest() { | |
| if (!accumulator.flushInProgress()) | ||
| accumulator.beginFlush(); | ||
| } | ||
| } | ||
|
|
||
| TransactionManager.TxnRequestHandler nextRequestHandler = transactionManager.nextRequestHandler(accumulator.hasIncomplete()); | ||
| if (nextRequestHandler == null) | ||
| return false; | ||
|
|
||
| /** | ||
| * Enqueue a FindCoordinatorRequest if needed, otherwise send the next request | ||
| */ | ||
| private boolean maybeSendTransactionalRequest(TransactionManager.TxnRequestHandler nextRequestHandler) { | ||
| AbstractRequest.Builder<?> requestBuilder = nextRequestHandler.requestBuilder(); | ||
| while (!forceClose) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not necessarily something we have to do here, but I think we should be able to get rid of this loop and just rely on the next iteration of |
||
| Node targetNode = null; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor simplification we can do below: if (targetNode == null || !awaitReady(client, targetNode, time, requestTimeoutMs)) {
transactionManager.lookupCoordinator(nextRequestHandler);
break;
}
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A helper for |
||
|
|
@@ -470,7 +481,7 @@ private boolean maybeSendTransactionalRequest() { | |
| metadata.requestUpdate(); | ||
| } | ||
| transactionManager.retry(nextRequestHandler); | ||
| return true; | ||
| return false; | ||
| } | ||
|
|
||
| private void maybeAbortBatches(RuntimeException exception) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is a bit awkward. I guess it's because
client.pollis disconnected from the send logic. I wonder if it would be reasonable to create a method likemaybePollTransactionalRequestwhich handles both the inflight check, sending the next request, and callingclient.pollif necessary.