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

Commit 3fc658a

Browse files
committed
addressed more feedback
1 parent 6aca433 commit 3fc658a

5 files changed

Lines changed: 35 additions & 33 deletions

File tree

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -363,18 +363,18 @@ async def _flush_internal(self, new_entries: list[RowMutationEntry]):
363363
new_entries list of RowMutationEntry objects to flush
364364
"""
365365
# flush new entries
366-
in_process_requests: list[CrossSync.Future[list[FailedMutationEntryError]]] = []
367-
in_process_batches: list[list[RowMutationEntry]] = []
366+
in_process_requests: list[
367+
tuple[
368+
CrossSync.Future[list[FailedMutationEntryError]], list[RowMutationEntry]
369+
]
370+
] = []
368371
async for batch in self._flow_control.add_to_flow(new_entries):
369372
batch_task = CrossSync.create_task(
370373
self._execute_mutate_rows, batch, sync_executor=self._sync_rpc_executor
371374
)
372-
in_process_requests.append(batch_task)
373-
in_process_batches.append(batch)
375+
in_process_requests.append((batch_task, batch))
374376
# wait for all inflight requests to complete
375-
found_exceptions = await self._wait_for_batch_results(
376-
in_process_requests, in_process_batches
377-
)
377+
found_exceptions = await self._wait_for_batch_results(*in_process_requests)
378378
# update exception data to reflect any new errors
379379
self._entries_processed_since_last_raise += len(new_entries)
380380
self._add_exceptions(found_exceptions)
@@ -524,17 +524,18 @@ def _on_exit(self):
524524
@staticmethod
525525
@CrossSync.convert
526526
async def _wait_for_batch_results(
527-
tasks: Sequence[
528-
CrossSync.Future[list[FailedMutationEntryError]] | CrossSync.Future[None]
527+
*tasks: tuple[
528+
CrossSync.Future[list[FailedMutationEntryError]] | CrossSync.Future[None],
529+
list[RowMutationEntry],
529530
],
530-
batches: Sequence[list[RowMutationEntry]],
531531
) -> list[FailedMutationEntryError]:
532532
"""
533533
Takes in a list of futures representing _execute_mutate_rows tasks,
534534
waits for them to complete, and returns a list of errors encountered.
535535
536536
Args:
537-
*tasks: futures representing _execute_mutate_rows or _flush_internal tasks
537+
*tasks: Tuples of futures representing _execute_mutate_rows or
538+
_flush_internal tasks, and their associated batches
538539
Returns:
539540
list[FailedMutationEntryError]:
540541
list of FailedMutationEntryError encountered by any of the tasks,
@@ -544,7 +545,7 @@ async def _wait_for_batch_results(
544545
if not tasks:
545546
return []
546547
exceptions: list[FailedMutationEntryError] = []
547-
for task, batch in list(zip(tasks, batches)):
548+
for task, batch in tasks:
548549
if CrossSync.is_async:
549550
# futures don't need to be awaited in sync mode
550551
await task

google/cloud/bigtable/data/_sync_autogen/mutations_batcher.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -308,18 +308,17 @@ def _flush_internal(self, new_entries: list[RowMutationEntry]):
308308
Args:
309309
new_entries list of RowMutationEntry objects to flush"""
310310
in_process_requests: list[
311-
CrossSync._Sync_Impl.Future[list[FailedMutationEntryError]]
311+
tuple[
312+
CrossSync._Sync_Impl.Future[list[FailedMutationEntryError]],
313+
list[RowMutationEntry],
314+
]
312315
] = []
313-
in_process_batches: list[list[RowMutationEntry]] = []
314316
for batch in self._flow_control.add_to_flow(new_entries):
315317
batch_task = CrossSync._Sync_Impl.create_task(
316318
self._execute_mutate_rows, batch, sync_executor=self._sync_rpc_executor
317319
)
318-
in_process_requests.append(batch_task)
319-
in_process_batches.append(batch)
320-
found_exceptions = self._wait_for_batch_results(
321-
in_process_requests, in_process_batches
322-
)
320+
in_process_requests.append((batch_task, batch))
321+
found_exceptions = self._wait_for_batch_results(*in_process_requests)
323322
self._entries_processed_since_last_raise += len(new_entries)
324323
self._add_exceptions(found_exceptions)
325324

@@ -439,17 +438,18 @@ def _on_exit(self):
439438

440439
@staticmethod
441440
def _wait_for_batch_results(
442-
tasks: Sequence[
441+
*tasks: tuple[
443442
CrossSync._Sync_Impl.Future[list[FailedMutationEntryError]]
444-
| CrossSync._Sync_Impl.Future[None]
445-
],
446-
batches: Sequence[list[RowMutationEntry]],
443+
| CrossSync._Sync_Impl.Future[None],
444+
list[RowMutationEntry],
445+
]
447446
) -> list[FailedMutationEntryError]:
448447
"""Takes in a list of futures representing _execute_mutate_rows tasks,
449448
waits for them to complete, and returns a list of errors encountered.
450449
451450
Args:
452-
*tasks: futures representing _execute_mutate_rows or _flush_internal tasks
451+
*tasks: Tuples of futures representing _execute_mutate_rows or
452+
_flush_internal tasks, and their associated batches
453453
Returns:
454454
list[FailedMutationEntryError]:
455455
list of FailedMutationEntryError encountered by any of the tasks,
@@ -458,7 +458,7 @@ def _wait_for_batch_results(
458458
if not tasks:
459459
return []
460460
exceptions: list[FailedMutationEntryError] = []
461-
for task, batch in list(zip(tasks, batches)):
461+
for task, batch in tasks:
462462
try:
463463
exc_list = task.result()
464464
if exc_list:

google/cloud/bigtable/data/exceptions.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,11 @@ def __repr__(self):
141141
return f"{self.__class__.__name__}({message!r}, {self.exceptions!r})"
142142

143143

144-
# TODO: When working on mutations batcher, rework exception handling to guarantee that
145-
# MutationsExceptionGroup only stores FailedMutationEntryErrors.
146144
class MutationsExceptionGroup(_BigtableExceptionGroup):
147145
"""
148146
Represents one or more exceptions that occur during a bulk mutation operation
149147
150-
Exceptions will typically be of type FailedMutationEntryError, but other exceptions may
151-
be included if they are raised during the mutation operation
148+
Exceptions will be of type FailedMutationEntryError.
152149
"""
153150

154151
@staticmethod

tests/unit/data/_async/test_mutations_batcher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ async def mock_call(*args, **kwargs):
642642
# let any flush jobs finish
643643
jobs = instance._flush_jobs
644644
await instance._wait_for_batch_results(
645-
jobs, [mock.MagicMock()] * len(jobs)
645+
*[(job, mock.MagicMock()) for job in jobs]
646646
)
647647
# should have only flushed once, with large mutation and first mutation in loop
648648
assert op_mock.call_count == 1
@@ -745,7 +745,7 @@ async def mock_call(*args, **kwargs):
745745
# allow flushes to complete
746746
jobs = instance._flush_jobs
747747
await instance._wait_for_batch_results(
748-
jobs, [mock.MagicMock()] * len(jobs)
748+
*[(job, mock.MagicMock()) for job in jobs]
749749
)
750750
duration = time.monotonic() - start_time
751751
assert len(instance._oldest_exceptions) == 0

tests/unit/data/_sync_autogen/test_mutations_batcher.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,9 @@ def mock_call(*args, **kwargs):
557557
for _ in range(num_entries):
558558
instance.append(self._make_mutation(size=1))
559559
jobs = instance._flush_jobs
560-
instance._wait_for_batch_results(jobs, [mock.MagicMock()] * len(jobs))
560+
instance._wait_for_batch_results(
561+
*[(job, mock.MagicMock()) for job in jobs]
562+
)
561563
assert op_mock.call_count == 1
562564
sent_batch = op_mock.call_args[0][0]
563565
assert len(sent_batch) == 2
@@ -648,7 +650,9 @@ def mock_call(*args, **kwargs):
648650
)
649651
CrossSync._Sync_Impl.sleep(0.01)
650652
jobs = instance._flush_jobs
651-
instance._wait_for_batch_results(jobs, [mock.MagicMock()] * len(jobs))
653+
instance._wait_for_batch_results(
654+
*[(job, mock.MagicMock()) for job in jobs]
655+
)
652656
duration = time.monotonic() - start_time
653657
assert len(instance._oldest_exceptions) == 0
654658
assert len(instance._newest_exceptions) == 0

0 commit comments

Comments
 (0)