Skip to content

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

Merged
jyemin merged 3 commits intomongodb:masterfrom
jyemin:j4244
Jul 27, 2021
Merged

Add top-level error labels to write concern error#766
jyemin merged 3 commits intomongodb:masterfrom
jyemin:j4244

Conversation

@jyemin
Copy link
Collaborator

@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
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
Collaborator 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
Collaborator 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
Collaborator 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
Collaborator 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
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
Collaborator 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants