diff options
author | Timo Tijhof <krinkle@fastmail.com> | 2024-09-26 00:14:04 -0700 |
---|---|---|
committer | Timo Tijhof <krinkle@fastmail.com> | 2024-10-22 01:20:41 +0100 |
commit | b781c5fce9b383d54a83c6dbe3c5a1352903123c (patch) | |
tree | 84108b9675c61bcf7e03887a8483ed3db5ae3ea2 /includes | |
parent | d521558b091ebf78923f5096363aa11c4f5196c8 (diff) | |
download | mediawikicore-b781c5fce9b383d54a83c6dbe3c5a1352903123c.tar.gz mediawikicore-b781c5fce9b383d54a83c6dbe3c5a1352903123c.zip |
rdbms: Remove reliance on internal STATUS_TRX and STATUS_SESS_ sequence
Follows-up I39cee1363496dfe2, which added a condition based on
`status > ERROR` which I think requires a reliance on, and
understanding/remembering of, the numerical sequence of statuses.
This sequence appears undocumented, both in the TransactionManager
constants and the trxStatus/sessionStatus methods, but either way is not
needed in any of the current cases. This made the code harder to
understand, increases doubt about its correctness, requiring additional
checking while debugging or code reviewing.
Change-Id: Ia0f4b0cfae02de52e7618e558cca6d266689e760
Diffstat (limited to 'includes')
-rw-r--r-- | includes/libs/rdbms/database/Database.php | 8 | ||||
-rw-r--r-- | includes/libs/rdbms/database/TransactionManager.php | 4 |
2 files changed, 6 insertions, 6 deletions
diff --git a/includes/libs/rdbms/database/Database.php b/includes/libs/rdbms/database/Database.php index 17ff248f3a5d..951f763877a0 100644 --- a/includes/libs/rdbms/database/Database.php +++ b/includes/libs/rdbms/database/Database.php @@ -2386,7 +2386,7 @@ abstract class Database implements Stringable, IDatabaseForOwner, IMaintainableD if ( !$this->trxLevel() ) { $this->transactionManager->setTrxStatusToNone(); $this->transactionManager->clearPreEndCallbacks(); - if ( $this->transactionManager->trxLevel() <= TransactionManager::STATUS_TRX_ERROR ) { + if ( $this->transactionManager->trxLevel() === TransactionManager::STATUS_TRX_ERROR ) { $this->logger->info( "$fname: acknowledged server-side transaction loss on {db_server}", $this->getLogContext() @@ -2475,7 +2475,7 @@ abstract class Database implements Stringable, IDatabaseForOwner, IMaintainableD ); } - if ( $this->transactionManager->sessionStatus() <= TransactionManager::STATUS_SESS_ERROR ) { + if ( $this->transactionManager->sessionStatus() === TransactionManager::STATUS_SESS_ERROR ) { // If the session state was already lost due to either an unacknowledged session // state loss error (e.g. dropped connection) or an explicit connection close call, // then there is nothing to do here. Note that in such cases, even temporary tables @@ -2947,8 +2947,8 @@ abstract class Database implements Stringable, IDatabaseForOwner, IMaintainableD // spam and confusing replacement of an original DBError with one about unlock(). // Unlock query will fail anyway; avoid possibly triggering errors in rollback() if ( - $this->transactionManager->sessionStatus() <= TransactionManager::STATUS_SESS_ERROR || - $this->transactionManager->trxStatus() <= TransactionManager::STATUS_TRX_ERROR + $this->transactionManager->sessionStatus() === TransactionManager::STATUS_SESS_ERROR || + $this->transactionManager->trxStatus() === TransactionManager::STATUS_TRX_ERROR ) { return; } diff --git a/includes/libs/rdbms/database/TransactionManager.php b/includes/libs/rdbms/database/TransactionManager.php index 1022c46245ed..c3bfc2e1a24e 100644 --- a/includes/libs/rdbms/database/TransactionManager.php +++ b/includes/libs/rdbms/database/TransactionManager.php @@ -177,7 +177,7 @@ class TransactionManager { } public function assertTransactionStatus( IDatabase $db, $deprecationLogger, $fname ) { - if ( $this->trxStatus < self::STATUS_TRX_OK ) { + if ( $this->trxStatus === self::STATUS_TRX_ERROR ) { throw new DBTransactionStateError( $db, "Cannot execute query from $fname while transaction status is ERROR", @@ -211,7 +211,7 @@ class TransactionManager { * @param Throwable $trxError */ public function setTransactionError( Throwable $trxError ) { - if ( $this->trxStatus > self::STATUS_TRX_ERROR ) { + if ( $this->trxStatus !== self::STATUS_TRX_ERROR ) { $this->trxStatus = self::STATUS_TRX_ERROR; $this->trxStatusCause = $trxError; } |