Merge "rdbms: make LBFactory "cliMode" check for phpdbg"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 11 Apr 2018 22:12:33 +0000 (22:12 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 11 Apr 2018 22:12:34 +0000 (22:12 +0000)
1  2 
includes/libs/rdbms/lbfactory/LBFactory.php
includes/libs/rdbms/loadbalancer/LoadBalancer.php

@@@ -52,8 -52,6 +52,8 @@@ abstract class LBFactory implements ILB
        protected $perfLogger;
        /** @var callable Error logger */
        protected $errorLogger;
 +      /** @var callable Deprecation logger */
 +      protected $deprecationLogger;
        /** @var BagOStuff */
        protected $srvCache;
        /** @var BagOStuff */
                $this->errorLogger = isset( $conf['errorLogger'] )
                        ? $conf['errorLogger']
                        : function ( Exception $e ) {
 -                              trigger_error( E_USER_WARNING, get_class( $e ) . ': ' . $e->getMessage() );
 +                              trigger_error( get_class( $e ) . ': ' . $e->getMessage(), E_USER_WARNING );
 +                      };
 +              $this->deprecationLogger = isset( $conf['deprecationLogger'] )
 +                      ? $conf['deprecationLogger']
 +                      : function ( $msg ) {
 +                              trigger_error( $msg, E_USER_DEPRECATED );
                        };
  
                $this->profiler = isset( $conf['profiler'] ) ? $conf['profiler'] : null;
                        'ChronologyPositionIndex' => isset( $_GET['cpPosIndex'] ) ? $_GET['cpPosIndex'] : null
                ];
  
-               $this->cliMode = isset( $conf['cliMode'] ) ? $conf['cliMode'] : PHP_SAPI === 'cli';
+               $this->cliMode = isset( $conf['cliMode'] )
+                       ? $conf['cliMode']
+                       : ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' );
                $this->hostname = isset( $conf['hostname'] ) ? $conf['hostname'] : gethostname();
                $this->agent = isset( $conf['agent'] ) ? $conf['agent'] : '';
  
                        'connLogger' => $this->connLogger,
                        'replLogger' => $this->replLogger,
                        'errorLogger' => $this->errorLogger,
 +                      'deprecationLogger' => $this->deprecationLogger,
                        'hostname' => $this->hostname,
                        'cliMode' => $this->cliMode,
                        'agent' => $this->agent,
@@@ -111,8 -111,6 +111,8 @@@ class LoadBalancer implements ILoadBala
  
        /** @var callable Exception logger */
        private $errorLogger;
 +      /** @var callable Deprecation logger */
 +      private $deprecationLogger;
  
        /** @var bool */
        private $disabled = false;
                        : function ( Exception $e ) {
                                trigger_error( get_class( $e ) . ': ' . $e->getMessage(), E_USER_WARNING );
                        };
 +              $this->deprecationLogger = isset( $params['deprecationLogger'] )
 +                      ? $params['deprecationLogger']
 +                      : function ( $msg ) {
 +                              trigger_error( $msg, E_USER_DEPRECATED );
 +                      };
  
                foreach ( [ 'replLogger', 'connLogger', 'queryLogger', 'perfLogger' ] as $key ) {
                        $this->$key = isset( $params[$key] ) ? $params[$key] : new NullLogger();
                                if ( $this->loads[$i] > 0 ) {
                                        $start = microtime( true );
                                        $ok = $this->doWait( $i, true, $timeout ) && $ok;
-                                       $timeout -= ( microtime( true ) - $start );
+                                       $timeout -= intval( microtime( true ) - $start );
                                        if ( $timeout <= 0 ) {
                                                break; // timeout reached
                                        }
                $server['connLogger'] = $this->connLogger;
                $server['queryLogger'] = $this->queryLogger;
                $server['errorLogger'] = $this->errorLogger;
 +              $server['deprecationLogger'] = $this->deprecationLogger;
                $server['profiler'] = $this->profiler;
                $server['trxProfiler'] = $this->trxProfiler;
                // Use the same agent and PHP mode for all DB handles
        }
  
        /**
 +       * Make all DB servers with DBO_DEFAULT/DBO_TRX set join the transaction round
 +       *
 +       * Some servers may have neither flag enabled, meaning that they opt out of such
 +       * transaction rounds and remain in auto-commit mode. Such behavior might be desired
 +       * when a DB server is used for something like simple key/value storage.
 +       *
         * @param IDatabase $conn
         */
        private function applyTransactionRoundFlags( IDatabase $conn ) {
                        // DBO_TRX is controlled entirely by CLI mode presence with DBO_DEFAULT.
                        // Force DBO_TRX even in CLI mode since a commit round is expected soon.
                        $conn->setFlag( $conn::DBO_TRX, $conn::REMEMBER_PRIOR );
 -                      // If config has explicitly requested DBO_TRX be either on or off by not
 -                      // setting DBO_DEFAULT, then respect that. Forcing no transactions is useful
 -                      // for things like blob stores (ExternalStore) which want auto-commit mode.
 +              }
 +
 +              if ( $conn->getFlag( $conn::DBO_TRX ) ) {
 +                      $conn->setLBInfo( 'trxRoundId', $this->trxRoundId );
                }
        }
  
                        return; // transaction rounds do not apply to these connections
                }
  
 +              if ( $conn->getFlag( $conn::DBO_TRX ) ) {
 +                      $conn->setLBInfo( 'trxRoundId', false );
 +              }
 +
                if ( $conn->getFlag( $conn::DBO_DEFAULT ) ) {
                        $conn->restoreFlags( $conn::RESTORE_PRIOR );
                }