为什么我会遇到python异常;操作失败:缺少local.oplog.rs。你把它掉了吗?如果是,请重新启动服务器“;每天早上在CI上?
最近,我们将CI上的mongodb设置为ReplicaSet。我们有两个节点localhost:27017、localhost:27018和localhost:27019上的仲裁器(journal=false) MongoDB版本为2.4.3,pymongo==2.5.2,在linux Ubuntu 11.10上运行 我们将群集配置为:为什么我会遇到python异常;操作失败:缺少local.oplog.rs。你把它掉了吗?如果是,请重新启动服务器“;每天早上在CI上?,python,mongodb,replication,Python,Mongodb,Replication,最近,我们将CI上的mongodb设置为ReplicaSet。我们有两个节点localhost:27017、localhost:27018和localhost:27019上的仲裁器(journal=false) MongoDB版本为2.4.3,pymongo==2.5.2,在linux Ubuntu 11.10上运行 我们将群集配置为: cfg = {
cfg = {
_id : 'my-data-cluster',
members : [
{ _id : 0, host : '127.0.0.1:27017' },
{ _id : 1, host : '127.0.0.1:27018' },
{ _id : 2, host : '127.0.0.1:27019', arbiterOnly: true}
]
};
rs.initiate(cfg);
并使用python调用:
MongoReplicaSetClient(hosts_or_uri=hosts, replicaSet='my-data-cluster')
好的,那么单元测试是绿色的,验收测试是绿色的。但每天早上(单元测试在午夜前后启动),所有mongo测试都会中断:
Traceback (most recent call last):
commons/test/test_user_dao.py line 12 in setUp
self.user_dao = UserDao(self.connection.get(UNIT_TEST))
commons/src/user_dao.py line 9 in __init__
self.__create_indexes()
commons/src/user_dao.py line 14 in __create_indexes
self.collection.ensure_index('login', pymongo.ASCENDING, unique=True, background=True)
DEV/lib/python2.7/site-packages/pymongo/collection.py line 916 in ensure_index
return self.create_index(key_or_list, cache_for, **kwargs)
DEV/lib/python2.7/site-packages/pymongo/collection.py line 823 in create_index
**self._get_wc_override())
DEV/lib/python2.7/site-packages/pymongo/collection.py line 357 in insert
continue_on_error, self.__uuid_subtype), safe)
lib/src/mongo_connection.py line 19 in wrapper
return func(*args, **kwargs)
lib/src/mongo_connection.py line 82 in _send_message
return super(ReconnectingMongoReplicaSetClient, self)._send_message(msg, with_last_error, _connection_to_use)
DEV/lib/python2.7/site-packages/pymongo/mongo_replica_set_client.py line 1360 in _send_message
rv = self.__check_response_to_last_error(response)
DEV/lib/python2.7/site-packages/pymongo/mongo_replica_set_client.py line 1271 in __check_response_to_last_error
raise OperationFailure(error["err"], error["code"])
OperationFailure: local.oplog.rs missing. did you drop it? if so restart server
我检查了服务器日志,看到的唯一可疑行如下所示:
09:13:53.788 [rsBackgroundSync] replSet db exception in producer: 1000 replSet source for syncing doesn't seem to be await capable -- is it an older version of mongodb?
当我重新启动三个Mongo实例时,测试恢复为绿色。我们发现我们每天晚上都在用以下方法清理Mongo数据库:
db.adminCommand("listDatabases").databases.forEach( function (d) {
if (d.name != "admin" && d.name != "config")
db.getSiblingDB(d.name).dropDatabase();
})
但是我们删除了db.local,这不是一个好主意:它保存了replicaset配置