6666from google .cloud .bigtable .data ._helpers import _get_retryable_errors
6767from google .cloud .bigtable .data ._helpers import _get_timeouts
6868from google .cloud .bigtable .data ._helpers import _attempt_timeout_generator
69- from google .cloud .bigtable .data ._helpers import TrackedBackoffGenerator
7069from google .cloud .bigtable .data .mutations import Mutation , RowMutationEntry
7170from google .cloud .bigtable .data .read_modify_write_rules import ReadModifyWriteRule
7271from google .cloud .bigtable .data .row_filters import RowFilter
@@ -805,18 +804,17 @@ def read_rows_stream(
805804 operation_timeout , attempt_timeout , self
806805 )
807806 retryable_excs = _get_retryable_errors (retryable_errors , self )
808- with self ._metrics .create_operation (
809- OperationType .READ_ROWS , streaming = True
810- ) as operation_metric :
811- row_merger = CrossSync ._Sync_Impl ._ReadRowsOperation (
812- query ,
813- self ,
814- operation_timeout = operation_timeout ,
815- attempt_timeout = attempt_timeout ,
816- metric = operation_metric ,
817- retryable_exceptions = retryable_excs ,
818- )
819- return row_merger .start_operation ()
807+ row_merger = CrossSync ._Sync_Impl ._ReadRowsOperation (
808+ query ,
809+ self ,
810+ operation_timeout = operation_timeout ,
811+ attempt_timeout = attempt_timeout ,
812+ metric = self ._metrics .create_operation (
813+ OperationType .READ_ROWS , streaming = True
814+ ),
815+ retryable_exceptions = retryable_excs ,
816+ )
817+ return row_merger .start_operation ()
820818
821819 def read_rows (
822820 self ,
@@ -906,22 +904,21 @@ def read_row(
906904 operation_timeout , attempt_timeout , self
907905 )
908906 retryable_excs = _get_retryable_errors (retryable_errors , self )
909- with self ._metrics .create_operation (
910- OperationType .READ_ROWS , streaming = False
911- ) as operation_metric :
912- row_merger = CrossSync ._Sync_Impl ._ReadRowsOperation (
913- query ,
914- self ,
915- operation_timeout = operation_timeout ,
916- attempt_timeout = attempt_timeout ,
917- metric = operation_metric ,
918- retryable_exceptions = retryable_excs ,
919- )
920- results_generator = row_merger .start_operation ()
921- try :
922- return results_generator .__next__ ()
923- except StopIteration :
924- return None
907+ row_merger = CrossSync ._Sync_Impl ._ReadRowsOperation (
908+ query ,
909+ self ,
910+ operation_timeout = operation_timeout ,
911+ attempt_timeout = attempt_timeout ,
912+ metric = self ._metrics .create_operation (
913+ OperationType .READ_ROWS , streaming = False
914+ ),
915+ retryable_exceptions = retryable_excs ,
916+ )
917+ results_generator = row_merger .start_operation ()
918+ try :
919+ return results_generator .__next__ ()
920+ except StopIteration :
921+ return None
925922
926923 def read_rows_sharded (
927924 self ,
@@ -1101,10 +1098,9 @@ def sample_row_keys(
11011098 )
11021099 retryable_excs = _get_retryable_errors (retryable_errors , self )
11031100 predicate = retries .if_exception_type (* retryable_excs )
1104- sleep_generator = TrackedBackoffGenerator (0.01 , 2 , 60 )
11051101 with self ._metrics .create_operation (
1106- OperationType .SAMPLE_ROW_KEYS , backoff_generator = sleep_generator
1107- ):
1102+ OperationType .SAMPLE_ROW_KEYS
1103+ ) as operation_metric :
11081104
11091105 def execute_rpc ():
11101106 results = self .client ._gapic_client .sample_row_keys (
@@ -1119,7 +1115,7 @@ def execute_rpc():
11191115 return CrossSync ._Sync_Impl .retry_target (
11201116 execute_rpc ,
11211117 predicate ,
1122- sleep_generator ,
1118+ operation_metric . backoff_generator ,
11231119 operation_timeout ,
11241120 exception_factory = _retry_exception_factory ,
11251121 )
@@ -1223,10 +1219,9 @@ def mutate_row(
12231219 )
12241220 else :
12251221 predicate = retries .if_exception_type ()
1226- sleep_generator = TrackedBackoffGenerator (0.01 , 2 , 60 )
12271222 with self ._metrics .create_operation (
1228- OperationType .MUTATE_ROW , backoff_generator = sleep_generator
1229- ):
1223+ OperationType .MUTATE_ROW
1224+ ) as operation_metric :
12301225 target = partial (
12311226 self .client ._gapic_client .mutate_row ,
12321227 request = MutateRowRequest (
@@ -1243,7 +1238,7 @@ def mutate_row(
12431238 return CrossSync ._Sync_Impl .retry_target (
12441239 target ,
12451240 predicate ,
1246- sleep_generator ,
1241+ operation_metric . backoff_generator ,
12471242 operation_timeout ,
12481243 exception_factory = _retry_exception_factory ,
12491244 )
0 commit comments