-
Notifications
You must be signed in to change notification settings - Fork 455
CDRIVER-3929 Include apiVersion in handshake commands #753
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
Changes from all commits
76e2cf0
4a5ff51
1abc83e
4a293c6
2458ca5
59df965
2b40720
f149b68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ struct _mongoc_client_pool_t { | |
int32_t error_api_version; | ||
bool error_api_set; | ||
mongoc_server_api_t *api; | ||
bool client_initialized; | ||
}; | ||
|
||
|
||
|
@@ -240,6 +241,8 @@ _initialize_new_client (mongoc_client_pool_t *pool, mongoc_client_t *client) | |
pool->topology->scanner->initiator, | ||
pool->topology->scanner->initiator_context); | ||
|
||
pool->client_initialized = true; | ||
client->is_pooled = true; | ||
client->error_api_version = pool->error_api_version; | ||
_mongoc_client_set_apm_callbacks_private ( | ||
client, &pool->apm_callbacks, pool->apm_context); | ||
|
@@ -528,6 +531,15 @@ mongoc_client_pool_set_server_api (mongoc_client_pool_t *pool, | |
return false; | ||
} | ||
|
||
if (pool->client_initialized) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On second thought, that would've worked. I had this in previously but refactored this since I thought the logic would allow changes when |
||
bson_set_error (error, | ||
MONGOC_ERROR_POOL, | ||
MONGOC_ERROR_POOL_API_TOO_LATE, | ||
"Cannot set server api after a client has been created"); | ||
return false; | ||
} | ||
|
||
pool->api = mongoc_server_api_copy (api); | ||
_mongoc_topology_scanner_set_server_api (pool->topology->scanner, api); | ||
alcaeus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return true; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -796,8 +796,8 @@ _txn_in_progress (mongoc_cmd_parts_t *parts) | |
} | ||
|
||
return (_mongoc_client_session_txn_in_progress (cs) | ||
/* commitTransaction and abortTransaction count as in progress, too. */ | ||
|| parts->assembled.is_txn_finish); | ||
/* commitTransaction and abortTransaction count as in progress, too. */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated whitespace change, but the tabs really stood out. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ugh that's from my text editor, I'm not sure why clang-format didn't fix it for me. Sorry! |
||
|| parts->assembled.is_txn_finish); | ||
} | ||
|
||
|
||
|
@@ -827,14 +827,12 @@ mongoc_cmd_parts_assemble (mongoc_cmd_parts_t *parts, | |
bson_error_t *error) | ||
{ | ||
mongoc_server_description_type_t server_type; | ||
mongoc_server_api_t *api; | ||
mongoc_client_session_t *cs; | ||
const bson_t *cluster_time = NULL; | ||
mongoc_read_prefs_t *prefs = NULL; | ||
const char *cmd_name; | ||
bool is_get_more; | ||
const mongoc_read_prefs_t *prefs_ptr; | ||
const char *string_version; | ||
bool ret = false; | ||
|
||
ENTRY; | ||
|
@@ -994,23 +992,8 @@ mongoc_cmd_parts_assemble (mongoc_cmd_parts_t *parts, | |
sending a getmore, or if we are in a transaction. */ | ||
if (parts->client->api) { | ||
if (!is_get_more && !_txn_in_progress (parts)) { | ||
api = parts->client->api; | ||
string_version = mongoc_server_api_version_to_string (api->version); | ||
|
||
bson_append_utf8 ( | ||
&parts->assembled_body, "apiVersion", -1, string_version, -1); | ||
|
||
if (api->strict.is_set) { | ||
bson_append_bool ( | ||
&parts->assembled_body, "apiStrict", -1, api->strict.value); | ||
} | ||
|
||
if (api->deprecation_errors.is_set) { | ||
bson_append_bool (&parts->assembled_body, | ||
"apiDeprecationErrors", | ||
-1, | ||
api->deprecation_errors.value); | ||
} | ||
_mongoc_cmd_append_server_api (&parts->assembled_body, | ||
parts->client->api); | ||
} | ||
} | ||
|
||
|
@@ -1155,3 +1138,43 @@ _mongoc_cmd_append_payload_as_array (const mongoc_cmd_t *cmd, bson_t *out) | |
|
||
bson_append_array_end (out, &bson); | ||
} | ||
|
||
/*-------------------------------------------------------------------------- | ||
* | ||
* _mongoc_cmd_append_server_api -- | ||
* Append versioned API fields to a mongoc_cmd_t | ||
* | ||
* Arguments: | ||
* cmd The mongoc_cmd_t, which will have versioned API fields added | ||
* api A mongoc_server_api_t holding server API information | ||
* | ||
* Pre-conditions: | ||
* - @api is initialized. | ||
bazile-clyde marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* - @command_body is initialised | ||
* | ||
*-------------------------------------------------------------------------- | ||
*/ | ||
void | ||
_mongoc_cmd_append_server_api (bson_t *command_body, | ||
const mongoc_server_api_t *api) | ||
{ | ||
const char *string_version; | ||
|
||
BSON_ASSERT (command_body); | ||
BSON_ASSERT (api); | ||
|
||
string_version = mongoc_server_api_version_to_string (api->version); | ||
|
||
bson_append_utf8 (command_body, "apiVersion", -1, string_version, -1); | ||
|
||
if (api->strict.is_set) { | ||
bson_append_bool (command_body, "apiStrict", -1, api->strict.value); | ||
} | ||
|
||
if (api->deprecation_errors.is_set) { | ||
bson_append_bool (command_body, | ||
"apiDeprecationErrors", | ||
-1, | ||
api->deprecation_errors.value); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to clarify, this is meant to be set when the first client created by this pool is initialized?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes