rdbms: reduce LoadBalancer replication log spam
[lhc/web/wiklou.git] / includes / libs / rdbms / loadbalancer / LoadBalancer.php
index b2b2391..ca18122 100644 (file)
@@ -312,7 +312,7 @@ class LoadBalancer implements ILoadBalancer {
                                                ": server {host} is not replicating?", [ 'host' => $host ] );
                                        unset( $loads[$i] );
                                } elseif ( $lag > $maxServerLag ) {
-                                       $this->replLogger->info(
+                                       $this->replLogger->debug(
                                                __METHOD__ .
                                                ": server {host} has {lag} seconds of lag (>= {maxlag})",
                                                [ 'host' => $host, 'lag' => $lag, 'maxlag' => $maxServerLag ]
@@ -1281,6 +1281,11 @@ class LoadBalancer implements ILoadBalancer {
        }
 
        public function closeConnection( IDatabase $conn ) {
+               if ( $conn instanceof DBConnRef ) {
+                       // Avoid calling close() but still leaving the handle in the pool
+                       throw new RuntimeException( __METHOD__ . ': got DBConnRef instance.' );
+               }
+
                $serverIndex = $conn->getLBInfo( 'serverIndex' );
                foreach ( $this->conns as $type => $connsByServer ) {
                        if ( !isset( $connsByServer[$serverIndex] ) ) {
@@ -1395,7 +1400,7 @@ class LoadBalancer implements ILoadBalancer {
                $failures = [];
 
                /** @noinspection PhpUnusedLocalVariableInspection */
-               $scope = $this->getScopedPHPBehaviorForCommit(); // try to ignore client aborts
+               $scope = ScopedCallback::newScopedIgnoreUserAbort(); // try to ignore client aborts
 
                $restore = ( $this->trxRoundId !== false );
                $this->trxRoundId = false;
@@ -1913,7 +1918,15 @@ class LoadBalancer implements ILoadBalancer {
                $this->indexAliases = $aliases;
        }
 
+       /**
+        * @param string $prefix
+        * @deprecated Since 1.33
+        */
        public function setDomainPrefix( $prefix ) {
+               $this->setLocalDomainPrefix( $prefix );
+       }
+
+       public function setLocalDomainPrefix( $prefix ) {
                // Find connections to explicit foreign domains still marked as in-use...
                $domainsInUse = [];
                $this->forEachOpenConnection( function ( IDatabase $conn ) use ( &$domainsInUse ) {
@@ -1945,6 +1958,12 @@ class LoadBalancer implements ILoadBalancer {
                } );
        }
 
+       public function redefineLocalDomain( $domain ) {
+               $this->closeAll();
+
+               $this->setLocalDomain( DatabaseDomain::newFromId( $domain ) );
+       }
+
        /**
         * @param DatabaseDomain $domain
         */
@@ -1960,23 +1979,6 @@ class LoadBalancer implements ILoadBalancer {
                }
        }
 
-       /**
-        * Make PHP ignore user aborts/disconnects until the returned
-        * value leaves scope. This returns null and does nothing in CLI mode.
-        *
-        * @return ScopedCallback|null
-        */
-       final protected function getScopedPHPBehaviorForCommit() {
-               if ( PHP_SAPI != 'cli' ) { // https://bugs.php.net/bug.php?id=47540
-                       $old = ignore_user_abort( true ); // avoid half-finished operations
-                       return new ScopedCallback( function () use ( $old ) {
-                               ignore_user_abort( $old );
-                       } );
-               }
-
-               return null;
-       }
-
        function __destruct() {
                // Avoid connection leaks for sanity
                $this->disable();