MediaWiki REL1_28
LBFactorySimple.php
Go to the documentation of this file.
1<?php
29 private $mainLB;
31 private $extLBs = [];
32
34 private $servers = [];
36 private $externalClusters = [];
37
40
53 public function __construct( array $conf ) {
54 parent::__construct( $conf );
55
56 $this->servers = isset( $conf['servers'] ) ? $conf['servers'] : [];
57 foreach ( $this->servers as $i => $server ) {
58 if ( $i == 0 ) {
59 $this->servers[$i]['master'] = true;
60 } else {
61 $this->servers[$i]['replica'] = true;
62 }
63 }
64
65 $this->externalClusters = isset( $conf['externalClusters'] )
66 ? $conf['externalClusters']
67 : [];
68 $this->loadMonitorClass = isset( $conf['loadMonitorClass'] )
69 ? $conf['loadMonitorClass']
70 : 'LoadMonitor';
71 }
72
77 public function newMainLB( $domain = false ) {
78 return $this->newLoadBalancer( $this->servers );
79 }
80
85 public function getMainLB( $domain = false ) {
86 if ( !isset( $this->mainLB ) ) {
87 $this->mainLB = $this->newMainLB( $domain );
88 $this->getChronologyProtector()->initLB( $this->mainLB );
89 }
90
91 return $this->mainLB;
92 }
93
94 public function newExternalLB( $cluster ) {
95 if ( !isset( $this->externalClusters[$cluster] ) ) {
96 throw new InvalidArgumentException( __METHOD__ . ": Unknown cluster \"$cluster\"." );
97 }
98
99 return $this->newLoadBalancer( $this->externalClusters[$cluster] );
100 }
101
102 public function getExternalLB( $cluster ) {
103 if ( !isset( $this->extLBs[$cluster] ) ) {
104 $this->extLBs[$cluster] = $this->newExternalLB( $cluster );
105 $this->getChronologyProtector()->initLB( $this->extLBs[$cluster] );
106 }
107
108 return $this->extLBs[$cluster];
109 }
110
111 private function newLoadBalancer( array $servers ) {
112 $lb = new LoadBalancer( array_merge(
113 $this->baseLoadBalancerParams(),
114 [
115 'servers' => $servers,
116 'loadMonitor' => [ 'class' => $this->loadMonitorClass ],
117 ]
118 ) );
119 $this->initLoadBalancer( $lb );
120
121 return $lb;
122 }
123
132 public function forEachLB( $callback, array $params = [] ) {
133 if ( isset( $this->mainLB ) ) {
134 call_user_func_array( $callback, array_merge( [ $this->mainLB ], $params ) );
135 }
136 foreach ( $this->extLBs as $lb ) {
137 call_user_func_array( $callback, array_merge( [ $lb ], $params ) );
138 }
139 }
140}
A simple single-master LBFactory that gets its configuration from the b/c globals.
newMainLB( $domain=false)
newLoadBalancer(array $servers)
array[] $servers
Map of (server index => server config)
__construct(array $conf)
LoadBalancer $mainLB
forEachLB( $callback, array $params=[])
Execute a function for each tracked load balancer The callback is called with the load balancer as th...
array[] $externalClusters
Map of (cluster => (server index => server config))
getExternalLB( $cluster)
LoadBalancer[] $extLBs
getMainLB( $domain=false)
newExternalLB( $cluster)
An interface for generating database load balancers.
Definition LBFactory.php:31
initLoadBalancer(ILoadBalancer $lb)
baseLoadBalancerParams()
Base parameters to LoadBalancer::__construct()
getChronologyProtector()
Database connection, tracking, load balancing, and transaction manager for a cluster.
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
the array() calling protocol came about after MediaWiki 1.4rc1.
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:37
storage can be distributed across multiple servers
Definition memcached.txt:33
$params