MediaWiki REL1_32
LBFactorySingle.php
Go to the documentation of this file.
1<?php
24namespace Wikimedia\Rdbms;
25
26use InvalidArgumentException;
27use BadMethodCallException;
28
34 private $lb;
35
40 public function __construct( array $conf ) {
41 parent::__construct( $conf );
42
43 if ( !isset( $conf['connection'] ) ) {
44 throw new InvalidArgumentException( "Missing 'connection' argument." );
45 }
46
47 $lb = new LoadBalancerSingle( array_merge( $this->baseLoadBalancerParams(), $conf ) );
48 $this->initLoadBalancer( $lb );
49 $this->lb = $lb;
50 }
51
58 public static function newFromConnection( IDatabase $db, array $params = [] ) {
59 return new static( array_merge(
60 [ 'localDomain' => $db->getDomainID() ],
61 $params,
62 [ 'connection' => $db ]
63 ) );
64 }
65
70 public function newMainLB( $domain = false ) {
71 return $this->lb;
72 }
73
78 public function getMainLB( $domain = false ) {
79 return $this->lb;
80 }
81
82 public function newExternalLB( $cluster ) {
83 throw new BadMethodCallException( "Method is not supported." );
84 }
85
86 public function getExternalLB( $cluster ) {
87 throw new BadMethodCallException( "Method is not supported." );
88 }
89
93 public function getAllMainLBs() {
94 return [ 'DEFAULT' => $this->lb ];
95 }
96
100 public function getAllExternalLBs() {
101 return [];
102 }
103
108 public function forEachLB( $callback, array $params = [] ) {
109 if ( isset( $this->lb ) ) { // may not be set during _destruct()
110 $callback( $this->lb, ...$params );
111 }
112 }
113}
An LBFactory class that always returns a single database object.
forEachLB( $callback, array $params=[])
static newFromConnection(IDatabase $db, array $params=[])
An interface for generating database load balancers.
Definition LBFactory.php:39
initLoadBalancer(ILoadBalancer $lb)
baseLoadBalancerParams()
Base parameters to ILoadBalancer::__construct()
Trivial LoadBalancer that always returns an injected connection handle.
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
getDomainID()
Return the currently selected domain ID.
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
$params