'DBLockManager' => __DIR__ . '/includes/filebackend/lockmanager/DBLockManager.php',
'DBMasterPos' => __DIR__ . '/includes/db/DatabaseUtility.php',
'DBQueryError' => __DIR__ . '/includes/db/DatabaseError.php',
+ 'DBReadOnlyError' => __DIR__ . '/includes/db/DatabaseError.php',
'DBSiteStore' => __DIR__ . '/includes/site/DBSiteStore.php',
'DBUnexpectedError' => __DIR__ . '/includes/db/DatabaseError.php',
'DataUpdate' => __DIR__ . '/includes/deferred/DataUpdate.php',
$isWriteQuery = $this->isWriteQuery( $sql );
if ( $isWriteQuery ) {
- if ( !$this->mDoneWrites ) {
- wfDebug( __METHOD__ . ': Writes done: ' .
- DatabaseBase::generalizeSQL( $sql ) . "\n" );
+ $reason = $this->getLBInfo( 'readOnlyReason' );
+ if ( is_string( $reason ) ) {
+ throw new DBReadOnlyError( $this, "Database is read-only: $reason" );
}
# Set a flag indicating that writes have been done
$this->mDoneWrites = microtime( true );
*/
class DBUnexpectedError extends DBError {
}
+
+/**
+ * @ingroup Database
+ */
+class DBReadOnlyError extends DBError {
+}
$trxProf->recordConnection( $host, $dbname, $masterOnly );
}
+ # Make master connections read only if in lagged slave mode
+ if ( $masterOnly && $this->getServerCount() > 1 && $this->getLaggedSlaveMode() ) {
+ $conn->setLBInfo( 'readOnlyReason',
+ 'The database has been automatically locked ' .
+ 'while the slave database servers catch up to the master'
+ );
+ }
+
return $conn;
}