/** @var int Default 'maxLag' when unspecified */
const MAX_LAG_DEFAULT = 10;
+ /** @var int Default 'waitTimeout' when unspecified */
+ const MAX_WAIT_DEFAULT = 10;
/** @var int Seconds to cache master server read-only status */
const TTL_CACHE_READONLY = 5;
: DatabaseDomain::newUnspecified();
$this->setLocalDomain( $localDomain );
- $this->mWaitTimeout = isset( $params['waitTimeout'] ) ? $params['waitTimeout'] : 10;
+ $this->mWaitTimeout = isset( $params['waitTimeout'] )
+ ? $params['waitTimeout']
+ : self::MAX_WAIT_DEFAULT;
$this->mReadIndex = -1;
$this->mConns = [
for ( $i = 1; $i < $serverCount; $i++ ) {
if ( $this->mLoads[$i] > 0 ) {
$start = microtime( true );
- $ok = $this->doWait( $i, true, max( 1, (int)$timeout ) ) && $ok;
+ $ok = $this->doWait( $i, true, $timeout ) && $ok;
$timeout -= ( microtime( true ) - $start );
if ( $timeout <= 0 ) {
break; // timeout reached
* @return bool
*/
protected function doWait( $index, $open = false, $timeout = null ) {
- $close = false; // close the connection afterwards
+ $timeout = max( 1, $timeout ?: $this->mWaitTimeout );
// Check if we already know that the DB has reached this point
$server = $this->getServerName( $index );
}
// Find a connection to wait on, creating one if needed and allowed
+ $close = false; // close the connection afterwards
$conn = $this->getAnyOpenConnection( $index );
if ( !$conn ) {
if ( !$open ) {
[ 'dbserver' => $server ]
);
- $timeout = $timeout ?: $this->mWaitTimeout;
$result = $conn->masterPosWait( $this->mWaitForPos, $timeout );
if ( $result === null ) {