-
Notifications
You must be signed in to change notification settings - Fork 65
Make commit_offset call retryable #736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+120
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| import asyncio | ||
| import functools | ||
| import inspect | ||
| import random | ||
| import time | ||
|
|
||
|
|
@@ -161,3 +163,64 @@ async def retry_operation_async(callee, retry_settings=None, *args, **kwargs): | |
| return await next_opt.result | ||
| except BaseException as e: # pylint: disable=W0703 | ||
| next_opt.set_exception(e) | ||
|
|
||
|
|
||
| def ydb_retry( | ||
| max_retries=10, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about use timeout as retries by default? |
||
| max_session_acquire_timeout=None, | ||
| on_ydb_error_callback=None, | ||
| backoff_ceiling=6, | ||
| backoff_slot_duration=1, | ||
| get_session_client_timeout=5, | ||
| fast_backoff_settings=None, | ||
| slow_backoff_settings=None, | ||
| idempotent=False, | ||
| retry_cancelled=False, | ||
| ): | ||
| """ | ||
| Decorator for automatic function retry in case of YDB errors. | ||
|
|
||
| Supports both synchronous and asynchronous functions. | ||
|
|
||
| :param max_retries: Maximum number of retries (default: 10) | ||
| :param max_session_acquire_timeout: Maximum session acquisition timeout (default: None) | ||
| :param on_ydb_error_callback: Callback for handling YDB errors (default: None) | ||
| :param backoff_ceiling: Ceiling for backoff algorithm (default: 6) | ||
| :param backoff_slot_duration: Slot duration for backoff (default: 1) | ||
| :param get_session_client_timeout: Session client timeout (default: 5) | ||
| :param fast_backoff_settings: Fast backoff settings (default: None) | ||
| :param slow_backoff_settings: Slow backoff settings (default: None) | ||
| :param idempotent: Whether the operation is idempotent (default: False) | ||
| :param retry_cancelled: Whether to retry cancelled operations (default: False) | ||
| """ | ||
|
|
||
| def decorator(func): | ||
| retry_settings = RetrySettings( | ||
| max_retries=max_retries, | ||
| max_session_acquire_timeout=max_session_acquire_timeout, | ||
| on_ydb_error_callback=on_ydb_error_callback, | ||
| backoff_ceiling=backoff_ceiling, | ||
| backoff_slot_duration=backoff_slot_duration, | ||
| get_session_client_timeout=get_session_client_timeout, | ||
| fast_backoff_settings=fast_backoff_settings, | ||
| slow_backoff_settings=slow_backoff_settings, | ||
| idempotent=idempotent, | ||
| retry_cancelled=retry_cancelled, | ||
| ) | ||
|
|
||
| if inspect.iscoroutinefunction(func): | ||
|
|
||
| @functools.wraps(func) | ||
| async def async_wrapper(*args, **kwargs): | ||
| return await retry_operation_async(func, retry_settings, *args, **kwargs) | ||
|
|
||
| return async_wrapper | ||
| else: | ||
|
|
||
| @functools.wraps(func) | ||
| def sync_wrapper(*args, **kwargs): | ||
| return retry_operation_sync(func, retry_settings, *args, **kwargs) | ||
|
|
||
| return sync_wrapper | ||
|
|
||
| return decorator | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about import to ydb namespace for common use as retry decorator for all operations, independent from topic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we already import it in init file
from .retries import * # noqa