Add LBFactory::disableChronologyProtection method
[lhc/web/wiklou.git] / includes / db / loadbalancer / LBFactorySimple.php
index 23cdbc6..1c9e094 100644 (file)
 class LBFactorySimple extends LBFactory {
        /** @var LoadBalancer */
        private $mainLB;
-
        /** @var LoadBalancer[] */
        private $extLBs = array();
 
-       /** @var ChronologyProtector */
-       private $chronProt;
+       /** @var string */
+       private $loadMonitorClass;
 
        public function __construct( array $conf ) {
-               $this->chronProt = new ChronologyProtector;
+               parent::__construct( $conf );
+
+               $this->loadMonitorClass = isset( $conf['loadMonitorClass'] )
+                       ? $conf['loadMonitorClass']
+                       : null;
        }
 
        /**
@@ -44,8 +47,16 @@ class LBFactorySimple extends LBFactory {
         */
        public function newMainLB( $wiki = false ) {
                global $wgDBservers;
-               if ( $wgDBservers ) {
+
+               if ( is_array( $wgDBservers ) ) {
                        $servers = $wgDBservers;
+                       foreach ( $servers as $i => &$server ) {
+                               if ( $i == 0 ) {
+                                       $server['master'] = true;
+                               } else {
+                                       $server['slave'] = true;
+                               }
+                       }
                } else {
                        global $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, $wgDBtype, $wgDebugDumpSql;
                        global $wgDBssl, $wgDBcompress;
@@ -68,12 +79,15 @@ class LBFactorySimple extends LBFactory {
                                'dbname' => $wgDBname,
                                'type' => $wgDBtype,
                                'load' => 1,
-                               'flags' => $flags
+                               'flags' => $flags,
+                               'master' => true
                        ) );
                }
 
                return new LoadBalancer( array(
                        'servers' => $servers,
+                       'loadMonitor' => $this->loadMonitorClass,
+                       'readOnlyReason' => $this->readOnlyReason
                ) );
        }
 
@@ -104,7 +118,9 @@ class LBFactorySimple extends LBFactory {
                }
 
                return new LoadBalancer( array(
-                       'servers' => $wgExternalServers[$cluster]
+                       'servers' => $wgExternalServers[$cluster],
+                       'loadMonitor' => $this->loadMonitorClass,
+                       'readOnlyReason' => $this->readOnlyReason
                ) );
        }
 
@@ -140,14 +156,10 @@ class LBFactorySimple extends LBFactory {
                }
        }
 
-       public function shutdown() {
-               if ( $this->mainLB ) {
-                       $this->chronProt->shutdownLB( $this->mainLB );
-               }
-               foreach ( $this->extLBs as $extLB ) {
-                       $this->chronProt->shutdownLB( $extLB );
+       public function shutdown( $flags = 0 ) {
+               if ( !( $flags & self::SHUTDOWN_NO_CHRONPROT ) ) {
+                       $this->shutdownChronologyProtector( $this->chronProt );
                }
-               $this->chronProt->shutdown();
-               $this->commitMasterChanges();
+               $this->commitMasterChanges(); // sanity
        }
 }