-
Notifications
You must be signed in to change notification settings - Fork 336
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
[Fix][producer] Fail all messages that are pending requests when closing like java #1059
Conversation
e193c86
to
dbf81be
Compare
Hi @graysonzeng. I think dataChan should be cleared in the I submit a fix PR in #1058 and I think |
I think that will be better, I think we can update this PR after @Gleiphir2769's PR is merged. @graysonzeng |
I agree. I will update this PR if #1058 is merged |
Hi @graysonzeng #1058 has been merged. |
update completed @RobertIndie |
Seems that in the Java client, the producer will fail all messages that are in the pending queue when closing: cnx.sendRequestWithId(cmd, requestId).handle((v, exception) -> {
cnx.removeProducer(producerId);
if (exception == null || !cnx.ctx().channel().isActive()) {
// Either we've received the success response for the close producer command from the broker, or the
// connection did break in the meantime. In any case, the producer is gone.
log.info("[{}] [{}] Closed Producer", topic, producerName);
closeAndClearPendingMessages(); // <- we call failPendingMessages in closeAndClearPendingMessages
closeFuture.complete(null);
} else {
closeFuture.completeExceptionally(exception);
}
return null;
}); |
From the user's perspective, I would like to have the submitted data sent out as much as possible when closing the client. The cost is I have to wait until timeout. And, when the user decide to close the client, as a producer, I think we would like to wait rather than handling the failed messages manually after the client is closed. |
The user can call the |
Hmm, this implies that users must call flush() before closing, and if they do so but still have unsent data, it looks like that the flush() implementation is not perfect. On the other hand, if users don't call flush(), they will have to bear the consequences themselves, in this case, it seems better to encapsulate flush() in close() to reduce the burden on users. It seems a bit contradictory. And, as a user, when it reach the time to call close(), I won't care about the results of the async callback of the failed requests, unless the close() returns the failed requests to me as the return value, in this case, it seems failing the pending reqeusts is of little meaning. |
In kafka. When the user actively closes, the waiting time can be specified until all messages in the queue are cleared. In pulsar-go, i think it is a good choice to use flush to send the pending data in the queue before closing。 If you think it's better to let the message fail directly. i can change it @RobertIndie |
The flush should guarantee that messages which are at least pushed into the data chan should be flushed to the broker. And that's the issue @Gleiphir2769 has fixed:#1057.
Yes. That's right. The user can choose to fail or flush the messages. IMO, the close should have only one responsibility: just close and release all the resources of the producer. |
OK. But I think we should think about the concerns aboved for the users, return the failed requests to the users rather than just calling the async callbacks, so that they can decide what to do to these failed requests. |
@gunli Thanks. You're right. I have created an issue to track this improvement: #1063 |
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.
We should fail the pending requests in the pending queue in the producer instead of the connection. Just like failTimeoutMessages
did:
pulsar-client-go/pulsar/producer_partition.go
Line 895 in e45122c
func (p *partitionProducer) failTimeoutMessages() { |
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.
Overall looks good to me. Could you add a test?
…ternalClose() was called
HI @RobertIndie . How can I stably make some messages that exist in pendQueue ? |
You can create a producer with relative large BatchingMaxPublishDelay and BatchingMaxMessages so that messages could stay in the pending queue stably. |
PTAL @RobertIndie |
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.
Thank you!
Fixes #1042 , link #1057
Motivation
producer not fail all messages that are in the pending queue when closing
Modifications
add
failPendingMessages()
to fail the pending requests when closing producerDoes this pull request potentially affect one of the following parts:
If
yes
was chosen, please highlight the changes