Skip to content

Commit 06c12a2

Browse files
committed
Update _execute_partitioned_dml_helper
1 parent 80faca0 commit 06c12a2

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

google/cloud/spanner_v1/database.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -766,14 +766,12 @@ def execute_pdml():
766766
) as span, MetricsCapture():
767767
with SessionCheckout(self._pool) as session:
768768
add_span_event(span, "Starting BeginTransaction")
769-
begin_txn_nth_request = self._next_nth_request
770-
begin_txn_attempt = AtomicCounter(0)
771769
txn = api.begin_transaction(
772770
session=session.name,
773771
options=txn_options,
774772
metadata=self.metadata_with_request_id(
775-
begin_txn_nth_request,
776-
begin_txn_attempt.increment(),
773+
self._next_nth_request,
774+
1,
777775
metadata,
778776
),
779777
)

tests/unit/test_database.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,8 @@ def _execute_partitioned_dml_helper(
12981298
("x-goog-spanner-route-to-leader", "true"),
12991299
(
13001300
"x-goog-spanner-request-id",
1301-
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.1.2",
1301+
# Please note that this try was by an abort and not from service unavailable.
1302+
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.3.1",
13021303
),
13031304
],
13041305
)
@@ -1370,14 +1371,32 @@ def _execute_partitioned_dml_helper(
13701371
query_options=expected_query_options,
13711372
request_options=expected_request_options,
13721373
)
1374+
1375+
api.begin_transaction.assert_called_with(
1376+
session=self.SESSION_NAME,
1377+
options=txn_options,
1378+
metadata=[
1379+
("google-cloud-resource-prefix", database.name),
1380+
("x-goog-spanner-route-to-leader", "true"),
1381+
(
1382+
"x-goog-spanner-request-id",
1383+
# Retrying on an aborted response involves creating the transaction afresh
1384+
# and also re-invoking execute_streaming_sql, hence the fresh request 4.1.
1385+
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.3.1",
1386+
),
1387+
],
1388+
)
1389+
13731390
api.execute_streaming_sql.assert_called_with(
13741391
request=expected_request,
13751392
metadata=[
13761393
("google-cloud-resource-prefix", database.name),
13771394
("x-goog-spanner-route-to-leader", "true"),
13781395
(
13791396
"x-goog-spanner-request-id",
1380-
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.2.2",
1397+
# Retrying on an aborted response involves creating the transaction afresh
1398+
# and also re-invoking execute_streaming_sql, hence the fresh request 4.1.
1399+
f"1.{REQ_RAND_PROCESS_ID}.{database._nth_client_id}.{database._channel_id}.4.1",
13811400
),
13821401
],
13831402
)

0 commit comments

Comments
 (0)