Skip to content

Commit aaee18d

Browse files
committed
CDRIVER-2418 send readConcern only with read cmds
1 parent e0fc953 commit aaee18d

File tree

6 files changed

+170
-68
lines changed

6 files changed

+170
-68
lines changed

src/mongoc/mongoc-client.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,7 @@ _mongoc_client_command_with_opts (mongoc_client_t *client,
17291729
BSON_ASSERT (command);
17301730

17311731
mongoc_cmd_parts_init (&parts, client, db_name, flags, command);
1732+
parts.is_read_command = (mode & MONGOC_CMD_READ);
17321733
parts.is_write_command = (mode & MONGOC_CMD_WRITE);
17331734

17341735
reply_ptr = reply ? reply : &reply_local;

src/mongoc/mongoc-cmd-private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ typedef struct _mongoc_cmd_parts_t {
6666
bson_t extra;
6767
const mongoc_read_prefs_t *read_prefs;
6868
bson_t assembled_body;
69+
bool is_read_command;
6970
bool is_write_command;
7071
bool prohibit_lsid;
7172
mongoc_cmd_parts_allow_txn_number_t allow_txn_number;

src/mongoc/mongoc-cmd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ mongoc_cmd_parts_init (mongoc_cmd_parts_t *parts,
3434
parts->body = command_body;
3535
parts->user_query_flags = user_query_flags;
3636
parts->read_prefs = NULL;
37+
parts->is_read_command = false;
3738
parts->is_write_command = false;
3839
parts->prohibit_lsid = false;
3940
parts->allow_txn_number = MONGOC_CMD_PARTS_ALLOW_TXN_NUMBER_UNKNOWN;
@@ -654,7 +655,7 @@ mongoc_cmd_parts_assemble (mongoc_cmd_parts_t *parts,
654655
&parts->assembled_body, "$clusterTime", 12, cluster_time);
655656
}
656657

657-
if (!is_get_more) {
658+
if (parts->is_read_command && !is_get_more) {
658659
/* This condition should never trigger for an implicit client session.
659660
* Even though the causal consistency option may default to true, an
660661
* implicit client session will have no previous operation time. */

src/mongoc/mongoc-collection.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2949,6 +2949,7 @@ mongoc_collection_find_and_modify_with_opts (
29492949

29502950
mongoc_cmd_parts_init (
29512951
&parts, collection->client, collection->db, MONGOC_QUERY_NONE, &command);
2952+
parts.is_read_command = true;
29522953
parts.is_write_command = true;
29532954

29542955
if (bson_iter_init (&iter, &opts->extra)) {
@@ -2989,8 +2990,9 @@ mongoc_collection_find_and_modify_with_opts (
29892990
* a new writable stream and retry. If server selection fails or the selected
29902991
* server does not support retryable writes, fall through and allow the
29912992
* original error to be reported. */
2992-
if (!ret && is_retryable && (error->domain == MONGOC_ERROR_STREAM ||
2993-
mongoc_cluster_is_not_master_error (error))) {
2993+
if (!ret && is_retryable &&
2994+
(error->domain == MONGOC_ERROR_STREAM ||
2995+
mongoc_cluster_is_not_master_error (error))) {
29942996
bson_error_t ignored_error;
29952997

29962998
/* each write command may be retried at most once */
@@ -3003,9 +3005,8 @@ mongoc_collection_find_and_modify_with_opts (
30033005
retry_server_stream =
30043006
mongoc_cluster_stream_for_writes (cluster, &ignored_error);
30053007

3006-
if (retry_server_stream &&
3007-
retry_server_stream->sd->max_wire_version >=
3008-
WIRE_VERSION_RETRY_WRITES) {
3008+
if (retry_server_stream && retry_server_stream->sd->max_wire_version >=
3009+
WIRE_VERSION_RETRY_WRITES) {
30093010
parts.assembled.server_stream = retry_server_stream;
30103011
GOTO (retry);
30113012
}

src/mongoc/mongoc-cursor.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,7 @@ _mongoc_cursor_run_command (mongoc_cursor_t *cursor,
13131313
cluster = &cursor->client->cluster;
13141314
mongoc_cmd_parts_init (
13151315
&parts, cursor->client, db, MONGOC_QUERY_NONE, command);
1316+
parts.is_read_command = true;
13161317
parts.read_prefs = cursor->read_prefs;
13171318
parts.assembled.operation_id = cursor->operation_id;
13181319
server_stream = _mongoc_cursor_fetch_stream (cursor);

0 commit comments

Comments
 (0)