Skip to content

Commit

Permalink
CDRIVER-4754 pre-4.4 mongos writeConcernError does not determine retr…
Browse files Browse the repository at this point in the history
…yability

Synced with mongodb/specifications#1486
  • Loading branch information
jmikola committed Jan 12, 2024
1 parent ee146c1 commit 60234b9
Show file tree
Hide file tree
Showing 7 changed files with 324 additions and 12 deletions.
3 changes: 1 addition & 2 deletions src/libmongoc/src/mongoc/mongoc-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1712,8 +1712,7 @@ _mongoc_client_retryable_write_command_with_stream (
ret = mongoc_cluster_run_command_monitored (
&client->cluster, &parts->assembled, reply, error);

_mongoc_write_error_handle_labels (
ret, error, reply, server_stream->sd->max_wire_version);
_mongoc_write_error_handle_labels (ret, error, reply, server_stream->sd);

if (is_retryable) {
_mongoc_write_error_update_if_unsupported_storage_engine (
Expand Down
2 changes: 1 addition & 1 deletion src/libmongoc/src/mongoc/mongoc-cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ _handle_txn_error_labels (bool cmd_ret,
}

_mongoc_write_error_handle_labels (
cmd_ret, cmd_err, reply, cmd->server_stream->sd->max_wire_version);
cmd_ret, cmd_err, reply, cmd->server_stream->sd);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/libmongoc/src/mongoc/mongoc-collection.c
Original file line number Diff line number Diff line change
Expand Up @@ -3548,7 +3548,7 @@ mongoc_collection_find_and_modify_with_opts (

if (parts.is_retryable_write) {
_mongoc_write_error_handle_labels (
ret, error, reply_ptr, server_stream->sd->max_wire_version);
ret, error, reply_ptr, server_stream->sd);
}

if (is_retryable) {
Expand Down
4 changes: 3 additions & 1 deletion src/libmongoc/src/mongoc/mongoc-error-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <bson/bson.h>
#include <stddef.h>

#include "mongoc-server-description.h"

BSON_BEGIN_DECLS

typedef enum {
Expand Down Expand Up @@ -72,7 +74,7 @@ void
_mongoc_write_error_handle_labels (bool cmd_ret,
const bson_error_t *cmd_err,
bson_t *reply,
int32_t server_max_wire_version);
mongoc_server_description_t *sd);

bool
_mongoc_error_is_shutdown (bson_error_t *error);
Expand Down
20 changes: 14 additions & 6 deletions src/libmongoc/src/mongoc/mongoc-error.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "mongoc-error-private.h"
#include "mongoc-rpc-private.h"
#include "mongoc-client-private.h"
#include "mongoc-server-description-private.h"

bool
mongoc_error_has_label (const bson_t *reply, const char *label)
Expand Down Expand Up @@ -102,7 +103,7 @@ void
_mongoc_write_error_handle_labels (bool cmd_ret,
const bson_error_t *cmd_err,
bson_t *reply,
int32_t server_max_wire_version)
mongoc_server_description_t *sd)
{
bson_error_t error;

Expand All @@ -115,14 +116,21 @@ _mongoc_write_error_handle_labels (bool cmd_ret,
return;
}

if (server_max_wire_version >= WIRE_VERSION_RETRYABLE_WRITE_ERROR_LABEL) {
if (sd->max_wire_version >= WIRE_VERSION_RETRYABLE_WRITE_ERROR_LABEL) {
return;
}

/* check for a server error. */
if (_mongoc_cmd_check_ok_no_wce (
reply, MONGOC_ERROR_API_VERSION_2, &error)) {
return;
/* Check for a server error. Do not consult writeConcernError for pre-4.4
* mongos. */
if (sd->type == MONGOC_SERVER_MONGOS) {
if (_mongoc_cmd_check_ok (reply, MONGOC_ERROR_API_VERSION_2, &error)) {
return;
}
} else {
if (_mongoc_cmd_check_ok_no_wce (
reply, MONGOC_ERROR_API_VERSION_2, &error)) {
return;
}
}

if (_mongoc_write_error_is_retryable (&error)) {
Expand Down
2 changes: 1 addition & 1 deletion src/libmongoc/src/mongoc/mongoc-write-command.c
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ _mongoc_write_opmsg (mongoc_write_command_t *command,

if (parts.is_retryable_write) {
_mongoc_write_error_handle_labels (
ret, error, &reply, server_stream->sd->max_wire_version);
ret, error, &reply, server_stream->sd);
}

/* Add this batch size so we skip these documents next time */
Expand Down
Loading

0 comments on commit 60234b9

Please sign in to comment.