2

最近,我们将 CI 上的 mongodb 设置为 ReplicaSet。我们有两个节点 localhost:27017、localhost:27018 和 localhost:27019 上的仲裁器(日志 = false)。

MongoDB版本是 2.4.3 和 pymongo==2.5.2 在 linux Ubuntu 11.10 上运行

我们配置了集群:

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 实例时,测试恢复为绿色。

4

1 回答 1

1

我们发现我们每晚都在清理 mongo 数据库:

db.adminCommand("listDatabases").databases.forEach( function (d) {
  if (d.name != "admin" && d.name != "config")
     db.getSiblingDB(d.name).dropDatabase();
})

但是我们放弃了 db.local 这不是一个好主意:它包含副本集配置!

于 2013-06-11T09:50:11.823 回答