startupPos === null ) { if ( !empty( $_SESSION[__CLASS__] ) ) { $this->startupPos = $_SESSION[__CLASS__]; } } if ( !$this->startupPos ) { return; } $masterName = $lb->getServerName( 0 ); if ( $lb->getServerCount() > 1 && !empty( $this->startupPos[$masterName] ) ) { $info = $lb->parentInfo(); $pos = $this->startupPos[$masterName]; wfDebug( __METHOD__ . ": LB " . $info['id'] . " waiting for master pos $pos\n" ); $lb->waitFor( $this->startupPos[$masterName] ); } } /** * Notify the ChronologyProtector that the LoadBalancer is about to shut * down. Saves replication positions. * * @param $lb LoadBalancer */ function shutdownLB( $lb ) { // Don't start a session, don't bother with non-replicated setups if ( strval( session_id() ) == '' || $lb->getServerCount() <= 1 ) { return; } $masterName = $lb->getServerName( 0 ); if ( isset( $this->shutdownPos[$masterName] ) ) { // Already done return; } // Only save the position if writes have been done on the connection $db = $lb->getAnyOpenConnection( 0 ); $info = $lb->parentInfo(); if ( !$db || !$db->doneWrites() ) { wfDebug( __METHOD__ . ": LB {$info['id']}, no writes done\n" ); return; } $pos = $db->getMasterPos(); wfDebug( __METHOD__ . ": LB {$info['id']} has master pos $pos\n" ); $this->shutdownPos[$masterName] = $pos; } /** * Notify the ChronologyProtector that the LBFactory is done calling shutdownLB() for now. * May commit chronology data to persistent storage. */ function shutdown() { if ( session_id() != '' && count( $this->shutdownPos ) ) { wfDebug( __METHOD__ . ": saving master pos for " . count( $this->shutdownPos ) . " master(s)\n" ); $_SESSION[__CLASS__] = $this->shutdownPos; } } }