Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 3935744

Browse files
committed
added operation logic to retry factory
1 parent 661d6eb commit 3935744

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

google/cloud/bigtable/data/_async/_read_rows.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from typing import Sequence, TYPE_CHECKING
1919

2020
import time
21+
from functools import partial
2122

2223
from google.cloud.bigtable_v2.types import ReadRowsRequest as ReadRowsRequestPB
2324
from google.cloud.bigtable_v2.types import ReadRowsResponse as ReadRowsResponsePB
@@ -121,7 +122,7 @@ def start_operation(self) -> CrossSync.Iterable[Row]:
121122
self._predicate,
122123
self._operation_metric.backoff_generator,
123124
self.operation_timeout,
124-
exception_factory=_retry_exception_factory,
125+
exception_factory=partial(_retry_exception_factory, operation=self._operation_metric),
125126
)
126127

127128
def _read_rows_attempt(self) -> CrossSync.Iterable[Row]:
@@ -340,8 +341,6 @@ async def merge_rows(
340341
except CrossSync.StopIteration:
341342
raise InvalidChunk("premature end of stream")
342343
except Exception as generic_exception:
343-
if not self._predicate(generic_exception):
344-
self._operation_metric.end_attempt_with_status(generic_exception)
345344
raise generic_exception
346345
else:
347346
self._operation_metric.end_with_success()

google/cloud/bigtable/data/_helpers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def _retry_exception_factory(
9090
exc_list: list[Exception],
9191
reason: RetryFailureReason,
9292
timeout_val: float | None,
93+
operation: "ActiveOperationMetric" | None=None,
9394
) -> tuple[Exception, Exception | None]:
9495
"""
9596
Build retry error based on exceptions encountered during operation
@@ -117,6 +118,16 @@ def _retry_exception_factory(
117118
# use the retry exception group as the cause of the exception
118119
cause_exc: Exception | None = RetryExceptionGroup(exc_list) if exc_list else None
119120
source_exc.__cause__ = cause_exc
121+
if operation:
122+
try:
123+
if isinstance(source_exc, core_exceptions.GoogleAPICallError) and source_exc.errors:
124+
rpc_error = source_exc.errors[-1]
125+
metadata = list(rpc_error.trailing_metadata()) + list(rpc_error.initial_metadata())
126+
operation.add_response_metadata({k:v for k,v in metadata})
127+
except Exception:
128+
# ignore errors in metadata collection
129+
pass
130+
operation.end_with_status(source_exc)
120131
return source_exc, cause_exc
121132

122133

0 commit comments

Comments
 (0)