From: Aaron Schulz Date: Sun, 21 Aug 2016 21:03:24 +0000 (-0700) Subject: Remove commit() hack from User::addToDatabase() X-Git-Tag: 1.31.0-rc.0~5949^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22brouteur%22%2C%28%24id_rubrique%20?a=commitdiff_plain;h=a618d84bfb1de5498556bf42b83c0fb1425b29e4;p=lhc%2Fweb%2Fwiklou.git Remove commit() hack from User::addToDatabase() This is likely not needed anymore to avoid deadlocks anymore as AuthManagar uses a lock in autoCreateUser() before hand. Change-Id: I19ae6562011854495efcb0dd832b7ae99ebbb224 --- diff --git a/includes/user/User.php b/includes/user/User.php index 83cfa40644..2f2d5d8f33 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -3961,7 +3961,6 @@ class User implements IDBAccessObject { $noPass = PasswordFactory::newInvalidPassword()->toString(); $dbw = wfGetDB( DB_MASTER ); - $inWrite = $dbw->writesOrCallbacksPending(); $seqVal = $dbw->nextSequenceValue( 'user_user_id_seq' ); $dbw->insert( 'user', [ @@ -3980,25 +3979,17 @@ class User implements IDBAccessObject { [ 'IGNORE' ] ); if ( !$dbw->affectedRows() ) { - // The queries below cannot happen in the same REPEATABLE-READ snapshot. - // Handle this by COMMIT, if possible, or by LOCK IN SHARE MODE otherwise. - if ( $inWrite ) { - // Can't commit due to pending writes that may need atomicity. - // This may cause some lock contention unlike the case below. - $options = [ 'LOCK IN SHARE MODE' ]; - $flags = self::READ_LOCKING; - } else { - // Often, this case happens early in views before any writes when - // using CentralAuth. It's should be OK to commit and break the snapshot. - $dbw->commit( __METHOD__, 'flush' ); - $options = []; - $flags = self::READ_LATEST; - } - $this->mId = $dbw->selectField( 'user', 'user_id', - [ 'user_name' => $this->mName ], __METHOD__, $options ); + // Use locking reads to bypass any REPEATABLE-READ snapshot. + $this->mId = $dbw->selectField( + 'user', + 'user_id', + [ 'user_name' => $this->mName ], + __METHOD__, + [ 'LOCK IN SHARE MODE' ] + ); $loaded = false; if ( $this->mId ) { - if ( $this->loadFromDatabase( $flags ) ) { + if ( $this->loadFromDatabase( self::READ_LOCKING ) ) { $loaded = true; } }