我正在使用c ++ 2.2.3驱动程序使用ScopedDbConnection连接到mongo replicaset。在测试故障转移方案后,应用程序崩溃并且无法恢复。
当所有从属设备都关闭时,它无法写入主设备,这是显而易见的,但在下一次mongo操作之前,我将设备重新启动,即使在之后也无法恢复。
但是,同样的方案适用于mongo 2.0和cpp驱动程序2.0以及以下代码。在我把奴隶备份后,它会恢复下一次运行。
mongo::DBClientBase * MongoKeyValueDataStore::getDbConnection(mongo::ScopedDbConnection * m_scopedDbConnection) {
DBClientBase * clientDbConnection;
try {
clientDbConnection = m_scopedDbConnection->get();
// Following is necessary to check and reconnect if server/replicaset came back up
// works with mongo v2.0 and 2.0 cpp driver but mongo v2.23 and 2.2.3 cpp driver always returns true for isFailed() method
if (clientDbConnection && clientDbConnection->isFailed()) {
m_scopedDbConnection->kill();
return NULL;
}
return clientDbConnection;
}
提前感谢您的帮助。