|
21 | 21 | _tx_ctx_impl, |
22 | 22 | tracing, |
23 | 23 | ) |
| 24 | +from ._errors import check_retriable_error |
24 | 25 |
|
25 | 26 | try: |
26 | 27 | from . import interceptor |
@@ -950,56 +951,28 @@ def retry_operation_impl(callee, retry_settings=None, *args, **kwargs): |
950 | 951 | if result.exc is not None: |
951 | 952 | raise result.exc |
952 | 953 |
|
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: |
983 | 955 | status = e |
984 | 956 | retry_settings.on_ydb_error_callback(e) |
985 | | - yield YdbRetryOperationSleepOpt( |
986 | | - retry_settings.fast_backoff.calc_timeout(attempt) |
987 | | - ) |
988 | 957 |
|
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: |
994 | 960 | raise |
995 | 961 |
|
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 | + ] |
999 | 968 |
|
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) |
1003 | 976 |
|
1004 | 977 | except Exception as e: |
1005 | 978 | # you should provide your own handler you want |
|
0 commit comments