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

Commit 96d1355

Browse files
committed
require backoff; refactor check
1 parent 9bd1e07 commit 96d1355

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class ActiveOperationMetric:
145145
op_type: OperationType
146146
uuid: str = field(default_factory=lambda: str(uuid.uuid4()))
147147
# create a default backoff generator, initialized with standard default backoff values
148-
backoff_generator: TrackedBackoffGenerator | None = field(
148+
backoff_generator: TrackedBackoffGenerator = field(
149149
default_factory=lambda: TrackedBackoffGenerator(initial=0.01, maximum=60, multiplier=2)
150150
)
151151
# keep monotonic timestamps for active operations
@@ -201,15 +201,16 @@ def start_attempt(self) -> ActiveAttemptMetric:
201201
INVALID_STATE_ERROR.format("start_attempt", self.state)
202202
)
203203

204-
# find backoff value
205-
if self.backoff_generator and len(self.completed_attempts) > 0:
206-
# find the attempt's backoff by sending attempt number to generator
207-
# generator will return the backoff time in seconds, so convert to nanoseconds
204+
try:
205+
# find backoff value before this attempt
206+
prev_attempt_idx = len(self.completed_attempts) - 1
208207
backoff = self.backoff_generator.get_attempt_backoff(
209-
len(self.completed_attempts) - 1
208+
prev_attempt_idx
210209
)
210+
# generator will return the backoff time in seconds, so convert to nanoseconds
211211
backoff_ns = int(backoff * 1e9)
212-
else:
212+
except IndexError:
213+
# backoff value not found
213214
backoff_ns = 0
214215

215216
self.active_attempt = ActiveAttemptMetric(backoff_before_attempt_ns=backoff_ns)

0 commit comments

Comments
 (0)