$this->mReadIndex = -1;
$this->mWriteIndex = -1;
- $this->mConns = array(
- 'local' => array(),
- 'foreignUsed' => array(),
- 'foreignFree' => array() );
- $this->mLoads = array();
+ $this->mConns = [
+ 'local' => [],
+ 'foreignUsed' => [],
+ 'foreignFree' => [] ];
+ $this->mLoads = [];
$this->mWaitForPos = false;
$this->mErrorConnection = false;
$this->mAllowLagged = false;
if ( isset( $server['groupLoads'] ) ) {
foreach ( $server['groupLoads'] as $group => $ratio ) {
if ( !isset( $this->mGroupLoads[$group] ) ) {
- $this->mGroupLoads[$group] = array();
+ $this->mGroupLoads[$group] = [];
}
$this->mGroupLoads[$group][$i] = $ratio;
}
return wfSetVar( $this->mParentInfo, $x );
}
- /**
- * Given an array of non-normalised probabilities, this function will select
- * an element and return the appropriate key
- *
- * @deprecated since 1.21, use ArrayUtils::pickRandom()
- *
- * @param array $weights
- * @return bool|int|string
- */
- public function pickRandom( array $weights ) {
- return ArrayUtils::pickRandom( $weights );
- }
-
/**
* @param array $loads
* @param bool|string $wiki Wiki to get non-lagged for
* @throws MWException
* @return DatabaseBase
*/
- public function getConnection( $i, $groups = array(), $wiki = false ) {
+ public function getConnection( $i, $groups = [], $wiki = false ) {
if ( $i === null || $i === false ) {
throw new MWException( 'Attempt to call ' . __METHOD__ .
' with invalid server index' );
$wiki = false;
}
- $groups = ( $groups === false || $groups === array() )
- ? array( false ) // check one "group": the generic pool
+ $groups = ( $groups === false || $groups === [] )
+ ? [ false ] // check one "group": the generic pool
: (array)$groups;
$masterOnly = ( $i == DB_MASTER || $i == $this->getWriterIndex() );
* @param string|bool $wiki Wiki ID, or false for the current wiki
* @return DBConnRef
*/
- public function getConnectionRef( $db, $groups = array(), $wiki = false ) {
+ public function getConnectionRef( $db, $groups = [], $wiki = false ) {
return new DBConnRef( $this, $this->getConnection( $db, $groups, $wiki ) );
}
* @param string|bool $wiki Wiki ID, or false for the current wiki
* @return DBConnRef
*/
- public function getLazyConnectionRef( $db, $groups = array(), $wiki = false ) {
- return new DBConnRef( $this, array( $db, $groups, $wiki ) );
+ public function getLazyConnectionRef( $db, $groups = [], $wiki = false ) {
+ return new DBConnRef( $this, [ $db, $groups, $wiki ] );
}
/**
$db->setLBInfo( $server );
$db->setLazyMasterHandle(
- $this->getLazyConnectionRef( DB_MASTER, array(), $db->getWikiID() )
+ $this->getLazyConnectionRef( DB_MASTER, [], $db->getWikiID() )
);
$db->setTransactionProfiler( $this->trxProfiler );
*/
private function reportConnectionError() {
$conn = $this->mErrorConnection; // The connection which caused the error
- $context = array(
+ $context = [
'method' => __METHOD__,
'last_error' => $this->mLastError,
- );
+ ];
if ( !is_object( $conn ) ) {
// No last connection, probably due to all servers being too busy
}
}
}
- $this->mConns = array(
- 'local' => array(),
- 'foreignFree' => array(),
- 'foreignUsed' => array(),
- );
+ $this->mConns = [
+ 'local' => [],
+ 'foreignFree' => [],
+ 'foreignUsed' => [],
+ ];
$this->connsOpened = 0;
}
* @since 1.23
*/
public function rollbackMasterChanges( $fname = __METHOD__ ) {
- $failedServers = array();
+ $failedServers = [];
$masterIndex = $this->getWriterIndex();
foreach ( $this->mConns as $conns2 ) {
* @since 1.27
*/
public function pendingMasterChangeCallers() {
- $fnames = array();
+ $fnames = [];
$masterIndex = $this->getWriterIndex();
foreach ( $this->mConns as $conns2 ) {
* @param callable $callback
* @param array $params
*/
- public function forEachOpenConnection( $callback, array $params = array() ) {
+ public function forEachOpenConnection( $callback, array $params = [] ) {
foreach ( $this->mConns as $conns2 ) {
foreach ( $conns2 as $conns3 ) {
foreach ( $conns3 as $conn ) {
- $mergedParams = array_merge( array( $conn ), $params );
+ $mergedParams = array_merge( [ $conn ], $params );
call_user_func_array( $callback, $mergedParams );
}
}
$maxIndex = 0;
if ( $this->getServerCount() <= 1 ) {
- return array( $host, $maxLag, $maxIndex ); // no replication = no lag
+ return [ $host, $maxLag, $maxIndex ]; // no replication = no lag
}
$lagTimes = $this->getLagTimes( $wiki );
}
}
- return array( $host, $maxLag, $maxIndex );
+ return [ $host, $maxLag, $maxIndex ];
}
/**
*/
public function getLagTimes( $wiki = false ) {
if ( $this->getServerCount() <= 1 ) {
- return array( 0 => 0 ); // no replication = no lag
+ return [ 0 => 0 ]; // no replication = no lag
}
# Send the request to the load monitor
* @return bool Success
* @since 1.27
*/
- public function safeWaitForPos( IDatabase $conn, $pos = false, $timeout = 10 ) {
+ public function safeWaitForMasterPos( IDatabase $conn, $pos = false, $timeout = 10 ) {
if ( $this->getServerCount() == 1 || !$conn->getLBInfo( 'slave' ) ) {
return true; // server is not a slave DB
}