PYTHON-2543 Do not mark a server unknown from a "writeErrors" response (#570)
This commit is contained in:
parent
3e97712728
commit
20d5a9cf81
@ -32,7 +32,8 @@ from pymongo.errors import (ConnectionFailure,
|
||||
NotMasterError,
|
||||
OperationFailure,
|
||||
PyMongoError,
|
||||
ServerSelectionTimeoutError)
|
||||
ServerSelectionTimeoutError,
|
||||
WriteError)
|
||||
from pymongo.monitor import SrvMonitor
|
||||
from pymongo.pool import PoolOptions
|
||||
from pymongo.server import Server
|
||||
@ -578,6 +579,9 @@ class Topology(object):
|
||||
# operation fails because of any network error besides a socket
|
||||
# timeout...."
|
||||
return
|
||||
elif issubclass(exc_type, WriteError):
|
||||
# Ignore writeErrors.
|
||||
return
|
||||
elif issubclass(exc_type, NotMasterError):
|
||||
# As per the SDAM spec if:
|
||||
# - the server sees a "not master" error, and
|
||||
|
||||
@ -0,0 +1,96 @@
|
||||
{
|
||||
"description": "writeErrors field is ignored",
|
||||
"uri": "mongodb://a/?replicaSet=rs",
|
||||
"phases": [
|
||||
{
|
||||
"description": "Primary A is discovered",
|
||||
"responses": [
|
||||
[
|
||||
"a:27017",
|
||||
{
|
||||
"ok": 1,
|
||||
"ismaster": true,
|
||||
"hosts": [
|
||||
"a:27017"
|
||||
],
|
||||
"setName": "rs",
|
||||
"minWireVersion": 0,
|
||||
"maxWireVersion": 9,
|
||||
"topologyVersion": {
|
||||
"processId": {
|
||||
"$oid": "000000000000000000000001"
|
||||
},
|
||||
"counter": {
|
||||
"$numberLong": "1"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
],
|
||||
"outcome": {
|
||||
"servers": {
|
||||
"a:27017": {
|
||||
"type": "RSPrimary",
|
||||
"setName": "rs",
|
||||
"topologyVersion": {
|
||||
"processId": {
|
||||
"$oid": "000000000000000000000001"
|
||||
},
|
||||
"counter": {
|
||||
"$numberLong": "1"
|
||||
}
|
||||
},
|
||||
"pool": {
|
||||
"generation": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
"topologyType": "ReplicaSetWithPrimary",
|
||||
"logicalSessionTimeoutMinutes": null,
|
||||
"setName": "rs"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Ignore command error with writeErrors field",
|
||||
"applicationErrors": [
|
||||
{
|
||||
"address": "a:27017",
|
||||
"when": "afterHandshakeCompletes",
|
||||
"maxWireVersion": 9,
|
||||
"type": "command",
|
||||
"response": {
|
||||
"ok": 1,
|
||||
"writeErrors": [
|
||||
{
|
||||
"errmsg": "NotMasterNoSlaveOk",
|
||||
"code": 13435
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"outcome": {
|
||||
"servers": {
|
||||
"a:27017": {
|
||||
"type": "RSPrimary",
|
||||
"setName": "rs",
|
||||
"topologyVersion": {
|
||||
"processId": {
|
||||
"$oid": "000000000000000000000001"
|
||||
},
|
||||
"counter": {
|
||||
"$numberLong": "1"
|
||||
}
|
||||
},
|
||||
"pool": {
|
||||
"generation": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
"topologyType": "ReplicaSetWithPrimary",
|
||||
"logicalSessionTimeoutMinutes": null,
|
||||
"setName": "rs"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -29,7 +29,8 @@ from pymongo.errors import (AutoReconnect,
|
||||
NetworkTimeout,
|
||||
NotMasterError,
|
||||
OperationFailure)
|
||||
from pymongo.helpers import _check_command_response
|
||||
from pymongo.helpers import (_check_command_response,
|
||||
_check_write_command_response)
|
||||
from pymongo.ismaster import IsMaster
|
||||
from pymongo.server_description import ServerDescription, SERVER_TYPE
|
||||
from pymongo.settings import TopologySettings
|
||||
@ -94,6 +95,7 @@ def got_app_error(topology, app_error):
|
||||
try:
|
||||
if error_type == 'command':
|
||||
_check_command_response(app_error['response'], max_wire_version)
|
||||
_check_write_command_response(app_error['response'])
|
||||
elif error_type == 'network':
|
||||
raise AutoReconnect('mock non-timeout network error')
|
||||
elif error_type == 'timeout':
|
||||
|
||||
Loading…
Reference in New Issue
Block a user