[CDRIVER-1322] Support sending writeConcern for commands that write Created: 10/Jun/16  Updated: 19/Oct/16  Resolved: 29/Aug/16

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

Type: New Feature Priority: Major - P3
Reporter: Rathi Gnanasekaran Assignee: Fiona Rowan
Resolution: Done Votes: 0
Labels: intern2016
Σ Remaining Estimate: Not Specified Remaining Estimate: Not Specified
Σ Time Spent: Not Specified Time Spent: Not Specified
Σ Original Estimate: Not Specified Original Estimate: Not Specified

Issue Links:
Depends
is depended on by CDRIVER-1448 private generic command function that... Closed
is depended on by CDRIVER-1460 on writeConcernError, parse wc err an... Closed
is depended on by CDRIVER-1526 Rename "_with_write_concern" function... Closed
is depended on by DRIVERS-290 Support sending writeConcern for comm... Closed
is depended on by CDRIVER-1384 mongoc_write_concern_append Closed
Related
is related to CDRIVER-1415 /Collection/aggregate_w_write_concern... Closed
Sub-Tasks:
Key
Summary
Type
Status
Assignee
CDRIVER-1414 Add mongoc_write_concern_t to mongoc_... Sub-task Closed Fiona Rowan  
Epic Link: MongoDB 3.4 Support

 Description   

When talking with server 3.4 or greater (maxWireVersion >=5), writeConcern should be a supported option for commands that write.
Helpers for the following commands therefore must be updated to support the option. The list is ordered according to likelihood that a driver has a helper for the command.

  • aggregate with $out mongoc_collection_aggregate
  • copydb - no helper function
  • create - mongoc_database_create_collection
  • createIndexes - mongoc_collection_create_index_2
  • drop - mongoc_collection_drop
  • dropDatabase - mongoc_database_drop
  • dropIndexes - mongoc_collection_drop_index
  • mapReduce with $out - no helper function
  • clone - no helper function
  • cloneCollection - no helper function
  • cloneCollectionAsCapped - no helper function
  • collMod - no helper function
  • convertToCapped - no helper function
  • renameCollection - mongoc_collection_rename
  • reindex - no helper

Note:

When the writeConcern on a command that writes fails, the resulting document still comes back with ok: 1. Hence, to check for write concern and raise the appropriate error to your users, you will need to check the resulting document for a writeConcernError field, in command-specific helper methods. If it is present, then writeConcern failed.

Generic command methods like mongoc_client_command do not check the result for a writeConcernError subdocument, that's the user's responsibility.

Plan for C Driver:

We want to include a BSON document like this with commands that write, if the configured writeConcern is not the default:

{ ... regular command document fields ...,
  writeConcern: {w: 2}  // <- for example
}

First, we want to know whether a mongoc_write_concern_t is the default or not. Add bool is_default to the mongoc_write_concern_t struct. It's true at first. All the mongoc_write_concern_set_ functions will set it to false. Do not make a public function for checking if a write_concern_t has the default options: we don't want to expand our public API unnecessarily.

Write some tests in test-mongoc-write-concern.c that "is_default" is properly managed.

Add to mongoc-client-private.h:

#define WIRE_VERSION_CMD_WRITE_CONCERN 5

Generic commands

*Update*: No mongoc_client_command_with_write_concern, mongoc_database_command_with_write_concern, or mongoc_collection_command_with_write_concern.

If you're running against a server with wire version 4 or older, you should not get an error. This test will verify that you're not sending writeConcern to older server versions.

Consider not testing mongoc_database_command_with_write_concern or mongoc_collection_command_with_write_concern, since they'll be very simple functions.

mongoc_collection_aggregate

This is the first example of a new function with a name ending in "with_write_concern". All functions with names ending with "with_write_concern" follow this plan.

Add mongoc_collection_aggregate_with_write_concern.

If selected_server->max_wire_version >= WIRE_VERSION_CMD_WRITE_CONCERN and write_concern is not the default, then append _mongoc_write_concern_get_bson (write_concern) to the "aggregate" command before sending to the server.

Parse the reply, if it's not a hard failure, for a writeConcernError subdocument, and if present fill out the error and return false along with the reply. *Update*: move this parsing back out of mongoc-rpc.c and put it in a private helper function _mongoc_parse_wc_err that all command helper functions like this one can use.

Document that mongoc_collection_aggregate_with_write_concern only sends writeConcern to the server if it's MongoDB 3.4+. Ask Kay Kim where in the MongoDB Manual your doc should send users for more info about writeConcern and commands.

To test mongoc_collection_aggregate_with_write_concern: use helper functions in test-libmongoc.h to determine the server config. If you're running against a server with wire version 5+ and it's a replica set, set write concern's "w" to 99. You should get a characteristic server error, and test that the error domain is MONGOC_ERROR_WRITE_CONCERN. If you're running against a server with wire version 5+ and it's a standalone you should get a slightly different error. Not sure what to expect if you're connected to mongos, see what happens and write your test accordingly. If you're connected to mongos, skip the test. If connected to a server with max_wire_version <=4, then you should not get an error (because you are not sending the write concern).

mongoc_collection_aggregate becomes a wrapper around mongoc_collection_aggregate_with_write_concern, which passes a NULL write concern.

mongoc_database_create_collection

Add mongoc_database_create_collection_with_write_concern, mongoc_database_create_collection becomes a thin wrapper that passes a NULL write concern. Consider not adding a test for its write concern handling, if it seems simple enough to trust.

mongoc_collection_create_index_2

Rename mongoc_collection_create_index_2 to mongoc_collection_create_index_with_write_concern.

Do test that it handles write concern properly, this might be slightly complicated.

The legacy fallback for mongoc_collection_create_index_with_write_concern just inserts into the system.indexes collection, no need to touch or test that code since writeConcern won't be used in that code path.

mongoc_collection_drop

Like mongoc_database_create_collection: add mongoc_collection_drop_with_write_concern.

mongoc_database_drop

Like mongoc_database_create_collection.

mongoc_collection_drop_index

Like mongoc_database_create_collection.

mongoc_collection_rename

Like mongoc_database_create_collection.



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

Author:

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

Message: Merge pull request #389 from fionaRowan/rename

CDRIVER-1322: mongoc_collection_rename_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/6c5ed136f9671fa3c137790a8da1ccce1352f358

Comment by Githook User [ 10/Aug/16 ]

Author:

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

Message: CDRIVER-1322: mongoc_collection_rename_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/333a129d3131e128f0063bd2d5ba615f151346bd

Comment by Githook User [ 10/Aug/16 ]

Author:

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

Message: Merge pull request #388 from fionaRowan/CDRIVER-1322-create

CDRIVER-1460: database_create_collection, parse wc err and return false
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/757eea8db4b5f91dfe2bd531a5b957a7f3f93bae

Comment by Hannes Magnusson [ 10/Aug/16 ]

(I reverted mongoc_aggregate_with_write_concern out of r1.4: https://github.com/mongodb/mongo-c-driver/commit/35af0c287c8ae447f3cd15eeb3810f7c095a889d)

Comment by Githook User [ 08/Aug/16 ]

Author:

{u'username': u'bjori', u'name': u'Hannes Magnusson', u'email': u'bjori@php.net'}

Message: Merge branch 'drop-index' of https://github.com/fionaRowan/mongo-c-driver into fionaRowan-drop-index

Conflicts:
build/autotools/versions.ldscript
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/b10c42e3c9fcf3f8a32b0f80b68c8f4c5be69424

Comment by Githook User [ 08/Aug/16 ]

Author:

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

Message: CDRIVER-1322: mongoc_collection_drop_index_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/4adcf29d9a285386ae1b0c5d264a871fcfdc5246

Comment by Githook User [ 08/Aug/16 ]

Author:

{u'username': u'bjori', u'name': u'Hannes Magnusson', u'email': u'bjori@10gen.com'}

Message: Merge pull request #384 from fionaRowan/index-2

CDRIVER-1322: mongoc_collection_create_index_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/4ca51b9bff61e7c3854ed1f65abdcb74778b7ab0

Comment by Githook User [ 08/Aug/16 ]

Author:

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

Message: CDRIVER-1322: mongoc_collection_create_index_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/259244edacc22a983147462d5fa0aa8060dc2753

Comment by Githook User [ 03/Aug/16 ]

Author:

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

Message: Merge pull request #381 from fionaRowan/index-2-doc

CDRIVER-1322: doc for mongoc_collection_create_index_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/55d2f03a3d1a9fa2a7c2fa3259af02b1c9d3f500

Comment by Githook User [ 03/Aug/16 ]

Author:

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

Message: CDRIVER-1322: doc for mongoc_collection_create_index_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/6de567df424654b69f83ffddcc87bcd5d5d82c68

Comment by Githook User [ 01/Aug/16 ]

Author:

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

Message: Merge pull request #378 from fionaRowan/CDRIVER-1322-create

CDRIVER-1322: capture error logs in test_create_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/16240ac0c170ca04ca1c368a426db82e8bb905d4

Comment by Githook User [ 01/Aug/16 ]

Author:

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

Message: Merge pull request #378 from fionaRowan/CDRIVER-1322-create

CDRIVER-1322: capture error logs in test_create_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/16240ac0c170ca04ca1c368a426db82e8bb905d4

Comment by Githook User [ 01/Aug/16 ]

Author:

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

Message: CDRIVER-1322: capture error logs in test_create_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/6efb89ccce1d1938c19495d8d44b1fbe3a903ab3

Comment by Githook User [ 01/Aug/16 ]

Author:

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

Message: Merge pull request #377 from fionaRowan/rename-doc

CDRIVER-1322: doc for mongoc_collection_rename_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/b395f6add98c1869f63951b09c1bdb38c71db07e

Comment by Githook User [ 01/Aug/16 ]

Author:

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

Message: CDRIVER-1322: doc for mongoc_collection_rename_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/8048d62b8c46fb887e7507974ea565d56988b8b4

Comment by Githook User [ 31/Jul/16 ]

Author:

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

Message: CDRIVER-1322 disable test_aggregate_w_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/b9a04a2369bfbc46c4bffa688f2b3deeca46bfe0

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 #375 from fionaRowan/drop-index-doc

CDRIVER-1322: doc for mongoc_collection_drop_index_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/a772c8cb2be11307b7287f9c7e13fd9cfdfb2cdc

Comment by Githook User [ 30/Jul/16 ]

Author:

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

Message: CDRIVER-1322: doc for mongoc_collection_drop_index_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/adf3c434bede46e18094190c9a8ad9aa4c605073

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 #374 from fionaRowan/db-drop-doc

CDRIVER-1322: doc for mongoc_database_drop_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/923c866d7e38eeee3ce1a8ff01699519913448d9

Comment by Githook User [ 30/Jul/16 ]

Author:

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

Message: CDRIVER-1322: doc for mongoc_database_drop_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/8ef5a50ba8aea8778c1917db9229a6c447838cae

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 #373 from fionaRowan/db-drop

CDRIVER-1322: mongoc_database_drop_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/9c53cca06a839b7bd4de3faecf8c0dd7e453269c

Comment by Githook User [ 30/Jul/16 ]

Author:

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

Message: CDRIVER-1322: mongoc_database_drop_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/014b66128f0af431a2b4ce55acea4bb0e9abfb0c

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 #371 from fionaRowan/drop-doc

CDRIVER-1322: doc for mongoc_collection_drop_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/9ca96f591c8caed607c5efb0450d35106844a6e9

Comment by Githook User [ 30/Jul/16 ]

Author:

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

Message: CDRIVER-1322: doc for mongoc_collection_drop_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/6ba2cd906d7ad741ec88325518cf95fb9ea45354

Comment by Githook User [ 29/Jul/16 ]

Author:

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

Message: CDRIVER-1322: doc for mongoc_database_create_collection_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/a980214183c8654d038ee4f6416585ffd63a0ed0

Comment by Githook User [ 29/Jul/16 ]

Author:

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

Message: Merge pull request #369 from fionaRowan/coll-drop

CDRIVER-1322: mongoc_collection_drop_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/4b3cc1f39a9836b4479d37761d64a3542590bf63

Comment by Githook User [ 29/Jul/16 ]

Author:

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

Message: CDRIVER-1322: mongoc_collection_drop_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/59c6bed61679beaf0be8f6d0a3ace206bcb8266b

Comment by Githook User [ 29/Jul/16 ]

Author:

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

Message: Merge pull request #368 from fionaRowan/CDRIVER-1322-create

CDRIVER-1322: mongoc_database_create_collection_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/0f6ce6e6d6072f5f5ca30c061e57d783b8569dcb

Comment by Githook User [ 29/Jul/16 ]

Author:

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

Message: Merge pull request #368 from fionaRowan/CDRIVER-1322-create

CDRIVER-1322: mongoc_database_create_collection_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/0f6ce6e6d6072f5f5ca30c061e57d783b8569dcb

Comment by Githook User [ 29/Jul/16 ]

Author:

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

Message: CDRIVER-1322: mongoc_database_create_collection_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/65ebe110dae80334c520bbc7f3e422a6d9add21b

Comment by Githook User [ 29/Jul/16 ]

Author:

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

Message: Merge pull request #367 from fionaRowan/CDRIVER-1322-agg

CDRIVER-1322: doc for mongoc_collection_aggregate_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/e246d624fca2ab96ef12c7c5405df056c4d7be61

Comment by Githook User [ 29/Jul/16 ]

Author:

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

Message: Merge pull request #367 from fionaRowan/CDRIVER-1322-agg

CDRIVER-1322: doc for mongoc_collection_aggregate_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/e246d624fca2ab96ef12c7c5405df056c4d7be61

Comment by Githook User [ 29/Jul/16 ]

Author:

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

Message: CDRIVER-1322: doc for mongoc_collection_aggregate_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/bae364816391f52afb82fa367cd8867527dff717

Comment by Githook User [ 26/Jul/16 ]

Author:

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

Message: git push origin masterMerge branch 'fionaRowan-1322-agg-improve'

Comment by Githook User [ 26/Jul/16 ]

Author:

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

Message: Merge branch '1322-agg-improve' of https://github.com/fionaRowan/mongo-c-driver into fionaRowan-1322-agg-improve

Comment by Githook User [ 26/Jul/16 ]

Author:

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

Message: CDRIVER-1322: improve test for aggregate_w_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/461a7fb91ae69eea902cce2fec40709960b78f58

Comment by Githook User [ 26/Jul/16 ]

Author:

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

Message: Merge pull request #358 from fionaRowan/CDRIVER-1322-agg

CDRIVER-1322: mongoc_collection_aggregate_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/46e3cc6aba44a9eaa57b1056181365a56ab1c4a7

Comment by Githook User [ 26/Jul/16 ]

Author:

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

Message: Merge pull request #358 from fionaRowan/CDRIVER-1322-agg

CDRIVER-1322: mongoc_collection_aggregate_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/46e3cc6aba44a9eaa57b1056181365a56ab1c4a7

Comment by Githook User [ 26/Jul/16 ]

Author:

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

Message: CDRIVER-1322: mongoc_collection_aggregate_with_write_concern
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/2ba99c4f57d97616c12195de3ff7f8cc607c57a3

Comment by Githook User [ 20/Jul/16 ]

Author:

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

Message: Merge pull request #352 from fionaRowan/C-1322-wc-support

CDRIVER-1322: internal helper functions and values
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/db2f2d278b849ab0490e81e6a4b7e5beb86ffb33

Comment by Githook User [ 20/Jul/16 ]

Author:

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

Message: CDRIVER-1322: internal helper functions and values
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/c6a019ef184862f2609080e747bc54419dbec03b

Comment by Githook User [ 19/Jul/16 ]

Author:

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

Message: Merge pull request #350 from fionaRowan/C-1322

CDRIVER-1322: test for generic command functions
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/52ff9bf551192d607b52d9ef2ec811af429a75e7

Comment by Githook User [ 19/Jul/16 ]

Author:

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

Message: CDRIVER-1322: test for generic command functions
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/b97a2dc1574b2e4c3ea45a607154601a128af4b3

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