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

Commit 0c9cde8

Browse files
crwilcoxtseaver
andauthored
fix: retry if failure occurs on initial call in MutateRows (#123)
* fix: Retry if failure occurs on initial call in MutateRows * fix: use exception clases to DRY RETRY_CODES Co-authored-by: Tres Seaver <tseaver@palladion.com>
1 parent 22cbd67 commit 0c9cde8

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

google/cloud/bigtable/table.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414

1515
"""User-friendly container for Google Cloud Bigtable Table."""
1616

17-
from grpc import StatusCode
18-
1917
from google.api_core import timeout
20-
from google.api_core.exceptions import RetryError
18+
from google.api_core.exceptions import Aborted
19+
from google.api_core.exceptions import DeadlineExceeded
2120
from google.api_core.exceptions import NotFound
21+
from google.api_core.exceptions import RetryError
22+
from google.api_core.exceptions import ServiceUnavailable
2223
from google.api_core.retry import if_exception_type
2324
from google.api_core.retry import Retry
2425
from google.api_core.gapic_v1.method import wrap_method
@@ -986,15 +987,12 @@ class _RetryableMutateRowsWorker(object):
986987
are retryable, any subsequent call on this callable will be a no-op.
987988
"""
988989

989-
# pylint: disable=unsubscriptable-object
990990
RETRY_CODES = (
991-
StatusCode.DEADLINE_EXCEEDED.value[0],
992-
StatusCode.ABORTED.value[0],
993-
StatusCode.UNAVAILABLE.value[0],
991+
Aborted.grpc_status_code.value[0],
992+
DeadlineExceeded.grpc_status_code.value[0],
993+
ServiceUnavailable.grpc_status_code.value[0],
994994
)
995995

996-
# pylint: enable=unsubscriptable-object
997-
998996
def __init__(self, client, table_name, rows, app_profile_id=None, timeout=None):
999997
self.client = client
1000998
self.table_name = table_name
@@ -1078,9 +1076,15 @@ def _do_mutate_retryable_rows(self):
10781076
client_info=data_client._client_info,
10791077
)
10801078

1081-
responses = data_client._inner_api_calls["mutate_rows"](
1082-
mutate_rows_request, retry=None
1083-
)
1079+
try:
1080+
responses = data_client._inner_api_calls["mutate_rows"](
1081+
mutate_rows_request, retry=None
1082+
)
1083+
except (ServiceUnavailable, DeadlineExceeded, Aborted):
1084+
# If an exception, considered retryable by `RETRY_CODES`, is
1085+
# returned from the initial call, consider
1086+
# it to be retryable. Wrap as a Bigtable Retryable Error.
1087+
raise _BigtableRetryableError
10841088

10851089
num_responses = 0
10861090
num_retryable_responses = 0

0 commit comments

Comments
 (0)