rdbms: disable ChronologyProtector if EmptyBagOStuff is used
[lhc/web/wiklou.git] / includes / libs / rdbms / lbfactory / LBFactory.php
index b1ea810..401e9b3 100644 (file)
@@ -30,6 +30,7 @@ use EmptyBagOStuff;
 use WANObjectCache;
 use Exception;
 use RuntimeException;
+use LogicException;
 
 /**
  * An interface for generating database load balancers
@@ -131,7 +132,9 @@ abstract class LBFactory implements ILBFactory {
                        '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'] : '';
 
@@ -463,6 +466,10 @@ abstract class LBFactory implements ILBFactory {
                        // Request opted out of using position wait logic. This is useful for requests
                        // done by the job queue or background ETL that do not have a meaningful session.
                        $this->chronProt->setWaitEnabled( false );
+               } elseif ( $this->memStash instanceof EmptyBagOStuff ) {
+                       // No where to store any DB positions and wait for them to appear
+                       $this->chronProt->setEnabled( false );
+                       $this->replLogger->info( 'Cannot use ChronologyProtector with EmptyBagOStuff.' );
                }
 
                $this->replLogger->debug( __METHOD__ . ': using request info ' .
@@ -525,7 +532,11 @@ abstract class LBFactory implements ILBFactory {
                        'hostname' => $this->hostname,
                        'cliMode' => $this->cliMode,
                        'agent' => $this->agent,
-                       'chronologyProtector' => $this->getChronologyProtector()
+                       'chronologyCallback' => function ( ILoadBalancer $lb ) {
+                               // Defer ChronologyProtector construction in case setRequestInfo() ends up
+                               // being called later (but before the first connection attempt) (T192611)
+                               $this->getChronologyProtector()->initLB( $lb );
+                       }
                ];
        }
 
@@ -583,6 +594,10 @@ abstract class LBFactory implements ILBFactory {
        }
 
        public function setRequestInfo( array $info ) {
+               if ( $this->chronProt ) {
+                       throw new LogicException( 'ChronologyProtector already initialized.' );
+               }
+
                $this->requestInfo = $info + $this->requestInfo;
        }