1 将servers的地址,选项解析出来后,具体的连接函数为mongo_get_connection_single(mcon/manager.c)
2 如果最近连接失败过的机器会加入黑名单,在短时间内不会去重试这台机器(默认是5秒)
3 每次取到连接后会ping一次,如果失败将连接置空,也不会重连(逻辑不太好,应该重连)
static mongo_connection *mongo_get_connection_single(mongo_con_manager *manager, mongo_server_def *server, mongo_server_options *options, int connection_flags, char **error_message)
{
char *hash;
mongo_connection *con = NULL;
mongo_connection_blacklist *blacklist = NULL;
hash = mongo_server_create_hash(server);
/* See if a connection is in our blacklist to short-circut trying to
* connect to a node that is known to be down. This is done so we don't
* waste precious time in connecting to unreachable nodes */
blacklist = mongo_manager_blacklist_find_by_hash(manager, hash);
if (blacklist) {
struct timeval start;