'LBFactorySimple', 'LBFactory_Single' => 'LBFactorySingle', 'LBFactory_Multi' => 'LBFactoryMulti', 'LBFactory_Fake' => 'LBFactoryFake', ); $class = $config['class']; if ( isset( $bcClasses[$class] ) ) { $class = $bcClasses[$class]; wfDeprecated( '$wgLBFactoryConf must be updated. See RELEASE-NOTES for details', '1.23' ); } return $class; } /** * Shut down, close connections and destroy the cached instance. */ public static function destroyInstance() { if ( self::$instance ) { self::$instance->shutdown(); self::$instance->forEachLBCallMethod( 'closeAll' ); self::$instance = null; } } /** * Set the instance to be the given object * * @param LBFactory $instance */ public static function setInstance( $instance ) { self::destroyInstance(); self::$instance = $instance; } /** * Create a new load balancer object. The resulting object will be untracked, * not chronology-protected, and the caller is responsible for cleaning it up. * * @param bool|string $wiki Wiki ID, or false for the current wiki * @return LoadBalancer */ abstract public function newMainLB( $wiki = false ); /** * Get a cached (tracked) load balancer object. * * @param bool|string $wiki Wiki ID, or false for the current wiki * @return LoadBalancer */ abstract public function getMainLB( $wiki = false ); /** * Create a new load balancer for external storage. The resulting object will be * untracked, not chronology-protected, and the caller is responsible for * cleaning it up. * * @param string $cluster External storage cluster, or false for core * @param bool|string $wiki Wiki ID, or false for the current wiki * @return LoadBalancer */ abstract protected function newExternalLB( $cluster, $wiki = false ); /** * Get a cached (tracked) load balancer for external storage * * @param string $cluster External storage cluster, or false for core * @param bool|string $wiki Wiki ID, or false for the current wiki * @return LoadBalancer */ abstract public function &getExternalLB( $cluster, $wiki = false ); /** * Execute a function for each tracked load balancer * The callback is called with the load balancer as the first parameter, * and $params passed as the subsequent parameters. * * @param callable $callback * @param array $params */ abstract public function forEachLB( $callback, array $params = array() ); /** * Prepare all tracked load balancers for shutdown * STUB */ public function shutdown() { } /** * Call a method of each tracked load balancer * * @param string $methodName * @param array $args */ private function forEachLBCallMethod( $methodName, array $args = array() ) { $this->forEachLB( function ( LoadBalancer $loadBalancer, $methodName, array $args ) { call_user_func_array( array( $loadBalancer, $methodName ), $args ); }, array( $methodName, $args ) ); } /** * Commit on all connections. Done for two reasons: * 1. To commit changes to the masters. * 2. To release the snapshot on all connections, master and slave. */ public function commitAll() { $this->forEachLBCallMethod( 'commitAll' ); } /** * Commit changes on all master connections */ public function commitMasterChanges() { $this->forEachLBCallMethod( 'commitMasterChanges' ); } /** * Rollback changes on all master connections * @since 1.23 */ public function rollbackMasterChanges() { $this->forEachLBCallMethod( 'rollbackMasterChanges' ); } /** * Determine if any master connection has pending changes * @return bool * @since 1.23 */ public function hasMasterChanges() { $ret = false; $this->forEachLB( function ( LoadBalancer $lb ) use ( &$ret ) { $ret = $ret || $lb->hasMasterChanges(); } ); return $ret; } /** * Detemine if any lagged slave connection was used * @since 1.27 * @return bool */ public function laggedSlaveUsed() { $ret = false; $this->forEachLB( function ( LoadBalancer $lb ) use ( &$ret ) { $ret = $ret || $lb->laggedSlaveUsed(); } ); return $ret; } /** * Determine if any master connection has pending/written changes from this request * @return bool * @since 1.27 */ public function hasOrMadeRecentMasterChanges() { $ret = false; $this->forEachLB( function ( LoadBalancer $lb ) use ( &$ret ) { $ret = $ret || $lb->hasOrMadeRecentMasterChanges(); } ); return $ret; } } /** * Exception class for attempted DB access */ class DBAccessError extends MWException { public function __construct() { parent::__construct( "Mediawiki tried to access the database via wfGetDB(). " . "This is not allowed." ); } }