private $mLastError = 'Unknown error';
/** @var integer Total connections opened */
private $connsOpened = 0;
- /** @var ProcessCacheLRU */
- private $mProcCache;
/** @var integer Warn when this many connection are held */
const CONN_HELD_WARN_THRESHOLD = 10;
}
}
}
-
- $this->mProcCache = new ProcessCacheLRU( 30 );
}
/**
return false;
}
- wfDebugLog( 'connect', __METHOD__ .
- ": Using reader #$i: {$this->mServers[$i]['host']}..." );
+ $serverName = $this->getServerName( $i );
+ wfDebugLog( 'connect', __METHOD__ . ": Using reader #$i: $serverName..." );
$conn = $this->openConnection( $i, $wiki );
if ( !$conn ) {
if ( $result == -1 || is_null( $result ) ) {
# Timed out waiting for slave, use master instead
- $server = $this->mServers[$index]['host'];
+ $server = $server = $this->getServerName( $index );
$msg = __METHOD__ . ": Timed out waiting on $server pos {$this->mWaitForPos}";
wfDebug( "$msg\n" );
wfDebugLog( 'DBPerformance', "$msg:\n" . wfBacktrace( true ) );
# Now we have an explicit index into the servers array
$conn = $this->openConnection( $i, $wiki );
if ( !$conn ) {
-
return $this->reportConnectionError();
}
public function openConnection( $i, $wiki = false ) {
if ( $wiki !== false ) {
$conn = $this->openForeignConnection( $i, $wiki );
-
- return $conn;
- }
- if ( isset( $this->mConns['local'][$i][0] ) ) {
+ } elseif ( isset( $this->mConns['local'][$i][0] ) ) {
$conn = $this->mConns['local'][$i][0];
} else {
$server = $this->mServers[$i];
$server['serverIndex'] = $i;
$conn = $this->reallyOpenConnection( $server, false );
+ $serverName = $this->getServerName( $i );
if ( $conn->isOpen() ) {
- wfDebug( "Connected to database $i at {$this->mServers[$i]['host']}\n" );
+ wfDebug( "Connected to database $i at $serverName\n" );
$this->mConns['local'][$i][0] = $conn;
} else {
- wfDebug( "Failed to connect to database $i at {$this->mServers[$i]['host']}\n" );
+ wfDebug( "Failed to connect to database $i at $serverName\n" );
$this->mErrorConnection = $conn;
$conn = false;
}
}
+ if ( $conn && !$conn->isOpen() ) {
+ // Connection was made but later unrecoverably lost for some reason.
+ // Do not return a handle that will just throw exceptions on use,
+ // but let the calling code (e.g. getReaderIndex) try another server.
+ // See DatabaseMyslBase::ping() for how this can happen.
+ $this->mErrorConnection = $conn;
+ $conn = false;
+ }
+
return $conn;
}
*/
public function getServerName( $i ) {
if ( isset( $this->mServers[$i]['hostName'] ) ) {
- return $this->mServers[$i]['hostName'];
+ $name = $this->mServers[$i]['hostName'];
} elseif ( isset( $this->mServers[$i]['host'] ) ) {
- return $this->mServers[$i]['host'];
+ $name = $this->mServers[$i]['host'];
} else {
- return '';
+ $name = '';
}
+
+ return ( $name != '' ) ? $name : 'localhost';
}
/**
return array( 0 => 0 ); // no replication = no lag
}
- if ( $this->mProcCache->has( 'slave_lag', 'times', 1 ) ) {
- return $this->mProcCache->get( 'slave_lag', 'times' );
- }
-
# Send the request to the load monitor
- $times = $this->getLoadMonitor()->getLagTimes( array_keys( $this->mServers ), $wiki );
-
- $this->mProcCache->set( 'slave_lag', 'times', $times );
-
- return $times;
+ return $this->getLoadMonitor()->getLagTimes( array_keys( $this->mServers ), $wiki );
}
/**
/**
* Clear the cache for slag lag delay times
+ *
+ * This is only used for testing
*/
public function clearLagTimeCache() {
- $this->mProcCache->clear( 'slave_lag' );
+ $this->getLoadMonitor()->clearCaches();
}
}