*/
class LoadBalancer {
private $mServers, $mConns, $mLoads, $mGroupLoads;
+
+ /** @var bool|DatabaseBase Database connection that caused a problem */
private $mErrorConnection;
private $mReadIndex, $mAllowLagged;
- private $mWaitForPos, $mWaitTimeout;
+
+ /** @var bool|DBMasterPos False if not set */
+ private $mWaitForPos;
+
+ private $mWaitTimeout;
private $mLaggedSlaveMode, $mLastError = 'Unknown error';
private $mParentInfo, $mLagTimes;
private $mLoadMonitorClass, $mLoadMonitor;
/**
* @param array $params with keys:
- * servers Required. Array of server info structures.
- * masterWaitTimeout Replication lag wait timeout
- * loadMonitor Name of a class used to fetch server lag and load.
+ * servers Required. Array of server info structures.
+ * masterWaitTimeout Replication lag wait timeout
+ * loadMonitor Name of a class used to fetch server lag and load.
* @throws MWException
*/
function __construct( $params ) {
} else {
$master = reset( $params['servers'] );
if ( isset( $master['type'] ) && $master['type'] === 'mysql' ) {
- $this->mLoadMonitorClass = 'LoadMonitor_MySQL';
+ $this->mLoadMonitorClass = 'LoadMonitorMySQL';
} else {
- $this->mLoadMonitorClass = 'LoadMonitor_Null';
+ $this->mLoadMonitorClass = 'LoadMonitorNull';
}
}
/**
* Get or set arbitrary data used by the parent object, usually an LBFactory
* @param $x
- * @return Mixed
+ * @return mixed
*/
function parentInfo( $x = null ) {
return wfSetVar( $this->mParentInfo, $x );
*
* @deprecated since 1.21, use ArrayUtils::pickRandom()
*
- * @param $weights array
- *
+ * @param array $weights
* @return bool|int|string
*/
function pickRandom( $weights ) {
}
/**
- * @param $loads array
- * @param $wiki bool
+ * @param array $loads
+ * @param bool|string $wiki Wiki to get non-lagged for
* @return bool|int|string
*/
function getRandomNonLagged( $loads, $wiki = false ) {
* always return a consistent index during a given invocation
*
* Side effect: opens connections to databases
- * @param $group bool
- * @param $wiki bool
+ * @param bool|string $group
+ * @param bool|string $wiki
* @throws MWException
* @return bool|int|string
*/
// Perform post-connection backoff
$threshold = isset( $this->mServers[$i]['max threads'] )
- ? $this->mServers[$i]['max threads'] : false;
+ ? $this->mServers[$i]['max threads'] : 0;
$backoff = $this->getLoadMonitor()->postConnectionBackoff( $conn, $threshold );
// Decrement reference counter, we are finished with this connection.
/**
* Wait for a specified number of microseconds, and return the period waited
- * @param $t int
+ * @param int $t
* @return int
*/
function sleep( $t ) {
* Set the master wait position
* If a DB_SLAVE connection has been opened already, waits
* Otherwise sets a variable telling it to wait if such a connection is opened
- * @param $pos DBMasterPos
+ * @param DBMasterPos $pos
*/
public function waitFor( $pos ) {
wfProfileIn( __METHOD__ );
/**
* Set the master wait position and wait for ALL slaves to catch up to it
- * @param $pos DBMasterPos
+ * @param DBMasterPos $pos
*/
public function waitForAll( $pos ) {
wfProfileIn( __METHOD__ );
* Get any open connection to a given server index, local or foreign
* Returns false if there is no connection open
*
- * @param $i int
+ * @param int $i
* @return DatabaseBase|bool False on failure
*/
function getAnyOpenConnection( $i ) {
*
* @param integer $db
* @param mixed $groups
- * @param string $wiki
+ * @param bool|string $wiki
* @return DBConnRef
*/
public function getConnectionRef( $db, $groups = array(), $wiki = false ) {
*
* @param integer $db
* @param mixed $groups
- * @param string $wiki
+ * @param bool|string $wiki
* @return DBConnRef
*/
public function getLazyConnectionRef( $db, $groups = array(), $wiki = false ) {
* error will be available via $this->mErrorConnection.
*
* @param $i Integer server index
- * @param string $wiki wiki ID to open
+ * @param bool|string $wiki wiki ID to open
* @return DatabaseBase
*
* @access private
/**
* Returns true if the specified index is a valid server index
*
- * @param $i
+ * @param string $i
* @return bool
*/
function haveIndex( $i ) {
/**
* Returns true if the specified index is valid and has non-zero load
*
- * @param $i
+ * @param string $i
* @return bool
*/
function isNonZeroLoad( $i ) {
/**
* Get the host name or IP address of the server with the specified index
* Prefer a readable name if available.
- * @param $i
+ * @param string $i
* @return string
*/
function getServerName( $i ) {
function closeAll() {
foreach ( $this->mConns as $conns2 ) {
foreach ( $conns2 as $conns3 ) {
+ /** @var DatabaseBase $conn */
foreach ( $conns3 as $conn ) {
$conn->close();
}
* Deprecated function, typo in function name
*
* @deprecated in 1.18
- * @param $conn
+ * @param DatabaseBase $conn
*/
function closeConnecton( $conn ) {
wfDeprecated( __METHOD__, '1.18' );
* Close a connection
* Using this function makes sure the LoadBalancer knows the connection is closed.
* If you use $conn->close() directly, the load balancer won't update its state.
- * @param $conn DatabaseBase
+ * @param DatabaseBase $conn
*/
function closeConnection( $conn ) {
$done = false;
function commitAll() {
foreach ( $this->mConns as $conns2 ) {
foreach ( $conns2 as $conns3 ) {
+ /** @var DatabaseBase[] $conns3 */
foreach ( $conns3 as $conn ) {
if ( $conn->trxLevel() ) {
$conn->commit( __METHOD__, 'flush' );
if ( empty( $conns2[$masterIndex] ) ) {
continue;
}
+ /** @var DatabaseBase $conn */
foreach ( $conns2[$masterIndex] as $conn ) {
if ( $conn->trxLevel() && $conn->writesOrCallbacksPending() ) {
$conn->commit( __METHOD__, 'flush' );
/**
* Disables/enables lag checks
- * @param $mode null
+ * @param null|bool $mode
* @return bool
*/
function allowLagged( $mode = null ) {
$success = true;
foreach ( $this->mConns as $conns2 ) {
foreach ( $conns2 as $conns3 ) {
+ /** @var DatabaseBase[] $conns3 */
foreach ( $conns3 as $conn ) {
if ( !$conn->ping() ) {
$success = false;
/**
* Call a function with each open connection object
- * @param $callback
+ * @param callable $callback
* @param array $params
*/
function forEachOpenConnection( $callback, $params = array() ) {
* May attempt to open connections to slaves on the default DB. If there is
* no lag, the maximum lag will be reported as -1.
*
- * @param string $wiki Wiki ID, or false for the default database
- *
+ * @param bool|string $wiki Wiki ID, or false for the default database
* @return array ( host, max lag, index of max lagged host )
*/
function getMaxLag( $wiki = false ) {
* Get lag time for each server
* Results are cached for a short time in memcached, and indefinitely in the process cache
*
- * @param $wiki
- *
+ * @param string|bool $wiki
* @return array
*/
function getLagTimes( $wiki = false ) {
* function instead of Database::getLag() avoids a fatal error in this
* case on many installations.
*
- * @param $conn DatabaseBase
- *
+ * @param DatabaseBase $conn
* @return int
*/
function safeGetLag( $conn ) {
class DBConnRef implements IDatabase {
/** @var LoadBalancer */
protected $lb;
+
/** @var DatabaseBase|null */
protected $conn;
- /** @var Array|null */
+
+ /** @var array|null */
protected $params;
/**
- * @param $lb LoadBalancer
- * @param $conn DatabaseBase|array Connection or (server index, group, wiki ID) array
+ * @param LoadBalancer $lb
+ * @param DatabaseBase|array $conn Connection or (server index, group, wiki ID) array
*/
public function __construct( LoadBalancer $lb, $conn ) {
$this->lb = $lb;