[CXX-644] auto_reconnect using ConnectionString API Created: 31/Jul/15  Updated: 11/Sep/19  Resolved: 31/Jul/15

Status: Closed
Project: C++ Driver
Component/s: API
Affects Version/s: legacy-1.0.0
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Judy Han [X] Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Linux version 2.6.32-504.3.3.el6.x86_64 (mockbuild@x86-028.build.eng.bos.redhat.com) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-9) (GCC) ) #1 SMP Fri Dec 12 16:05:43 EST 2014



 Description   

If I use DBClientConnection () API to make mongodb connection, I can specify _autoReconnect to be true which allow automatic reconnect on a connection failure.

However, I am using following API to connect (recommended way?):
=====================================================
std::string errString;
mongo::ConnectionString mongoConnectionString = mongo::ConnectionString::parse(hostAndPortStr_, errString);
...
mongoPtr_ = mongoConnectionString.connect(errString);
if (!mongoPtr_->auth(mongodbDatabase_, mongodbUsername_, mongodbPassword_, errString))

{ ... return false; }

;
============================================
I don't see a way to set auto_reconnect to true using this API.
Is auto_reconnect true or false in this case?
If it is false, how do I set it to true?

Thanks in advance!



 Comments   
Comment by Judy Han [X] [ 31/Jul/15 ]

Great, Thanks a lot! Please feel free to close the ticket.

Comment by Adam Midvidy [ 31/Jul/15 ]

Hi Judy, If your deployment is a replicaSet (i.e. the connection string has the 'replSet' parameter) then autoReconnect is enabled by default, as ConnectionString::connect will return an instance of DBClientReplicaSet. As I mentioned earlier, DBClientReplicaSet always uses autoReconnect.

Adam

Comment by Judy Han [X] [ 31/Jul/15 ]

Hi Adam,
Thanks for the response. I have some follow up questions:
Suppose I am using ConnectionString::connect() interface, and my server is configured as a replica set, do I have auto-reconnect enabled?
If the answer is yes, in case the whole replica set is down for a period of time before come up again, will auto-reconnect happen?
If the answer is no, and I want auto-reconnect, what options do I have and what is the recommended options?
Thanks!
Judy

Comment by Adam Midvidy [ 31/Jul/15 ]

Judy.Han, the default value for autoReconnect on DBClientConnection is false. If you would like to specify autoReconnect, you should manually construct an instance of DBClientConnection and pass a value of true to the constructor for the autoReconnect parameter.

The reason this is not supported through the ConnectionString::connect() interface is that other connection types, such as DBClientReplicaSet, have different autoReconnect semantics - i.e. for DBClientReplicaSet, autoReocnnect is always enabled.

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