问题处理此类错误的最佳方法是什么?比如说,最多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
答案 0 :(得分:8)
我会仔细检查您的副本集配置。在其中一个副本集成员上运行rs.status()
,并确保每个成员的“名称”字段实际上是正确的,并从运行应用程序的计算机中解析。
答案 1 :(得分:3)
检查您的connectTimeoutMS
和socketTimeoutMS
。可能是,它很小?
答案 2 :(得分:2)
我也遇到过这个问题。
rs.status()
并记下“syncingTo”字段的计算机名称。/etc/hosts
。有关配置/etc/hosts
的Mongo文档here。