Skip to content

Commit d3f9d05

Browse files
committed
simplified helper
1 parent 9d63963 commit d3f9d05

File tree

4 files changed

+26
-29
lines changed

4 files changed

+26
-29
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def __init__(
107107
metric.backoff_generator,
108108
operation_timeout,
109109
exception_factory=self._operation_metric.track_terminal_error(_retry_exception_factory),
110-
on_error=self._operation_metric.track_retryable_error(),
110+
on_error=self._operation_metric.track_retryable_error,
111111
)
112112
# initialize state
113113
self.timeout_generator = _attempt_timeout_generator(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def start_operation(self) -> CrossSync.Iterable[Row]:
124124
self._operation_metric.backoff_generator,
125125
self.operation_timeout,
126126
exception_factory=self._operation_metric.track_terminal_error(_retry_exception_factory),
127-
on_error=self._operation_metric.track_retryable_error(),
127+
on_error=self._operation_metric.track_retryable_error,
128128
)
129129

130130
def _read_rows_attempt(self) -> CrossSync.Iterable[Row]:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,7 @@ async def execute_rpc():
13921392
operation_metric.backoff_generator,
13931393
operation_timeout,
13941394
exception_factory=operation_metric.track_terminal_error(_retry_exception_factory),
1395-
on_error=operation_metric.track_retryable_error(),
1395+
on_error=operation_metric.track_retryable_error,
13961396
)
13971397

13981398
@CrossSync.convert(replace_symbols={"MutationsBatcherAsync": "MutationsBatcher"})
@@ -1527,7 +1527,7 @@ async def mutate_row(
15271527
operation_metric.backoff_generator,
15281528
operation_timeout,
15291529
exception_factory=operation_metric.track_terminal_error(_retry_exception_factory),
1530-
on_error=operation_metric.track_retryable_error(),
1530+
on_error=operation_metric.track_retryable_error,
15311531
)
15321532

15331533
@CrossSync.convert

google/cloud/bigtable/data/_metrics/data_model.py

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -399,35 +399,32 @@ def _exc_to_status(exc: BaseException) -> StatusCode:
399399
return exc.code()
400400
return StatusCode.UNKNOWN
401401

402-
def track_retryable_error(self) -> callable[[Exception], None]:
402+
def track_retryable_error(self, exc: Exception) -> None:
403403
"""
404404
Used as input to api_core.Retry classes, to track when retryable errors are encountered
405405
406406
Should be passed as on_error callback
407407
"""
408-
409-
def wrapper(exc: Exception) -> None:
410-
try:
411-
# record metadata from failed rpc
412-
if (
413-
isinstance(exc, GoogleAPICallError)
414-
and exc.errors
415-
):
416-
rpc_error = exc.errors[-1]
417-
metadata = list(rpc_error.trailing_metadata()) + list(
418-
rpc_error.initial_metadata()
419-
)
420-
self.add_response_metadata({k: v for k, v in metadata})
421-
except Exception:
422-
# ignore errors in metadata collection
423-
pass
424-
if isinstance(exc, _MutateRowsIncomplete):
425-
# _MutateRowsIncomplete represents a successful rpc with some failed mutations
426-
# mark the attempt as successful
427-
self.end_attempt_with_status(StatusCode.OK)
428-
else:
429-
self.end_attempt_with_status(exc)
430-
return wrapper
408+
try:
409+
# record metadata from failed rpc
410+
if (
411+
isinstance(exc, GoogleAPICallError)
412+
and exc.errors
413+
):
414+
rpc_error = exc.errors[-1]
415+
metadata = list(rpc_error.trailing_metadata()) + list(
416+
rpc_error.initial_metadata()
417+
)
418+
self.add_response_metadata({k: v for k, v in metadata})
419+
except Exception:
420+
# ignore errors in metadata collection
421+
pass
422+
if isinstance(exc, _MutateRowsIncomplete):
423+
# _MutateRowsIncomplete represents a successful rpc with some failed mutations
424+
# mark the attempt as successful
425+
self.end_attempt_with_status(StatusCode.OK)
426+
else:
427+
self.end_attempt_with_status(exc)
431428

432429
def track_terminal_error(self, exception_factory:callable[
433430
[list[Exception], RetryFailureReason, float | None],tuple[Exception, Exception | None],
@@ -458,7 +455,7 @@ def wrapper(
458455
if reason == RetryFailureReason.TIMEOUT and self.state == OperationState.ACTIVE_ATTEMPT and exc_list:
459456
# record ending attempt for timeout failures
460457
attempt_exc = exc_list[-1]
461-
self.track_retryable_error()(attempt_exc)
458+
self.track_retryable_error(attempt_exc)
462459
self.end_with_status(source_exc)
463460
return source_exc, cause_exc
464461
return wrapper

0 commit comments

Comments
 (0)