* @ingroup Database
*/
class LoadBalancer {
- /* private */ var $mServers, $mConns, $mLoads, $mGroupLoads;
- /* private */ var $mErrorConnection;
- /* private */ var $mReadIndex, $mAllowLagged;
- /* private */ var $mWaitForPos, $mWaitTimeout;
- /* private */ var $mLaggedSlaveMode, $mLastError = 'Unknown error';
- /* private */ var $mParentInfo, $mLagTimes;
- /* private */ var $mLoadMonitorClass, $mLoadMonitor;
+ private $mServers, $mConns, $mLoads, $mGroupLoads;
+ private $mErrorConnection;
+ private $mReadIndex, $mAllowLagged;
+ private $mWaitForPos, $mWaitTimeout;
+ private $mLaggedSlaveMode, $mLastError = 'Unknown error';
+ private $mParentInfo, $mLagTimes;
+ private $mLoadMonitorClass, $mLoadMonitor;
/**
* @param $params Array with keys:
/**
* Get a LoadMonitor instance
+ *
+ * @return LoadMonitor
*/
function getLoadMonitor() {
if ( !isset( $this->mLoadMonitor ) ) {
* Given an array of non-normalised probabilities, this function will select
* an element and return the appropriate key
*/
- function pickRandom( $weights )
- {
+ function pickRandom( $weights ) {
if ( !is_array( $weights ) || count( $weights ) == 0 ) {
return false;
}
$i = $this->getRandomNonLagged( $currentLoads, $wiki );
if ( $i === false && count( $currentLoads ) != 0 ) {
# All slaves lagged. Switch to read-only mode
- $wgReadOnly = wfMsgNoDBForContent( 'readonly_lag' );
+ $wgReadOnly = wfMessage( 'readonly_lag' )->useDatabase( false )->plain();
$i = $this->pickRandom( $currentLoads );
$laggedSlaveMode = true;
}
/**
* Get any open connection to a given server index, local or foreign
* Returns false if there is no connection open
+ *
+ * @return DatabaseBase
*/
function getAnyOpenConnection( $i ) {
foreach ( $this->mConns as $conns ) {
* Mark a foreign connection as being available for reuse under a different
* DB name or prefix. This mechanism is reference-counted, and must be called
* the same number of times as getConnection() to work.
+ *
+ * @param DatabaseBase $conn
*/
public function reuseConnection( $conn ) {
$serverIndex = $conn->getLBInfo('serverIndex');
}
}
+ /**
+ * Sets the server info structure for the given index. Entry at index $i is created if it doesn't exist
+ */
+ function setServerInfo( $i, $serverInfo ) {
+ $this->mServers[$i] = $serverInfo;
+ }
+
/**
* Get the current master position for chronology control purposes
* @return mixed