-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
[#24971] Add a retry policy for JmsIO #24971 #24973
Conversation
Assigning reviewers. If you would like to opt out of this review, comment R: @robertwb for label java. Available commands:
The PR bot will only process comments in the main thread (not review comments). |
just fyi beam has backoff utility classes for retry: EDIT: never mind, I see the implenetation is using FluentBackoff. |
The issue is that JmsIO doesn't retry at all when publishing a message, any message that is failed to publish is pushed to ouput as you can see in JmsIO code: @ProcessElement
public void processElement(ProcessContext ctx) {
Destination destinationToSendTo = destination;
try {
Message message = spec.getValueMapper().apply(ctx.element(), session);
if (spec.getTopicNameMapper() != null) {
destinationToSendTo =
session.createTopic(spec.getTopicNameMapper().apply(ctx.element()));
}
producer.send(destinationToSendTo, message);
} catch (Exception ex) {
LOG.error("Error sending message on topic {}", destinationToSendTo);
ctx.output(failedMessageTag, ctx.element());
}
} If there are any exceptions, they will be catched and the message is pushed to failed message tag's output. Which means we will need to get the failed messages and retry by ourselves N times like this: public PDone expand(PCollection<Message> messages) {
// Retry 3 times when the session is closed
messages.apply(getJmsWriter(sinkOptions))
.getFailedMessages()
.apply(REPUBLISH_FAILED_MESSAGE_NAME, getJmsWriter(sinkOptions))
.getFailedMessages()
.apply(REPUBLISH_FAILED_MESSAGE_NAME, getJmsWriter(sinkOptions))
.getFailedMessages()
.apply(REPUBLISH_FAILED_MESSAGE_NAME, getJmsWriter(sinkOptions));
return PDone.in(messages.getPipeline());
}
private static JmsIO.Write<Message> getJmsWriter(SinkOptions sinkOptions) {
return JmsIO.<Message>write()
.withConnectionFactory(SinkOptions.getConnectionFactory())
.withValueMapper(getValueMapper())
.withTopicNameMapper(getTopicNameMapper());
} When the session is closed and the first PTransform that is publishing the message is displaying error logs
|
sdks/java/io/jms/src/main/java/org/apache/beam/sdk/io/jms/JmsIOProducer.java
Outdated
Show resolved
Hide resolved
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.
Thanks for the change! I see what has caused the issue, and commented above that there are changes still needed in order to fix it. Please let me know if it is not clear to you or if there is any questions.
sdks/java/io/jms/src/main/java/org/apache/beam/sdk/io/jms/JmsIO.java
Outdated
Show resolved
Hide resolved
sdks/java/io/jms/src/main/java/org/apache/beam/sdk/io/jms/JmsIO.java
Outdated
Show resolved
Hide resolved
sdks/java/io/jms/src/test/java/org/apache/beam/sdk/io/jms/FakeConnection.java
Outdated
Show resolved
Hide resolved
Reminder, please take a look at this pr: @robertwb @johnjcasey |
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.
Thanks for the change. got a couple of comments should be easy to resolve. Thanks for your patience.
sdks/java/io/jms/src/main/java/org/apache/beam/sdk/io/jms/JmsIO.java
Outdated
Show resolved
Hide resolved
sdks/java/io/jms/src/main/java/org/apache/beam/sdk/io/jms/JmsIO.java
Outdated
Show resolved
Hide resolved
sdks/java/io/jms/src/main/java/org/apache/beam/sdk/io/jms/JmsIO.java
Outdated
Show resolved
Hide resolved
sdks/java/io/jms/src/main/java/org/apache/beam/sdk/io/jms/JmsIO.java
Outdated
Show resolved
Hide resolved
Add a retry policy to publish messages in case of connection closed Fixes#24971 Co-Authored-By: Amrane Ait Zeouay <[email protected]>
Fixes #24971 Co-Authored-By: Amrane Ait Zeouay <[email protected]>
…w exceptions #24973 Fixes #24971 Co-Authored-By: Amrane Ait Zeouay <[email protected]>
Hello @Abacn, Sorry I was busy with work. I redesigned the flow of
|
Fixes #24971 Co-Authored-By: Amrane Ait Zeouay <[email protected]>
Assigning new set of reviewers because Pr has gone too long without review. If you would like to opt out of this review, comment R: @apilloud for label java. Available commands:
|
R: @Abacn |
Sorry for the delay. Will take another look tomorrow. |
Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control |
Fixes #24971 Co-Authored-By: Amrane Ait Zeouay <[email protected]>
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.
Thanks, it's getting close. Found a bug and a design suggestion here.
sdks/java/io/jms/src/main/java/org/apache/beam/sdk/io/jms/JmsIO.java
Outdated
Show resolved
Hide resolved
sdks/java/io/jms/src/main/java/org/apache/beam/sdk/io/jms/JmsIO.java
Outdated
Show resolved
Hide resolved
Fixes #24971 Co-Authored-By: Amrane Ait Zeouay <[email protected]>
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.
Thanks. This LGTM.
nit: the added back-off unit tests take a while to complete. In the case of test may use a mocked sleeper
I will improve the test with the new API calls. |
@Abacn can you please merge the PR, I don't have access to merge it :( ? |
Add a retry policy to publish messages in case of connection closed
Fixes #24971
Co-Authored-By: Amrane Ait Zeouay [email protected]
When trying to publish messages using
JmsIO
with a closed/failed connection, the messages are not published and lost. We will need to get the failed messages with the functiongetFailedMessages
and try again and again multiple times.To not have multiple steps for retrying the failed publication, we added a
Retry Policy
which consist on retrying the publication n times (the number is given by the user) until the timeout (given by the user too) is finished. Also, we added a predicate function, to give the user the option to handle when the connection should be reconnected or not in case of a failed connection.Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123
), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>
instead.CHANGES.md
with noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI.