Merge "Add ext-dom to composer.json"
[lhc/web/wiklou.git] / includes / libs / rdbms / loadbalancer / LoadBalancer.php
index 0f107a2..771700c 100644 (file)
@@ -68,7 +68,9 @@ class LoadBalancer implements ILoadBalancer {
        /** @var DatabaseDomain Local DB domain ID and default for selectDB() calls */
        private $localDomain;
 
-       /** @var Database[][][] Map of (connection category => server index => IDatabase[]) */
+       /**
+        * @var IDatabase[][][]|Database[][][] Map of (connection category => server index => IDatabase[])
+        */
        private $conns;
 
        /** @var array[] Map of (server index => server config array) */
@@ -99,7 +101,7 @@ class LoadBalancer implements ILoadBalancer {
        private $tableAliases = [];
        /** @var string[] Map of (index alias => index) */
        private $indexAliases = [];
-       /** @var array[] Map of (name => callable) */
+       /** @var callable[] Map of (name => callable) */
        private $trxRecurringCallbacks = [];
        /** @var bool[] Map of (domain => whether to use "temp tables only" mode) */
        private $tempTablesOnlyMode = [];
@@ -970,17 +972,7 @@ class LoadBalancer implements ILoadBalancer {
                $serverIndex = $conn->getLBInfo( 'serverIndex' );
                $refCount = $conn->getLBInfo( 'foreignPoolRefCount' );
                if ( $serverIndex === null || $refCount === null ) {
-                       /**
-                        * This can happen in code like:
-                        *   foreach ( $dbs as $db ) {
-                        *     $conn = $lb->getConnection( $lb::DB_REPLICA, [], $db );
-                        *     ...
-                        *     $lb->reuseConnection( $conn );
-                        *   }
-                        * When a connection to the local DB is opened in this way, reuseConnection()
-                        * should be ignored
-                        */
-                       return;
+                       return; // non-foreign connection; no domain-use tracking to update
                } elseif ( $conn instanceof DBConnRef ) {
                        // DBConnRef already handles calling reuseConnection() and only passes the live
                        // Database instance to this method. Any caller passing in a DBConnRef is broken.
@@ -1508,6 +1500,11 @@ class LoadBalancer implements ILoadBalancer {
        }
 
        public function closeAll() {
+               if ( $this->ownerId === null ) {
+                       /** @noinspection PhpUnusedLocalVariableInspection */
+                       $scope = ScopedCallback::newScopedIgnoreUserAbort();
+               }
+
                $fname = __METHOD__;
                $this->forEachOpenConnection( function ( IDatabase $conn ) use ( $fname ) {
                        $host = $conn->getServer();
@@ -1554,6 +1551,10 @@ class LoadBalancer implements ILoadBalancer {
        public function finalizeMasterChanges( $fname = __METHOD__, $owner = null ) {
                $this->assertOwnership( $fname, $owner );
                $this->assertTransactionRoundStage( [ self::ROUND_CURSORY, self::ROUND_FINALIZED ] );
+               if ( $this->ownerId === null ) {
+                       /** @noinspection PhpUnusedLocalVariableInspection */
+                       $scope = ScopedCallback::newScopedIgnoreUserAbort();
+               }
 
                $this->trxRoundStage = self::ROUND_ERROR; // "failed" until proven otherwise
                // Loop until callbacks stop adding callbacks on other connections
@@ -1579,6 +1580,10 @@ class LoadBalancer implements ILoadBalancer {
        public function approveMasterChanges( array $options, $fname = __METHOD__, $owner = null ) {
                $this->assertOwnership( $fname, $owner );
                $this->assertTransactionRoundStage( self::ROUND_FINALIZED );
+               if ( $this->ownerId === null ) {
+                       /** @noinspection PhpUnusedLocalVariableInspection */
+                       $scope = ScopedCallback::newScopedIgnoreUserAbort();
+               }
 
                $limit = $options['maxWriteDuration'] ?? 0;
 
@@ -1619,6 +1624,10 @@ class LoadBalancer implements ILoadBalancer {
                        );
                }
                $this->assertTransactionRoundStage( self::ROUND_CURSORY );
+               if ( $this->ownerId === null ) {
+                       /** @noinspection PhpUnusedLocalVariableInspection */
+                       $scope = ScopedCallback::newScopedIgnoreUserAbort();
+               }
 
                // Clear any empty transactions (no writes/callbacks) from the implicit round
                $this->flushMasterSnapshots( $fname );
@@ -1638,12 +1647,13 @@ class LoadBalancer implements ILoadBalancer {
        public function commitMasterChanges( $fname = __METHOD__, $owner = null ) {
                $this->assertOwnership( $fname, $owner );
                $this->assertTransactionRoundStage( self::ROUND_APPROVED );
+               if ( $this->ownerId === null ) {
+                       /** @noinspection PhpUnusedLocalVariableInspection */
+                       $scope = ScopedCallback::newScopedIgnoreUserAbort();
+               }
 
                $failures = [];
 
-               /** @noinspection PhpUnusedLocalVariableInspection */
-               $scope = ScopedCallback::newScopedIgnoreUserAbort(); // try to ignore client aborts
-
                $restore = ( $this->trxRoundId !== false );
                $this->trxRoundId = false;
                $this->trxRoundStage = self::ROUND_ERROR; // "failed" until proven otherwise
@@ -1686,6 +1696,10 @@ class LoadBalancer implements ILoadBalancer {
                                "Transaction should be in the callback stage (not '{$this->trxRoundStage}')"
                        );
                }
+               if ( $this->ownerId === null ) {
+                       /** @noinspection PhpUnusedLocalVariableInspection */
+                       $scope = ScopedCallback::newScopedIgnoreUserAbort();
+               }
 
                $oldStage = $this->trxRoundStage;
                $this->trxRoundStage = self::ROUND_ERROR; // "failed" until proven otherwise
@@ -1756,6 +1770,10 @@ class LoadBalancer implements ILoadBalancer {
                                "Transaction should be in the callback stage (not '{$this->trxRoundStage}')"
                        );
                }
+               if ( $this->ownerId === null ) {
+                       /** @noinspection PhpUnusedLocalVariableInspection */
+                       $scope = ScopedCallback::newScopedIgnoreUserAbort();
+               }
 
                $e = null;
 
@@ -1774,6 +1792,10 @@ class LoadBalancer implements ILoadBalancer {
 
        public function rollbackMasterChanges( $fname = __METHOD__, $owner = null ) {
                $this->assertOwnership( $fname, $owner );
+               if ( $this->ownerId === null ) {
+                       /** @noinspection PhpUnusedLocalVariableInspection */
+                       $scope = ScopedCallback::newScopedIgnoreUserAbort();
+               }
 
                $restore = ( $this->trxRoundId !== false );
                $this->trxRoundId = false;