* @ingroup Database
*/
+namespace Wikimedia\Rdbms;
+
+use InvalidArgumentException;
+
/**
* A simple single-master LBFactory that gets its configuration from the b/c globals
*/
/** @var string */
private $loadMonitorClass;
+ /**
+ * @see LBFactory::__construct()
+ * @param array $conf Parameters of LBFactory::__construct() as well as:
+ * - servers : list of server configuration maps to Database::factory().
+ * Additionally, the server maps should have a 'load' key, which is used to decide
+ * how often clients connect to one server verses the others. A 'max lag' key should
+ * also be set on server maps, indicating how stale the data can be before the load
+ * balancer tries to avoid using it. The map can have 'is static' set to disable blocking
+ * replication sync checks (intended for archive servers with unchanging data).
+ * - externalClusters : map of cluster names to server arrays. The servers arrays have the
+ * same format as "servers" above.
+ */
public function __construct( array $conf ) {
parent::__construct( $conf );
: [];
$this->loadMonitorClass = isset( $conf['loadMonitorClass'] )
? $conf['loadMonitorClass']
- : null;
+ : 'LoadMonitor';
}
/**
return $this->mainLB;
}
- /**
- * @param string $cluster
- * @param bool|string $domain
- * @return LoadBalancer
- * @throws InvalidArgumentException
- */
- protected function newExternalLB( $cluster, $domain = false ) {
+ public function newExternalLB( $cluster ) {
if ( !isset( $this->externalClusters[$cluster] ) ) {
throw new InvalidArgumentException( __METHOD__ . ": Unknown cluster \"$cluster\"." );
}
return $this->newLoadBalancer( $this->externalClusters[$cluster] );
}
- /**
- * @param string $cluster
- * @param bool|string $domain
- * @return array
- */
- public function getExternalLB( $cluster, $domain = false ) {
+ public function getExternalLB( $cluster ) {
if ( !isset( $this->extLBs[$cluster] ) ) {
- $this->extLBs[$cluster] = $this->newExternalLB( $cluster, $domain );
+ $this->extLBs[$cluster] = $this->newExternalLB( $cluster );
$this->getChronologyProtector()->initLB( $this->extLBs[$cluster] );
}
return $this->extLBs[$cluster];
}
+ public function getAllMainLBs() {
+ return [ 'DEFAULT' => $this->getMainLB() ];
+ }
+
+ public function getAllExternalLBs() {
+ $lbs = [];
+ foreach ( $this->externalClusters as $cluster => $unused ) {
+ $lbs[$cluster] = $this->getExternalLB( $cluster );
+ }
+
+ return $lbs;
+ }
+
private function newLoadBalancer( array $servers ) {
$lb = new LoadBalancer( array_merge(
$this->baseLoadBalancerParams(),
[
'servers' => $servers,
- 'loadMonitor' => $this->loadMonitorClass,
+ 'loadMonitor' => [ 'class' => $this->loadMonitorClass ],
]
) );
$this->initLoadBalancer( $lb );