const MAX_LAG_DEFAULT = 10;
/** @var int Seconds to cache master server read-only status */
const TTL_CACHE_READONLY = 5;
const MAX_LAG_DEFAULT = 10;
/** @var int Seconds to cache master server read-only status */
const TTL_CACHE_READONLY = 5;
if ( isset( $params['loadMonitor'] ) ) {
$this->loadMonitorConfig = $params['loadMonitor'];
} else {
$this->loadMonitorConfig = [ 'class' => 'LoadMonitorNull' ];
}
if ( isset( $params['loadMonitor'] ) ) {
$this->loadMonitorConfig = $params['loadMonitor'];
} else {
$this->loadMonitorConfig = [ 'class' => 'LoadMonitorNull' ];
}
# How much lag this server nominally is allowed to have
$maxServerLag = isset( $this->mServers[$i]['max lag'] )
? $this->mServers[$i]['max lag']
# How much lag this server nominally is allowed to have
$maxServerLag = isset( $this->mServers[$i]['max lag'] )
? $this->mServers[$i]['max lag']
# Constrain that futher by $maxLag argument
$maxServerLag = min( $maxServerLag, $maxLag );
# Constrain that futher by $maxLag argument
$maxServerLag = min( $maxServerLag, $maxLag );
"Server {host} is not replicating?", [ 'host' => $host ] );
unset( $loads[$i] );
} elseif ( $lag > $maxServerLag ) {
"Server {host} is not replicating?", [ 'host' => $host ] );
unset( $loads[$i] );
} elseif ( $lag > $maxServerLag ) {
"Server {host} has {lag} seconds of lag (>= {maxlag})",
[ 'host' => $host, 'lag' => $lag, 'maxlag' => $maxServerLag ]
);
"Server {host} has {lag} seconds of lag (>= {maxlag})",
[ 'host' => $host, 'lag' => $lag, 'maxlag' => $maxServerLag ]
);
$timeout = $timeout ?: $this->mWaitTimeout;
$result = $conn->masterPosWait( $this->mWaitForPos, $timeout );
if ( $result == -1 || is_null( $result ) ) {
// Timed out waiting for replica DB, use master instead
$this->replLogger->warning(
$timeout = $timeout ?: $this->mWaitTimeout;
$result = $conn->masterPosWait( $this->mWaitForPos, $timeout );
if ( $result == -1 || is_null( $result ) ) {
// Timed out waiting for replica DB, use master instead
$this->replLogger->warning(
- __METHOD__ . ": Timed out waiting on {host} pos {$this->mWaitForPos}",
- [ 'host' => $server ]
+ __METHOD__ . ': Timed out waiting on {host} pos {pos}',
+ [ 'host' => $server, 'pos' => $this->mWaitForPos ]
// a) those are usually set to implicitly use transaction rounds via DBO_TRX
// b) those must support the use of explicit transaction rounds via beginMasterChanges()
$autoCommit = ( ( $flags & self::CONN_TRX_AUTO ) == self::CONN_TRX_AUTO );
// a) those are usually set to implicitly use transaction rounds via DBO_TRX
// b) those must support the use of explicit transaction rounds via beginMasterChanges()
$autoCommit = ( ( $flags & self::CONN_TRX_AUTO ) == self::CONN_TRX_AUTO );
+ $noWrite = ( ( $flags & self::CONN_NO_WRITE ) == self::CONN_NO_WRITE );
+
+ if ( $noWrite && $i === $this->getWriterIndex() ) {
+ // We can't disable writes on the master connection!
+ // TODO: Wrap the master connection, so write operations fail!
+ $noWrite = false;
+ }
$server['autoCommitOnly'] = $autoCommit;
$conn = $this->reallyOpenConnection( $server, false );
$host = $this->getServerName( $i );
$server['autoCommitOnly'] = $autoCommit;
$conn = $this->reallyOpenConnection( $server, false );
$host = $this->getServerName( $i );
$dbName = $domainInstance->getDatabase();
$prefix = $domainInstance->getTablePrefix();
$autoCommit = ( ( $flags & self::CONN_TRX_AUTO ) == self::CONN_TRX_AUTO );
$dbName = $domainInstance->getDatabase();
$prefix = $domainInstance->getTablePrefix();
$autoCommit = ( ( $flags & self::CONN_TRX_AUTO ) == self::CONN_TRX_AUTO );
+ $noWrite = ( ( $flags & self::CONN_NO_WRITE ) == self::CONN_NO_WRITE );
+
+ if ( $noWrite && $i === $this->getWriterIndex() ) {
+ // We can't disable writes on the master connection!
+ // TODO: Wrap the master connection, so write operations fail!
+ $noWrite = false;
+ }
$server['foreignPoolRefCount'] = 0;
$server['foreign'] = true;
$server['autoCommitOnly'] = $autoCommit;
$server['foreignPoolRefCount'] = 0;
$server['foreign'] = true;
$server['autoCommitOnly'] = $autoCommit;
$conn = $this->reallyOpenConnection( $server, $dbName );
if ( !$conn->isOpen() ) {
$this->connLogger->warning( __METHOD__ . ": connection error for $i/$domain" );
$conn = $this->reallyOpenConnection( $server, $dbName );
if ( !$conn->isOpen() ) {
$this->connLogger->warning( __METHOD__ . ": connection error for $i/$domain" );
if ( $pos instanceof DBMasterPos ) {
$result = $conn->masterPosWait( $pos, $timeout );
if ( $result == -1 || is_null( $result ) ) {
if ( $pos instanceof DBMasterPos ) {
$result = $conn->masterPosWait( $pos, $timeout );
if ( $result == -1 || is_null( $result ) ) {
- $msg = __METHOD__ . ": Timed out waiting on {$conn->getServer()} pos {$pos}";
- $this->replLogger->warning( "$msg" );
+ $msg = __METHOD__ . ': Timed out waiting on {host} pos {pos}';
+ $this->replLogger->warning( $msg,
+ [ 'host' => $conn->getServer(), 'pos' => $pos ] );