Skip to content
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

Add top-level error labels to write concern error #766

Merged
merged 3 commits into from Jul 27, 2021

Conversation

jyemin
Copy link
Contributor

@jyemin jyemin commented Jul 26, 2021

This will allow the driver to properly retry writes that the server
has labeled as a RetryableWriteError.

JAVA-4244

This will allow the driver to properly retry writes that the server
has labeled as a RetryableWriteError.

JAVA-4244
@jyemin jyemin self-assigned this Jul 26, 2021
@jyemin jyemin requested a review from rozza July 26, 2021 18:35
@jyemin jyemin marked this pull request as draft July 26, 2021 18:55
@@ -264,7 +265,9 @@ public static MongoException createSpecialException(final BsonDocument response,
} else if (isNotPrimaryError(errorCode, errorMessage)) {
return new MongoNotPrimaryException(response, serverAddress);
} else if (response.containsKey("writeConcernError")) {
return createSpecialException(response.getDocument("writeConcernError"), serverAddress, "errmsg");
return createSpecialException(response.getDocument("writeConcernError").clone()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's pretty hacky to clone the writeConcernError document so we can append errorLabels to it, but it's the most localized fix. Happy to entertain other ideas though

import java.net.URISyntaxException;
import java.util.Collection;

public class UnifiedRetryableWritesTest extends UnifiedReactiveStreamsTest {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the first unified retryable writes tests so need new runners for them.

@@ -0,0 +1,205 @@
{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added these two new unified tests for this, in scope of already existing DRIVERS-1385 ticket.

@jyemin
Copy link
Contributor Author

jyemin commented Jul 26, 2021

Sharded tests are failing... Converting to draft while investigation is in progress.

@jyemin jyemin marked this pull request as ready for review July 26, 2021 22:25
@@ -264,7 +265,16 @@ public static MongoException createSpecialException(final BsonDocument response,
} else if (isNotPrimaryError(errorCode, errorMessage)) {
return new MongoNotPrimaryException(response, serverAddress);
} else if (response.containsKey("writeConcernError")) {
return createSpecialException(response.getDocument("writeConcernError"), serverAddress, "errmsg");
BsonDocument writeConcernError = response.getDocument("writeConcernError");
Copy link
Member

@rozza rozza Jul 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is more complex than it needs to be:

MongoException error = createSpecialException(response.getDocument("writeConcernError"), serverAddress, "errmsg");
for (BsonValue errorLabel : response.getArray("errorLabels", new BsonArray())) {
    error.addLabel(errorLabel.asString().getValue());
}
return error;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's so much better. Thanks. Added a couple of checks to a conditional protecting the loop. One is necessary for correctness, the other just to document intent.

Done.

@jyemin jyemin requested a review from rozza July 27, 2021 13:29
Copy link
Member

@rozza rozza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jyemin jyemin merged commit 07e85a9 into mongodb:master Jul 27, 2021
@jyemin jyemin deleted the j4244 branch July 27, 2021 16:49
jyemin added a commit to jyemin/mongo-java-driver that referenced this pull request Jul 27, 2021
This will allow the driver to properly retry writes that the server
has labeled as a RetryableWriteError.

JAVA-4244
jyemin added a commit to jyemin/mongo-java-driver that referenced this pull request Jul 27, 2021
This will allow the driver to properly retry writes that the server
has labeled as a RetryableWriteError.

JAVA-4244
ispringer pushed a commit to evergage/mongo-java-driver that referenced this pull request May 16, 2023
This will allow the driver to properly retry writes that the server
has labeled as a RetryableWriteError.

JAVA-4244
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants