Skip to content

Commit

Permalink
commit with error test
Browse files Browse the repository at this point in the history
  • Loading branch information
ajupazhamayil committed Oct 17, 2023
1 parent 17990d8 commit 5f5a66c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Spanner/src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ public function runTransaction(callable $operation, array $options = [])
$startTransactionFn = function ($session, $options) use (&$attempt) {
if ($attempt > 0) {
$options['isRetry'] = true;
} else {
} elseif (!isset($options['transactionOptions']['partitionedDml'])) {
// Make the begin options
$options['begin'] = $options['transactionOptions'];
}
Expand Down Expand Up @@ -1787,7 +1787,7 @@ public function executePartitionedUpdate($statement, array $options = [])
try {
return $this->operation->executeUpdate($session, $transaction, $statement, [
'statsItem' => 'rowCountLowerBound'
] + $options);
] + $options, $transaction->getIdReference());
} finally {
$session->setExpiration();
}
Expand Down
15 changes: 9 additions & 6 deletions Spanner/src/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public function executeUpdate(
&$transactionId = null
) {
if ( !is_null($transactionId) and !is_array($transactionId) ) {
$options += ['transactionId' => $transaction->id()];
$options += ['transactionId' => $transactionId];
}
$res = $this->execute($session, $sql, $options, $transactionId);

Expand Down Expand Up @@ -363,7 +363,7 @@ public function executeUpdateBatch(
}

if ( !is_null($transactionId) and !is_array($transactionId) ) {
$options += ['transactionId' => $transaction->id()];
$options += ['transactionId' => $transactionId];
}

$res = $this->connection->executeBatchDml([
Expand All @@ -373,10 +373,10 @@ public function executeUpdateBatch(
] + $options);

if (
isset($res['metadata']['transaction']['id']) &&
$res['metadata']['transaction']['id']
isset($res['resultSets'][0]['metadata']['transaction']['id']) and
$res['resultSets'][0]['metadata']['transaction']['id']
) {
$this->transactionId = $result['metadata']['transaction']['id'];
$transactionId = $res['resultSets'][0]['metadata']['transaction']['id'];
}

$errorStatement = null;
Expand Down Expand Up @@ -483,7 +483,10 @@ public function transaction(Session $session, array $options = [])
}

if (!$options['singleUse']) {
if (isset($options['begin']) and !isset($transactionOptions['partitionedDml'])) {
if (
isset($options['begin']) and
!isset($options['transactionOptions']['partitionedDml'])
) {
$res = ['id' => ['begin' => $options['begin']]];
} else {
$res = $this->beginTransaction($session, $options);
Expand Down
10 changes: 6 additions & 4 deletions Spanner/src/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public function executeUpdate($sql, array $options = [])
} else {
$options['transactionId'] = $this->transactionId;
}
$selector = $this->transactionSelector($options, $this->options);
$selector = $this->transactionSelector($options);

$options['transaction'] = $selector[0];

Expand Down Expand Up @@ -558,11 +558,13 @@ public function executeUpdateBatch(array $statements, array $options = [])

$options['transactionType'] = $this->context;
if (is_array($this->transactionId) and isset($this->transactionId['begin'])) {
$options['begin'] = true;
$options['begin'] = $this->transactionId['begin'];
} else {
$options['transactionId'] = $this->transactionId;
}
$selector = $this->transactionSelector($options, $this->options);
$selector = $this->transactionSelector($options);

$options['transaction'] = $selector[0];

return $this->operation
->executeUpdateBatch(
Expand Down Expand Up @@ -647,7 +649,6 @@ public function commit(array $options = [])
}

if (is_array($this->transactionId) and isset($this->transactionId['begin'])) {
unset($this->options['begin']);
$res = $this->operation->transaction($this->session, $this->options+[
'fromTransaction' => true
]);
Expand All @@ -657,6 +658,7 @@ public function commit(array $options = [])
// singleUse transaction
$this->transactionId = null;
}
unset($this->options['begin']);
}

if (!$this->singleUseState()) {
Expand Down
5 changes: 5 additions & 0 deletions Spanner/src/TransactionalReadTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@ public function id()
return $this->transactionId;
}

public function &getIdReference()
{
return $this->transactionId;
}

/**
* Get the Transaction Type.
*
Expand Down

0 comments on commit 5f5a66c

Please sign in to comment.