Support sending writeConcern for commands that write (CDRIVER-1322)

[CDRIVER-1414] Add mongoc_write_concern_t to mongoc_cursor_t Created: 26/Jul/16  Updated: 10/Aug/16  Resolved: 04/Aug/16

Status: Closed
Project: C Driver
Component/s: libmongoc
Affects Version/s: None
Fix Version/s: 1.4.0

Type: Sub-task Priority: Major - P3
Reporter: A. Jesse Jiryu Davis Assignee: Fiona Rowan
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

I'm accepting Pull Request 358, which adds mongoc_collection_aggregate_with_write_concern, but I noticed a problem. The algorithm there is:

  • Select a server
  • If its wire version is 5+ and the user passed a write concern, append it to the command document
  • Create a cursor with the command document

Then, as always, when the user runs mongoc_cursor_next, its algorithm is:

  • Select a server
  • Send the command document to the server

But the two selections may select different members of the replica set or different mongos servers in a sharded cluster, and these servers may have different wire versions!

Instead, let's add a mongoc_write_concern_t to mongoc_cursor_t, similar to the read prefs and read concern it has already. Whenever a cursor is created, if and only if it's created by one of the command helpers whose names end in _with_write_concern, set the cursor's write concern. Don't append it to the command document yet.

Then, when the user calls mongoc_cursor_next it calls _mongoc_cursor_cursorid_refresh_from_command which calls _mongoc_cursor_run_command. In there we get a server stream and know its wire version for certain. If it's 5+ and cursor->write_concern is not NULL or the default, append the write concern to the command before the call to mongoc_cluster_run_command_monitored.



 Comments   
Comment by Githook User [ 02/Aug/16 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@emptysquare.net'}

Message: Merge pull request #380 from fionaRowan/C-1414

CDRIVER-1414: parse writeConcernErrors in command helper
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/98713feddcc334e667c0f7a0cff82c4f5a900dcd

Comment by Githook User [ 02/Aug/16 ]

Author:

{u'name': u'Fiona Rowan', u'email': u'fiona.rowan@10gen.com'}

Message: CDRIVER-1414: parse writeConcernErrors in command helper
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/954b787f6217b69c2a6b7dee432654d27a5f741c

Comment by Githook User [ 30/Jul/16 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@emptysquare.net'}

Message: Merge pull request #372 from fionaRowan/CDRIVER-1414

CDRIVER-1414: add mongoc_write_concern_t to mongoc_cursor_t
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/6fcafbec048982eaf2f622178c366d53d25fcf75

Comment by Githook User [ 30/Jul/16 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@emptysquare.net'}

Message: Merge pull request #372 from fionaRowan/CDRIVER-1414

CDRIVER-1414: add mongoc_write_concern_t to mongoc_cursor_t
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/6fcafbec048982eaf2f622178c366d53d25fcf75

Comment by Githook User [ 30/Jul/16 ]

Author:

{u'name': u'Fiona Rowan', u'email': u'fiona.rowan@10gen.com'}

Message: CDRIVER-1414: add mongoc_write_concern_t to mongoc_cursor_t
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/b0a696036d40e526d1ef9c9f8512361b398f8308

Generated at Wed Feb 07 21:12:27 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.