Skip to content

Commit 71ec0db

Browse files
committed
extract error check to external function
1 parent b10af45 commit 71ec0db

File tree

2 files changed

+18
-45
lines changed

2 files changed

+18
-45
lines changed

ydb/_errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
]
1919

2020

21-
def check_retriable_error(err, retry_settings, attempt) -> "ErrorRetryInfo":
21+
def check_retriable_error(err, retry_settings, attempt):
2222
if isinstance(err, issues.NotFound):
2323
if retry_settings.retry_not_found:
2424
return ErrorRetryInfo(True, retry_settings.fast_backoff.calc_timeout(attempt))

ydb/table.py

Lines changed: 17 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
_tx_ctx_impl,
2222
tracing,
2323
)
24+
from ._errors import check_retriable_error
2425

2526
try:
2627
from . import interceptor
@@ -950,56 +951,28 @@ def retry_operation_impl(callee, retry_settings=None, *args, **kwargs):
950951
if result.exc is not None:
951952
raise result.exc
952953

953-
except (
954-
issues.Aborted,
955-
issues.BadSession,
956-
issues.NotFound,
957-
issues.InternalError,
958-
) as e:
959-
status = e
960-
retry_settings.on_ydb_error_callback(e)
961-
962-
if isinstance(e, issues.NotFound) and not retry_settings.retry_not_found:
963-
raise e
964-
965-
if (
966-
isinstance(e, issues.InternalError)
967-
and not retry_settings.retry_internal_error
968-
):
969-
raise e
970-
971-
except (
972-
issues.Overloaded,
973-
issues.SessionPoolEmpty,
974-
issues.ConnectionError,
975-
) as e:
976-
status = e
977-
retry_settings.on_ydb_error_callback(e)
978-
yield YdbRetryOperationSleepOpt(
979-
retry_settings.slow_backoff.calc_timeout(attempt)
980-
)
981-
982-
except issues.Unavailable as e:
954+
except issues.Error as e:
983955
status = e
984956
retry_settings.on_ydb_error_callback(e)
985-
yield YdbRetryOperationSleepOpt(
986-
retry_settings.fast_backoff.calc_timeout(attempt)
987-
)
988957

989-
except issues.Undetermined as e:
990-
status = e
991-
retry_settings.on_ydb_error_callback(e)
992-
if not retry_settings.idempotent:
993-
# operation is not idempotent, so we cannot retry.
958+
retriable_info = check_retriable_error(e, retry_settings, attempt)
959+
if not retriable_info.is_retriable:
994960
raise
995961

996-
yield YdbRetryOperationSleepOpt(
997-
retry_settings.fast_backoff.calc_timeout(attempt)
998-
)
962+
skip_yield_error_types = [
963+
issues.Aborted,
964+
issues.BadSession,
965+
issues.NotFound,
966+
issues.InternalError,
967+
]
999968

1000-
except issues.Error as e:
1001-
retry_settings.on_ydb_error_callback(e)
1002-
raise
969+
yield_sleep = True
970+
for t in skip_yield_error_types:
971+
if isinstance(e, t):
972+
yield_sleep = False
973+
974+
if yield_sleep:
975+
yield YdbRetryOperationSleepOpt(retriable_info.sleep_timeout_seconds)
1003976

1004977
except Exception as e:
1005978
# you should provide your own handler you want

0 commit comments

Comments
 (0)