From 5f5a66c19a8574d4c32cd0387d7d7f0ef3e5fe4f Mon Sep 17 00:00:00 2001 From: Ajumal P A Date: Mon, 16 Oct 2023 13:10:48 +0000 Subject: [PATCH] commit with error test --- Spanner/src/Database.php | 4 ++-- Spanner/src/Operation.php | 15 +++++++++------ Spanner/src/Transaction.php | 10 ++++++---- Spanner/src/TransactionalReadTrait.php | 5 +++++ 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/Spanner/src/Database.php b/Spanner/src/Database.php index 4b49e26bb72b..a1bc064c5b3f 100644 --- a/Spanner/src/Database.php +++ b/Spanner/src/Database.php @@ -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']; } @@ -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(); } diff --git a/Spanner/src/Operation.php b/Spanner/src/Operation.php index 21583ed3c759..82377103ab0f 100644 --- a/Spanner/src/Operation.php +++ b/Spanner/src/Operation.php @@ -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); @@ -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([ @@ -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; @@ -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); diff --git a/Spanner/src/Transaction.php b/Spanner/src/Transaction.php index bd1e7020f750..679f6bd3969d 100644 --- a/Spanner/src/Transaction.php +++ b/Spanner/src/Transaction.php @@ -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]; @@ -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( @@ -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 ]); @@ -657,6 +658,7 @@ public function commit(array $options = []) // singleUse transaction $this->transactionId = null; } + unset($this->options['begin']); } if (!$this->singleUseState()) { diff --git a/Spanner/src/TransactionalReadTrait.php b/Spanner/src/TransactionalReadTrait.php index 69ad2a2376cf..ebea4d0c74f5 100644 --- a/Spanner/src/TransactionalReadTrait.php +++ b/Spanner/src/TransactionalReadTrait.php @@ -384,6 +384,11 @@ public function id() return $this->transactionId; } + public function &getIdReference() + { + return $this->transactionId; + } + /** * Get the Transaction Type. *