summaryrefslogtreecommitdiffstats
path: root/contrib/python
diff options
context:
space:
mode:
authorrobot-piglet <[email protected]>2025-12-11 12:03:10 +0300
committerrobot-piglet <[email protected]>2025-12-11 12:57:36 +0300
commita23e41f2affd873daed9bdba465c4a8ee3526bf8 (patch)
treecc69790f6c33c9dad2116c3936d486b485e6d1ee /contrib/python
parent546cc30d9bfb75fb7388fa34e6181b22c538d3c2 (diff)
Intermediate changes
commit_hash:42f07b10db90ba7011be8a94c8eca82896cccdc6
Diffstat (limited to 'contrib/python')
-rw-r--r--contrib/python/ydb/py3/.dist-info/METADATA2
-rw-r--r--contrib/python/ydb/py3/ya.make2
-rw-r--r--contrib/python/ydb/py3/ydb/retries.py63
-rw-r--r--contrib/python/ydb/py3/ydb/topic.py4
-rw-r--r--contrib/python/ydb/py3/ydb/ydb_version.py2
5 files changed, 70 insertions, 3 deletions
diff --git a/contrib/python/ydb/py3/.dist-info/METADATA b/contrib/python/ydb/py3/.dist-info/METADATA
index f3e82d24211..dcbd4a4b4d0 100644
--- a/contrib/python/ydb/py3/.dist-info/METADATA
+++ b/contrib/python/ydb/py3/.dist-info/METADATA
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: ydb
-Version: 3.22.2
+Version: 3.22.3
Summary: YDB Python SDK
Home-page: http://github.com/ydb-platform/ydb-python-sdk
Author: Yandex LLC
diff --git a/contrib/python/ydb/py3/ya.make b/contrib/python/ydb/py3/ya.make
index b132117a3e3..7d8a50525aa 100644
--- a/contrib/python/ydb/py3/ya.make
+++ b/contrib/python/ydb/py3/ya.make
@@ -2,7 +2,7 @@
PY3_LIBRARY()
-VERSION(3.22.2)
+VERSION(3.22.3)
LICENSE(Apache-2.0)
diff --git a/contrib/python/ydb/py3/ydb/retries.py b/contrib/python/ydb/py3/ydb/retries.py
index 5331f1b00f0..7533276852d 100644
--- a/contrib/python/ydb/py3/ydb/retries.py
+++ b/contrib/python/ydb/py3/ydb/retries.py
@@ -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,
+ 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
diff --git a/contrib/python/ydb/py3/ydb/topic.py b/contrib/python/ydb/py3/ydb/topic.py
index 5e86be68e17..f457b7dc884 100644
--- a/contrib/python/ydb/py3/ydb/topic.py
+++ b/contrib/python/ydb/py3/ydb/topic.py
@@ -98,6 +98,8 @@ from ._grpc.grpcwrapper.ydb_topic_public_types import ( # noqa: F401
PublicAlterAutoPartitioningSettings as TopicAlterAutoPartitioningSettings,
)
+from .retries import ydb_retry
+
logger = logging.getLogger(__name__)
@@ -348,6 +350,7 @@ class TopicClientAsyncIO:
return TopicTxWriterAsyncIO(tx=tx, driver=self._driver, settings=settings, _client=self)
+ @ydb_retry(retry_cancelled=True, idempotent=True)
async def commit_offset(
self, path: str, consumer: str, partition_id: int, offset: int, read_session_id: Optional[str] = None
) -> None:
@@ -645,6 +648,7 @@ class TopicClient:
return TopicTxWriter(tx, self._driver, settings, _parent=self)
+ @ydb_retry(retry_cancelled=True, idempotent=True)
def commit_offset(
self, path: str, consumer: str, partition_id: int, offset: int, read_session_id: Optional[str] = None
) -> None:
diff --git a/contrib/python/ydb/py3/ydb/ydb_version.py b/contrib/python/ydb/py3/ydb/ydb_version.py
index cb84fa661d5..65cdcd21253 100644
--- a/contrib/python/ydb/py3/ydb/ydb_version.py
+++ b/contrib/python/ydb/py3/ydb/ydb_version.py
@@ -1 +1 @@
-VERSION = "3.22.2"
+VERSION = "3.22.3"