26use InvalidArgumentException;
114 const MAX_LAG_DEFAULT = 10;
174 parent::__construct(
$conf );
177 $required = [
'sectionsByDB',
'sectionLoads',
'serverTemplate' ];
178 $optional = [
'groupLoadsBySection',
'groupLoadsByDB',
'hostsByName',
179 'externalLoads',
'externalTemplateOverrides',
'templateOverridesByServer',
180 'templateOverridesByCluster',
'templateOverridesBySection',
'masterTemplateOverrides',
181 'readOnlyBySection',
'maxLag',
'loadMonitorClass' ];
183 foreach ( $required as $key ) {
184 if ( !isset(
$conf[$key] ) ) {
185 throw new InvalidArgumentException( __CLASS__ .
": $key is required." );
187 $this->$key =
$conf[$key];
190 foreach ( $optional as $key ) {
191 if ( isset(
$conf[$key] ) ) {
192 $this->$key =
$conf[$key];
202 if ( $this->lastDomain === $domain ) {
206 if ( isset( $this->sectionsByDB[$dbName] ) ) {
207 $section = $this->sectionsByDB[$dbName];
212 $this->lastDomain = $domain;
224 if ( isset( $this->groupLoadsByDB[$dbName] ) ) {
225 $groupLoads = $this->groupLoadsByDB[$dbName];
230 if ( isset( $this->groupLoadsBySection[
$section] ) ) {
231 $groupLoads = array_merge_recursive(
232 $groupLoads, $this->groupLoadsBySection[
$section] );
242 if ( isset( $this->templateOverridesBySection[
$section] ) ) {
260 if ( !isset( $this->mainLBs[
$section] ) ) {
268 if ( !isset( $this->externalLoads[$cluster] ) ) {
269 throw new InvalidArgumentException( __METHOD__ .
": Unknown cluster \"$cluster\"" );
272 if ( $this->externalTemplateOverrides ) {
275 if ( isset( $this->templateOverridesByCluster[$cluster] ) ) {
281 $this->externalLoads[$cluster],
283 $this->readOnlyReason
288 if ( !isset( $this->extLBs[$cluster] ) ) {
292 return $this->extLBs[$cluster];
297 foreach ( $this->sectionsByDB as $db =>
$section ) {
308 foreach ( $this->externalLoads as $cluster => $unused ) {
329 'maxLag' => $this->maxLag,
330 'loadMonitor' => [
'class' => $this->loadMonitorClass ],
351 foreach ( $groupLoadsByServer as $server => $stuff ) {
352 if ( !isset( $loads[$server] ) ) {
356 foreach ( $loads as $serverName => $load ) {
359 $serverInfo[
'master'] =
true;
360 if ( $this->masterTemplateOverrides ) {
361 $serverInfo = $this->masterTemplateOverrides + $serverInfo;
365 $serverInfo[
'replica'] =
true;
367 if ( isset( $this->templateOverridesByServer[$serverName] ) ) {
368 $serverInfo = $this->templateOverridesByServer[$serverName] + $serverInfo;
370 if ( isset( $groupLoadsByServer[$serverName] ) ) {
371 $serverInfo[
'groupLoads'] = $groupLoadsByServer[$serverName];
373 if ( isset( $this->hostsByName[$serverName] ) ) {
374 $serverInfo[
'host'] = $this->hostsByName[$serverName];
376 $serverInfo[
'host'] = $serverName;
378 $serverInfo[
'hostName'] = $serverName;
379 $serverInfo[
'load'] = $load;
380 $serverInfo += [
'flags' => IDatabase::DBO_DEFAULT ];
382 $servers[] = $serverInfo;
395 foreach ( $groupLoads as $group => $loads ) {
396 foreach ( $loads as $server => $load ) {
397 $reindexed[$server][$group] = $load;
409 $domain = ( $domain ===
false )
413 return [ $domain->getDatabase(), $domain->getTablePrefix() ];
424 foreach ( $this->mainLBs as $lb ) {
425 call_user_func_array( $callback, array_merge( [ $lb ],
$params ) );
427 foreach ( $this->extLBs as $lb ) {
428 call_user_func_array( $callback, array_merge( [ $lb ],
$params ) );
static newFromId( $domain)
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping $template
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template $section
processing should stop and the error should be shown to the user * false