pymongoで接続が常にに接続しようとしているように見えます。をPRIMARYから読み込み、ダウンしているときは新しい選出プロセスが完了するまでソケットエラーが発生します。マスタがダウンしたときにスレーブから読み取る
replicSetの目的の1つは読み込み負荷のバランスをとることですが、ここで重要な概念が欠けていない限り、これは大きな欠陥のようです。
私はslave_ok thingyを提供していますが、利用可能なプライマリがない限り、読み込みはできませんが、書き込みはできません。
私はポート8910,8911と8912でmongodの3つのインスタンスを立ち上げ、最後のものが残っているときに次々にそれらを取り除きました。そこから読める方法はありませんでした。あなたはmongo(cli) 。使用中
バージョン:
mongodb: 2.0.2
pymongo: 2.1.1
ダウン1、次いで3つのインスタンス(プライマリもの)、及びの撮影コンソール出力
>>> collection = Connection("localhost:8910, localhost:8911, localhost:8912", slave_okay=True).testdb['TEST']
>>> len(list(collection.find()))
0
>>> collection.insert({"a": 1})
ObjectId('4f4a491bb9efb72ec8000045')
>>> len(list(collection.find()))
1
pymongo ...
>>> len(list(collection.find()))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/cursor.py", line 703, in next
if len(self.__data) or self._refresh():
File "/usr/local/lib/python2.7/dist-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/cursor.py", line 666, in _refresh
self.__uuid_subtype))
File "/usr/local/lib/python2.7/dist-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/cursor.py", line 616, in __send_message
**kwargs)
File "/usr/local/lib/python2.7/dist-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/connection.py", line 880, in _send_message_with_response
sock = self.__socket()
File "/usr/local/lib/python2.7/dist-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/connection.py", line 686, in __socket
sock, from_pool = self.__pool.get_socket(host, port)
File "/usr/local/lib/python2.7/dist-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/connection.py", line 165, in get_socket
self.sock = (pid, self.connect(host, port))
File "/usr/local/lib/python2.7/dist-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/connection.py", line 127, in connect
s.connect((host, port))
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 111] Connection refused
>>>
新しいプライマリが選出された
、そして...
>>> len(list(collection.find()))
1
は
>>> collection.insert({"c": 3})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/collection.py", line 312, in insert
continue_on_error, self.__uuid_subtype), safe)
File "/usr/local/lib/python2.7/dist-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/connection.py", line 811, in _send_message
sock = self.__socket()
File "/usr/local/lib/python2.7/dist-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/connection.py", line 674, in __socket
host, port = self.__find_node()
File "/usr/local/lib/python2.7/dist-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/connection.py", line 659, in __find_node
raise AutoReconnect(', '.join(errors))
pymongo.errors.AutoReconnect: could not connect to localhost:8911: [Errno -5] No address associated with hostname, could not connect to localhost:8911: [Errno 111] Connection refused, could not connect to localhost:8912: [Errno 111] Connection refused, could not connect to localhost:8912: [Errno -5] No address associated with hostname, localhost:8910 is not primary or master
>>>
>>>
>>> collection.insert({"c": 3})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/collection.py", line 312, in insert
continue_on_error, self.__uuid_subtype), safe)
File "/usr/local/lib/python2.7/dist-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/connection.py", line 811, in _send_message
sock = self.__socket()
File "/usr/local/lib/python2.7/dist-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/connection.py", line 674, in __socket
host, port = self.__find_node()
File "/usr/local/lib/python2.7/dist-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/connection.py", line 659, in __find_node
raise AutoReconnect(', '.join(errors))
pymongo.errors.AutoReconnect: could not connect to localhost:8911: [Errno -5] No address associated with hostname, could not connect to localhost:8911: [Errno 111] Connection refused, could not connect to localhost:8912: [Errno 111] Connection refused, could not connect to localhost:8912: [Errno -5] No address associated with hostname, localhost:8910 is not primary or master
>>>
>>>
>>> len(list(collection.find()))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/cursor.py", line 703, in next
if len(self.__data) or self._refresh():
File "/usr/local/lib/python2.7/dist-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/cursor.py", line 666, in _refresh
self.__uuid_subtype))
File "/usr/local/lib/python2.7/dist-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/cursor.py", line 616, in __send_message
**kwargs)
File "/usr/local/lib/python2.7/dist-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/connection.py", line 880, in _send_message_with_response
sock = self.__socket()
File "/usr/local/lib/python2.7/dist-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/connection.py", line 674, in __socket
host, port = self.__find_node()
File "/usr/local/lib/python2.7/dist-packages/pymongo-2.1.1-py2.7-linux-x86_64.egg/pymongo/connection.py", line 659, in __find_node
raise AutoReconnect(', '.join(errors))
pymongo.errors.AutoReconnect: could not connect to localhost:8911: [Errno -5] No
address associated with hostname, could not connect to localhost:8911: [Errno 111]
Connection refused, could not connect to localhost:8912: [Errno 111] Connection refused,
could not connect to localhost:8912: [Errno -5] No address associated with hostname,
localhost:8910 is not primary or master
>>>
モンゴ(CLI)...その後3のうちの2番目のインスタンスを降ろすこと、および出力
SECONDARY> rs.status()
{
"set" : "myset",
"date" : ISODate("2012-02-26T15:09:49Z"),
"myState" : 2,
"members" : [
{
"_id" : 0,
"name" : "localhost:8910",
"health" : 0,
"state" : 8,
"stateStr" : "(not reachable/healthy)",
"uptime" : 0,
"optime" : {
"t" : 1330268443000,
"i" : 1
},
"optimeDate" : ISODate("2012-02-26T15:00:43Z"),
"lastHeartbeat" : ISODate("2012-02-26T15:09:37Z"),
"pingMs" : 0,
"errmsg" : "socket exception"
},
{
"_id" : 1,
"name" : "localhost:8911",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"optime" : {
"t" : 1330268443000,
"i" : 1
},
"optimeDate" : ISODate("2012-02-26T15:00:43Z"),
"self" : true
},
{
"_id" : 2,
"name" : "localhost:8912",
"health" : 0,
"state" : 8,
"stateStr" : "(not reachable/healthy)",
"uptime" : 0,
"optime" : {
"t" : 1330268443000,
"i" : 1
},
"optimeDate" : ISODate("2012-02-26T15:00:43Z"),
"lastHeartbeat" : ISODate("2012-02-26T15:09:37Z"),
"pingMs" : 0,
"errmsg" : "socket exception"
}
],
"ok" : 1
}
SECONDARY>
SECONDARY>
SECONDARY> db.TEST.find().count()
54
SECONDARY> db.TEST.insert({eeee:23232323})
not master
SECONDARY>
SECONDARY> db.TEST.find().count()
54
あなたはプレーンな接続の種類の代わりにReplicaSetConnectionタイプを使用してみましたか?最近のPyMongoのリリースで登場し、PyMongoドライバをレプリカセットで使用するという面倒を少しでも修正したようだ。 – mattbornski
チップのおかげでありがとう、私はReplicaSetConnectionと非常に同じ問題を遵守します。 –