问题处理这种错误的最佳方法是什么?说后重试,最多 30 秒。5倍?
设置 我在 AWS ECS 上有一个 PRIMARY + 两个 SECONDARY 设置,并且没有一个盒子被关闭。
从异常消息来看,Mongo 似乎在说“我没有 PRIMARY,我试图从 SECONDARY 获取数据,但它们也失败了”。但是,没有一个 Mongo 服务器出现故障。我有另一个进程正在运行,它的默认read_preference
值为SECONDARY
并且一直运行良好。
例外
is_auth = db.authenticate("myid","mypass")
File "/usr/local/lib/python2.7/dist-packages/pymongo/database.py", line
720, in authenticate
read_preference=read_pref)["nonce"]
File "/usr/local/lib/python2.7/dist-packages/pymongo/database.py", line
390, in command
result = self["$cmd"].find_one(command, **extra_opts)
File "/usr/local/lib/python2.7/dist-packages/pymongo/collection.py",
line 598, in find_one
for result in self.find(spec_or_id, *args, **kwargs).limit(-1):
File "/usr/local/lib/python2.7/dist-packages/pymongo/cursor.py", line
814, in next
if len(self.__data) or self._refresh():
File "/usr/local/lib/python2.7/dist-packages/pymongo/cursor.py", line
763, in _refresh
self.__uuid_subtype))
File "/usr/local/lib/python2.7/dist-packages/pymongo/cursor.py", line
700, in __send_message
**kwargs)
File
"/usr/local/lib/python2.7/dist-packages/pymongo/mongo_replica_set_client.py
", line 1210, in _send_message_with_response
raise AutoReconnect(msg, errors)
AutoReconnect: No replica set members available for query with
ReadPreference PRIMARY_PREFERRED
代码
connection = MongoReplicaSetClient(, replicaSet='myReplica-2', use_greenlets = True)
db = "my_real_db"
db.read_preference = ReadPreference.PRIMARY
is_auth = db.authenticate("myid", "mypass") # ERROR at this line
版本 MongoDB:2.2.0 和 PyMongo:2.4.2