26use InvalidArgumentException;
48 const MAX_LAG_DEFAULT = 10;
63 parent::__construct( $conf );
65 $this->
servers = isset( $conf[
'servers'] ) ? $conf[
'servers'] : [];
66 foreach ( $this->
servers as $i => $server ) {
68 $this->
servers[$i][
'master'] =
true;
70 $this->
servers[$i][
'replica'] =
true;
74 $this->externalClusters = isset( $conf[
'externalClusters'] )
75 ? $conf[
'externalClusters']
77 $this->loadMonitorClass = isset( $conf[
'loadMonitorClass'] )
78 ? $conf[
'loadMonitorClass']
80 $this->maxLag = isset( $conf[
'maxLag'] ) ? $conf[
'maxLag'] : self::MAX_LAG_DEFAULT;
96 if ( !isset( $this->mainLB ) ) {
97 $this->mainLB = $this->
newMainLB( $domain );
104 if ( !isset( $this->externalClusters[$cluster] ) ) {
105 throw new InvalidArgumentException( __METHOD__ .
": Unknown cluster \"$cluster\"." );
112 if ( !isset( $this->extLBs[$cluster] ) ) {
116 return $this->extLBs[$cluster];
120 return [
'DEFAULT' => $this->
getMainLB() ];
125 foreach ( $this->externalClusters as $cluster => $unused ) {
136 'servers' => $servers,
137 'maxLag' => $this->maxLag,
138 'loadMonitor' => [
'class' => $this->loadMonitorClass ],
155 if ( isset( $this->mainLB ) ) {
156 call_user_func_array( $callback, array_merge( [ $this->mainLB ],
$params ) );
158 foreach ( $this->extLBs as $lb ) {
159 call_user_func_array( $callback, array_merge( [ $lb ],
$params ) );
storage can be distributed across multiple servers