Skip to content

CDRIVER-3974 Append Versioned API options to all commands #792

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

Merged
merged 1 commit into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions src/libmongoc/src/mongoc/mongoc-cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -785,22 +785,6 @@ _is_retryable_read (const mongoc_cmd_parts_t *parts,
}


static bool
_txn_in_progress (mongoc_cmd_parts_t *parts)
{
mongoc_client_session_t *cs;

cs = parts->prohibit_lsid ? NULL : parts->assembled.session;
if (!cs) {
return false;
}

return (_mongoc_client_session_txn_in_progress (cs)
/* commitTransaction and abortTransaction count as in progress, too. */
|| parts->assembled.is_txn_finish);
}


/*
*--------------------------------------------------------------------------
*
Expand Down Expand Up @@ -988,13 +972,10 @@ mongoc_cmd_parts_assemble (mongoc_cmd_parts_t *parts,
&parts->assembled_body, "$clusterTime", 12, cluster_time);
}

/* Add versioned server api, if it is set. Do not add api if we are
sending a getmore, or if we are in a transaction. */
/* Add versioned server api, if it is set. */
if (parts->client->api) {
if (!is_get_more && !_txn_in_progress (parts)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice! Always appending a versioned API does help simplify this logic.

_mongoc_cmd_append_server_api (&parts->assembled_body,
parts->client->api);
}
_mongoc_cmd_append_server_api (&parts->assembled_body,
parts->client->api);
}

if (!is_get_more) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@
]
},
{
"description": "find command with declared API version appends to the command, but getMore does not",
"description": "find and getMore append API version",
"operations": [
{
"name": "find",
Expand Down Expand Up @@ -712,14 +712,10 @@
"long"
]
},
"apiVersion": {
"$$exists": false
},
"apiStrict": {
"$$exists": false
},
"apiVersion": "1",
"apiStrict": true,
"apiDeprecationErrors": {
"$$exists": false
"$$unsetOrMatches": false
}
}
}
Expand Down Expand Up @@ -1111,4 +1107,4 @@
]
}
]
}
}
16 changes: 6 additions & 10 deletions src/libmongoc/tests/json/versioned_api/crud-api-version-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@
]
},
{
"description": "estimatedDocumentCount appends declared API version",
"description": "estimatedDocumentCount appends declared API version on 4.9.0 or greater",
"operations": [
{
"name": "estimatedDocumentCount",
Expand Down Expand Up @@ -643,7 +643,7 @@
]
},
{
"description": "find command with declared API version appends to the command, but getMore does not",
"description": "find and getMore append API version",
"operations": [
{
"name": "find",
Expand Down Expand Up @@ -704,15 +704,11 @@
"long"
]
},
"apiVersion": {
"$$exists": false
},
"apiVersion": "1",
"apiStrict": {
"$$exists": false
"$$unsetOrMatches": false
},
"apiDeprecationErrors": {
"$$exists": false
}
"apiDeprecationErrors": true
}
}
}
Expand Down Expand Up @@ -1103,4 +1099,4 @@
]
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@
]
}
]
}
}
Loading