-
Type: Task
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: libmongoc
-
None
mongoc_cmd_parts_assemble assembles options and the base command document into a final command to send.
parts->body is the base command, like
{insert: "coll"}
parts->assembled_body is the base command with options set, like:
{insert: "coll", "readConcern": { "level": "majority" }}
parts->assembled.command is the final assembled command to send. This either points to parts->body if no options are required to be appended to the base command, or is set to parts->assembled_body otherwise. (I think perhaps this is a micro optimization, to avoid copying the command if we don't need to.)
So, at the start of the mongoc_cmd_parts_assemble there is:
parts->assembled.command = parts->body;
And whenever an option is set, you're supposed to call
_mongoc_cmd_parts_ensure_copied, which switches it over:
parts->assembled.command = &parts->assembled_body;
My guess is that this is a micro-optimization, to avoid copying parts->body if no options were set and nothing changed. However, we don't always call _mongoc_cmd_parts_ensure_copied every time options are set, meaning we might omit sending them. I don't think it's currently possible for this to surface because this only applies when:
- no $lsid (session ID) is appended
- we're using OP_MSG (so, post 3.6)
- user manually specifies $db in the command document (which is probably pretty rare)
Because of CDRIVER-3070, we always (incorrectly) assume a 3.6+ server supports sessions and append the $lsid. When that's fixed, we'll need to fix this.
- is depended on by
-
CDRIVER-3070 Do not include lsid in commands if topology does not support sessions
- Closed
- related to
-
CDRIVER-3657 Make command assembly more robust regarding options
- Backlog