Skip to content

Commit 0f03986

Browse files
committed
removed all retryable tracking logic
1 parent cf2d756 commit 0f03986

8 files changed

Lines changed: 18 additions & 42 deletions

File tree

pymongo/asynchronous/helpers.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@
2222
import socket
2323
import sys
2424
import time as time # noqa: PLC0414 # needed in sync version
25-
from contextvars import ContextVar
2625
from typing import (
2726
Any,
2827
Callable,
2928
TypeVar,
3029
cast,
3130
)
3231

33-
from pymongo import _csot
32+
from pymongo import _csot, common
3433
from pymongo.errors import (
3534
OperationFailure,
3635
)
@@ -77,13 +76,9 @@ async def inner(*args: Any, **kwargs: Any) -> Any:
7776
return cast(F, inner)
7877

7978

80-
_MAX_RETRIES = 2
8179
_BACKOFF_INITIAL = 0.1
8280
_BACKOFF_MAX = 10
8381

84-
# Context variable used to pass the current retry attempt number to conn.command()
85-
# so that retry metadata can be injected into outgoing command bodies.
86-
_RETRY_ATTEMPT: ContextVar[int] = ContextVar("_retry_attempt", default=0)
8782
DEFAULT_RETRY_TOKEN_CAPACITY = 1000.0
8883
DEFAULT_RETRY_TOKEN_RETURN = 0.1
8984

@@ -133,7 +128,7 @@ class _RetryPolicy:
133128
def __init__(
134129
self,
135130
token_bucket: _TokenBucket,
136-
attempts: int = _MAX_RETRIES,
131+
attempts: int = common._MAX_RETRIES,
137132
backoff_initial: float = _BACKOFF_INITIAL,
138133
backoff_max: float = _BACKOFF_MAX,
139134
adaptive_retry: bool = False,

pymongo/asynchronous/mongo_client.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
from pymongo.asynchronous.client_session import _SESSION, _EmptyServerSession
7070
from pymongo.asynchronous.command_cursor import AsyncCommandCursor
7171
from pymongo.asynchronous.helpers import (
72-
_RETRY_ATTEMPT,
7372
_RetryPolicy,
7473
_TokenBucket,
7574
)
@@ -897,7 +896,7 @@ def __init__(
897896

898897
self._retry_policy = _RetryPolicy(
899898
_TokenBucket(),
900-
attempts=self._options.max_adaptive_retries,
899+
attempts=self._options.max_retries,
901900
adaptive_retry=self._options.adaptive_retries,
902901
)
903902

@@ -2823,7 +2822,6 @@ async def run(self) -> T:
28232822

28242823
while True:
28252824
self._check_last_error(check_csot=True)
2826-
retry_token = _RETRY_ATTEMPT.set(self._attempt_number)
28272825
try:
28282826
res = await self._read() if self._is_read else await self._write()
28292827
await self._retry_policy.record_success(self._attempt_number > 0)
@@ -2950,8 +2948,6 @@ async def run(self) -> T:
29502948
else:
29512949
raise
29522950
await asyncio.sleep(delay)
2953-
finally:
2954-
_RETRY_ATTEMPT.reset(retry_token)
29552951

29562952
def _is_not_eligible_for_retry(self) -> bool:
29572953
"""Checks if the exchange is not eligible for retry"""

pymongo/asynchronous/pool.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from bson import DEFAULT_CODEC_OPTIONS
4040
from pymongo import _csot, helpers_shared
4141
from pymongo.asynchronous.client_session import _validate_session_write_concern
42-
from pymongo.asynchronous.helpers import _RETRY_ATTEMPT, _handle_reauth
42+
from pymongo.asynchronous.helpers import _handle_reauth
4343
from pymongo.asynchronous.network import command
4444
from pymongo.common import (
4545
MAX_BSON_SIZE,
@@ -395,9 +395,6 @@ async def command(
395395
if session:
396396
session._apply_to(spec, retryable_write, read_preference, self)
397397
self.send_cluster_time(spec, session, client)
398-
retry_attempt = _RETRY_ATTEMPT.get()
399-
if retry_attempt > 0:
400-
spec["retry"] = retry_attempt
401398
listeners = self.listeners if publish_events else None
402399
unacknowledged = bool(write_concern and not write_concern.acknowledged)
403400
if self.op_msg_enabled:

pymongo/client_options.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,10 @@ def __init__(
240240
if "adaptive_retries" in options
241241
else options.get("adaptiveretries", common.ADAPTIVE_RETRIES)
242242
)
243-
self.__max_adaptive_retries = (
244-
options.get("max_adaptive_retries", common.MAX_ADAPTIVE_RETRIES)
245-
if "max_adaptive_retries" in options
246-
else options.get("maxadaptiveretries", common.MAX_ADAPTIVE_RETRIES)
243+
self.__max_retries = (
244+
options.get("max_retries", common._MAX_RETRIES)
245+
if "max_retries" in options
246+
else options.get("maxretries", common._MAX_RETRIES)
247247
)
248248
self.__enable_overload_retargeting = (
249249
options.get("enable_overload_retargeting", common.ENABLE_OVERLOAD_RETARGETING)
@@ -371,12 +371,12 @@ def adaptive_retries(self) -> bool:
371371
return self.__adaptive_retries
372372

373373
@property
374-
def max_adaptive_retries(self) -> int:
375-
"""The configured maxAdaptiveRetries option.
374+
def max_retries(self) -> int:
375+
"""The configured maxRetries option.
376376
377377
.. versionadded:: 4.XX
378378
"""
379-
return self.__max_adaptive_retries
379+
return self.__max_retries
380380

381381
@property
382382
def enable_overload_retargeting(self) -> bool:

pymongo/common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@
143143
# Default value for adaptiveRetries
144144
ADAPTIVE_RETRIES = False
145145

146-
# Default value for maxAdaptiveRetries
147-
MAX_ADAPTIVE_RETRIES = 2
146+
# Default value for max retries
147+
_MAX_RETRIES = 2
148148

149149
# Default value for enableOverloadRetargeting
150150
ENABLE_OVERLOAD_RETARGETING = False
@@ -782,7 +782,7 @@ def validate_server_monitoring_mode(option: str, value: str) -> str:
782782
"auto_encryption_opts": validate_auto_encryption_opts_or_none,
783783
"authoidcallowedhosts": validate_list,
784784
"adaptive_retries": validate_boolean_or_string,
785-
"max_adaptive_retries": validate_non_negative_integer,
785+
"max_retries": validate_non_negative_integer,
786786
"enable_overload_retargeting": validate_boolean_or_string,
787787
}
788788

pymongo/synchronous/helpers.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@
2222
import socket
2323
import sys
2424
import time as time # noqa: PLC0414 # needed in sync version
25-
from contextvars import ContextVar
2625
from typing import (
2726
Any,
2827
Callable,
2928
TypeVar,
3029
cast,
3130
)
3231

33-
from pymongo import _csot
32+
from pymongo import _csot, common
3433
from pymongo.errors import (
3534
OperationFailure,
3635
)
@@ -77,13 +76,9 @@ def inner(*args: Any, **kwargs: Any) -> Any:
7776
return cast(F, inner)
7877

7978

80-
_MAX_RETRIES = 2
8179
_BACKOFF_INITIAL = 0.1
8280
_BACKOFF_MAX = 10
8381

84-
# Context variable used to pass the current retry attempt number to conn.command()
85-
# so that retry metadata can be injected into outgoing command bodies.
86-
_RETRY_ATTEMPT: ContextVar[int] = ContextVar("_retry_attempt", default=0)
8782
DEFAULT_RETRY_TOKEN_CAPACITY = 1000.0
8883
DEFAULT_RETRY_TOKEN_RETURN = 0.1
8984

@@ -133,7 +128,7 @@ class _RetryPolicy:
133128
def __init__(
134129
self,
135130
token_bucket: _TokenBucket,
136-
attempts: int = _MAX_RETRIES,
131+
attempts: int = common._MAX_RETRIES,
137132
backoff_initial: float = _BACKOFF_INITIAL,
138133
backoff_max: float = _BACKOFF_MAX,
139134
adaptive_retry: bool = False,

pymongo/synchronous/mongo_client.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@
112112
from pymongo.synchronous.client_session import _SESSION, _EmptyServerSession
113113
from pymongo.synchronous.command_cursor import CommandCursor
114114
from pymongo.synchronous.helpers import (
115-
_RETRY_ATTEMPT,
116115
_RetryPolicy,
117116
_TokenBucket,
118117
)
@@ -897,7 +896,7 @@ def __init__(
897896

898897
self._retry_policy = _RetryPolicy(
899898
_TokenBucket(),
900-
attempts=self._options.max_adaptive_retries,
899+
attempts=self._options.max_retries,
901900
adaptive_retry=self._options.adaptive_retries,
902901
)
903902

@@ -2813,7 +2812,6 @@ def run(self) -> T:
28132812

28142813
while True:
28152814
self._check_last_error(check_csot=True)
2816-
retry_token = _RETRY_ATTEMPT.set(self._attempt_number)
28172815
try:
28182816
res = self._read() if self._is_read else self._write()
28192817
self._retry_policy.record_success(self._attempt_number > 0)
@@ -2940,8 +2938,6 @@ def run(self) -> T:
29402938
else:
29412939
raise
29422940
time.sleep(delay)
2943-
finally:
2944-
_RETRY_ATTEMPT.reset(retry_token)
29452941

29462942
def _is_not_eligible_for_retry(self) -> bool:
29472943
"""Checks if the exchange is not eligible for retry"""

pymongo/synchronous/pool.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
from pymongo.server_type import SERVER_TYPE
8989
from pymongo.socket_checker import SocketChecker
9090
from pymongo.synchronous.client_session import _validate_session_write_concern
91-
from pymongo.synchronous.helpers import _RETRY_ATTEMPT, _handle_reauth
91+
from pymongo.synchronous.helpers import _handle_reauth
9292
from pymongo.synchronous.network import command
9393

9494
if TYPE_CHECKING:
@@ -395,9 +395,6 @@ def command(
395395
if session:
396396
session._apply_to(spec, retryable_write, read_preference, self)
397397
self.send_cluster_time(spec, session, client)
398-
retry_attempt = _RETRY_ATTEMPT.get()
399-
if retry_attempt > 0:
400-
spec["retry"] = retry_attempt
401398
listeners = self.listeners if publish_events else None
402399
unacknowledged = bool(write_concern and not write_concern.acknowledged)
403400
if self.op_msg_enabled:

0 commit comments

Comments
 (0)