rdbms: add LoadBalancer::getLocalDomainId() method
[lhc/web/wiklou.git] / includes / libs / rdbms / loadbalancer / LoadBalancer.php
index b622ddc..e80b952 100644 (file)
@@ -18,7 +18,6 @@
  * http://www.gnu.org/copyleft/gpl.html
  *
  * @file
- * @ingroup Database
  */
 namespace Wikimedia\Rdbms;
 
@@ -189,6 +188,7 @@ class LoadBalancer implements ILoadBalancer {
                } else {
                        $this->loadMonitorConfig = [ 'class' => 'LoadMonitorNull' ];
                }
+               $this->loadMonitorConfig += [ 'lagWarnThreshold' => $this->maxLag ];
 
                foreach ( $params['servers'] as $i => $server ) {
                        $this->mLoads[$i] = $server['load'];
@@ -232,7 +232,9 @@ class LoadBalancer implements ILoadBalancer {
                $this->host = isset( $params['hostname'] )
                        ? $params['hostname']
                        : ( gethostname() ?: 'unknown' );
-               $this->cliMode = isset( $params['cliMode'] ) ? $params['cliMode'] : PHP_SAPI === 'cli';
+               $this->cliMode = isset( $params['cliMode'] )
+                       ? $params['cliMode']
+                       : ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' );
                $this->agent = isset( $params['agent'] ) ? $params['agent'] : '';
 
                if ( isset( $params['chronologyProtector'] ) ) {
@@ -240,6 +242,17 @@ class LoadBalancer implements ILoadBalancer {
                }
        }
 
+       /**
+        * Get the local (and default) database domain ID of connection handles
+        *
+        * @see DatabaseDomain
+        * @return string Database domain ID; this specifies DB name, schema, and table prefix
+        * @since 1.31
+        */
+       public function getLocalDomainID() {
+               return $this->localDomain->getId();
+       }
+
        /**
         * Get a LoadMonitor instance
         *
@@ -291,7 +304,7 @@ class LoadBalancer implements ILoadBalancer {
                                                "Server {host} is not replicating?", [ 'host' => $host ] );
                                        unset( $loads[$i] );
                                } elseif ( $lag > $maxServerLag ) {
-                                       $this->replLogger->warning(
+                                       $this->replLogger->info(
                                                "Server {host} has {lag} seconds of lag (>= {maxlag})",
                                                [ 'host' => $host, 'lag' => $lag, 'maxlag' => $maxServerLag ]
                                        );
@@ -939,7 +952,7 @@ class LoadBalancer implements ILoadBalancer {
         * @return bool
         */
        private function isOpen( $index ) {
-               if ( !is_integer( $index ) ) {
+               if ( !is_int( $index ) ) {
                        return false;
                }
 
@@ -1080,26 +1093,6 @@ class LoadBalancer implements ILoadBalancer {
                return isset( $this->mServers[$i]['type'] ) ? $this->mServers[$i]['type'] : 'unknown';
        }
 
-       /**
-        * @deprecated Since 1.30, no alternative
-        */
-       public function getServerInfo( $i ) {
-               wfDeprecated( __METHOD__, '1.30' );
-               if ( isset( $this->mServers[$i] ) ) {
-                       return $this->mServers[$i];
-               } else {
-                       return false;
-               }
-       }
-
-       /**
-        * @deprecated Since 1.30, construct new object
-        */
-       public function setServerInfo( $i, array $serverInfo ) {
-               wfDeprecated( __METHOD__, '1.30' );
-               $this->mServers[$i] = $serverInfo;
-       }
-
        public function getMasterPos() {
                # If this entire request was served from a replica DB without opening a connection to the
                # master (however unlikely that may be), then we can fetch the position from the replica DB.