Unbreak "localDBMaster" mode in MySqlLockManager by using a separate connection
authorAaron Schulz <aschulz@wikimedia.org>
Sat, 30 Jul 2016 02:18:58 +0000 (19:18 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Sat, 30 Jul 2016 02:18:58 +0000 (19:18 -0700)
Change-Id: I4f9328e1555d814e0849cea86aca20896c6dfacf

includes/filebackend/lockmanager/DBLockManager.php

index e5ded45..b61b08d 100644 (file)
@@ -150,8 +150,7 @@ abstract class DBLockManager extends QuorumLockManager {
                if ( !isset( $this->conns[$lockDb] ) ) {
                        $db = null;
                        if ( $lockDb === 'localDBMaster' ) {
-                               $lb = wfGetLBFactory()->getMainLB( $this->domain );
-                               $db = $lb->getConnection( DB_MASTER, [], $this->domain );
+                               $db = $this->getLocalLB()->getConnection( DB_MASTER, [], $this->domain );
                        } elseif ( isset( $this->dbServers[$lockDb] ) ) {
                                $config = $this->dbServers[$lockDb];
                                $db = DatabaseBase::factory( $config['type'], $config );
@@ -178,6 +177,13 @@ abstract class DBLockManager extends QuorumLockManager {
                return $this->conns[$lockDb];
        }
 
+       /**
+        * @return LoadBalancer
+        */
+       protected function getLocalLB() {
+               return wfGetLBFactory()->getMainLB( $this->domain );
+       }
+
        /**
         * Do additional initialization for new lock DB connection
         *
@@ -249,10 +255,11 @@ class MySqlLockManager extends DBLockManager {
                self::LOCK_EX => self::LOCK_EX
        ];
 
-       /**
-        * @param string $lockDb
-        * @param IDatabase $db
-        */
+       protected function getLocalLB() {
+               // Use a separate connection so releaseAllLocks() doesn't rollback the main trx
+               return wfGetLBFactory()->newMainLB( $this->domain );
+       }
+
        protected function initConnection( $lockDb, IDatabase $db ) {
                # Let this transaction see lock rows from other transactions
                $db->query( "SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;" );