[CXX-1309] autreconnect behaviour Created: 12/Apr/17 Updated: 11/Sep/19 Resolved: 24/Apr/17 |
|
| Status: | Closed |
| Project: | C++ Driver |
| Component/s: | None |
| Affects Version/s: | legacy-1.1.2 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Minor - P4 |
| Reporter: | Christian Wyss | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | legacy-cxx | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Linux |
||
| Description |
|
On stepdown of a replicaset master the driver does not seem to retry. I found a post somewhere that says that when connecting a replset, the autoreconnect flag is set automatically - but was not able to find documentation for this feature that permits understanding the behaviuor. What is the expected behaviour concerning autoreconnect, and how can we influence it (number of retries..) ? We use ConnectionString to establish connections, so can't use the constructor of DBClientConnection to pass anything. Thank you, |
| Comments |
| Comment by J Rassi [ 15/Apr/17 ] |
|
[Note to readers: this question concerns the behavior of the C++ legacy driver, which is no longer recommended for new projects that are C++11-compatible. See the MongoDB C++ Driver Manual for more information on mongocxx, which is the official replacement for the legacy C++ driver]. The legacy driver documentation is indeed quite sparse. "autoreconnect" is covered in the documentation for several DBClientConnection methods, but I'll explain it in slightly more detail below. When a network error is encountered in a method call on a DBClientConnection object, the driver will never attempt to automatically retry the requested operation. Instead, an exception is thrown and the DBClientConnection object is marked as "failed". Applications using the driver that want retry behavior need to manually implement their own retry logic. "autoreconnect" is an option that allows a "failed" DBClientConnection to be re-used for manual retries, and potentially marked transitioned back to the "alive" state:
So, to handle stepdown of a replica set primary, your application needs to catch the exception thrown by the DBClientReplicaSet method call, and attempt the same method call later (assuming the database operation is idempotent or otherwise safe to perform again). Your application can repeat this process multiple times if needed. In the future, please post questions about the C++ driver to the mongodb-user group, instead of filing "Question" tickets in the CXX project. mongodb-user is the appropriate place for questions about the driver, and your question will be seen by more people there (the C++ driver maintainers monitor it, too). Here's a link to the group page: https://groups.google.com/forum/#!forum/mongodb-user. |