if ( !$success ) {
$this->reportConnectionError();
- $this->close();
}
$this->mOpened = $success;
return $success;
/**
* @access private
* @param string $msg error message ?
- * @todo parameter $msg is not used
*/
- function reportConnectionError( $msg = '') {
+ function reportConnectionError() {
if ( $this->mFailFunction ) {
if ( !is_int( $this->mFailFunction ) ) {
$ff = $this->mFailFunction;
$ff( $this, $this->lastError() );
}
} else {
- wfEmergencyAbort( $this, mysql_error() );
+ wfEmergencyAbort( $this, $this->lastError() );
}
}
*/
function lastError() {
if ( $this->mConn ) {
+ # Even if it's non-zero, it can still be invalid
+ wfSuppressWarnings();
$error = mysql_error( $this->mConn );
+ if ( !$error ) {
+ $error = mysql_error();
+ }
+ wfRestoreWarnings();
} else {
$error = mysql_error();
}
*/
function wfEmergencyAbort( &$conn, $error ) {
global $wgTitle, $wgUseFileCache, $title, $wgInputEncoding, $wgOutputEncoding;
- global $wgSitename, $wgServer;
+ global $wgSitename, $wgServer, $wgMessageCache;
# I give up, Brion is right. Getting the message cache to work when there is no DB is tricky.
# Hard coding strings instead.
header( 'Cache-control: none' );
header( 'Pragma: nocache' );
}
+
+ # No database access
+ $wgMessageCache->disable();
+
$msg = wfGetSiteNotice();
if($msg == '') {
$msg = str_replace( '$1', $error, $noconnect );
*/
class LoadBalancer {
/* private */ var $mServers, $mConnections, $mLoads, $mGroupLoads;
- /* private */ var $mFailFunction;
+ /* private */ var $mFailFunction, $mErrorConnection;
/* private */ var $mForce, $mReadIndex, $mLastIndex;
/* private */ var $mWaitForFile, $mWaitForPos, $mWaitTimeout;
/* private */ var $mLaggedSlaveMode;
$this->mReadIndex = -1;
$this->mForce = -1;
$this->mLastIndex = -1;
+ $this->mErrorConnection = false;
}
function newFromParams( $servers, $failFunction = false, $waitTimeout = 10 )
$i = $this->getWriterIndex();
}
}
+ # Couldn't find a working server in getReaderIndex()?
+ if ( $i === false ) {
+ $this->reportConnectionError( $this->mErrorConnection );
+ }
# Now we have an explicit index into the servers array
$this->openConnection( $i, $fail );
if ( $fail ) {
$this->reportConnectionError( $this->mConnections[$i] );
}
+ $this->mErrorConnection = $this->mConnections[$i];
$this->mConnections[$i] = false;
$success = false;
}
if ( $this->mFailFunction ) {
$conn->failFunction( $this->mFailFunction );
} else {
- $conn->failFunction( 'wfEmergencyAbort' );
+ $conn->failFunction( false );
}
$conn->reportConnectionError();
$reporting = false;