MediaWiki  1.27.2
LBFactorySimple.php
Go to the documentation of this file.
1 <?php
27 class LBFactorySimple extends LBFactory {
29  private $mainLB;
31  private $extLBs = [];
32 
35 
36  public function __construct( array $conf ) {
37  parent::__construct( $conf );
38 
39  $this->loadMonitorClass = isset( $conf['loadMonitorClass'] )
40  ? $conf['loadMonitorClass']
41  : null;
42  }
43 
48  public function newMainLB( $wiki = false ) {
50 
51  if ( is_array( $wgDBservers ) ) {
52  $servers = $wgDBservers;
53  foreach ( $servers as $i => &$server ) {
54  if ( $i == 0 ) {
55  $server['master'] = true;
56  } else {
57  $server['slave'] = true;
58  }
59  }
60  } else {
63 
65  if ( $wgDebugDumpSql ) {
66  $flags |= DBO_DEBUG;
67  }
68  if ( $wgDBssl ) {
69  $flags |= DBO_SSL;
70  }
71  if ( $wgDBcompress ) {
73  }
74 
75  $servers = [ [
76  'host' => $wgDBserver,
77  'user' => $wgDBuser,
78  'password' => $wgDBpassword,
79  'dbname' => $wgDBname,
80  'type' => $wgDBtype,
81  'load' => 1,
82  'flags' => $flags,
83  'master' => true
84  ] ];
85  }
86 
87  return new LoadBalancer( [
88  'servers' => $servers,
89  'loadMonitor' => $this->loadMonitorClass,
90  'readOnlyReason' => $this->readOnlyReason,
91  'trxProfiler' => $this->trxProfiler
92  ] );
93  }
94 
99  public function getMainLB( $wiki = false ) {
100  if ( !isset( $this->mainLB ) ) {
101  $this->mainLB = $this->newMainLB( $wiki );
102  $this->mainLB->parentInfo( [ 'id' => 'main' ] );
103  $this->chronProt->initLB( $this->mainLB );
104  }
105 
106  return $this->mainLB;
107  }
108 
115  protected function newExternalLB( $cluster, $wiki = false ) {
117  if ( !isset( $wgExternalServers[$cluster] ) ) {
118  throw new MWException( __METHOD__ . ": Unknown cluster \"$cluster\"" );
119  }
120 
121  return new LoadBalancer( [
122  'servers' => $wgExternalServers[$cluster],
123  'loadMonitor' => $this->loadMonitorClass,
124  'readOnlyReason' => $this->readOnlyReason,
125  'trxProfiler' => $this->trxProfiler
126  ] );
127  }
128 
134  public function &getExternalLB( $cluster, $wiki = false ) {
135  if ( !isset( $this->extLBs[$cluster] ) ) {
136  $this->extLBs[$cluster] = $this->newExternalLB( $cluster, $wiki );
137  $this->extLBs[$cluster]->parentInfo( [ 'id' => "ext-$cluster" ] );
138  $this->chronProt->initLB( $this->extLBs[$cluster] );
139  }
140 
141  return $this->extLBs[$cluster];
142  }
143 
152  public function forEachLB( $callback, array $params = [] ) {
153  if ( isset( $this->mainLB ) ) {
154  call_user_func_array( $callback, array_merge( [ $this->mainLB ], $params ) );
155  }
156  foreach ( $this->extLBs as $lb ) {
157  call_user_func_array( $callback, array_merge( [ $lb ], $params ) );
158  }
159  }
160 
161  public function shutdown( $flags = 0 ) {
162  if ( !( $flags & self::SHUTDOWN_NO_CHRONPROT ) ) {
163  $this->shutdownChronologyProtector( $this->chronProt );
164  }
165  $this->commitMasterChanges( __METHOD__ ); // sanity
166  }
167 }
the array() calling protocol came about after MediaWiki 1.4rc1.
A simple single-master LBFactory that gets its configuration from the b/c globals.
shutdownChronologyProtector(ChronologyProtector $cp)
Definition: LBFactory.php:447
$wgDBpassword
Database user's password.
$wgDBtype
Database type.
newExternalLB($cluster, $wiki=false)
$wgDBserver
Database host name or IP address.
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2548
$wgDBuser
Database username.
const DBO_COMPRESS
Definition: Defines.php:39
const DBO_DEBUG
Definition: Defines.php:30
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
commitMasterChanges($fname=__METHOD__, array $options=[])
Commit changes on all master connections.
Definition: LBFactory.php:234
LoadBalancer[] $extLBs
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1798
Database load balancing object.
& getExternalLB($cluster, $wiki=false)
$wgExternalServers
An array of external MySQL servers.
An interface for generating database load balancers.
Definition: LBFactory.php:31
__construct(array $conf)
$wgDBssl
Whether to use SSL in DB connection.
$params
const DBO_SSL
Definition: Defines.php:38
$wgDBservers
Database load balancer This is a two-dimensional array, an array of server info structures Fields are...
LoadBalancer $mainLB
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
$wgDBcompress
Whether to use compression in DB connection.
getMainLB($wiki=false)
const DBO_DEFAULT
Definition: Defines.php:34
forEachLB($callback, array $params=[])
Execute a function for each tracked load balancer The callback is called with the load balancer as th...
controlled by $wgMainCacheType controlled by $wgParserCacheType controlled by $wgMessageCacheType If you set CACHE_NONE to one of the three control default value for MediaWiki still create a but requests to it are no ops and we always fall through to the database If the cache daemon can t be it should also disable itself fairly smoothly By $wgMemc is used but when it is $parserMemc or $messageMemc this is mentioned $wgDBname
Definition: memcached.txt:96
newMainLB($wiki=false)