Skip to content

Commit 5835e5c

Browse files
committed
add TODO, docs for ILB, simplify commitWithResponse
1 parent fcdc554 commit 5835e5c

2 files changed

Lines changed: 12 additions & 19 deletions

File tree

Spanner/src/Operation.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,14 @@ public function commitWithResponse(Session $session, array $mutations, array $op
161161
'session' => $session->name(),
162162
'mutations' => $mutations
163163
];
164-
$commitRequest = $this->formatSingleUseTransactionOptions($commitRequest);
164+
165+
// Configure Single Use Transaction options
166+
// @TODO: Find out why we do this
167+
if (isset($commitRequest['singleUseTransaction'])) {
168+
$commitRequest['singleUseTransaction'] = ['readWrite' => []];
169+
// CommitRequest ignores singleUseTransaction if the transactionId is set
170+
unset($commitRequest['transactionId']);
171+
}
165172

166173
$request = $this->serializer->decodeMessage(new CommitRequest(), $commitRequest);
167174
$response = $this->spannerClient->commit($request, $callOptions + [
@@ -1078,21 +1085,6 @@ private function streamingRead(array $args, array $callOptions): \Generator
10781085
return $this->handleResponse($response);
10791086
}
10801087

1081-
/**
1082-
* @param array $args
1083-
* @return array
1084-
*/
1085-
private function formatSingleUseTransactionOptions(array $args): array
1086-
{
1087-
if (isset($args['singleUseTransaction'])) {
1088-
$args['singleUseTransaction'] = ['readWrite' => []];
1089-
// request ignores singleUseTransaction even if the transactionId is set to null
1090-
unset($args['transactionId']);
1091-
}
1092-
1093-
return $args;
1094-
}
1095-
10961088
/**
10971089
* @param array $args
10981090
*

Spanner/src/Transaction.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ class Transaction implements TransactionalReadInterface
8585
* @type bool $isRetry Whether the transaction will automatically retry or not.
8686
* @type string $tag A transaction tag. Requests made using this transaction will
8787
* use this as the transaction tag.
88-
* @type array $begin The begin Transaction options. See {@see V1\TransactionOptions}.
88+
* @type array $begin The begin Transaction options, for using inline begin transactions.
89+
* See {@see V1\TransactionOptions}.
8990
* @type array $requestOptions See {@see V1\RequestOptions}.
9091
* @type array $transactionOptions See {@see V1\TransactionOptions}.
9192
* }
@@ -412,8 +413,7 @@ public function commit(array $options = []): Timestamp
412413
}
413414

414415
// For commit, A transaction ID is mandatory for non-single-use transactions,
415-
// and the `begin` option is not supported.
416-
// @TODO: Find out why the `begin` option is not supported for calling the `beginTransaction` RPC
416+
// and the `begin` option is not supported (because `begin` is only used in "inline begin transactions")
417417
if (empty($this->transactionId) && isset($this->transactionSelector['begin'])) {
418418
$operationTransactionOptions = [
419419
'requestOptions' => $this->requestOptions,
@@ -446,6 +446,7 @@ public function commit(array $options = []): Timestamp
446446

447447
$t = $this->transactionOptions($options);
448448

449+
// @TODO find out what this is and clean it up
449450
$options[$t[1]] = $t[0];
450451

451452
$res = $this->operation->commitWithResponse($this->session, $this->pluck('mutations', $options), $options);

0 commit comments

Comments
 (0)