Mongo在数据查找时找不到master
我正在使用 pymongo 运行大型数据更新。要运行更新,需要使用collection.find_one(unique criteria)
找到各个记录,进行更改,批量更新,最后使用db.collection.save([要保存的长记录列表])
在我的本地计算机(运行 1.6.3)上,导入工作正常。
在比我的本地计算机快得多的远程服务器(运行1.6.0)上,我可以很好地完成部分插入,但在查找原始记录时会突然出现以下错误:
connection = Connection(...)
...
raise AutoReconnect("could not find master/primary")
pymongo.errors.AutoReconnect: could not find master/primary
记录数我能通过的情况有所不同,但不是随机的。
起初我以为我遇到了连接限制。我在每次记录查找后开始手动关闭连接:
collection.database.connection.disconnect()
这并没有解决问题。我走在正确的轨道上吗?
I am running a large data update using pymongo. To run the updates, individual records are found using collection.find_one(unique criteria)
, changes are made, the updates are batched, and finally sent in chunks using db.collection.save([long list of records to save])
On my local machine (running 1.6.3), the imports work fine.
On a remote server (running 1.6.0), which is much faster than my local machine, I can get through a portion of the inserts just fine, but then will suddenly get the following error when looking up original records:
connection = Connection(...)
...
raise AutoReconnect("could not find master/primary")
pymongo.errors.AutoReconnect: could not find master/primary
The number of records I can get through is varies somewhat, but is not random.
At first I thought I was running into the connection limit. I started closing connections manually after each record lookup:
collection.database.connection.disconnect()
Which didn't solve the problem. Am I on the right track?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因此,这里存在一些潜在的问题:
该错误表明现有连接已以某种方式失效。发生这种情况的原因有很多。
发生这种情况的最常见原因是副本集的主节点已下台或发生故障。在这种情况下,您的代码需要:
你在这样做吗?
您运行的是副本集还是主/从?
您对这些服务器的性能有任何跟踪吗?
他们有网络问题吗?
他们在互换角色吗?
异常“发生”在哪里?它来自连接本身还是保存命令?
在撰写本文时,1.6.0 是 MongoDB 的一个非常旧的版本。在后续的 1.6.x 版本和 1.7.x 版本中修复了多个复制错误。 (我们已经是 1.8.1rc-0)
我会首先查看您的服务器发生的情况,但这很可能会引导您走上升级之路。
So there are a couple of potential issues here:
That error indicates that the existing connection has somehow been invalidated. There are a number of reasons this could happen.
The most common reason this happens is that that the Primary of a Replica Set has stepped down or has failed. In this case your code needs to:
Are you doing this?
Are you running Replica Sets or Master/Slave?
Do you have any tracking for the performance of these servers?
Are they having network issues?
Are they switching roles?
Where is the exception "happening"? Is it coming from the connection itself or the save command?
As of this writing, 1.6.0 is a very old version of MongoDB. There were multiple replication bugs fixed in the subsequent 1.6.x versions and 1.7.x versions. (we're already at 1.8.1rc-0)
I would start by looking at what's happening with your servers, but that may well lead you down the upgrade path.
我在与 pymongo 的交互式 python 使用中遇到了这个问题,我让会话空闲并在返回时遇到 AutoReconnect 。我是这样处理的:
YMMV
I've encountered this problem in interactive python usage with pymongo, where I leave the session idle and encounter AutoReconnect upon returning. I've handled it this way:
YMMV