Revert "PYTHON-2970 Prioritize electionId over setVersion for stale primary check (#845)"
This reverts commit 52d77952d6.
This commit is contained in:
parent
ee262d680f
commit
ab9ca27aad
@ -12,8 +12,6 @@ PyMongo 3.13 drops support for Python 3.4.
|
||||
Bug fixes
|
||||
.........
|
||||
|
||||
- Fixed a bug where the client could be unable to discover the new primary
|
||||
after a simultaneous replica set election and reconfig (`PYTHON-2970`_).
|
||||
- Fixed a memory leak bug when calling :func:`~bson.decode_all` without a
|
||||
``codec_options`` argument (`PYTHON-3222`_).
|
||||
- Fixed a bug where :func:`~bson.decode_all` did not accept ``codec_options``
|
||||
@ -29,7 +27,6 @@ Deprecations
|
||||
See the `PyMongo 3.13.0 release notes in JIRA`_ for the list of resolved issues
|
||||
in this release.
|
||||
|
||||
.. _PYTHON-2970: https://jira.mongodb.org/browse/PYTHON-2970
|
||||
.. _PYTHON-3222: https://jira.mongodb.org/browse/PYTHON-3222
|
||||
.. _PyMongo 3.13.0 release notes in JIRA: https://jira.mongodb.org/secure/ReleaseNote.jspa?projectId=10004&version=31570
|
||||
|
||||
|
||||
@ -3109,8 +3109,6 @@ class Collection(common.BaseObject):
|
||||
|
||||
- https://docs.mongodb.com/manual/reference/map-reduce-to-aggregation-pipeline/
|
||||
- https://docs.mongodb.com/manual/reference/aggregation-commands-comparison/
|
||||
|
||||
.. _mapReduce command: https://docs.mongodb.com/manual/reference/command/mapReduce/
|
||||
.. versionchanged:: 3.4
|
||||
Added the `collation` option.
|
||||
.. versionchanged:: 2.2
|
||||
@ -3119,7 +3117,6 @@ class Collection(common.BaseObject):
|
||||
.. _map reduce command: http://docs.mongodb.org/manual/reference/command/mapReduce/
|
||||
|
||||
.. seealso:: The MongoDB documentation on `mapreduce <https://dochub.mongodb.org/core/mapreduce>`_.
|
||||
|
||||
"""
|
||||
warnings.warn(
|
||||
'map_reduce is deprecated, use aggregate instead',
|
||||
@ -3183,7 +3180,7 @@ class Collection(common.BaseObject):
|
||||
.. versionchanged:: 3.4
|
||||
Added the `collation` option.
|
||||
|
||||
.. _mapReduce command: https://docs.mongodb.com/manual/reference/command/mapReduce/
|
||||
.. _map reduce command: http://docs.mongodb.org/manual/reference/command/mapReduce/
|
||||
"""
|
||||
warnings.warn(
|
||||
'inline_map_reduce is deprecated, use aggregate instead',
|
||||
|
||||
@ -16,7 +16,6 @@
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
from bson.min_key import MinKey
|
||||
from pymongo import common
|
||||
from pymongo.errors import ConfigurationError
|
||||
from pymongo.read_preferences import ReadPreference
|
||||
@ -495,16 +494,24 @@ def _update_rs_from_primary(
|
||||
sds.pop(server_description.address)
|
||||
return (_check_has_primary(sds), replica_set_name, max_set_version, max_election_id)
|
||||
|
||||
new_election_tuple = server_description.election_id, server_description.set_version
|
||||
max_election_tuple = max_election_id, max_set_version
|
||||
new_election_safe = tuple(MinKey() if i is None else i for i in new_election_tuple)
|
||||
max_election_safe = tuple(MinKey() if i is None else i for i in max_election_tuple)
|
||||
if new_election_safe >= max_election_safe:
|
||||
max_election_id, max_set_version = new_election_tuple
|
||||
else:
|
||||
# Stale primary, set to type Unknown.
|
||||
sds[server_description.address] = server_description.to_unknown()
|
||||
return _check_has_primary(sds), replica_set_name, max_set_version, max_election_id
|
||||
max_election_tuple = max_set_version, max_election_id
|
||||
if None not in server_description.election_tuple:
|
||||
if (
|
||||
None not in max_election_tuple
|
||||
and max_election_tuple > server_description.election_tuple
|
||||
):
|
||||
|
||||
# Stale primary, set to type Unknown.
|
||||
sds[server_description.address] = server_description.to_unknown()
|
||||
return (_check_has_primary(sds), replica_set_name, max_set_version, max_election_id)
|
||||
|
||||
max_election_id = server_description.election_id
|
||||
|
||||
if server_description.set_version is not None and (
|
||||
max_set_version is None or server_description.set_version > max_set_version
|
||||
):
|
||||
|
||||
max_set_version = server_description.set_version
|
||||
|
||||
# We've heard from the primary. Is it the same primary as before?
|
||||
for server in sds.values():
|
||||
|
||||
@ -1,92 +0,0 @@
|
||||
{
|
||||
"description": "ElectionId is considered higher precedence than setVersion",
|
||||
"uri": "mongodb://a/?replicaSet=rs",
|
||||
"phases": [
|
||||
{
|
||||
"responses": [
|
||||
[
|
||||
"a:27017",
|
||||
{
|
||||
"ok": 1,
|
||||
"helloOk": true,
|
||||
"isWritablePrimary": true,
|
||||
"hosts": [
|
||||
"a:27017",
|
||||
"b:27017"
|
||||
],
|
||||
"setName": "rs",
|
||||
"setVersion": 1,
|
||||
"electionId": {
|
||||
"$oid": "000000000000000000000001"
|
||||
},
|
||||
"minWireVersion": 0,
|
||||
"maxWireVersion": 6
|
||||
}
|
||||
],
|
||||
[
|
||||
"b:27017",
|
||||
{
|
||||
"ok": 1,
|
||||
"helloOk": true,
|
||||
"isWritablePrimary": true,
|
||||
"hosts": [
|
||||
"a:27017",
|
||||
"b:27017"
|
||||
],
|
||||
"setName": "rs",
|
||||
"setVersion": 2,
|
||||
"electionId": {
|
||||
"$oid": "000000000000000000000001"
|
||||
},
|
||||
"minWireVersion": 0,
|
||||
"maxWireVersion": 6
|
||||
}
|
||||
],
|
||||
[
|
||||
"a:27017",
|
||||
{
|
||||
"ok": 1,
|
||||
"helloOk": true,
|
||||
"isWritablePrimary": true,
|
||||
"hosts": [
|
||||
"a:27017",
|
||||
"b:27017"
|
||||
],
|
||||
"setName": "rs",
|
||||
"setVersion": 1,
|
||||
"electionId": {
|
||||
"$oid": "000000000000000000000002"
|
||||
},
|
||||
"minWireVersion": 0,
|
||||
"maxWireVersion": 6
|
||||
}
|
||||
]
|
||||
],
|
||||
"outcome": {
|
||||
"servers": {
|
||||
"a:27017": {
|
||||
"type": "RSPrimary",
|
||||
"setName": "rs",
|
||||
"setVersion": 1,
|
||||
"electionId": {
|
||||
"$oid": "000000000000000000000002"
|
||||
}
|
||||
},
|
||||
"b:27017": {
|
||||
"type": "Unknown",
|
||||
"setName": null,
|
||||
"setVersion": null,
|
||||
"electionId": null
|
||||
}
|
||||
},
|
||||
"topologyType": "ReplicaSetWithPrimary",
|
||||
"logicalSessionTimeoutMinutes": null,
|
||||
"setName": "rs",
|
||||
"maxSetVersion": 1,
|
||||
"maxElectionId": {
|
||||
"$oid": "000000000000000000000002"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -120,18 +120,15 @@
|
||||
"outcome": {
|
||||
"servers": {
|
||||
"a:27017": {
|
||||
"type": "Unknown",
|
||||
"setName": null,
|
||||
"setVersion": null,
|
||||
"electionId": null
|
||||
},
|
||||
"b:27017": {
|
||||
"type": "RSPrimary",
|
||||
"setName": "rs",
|
||||
"setVersion": 1,
|
||||
"electionId": {
|
||||
"$oid": "000000000000000000000002"
|
||||
}
|
||||
"electionId": null
|
||||
},
|
||||
"b:27017": {
|
||||
"type": "Unknown",
|
||||
"setName": null,
|
||||
"electionId": null
|
||||
},
|
||||
"c:27017": {
|
||||
"type": "Unknown",
|
||||
@ -173,18 +170,15 @@
|
||||
"outcome": {
|
||||
"servers": {
|
||||
"a:27017": {
|
||||
"type": "Unknown",
|
||||
"setName": null,
|
||||
"setVersion": null,
|
||||
"electionId": null
|
||||
},
|
||||
"b:27017": {
|
||||
"type": "RSPrimary",
|
||||
"setName": "rs",
|
||||
"setVersion": 1,
|
||||
"electionId": {
|
||||
"$oid": "000000000000000000000002"
|
||||
}
|
||||
"electionId": null
|
||||
},
|
||||
"b:27017": {
|
||||
"type": "Unknown",
|
||||
"setName": null,
|
||||
"electionId": null
|
||||
},
|
||||
"c:27017": {
|
||||
"type": "Unknown",
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"description": "Secondary ignored when ok is zero",
|
||||
"description": "New primary",
|
||||
"uri": "mongodb://a,b/?replicaSet=rs",
|
||||
"phases": [
|
||||
{
|
||||
|
||||
@ -1,149 +0,0 @@
|
||||
{
|
||||
"description": "Set version rolls back after new primary with higher election Id",
|
||||
"uri": "mongodb://a/?replicaSet=rs",
|
||||
"phases": [
|
||||
{
|
||||
"responses": [
|
||||
[
|
||||
"a:27017",
|
||||
{
|
||||
"ok": 1,
|
||||
"hello": true,
|
||||
"isWritablePrimary": true,
|
||||
"hosts": [
|
||||
"a:27017",
|
||||
"b:27017"
|
||||
],
|
||||
"setName": "rs",
|
||||
"setVersion": 2,
|
||||
"electionId": {
|
||||
"$oid": "000000000000000000000001"
|
||||
},
|
||||
"minWireVersion": 0,
|
||||
"maxWireVersion": 6
|
||||
}
|
||||
]
|
||||
],
|
||||
"outcome": {
|
||||
"servers": {
|
||||
"a:27017": {
|
||||
"type": "RSPrimary",
|
||||
"setName": "rs",
|
||||
"setVersion": 2,
|
||||
"electionId": {
|
||||
"$oid": "000000000000000000000001"
|
||||
}
|
||||
},
|
||||
"b:27017": {
|
||||
"type": "Unknown",
|
||||
"setName": null,
|
||||
"electionId": null
|
||||
}
|
||||
},
|
||||
"topologyType": "ReplicaSetWithPrimary",
|
||||
"logicalSessionTimeoutMinutes": null,
|
||||
"setName": "rs",
|
||||
"maxSetVersion": 2,
|
||||
"maxElectionId": {
|
||||
"$oid": "000000000000000000000001"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"_comment": "Response from new primary with newer election Id",
|
||||
"responses": [
|
||||
[
|
||||
"b:27017",
|
||||
{
|
||||
"ok": 1,
|
||||
"hello": true,
|
||||
"isWritablePrimary": true,
|
||||
"hosts": [
|
||||
"a:27017",
|
||||
"b:27017"
|
||||
],
|
||||
"setName": "rs",
|
||||
"setVersion": 1,
|
||||
"electionId": {
|
||||
"$oid": "000000000000000000000002"
|
||||
},
|
||||
"minWireVersion": 0,
|
||||
"maxWireVersion": 6
|
||||
}
|
||||
]
|
||||
],
|
||||
"outcome": {
|
||||
"servers": {
|
||||
"a:27017": {
|
||||
"type": "Unknown",
|
||||
"setName": null,
|
||||
"electionId": null
|
||||
},
|
||||
"b:27017": {
|
||||
"type": "RSPrimary",
|
||||
"setName": "rs",
|
||||
"setVersion": 1,
|
||||
"electionId": {
|
||||
"$oid": "000000000000000000000002"
|
||||
}
|
||||
}
|
||||
},
|
||||
"topologyType": "ReplicaSetWithPrimary",
|
||||
"logicalSessionTimeoutMinutes": null,
|
||||
"setName": "rs",
|
||||
"maxSetVersion": 1,
|
||||
"maxElectionId": {
|
||||
"$oid": "000000000000000000000002"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"_comment": "Response from stale primary",
|
||||
"responses": [
|
||||
[
|
||||
"a:27017",
|
||||
{
|
||||
"ok": 1,
|
||||
"hello": true,
|
||||
"isWritablePrimary": true,
|
||||
"hosts": [
|
||||
"a:27017",
|
||||
"b:27017"
|
||||
],
|
||||
"setName": "rs",
|
||||
"setVersion": 2,
|
||||
"electionId": {
|
||||
"$oid": "000000000000000000000001"
|
||||
},
|
||||
"minWireVersion": 0,
|
||||
"maxWireVersion": 6
|
||||
}
|
||||
]
|
||||
],
|
||||
"outcome": {
|
||||
"servers": {
|
||||
"a:27017": {
|
||||
"type": "Unknown",
|
||||
"setName": null,
|
||||
"electionId": null
|
||||
},
|
||||
"b:27017": {
|
||||
"type": "RSPrimary",
|
||||
"setName": "rs",
|
||||
"setVersion": 1,
|
||||
"electionId": {
|
||||
"$oid": "000000000000000000000002"
|
||||
}
|
||||
}
|
||||
},
|
||||
"topologyType": "ReplicaSetWithPrimary",
|
||||
"logicalSessionTimeoutMinutes": null,
|
||||
"setName": "rs",
|
||||
"maxSetVersion": 1,
|
||||
"maxElectionId": {
|
||||
"$oid": "000000000000000000000002"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -1,84 +0,0 @@
|
||||
{
|
||||
"description": "setVersion version that is equal is treated the same as greater than if there is no electionId",
|
||||
"uri": "mongodb://a/?replicaSet=rs",
|
||||
"phases": [
|
||||
{
|
||||
"responses": [
|
||||
[
|
||||
"a:27017",
|
||||
{
|
||||
"ok": 1,
|
||||
"helloOk": true,
|
||||
"isWritablePrimary": true,
|
||||
"hosts": [
|
||||
"a:27017",
|
||||
"b:27017"
|
||||
],
|
||||
"setName": "rs",
|
||||
"setVersion": 1,
|
||||
"minWireVersion": 0,
|
||||
"maxWireVersion": 6
|
||||
}
|
||||
]
|
||||
],
|
||||
"outcome": {
|
||||
"servers": {
|
||||
"a:27017": {
|
||||
"type": "RSPrimary",
|
||||
"setName": "rs",
|
||||
"setVersion": 1,
|
||||
"electionId": null
|
||||
},
|
||||
"b:27017": {
|
||||
"type": "Unknown",
|
||||
"setName": null,
|
||||
"electionId": null
|
||||
}
|
||||
},
|
||||
"topologyType": "ReplicaSetWithPrimary",
|
||||
"logicalSessionTimeoutMinutes": null,
|
||||
"setName": "rs",
|
||||
"maxSetVersion": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"responses": [
|
||||
[
|
||||
"b:27017",
|
||||
{
|
||||
"ok": 1,
|
||||
"helloOk": true,
|
||||
"isWritablePrimary": true,
|
||||
"hosts": [
|
||||
"a:27017",
|
||||
"b:27017"
|
||||
],
|
||||
"setName": "rs",
|
||||
"setVersion": 1,
|
||||
"minWireVersion": 0,
|
||||
"maxWireVersion": 6
|
||||
}
|
||||
]
|
||||
],
|
||||
"outcome": {
|
||||
"servers": {
|
||||
"a:27017": {
|
||||
"type": "Unknown",
|
||||
"setName": null,
|
||||
"electionId": null
|
||||
},
|
||||
"b:27017": {
|
||||
"type": "RSPrimary",
|
||||
"setName": "rs",
|
||||
"setVersion": 1,
|
||||
"electionId": null
|
||||
}
|
||||
},
|
||||
"topologyType": "ReplicaSetWithPrimary",
|
||||
"logicalSessionTimeoutMinutes": null,
|
||||
"setName": "rs",
|
||||
"maxSetVersion": 1
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -1,84 +0,0 @@
|
||||
{
|
||||
"description": "setVersion that is greater than maxSetVersion is used if there is no electionId",
|
||||
"uri": "mongodb://a/?replicaSet=rs",
|
||||
"phases": [
|
||||
{
|
||||
"responses": [
|
||||
[
|
||||
"a:27017",
|
||||
{
|
||||
"ok": 1,
|
||||
"helloOk": true,
|
||||
"isWritablePrimary": true,
|
||||
"hosts": [
|
||||
"a:27017",
|
||||
"b:27017"
|
||||
],
|
||||
"setName": "rs",
|
||||
"setVersion": 1,
|
||||
"minWireVersion": 0,
|
||||
"maxWireVersion": 6
|
||||
}
|
||||
]
|
||||
],
|
||||
"outcome": {
|
||||
"servers": {
|
||||
"a:27017": {
|
||||
"type": "RSPrimary",
|
||||
"setName": "rs",
|
||||
"setVersion": 1,
|
||||
"electionId": null
|
||||
},
|
||||
"b:27017": {
|
||||
"type": "Unknown",
|
||||
"setName": null,
|
||||
"electionId": null
|
||||
}
|
||||
},
|
||||
"topologyType": "ReplicaSetWithPrimary",
|
||||
"logicalSessionTimeoutMinutes": null,
|
||||
"setName": "rs",
|
||||
"maxSetVersion": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"responses": [
|
||||
[
|
||||
"b:27017",
|
||||
{
|
||||
"ok": 1,
|
||||
"helloOk": true,
|
||||
"isWritablePrimary": true,
|
||||
"hosts": [
|
||||
"a:27017",
|
||||
"b:27017"
|
||||
],
|
||||
"setName": "rs",
|
||||
"setVersion": 2,
|
||||
"minWireVersion": 0,
|
||||
"maxWireVersion": 6
|
||||
}
|
||||
]
|
||||
],
|
||||
"outcome": {
|
||||
"servers": {
|
||||
"a:27017": {
|
||||
"type": "Unknown",
|
||||
"setName": null,
|
||||
"electionId": null
|
||||
},
|
||||
"b:27017": {
|
||||
"type": "RSPrimary",
|
||||
"setName": "rs",
|
||||
"setVersion": 2,
|
||||
"electionId": null
|
||||
}
|
||||
},
|
||||
"topologyType": "ReplicaSetWithPrimary",
|
||||
"logicalSessionTimeoutMinutes": null,
|
||||
"setName": "rs",
|
||||
"maxSetVersion": 2
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"description": "setVersion that is less than maxSetVersion is ignored if there is no electionId",
|
||||
"description": "setVersion is ignored if there is no electionId",
|
||||
"uri": "mongodb://a/?replicaSet=rs",
|
||||
"phases": [
|
||||
{
|
||||
@ -61,14 +61,14 @@
|
||||
"outcome": {
|
||||
"servers": {
|
||||
"a:27017": {
|
||||
"type": "RSPrimary",
|
||||
"setName": "rs",
|
||||
"setVersion": 2,
|
||||
"type": "Unknown",
|
||||
"setName": null,
|
||||
"electionId": null
|
||||
},
|
||||
"b:27017": {
|
||||
"type": "Unknown",
|
||||
"setName": null,
|
||||
"type": "RSPrimary",
|
||||
"setName": "rs",
|
||||
"setVersion": 1,
|
||||
"electionId": null
|
||||
}
|
||||
},
|
||||
|
||||
@ -69,23 +69,20 @@
|
||||
"outcome": {
|
||||
"servers": {
|
||||
"a:27017": {
|
||||
"type": "RSPrimary",
|
||||
"setName": "rs",
|
||||
"setVersion": 1,
|
||||
"electionId": {
|
||||
"$oid": "000000000000000000000001"
|
||||
}
|
||||
},
|
||||
"b:27017": {
|
||||
"type": "Unknown",
|
||||
"setName": null,
|
||||
"electionId": null
|
||||
},
|
||||
"b:27017": {
|
||||
"type": "RSPrimary",
|
||||
"setName": "rs",
|
||||
"setVersion": 2
|
||||
}
|
||||
},
|
||||
"topologyType": "ReplicaSetWithPrimary",
|
||||
"logicalSessionTimeoutMinutes": null,
|
||||
"setName": "rs",
|
||||
"maxSetVersion": 1,
|
||||
"maxSetVersion": 2,
|
||||
"maxElectionId": {
|
||||
"$oid": "000000000000000000000001"
|
||||
}
|
||||
@ -115,25 +112,22 @@
|
||||
"outcome": {
|
||||
"servers": {
|
||||
"a:27017": {
|
||||
"type": "RSPrimary",
|
||||
"setName": "rs",
|
||||
"setVersion": 1,
|
||||
"electionId": {
|
||||
"$oid": "000000000000000000000002"
|
||||
}
|
||||
},
|
||||
"b:27017": {
|
||||
"type": "Unknown",
|
||||
"setName": null,
|
||||
"electionId": null
|
||||
},
|
||||
"b:27017": {
|
||||
"type": "RSPrimary",
|
||||
"setName": "rs",
|
||||
"setVersion": 2
|
||||
}
|
||||
},
|
||||
"topologyType": "ReplicaSetWithPrimary",
|
||||
"logicalSessionTimeoutMinutes": null,
|
||||
"setName": "rs",
|
||||
"maxSetVersion": 1,
|
||||
"maxSetVersion": 2,
|
||||
"maxElectionId": {
|
||||
"$oid": "000000000000000000000002"
|
||||
"$oid": "000000000000000000000001"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user