Wikia code/includes/db/Database.php
This page is obsolete. It is being retained for archival purposes. It may document extensions or features that are obsolete and/or no longer supported. Do not rely on the information here being up-to-date. The information shown below refers to the now unmaintained 1.16 MediaWiki release. The current stable release number is 1.42.3. |
--- D:\Programming\SVN\mediawiki\branches\REL1_16\phase3\includes\db\Database.php 2011-07-18 22:30:57.687500000 +0100
+++ D:\Programming\SVN\wikia\trunk\includes\db\Database.php 2011-08-17 15:28:13.507812500 +0100
@@ -483,7 +483,14 @@
} else {
$userName = '';
}
- $commentedSql = preg_replace('/\s/', " /* $fname $userName */ ", $sql, 1);
+
+ /* Wikia change begin - @author: Marooned */
+ /* add URL to log, DO NOT use any wgObject here! */
+ // back to whiteboard, use wfGetCurrentUrl()
+ $url = "";
+
+ $commentedSql = preg_replace('/\s/', " /* $fname $userName URL:$url */ ", $sql, 1);
+ /* Wikia change end */
#} else {
# $commentedSql = $sql;
#}
@@ -561,11 +568,15 @@
* @param $tempIgnore Boolean
*/
function reportQueryError( $error, $errno, $sql, $fname, $tempIgnore = false ) {
- global $wgCommandLineMode;
+ global $wgCommandLineMode, $wgEnabledDBReadOnlyRedirect;
# Ignore errors during error handling to avoid infinite recursion
$ignore = $this->ignoreErrors( true );
++$this->mErrorCount;
+ if ( $wgEnabledDBReadOnlyRedirect && function_exists( 'wfDBReadOnlyFailed' ) && $this->wasReadOnlyError() ) {
+ wfDBReadOnlyFailed();
+ }
+
if( $ignore || $tempIgnore ) {
wfDebug("SQL ERROR (ignored): $error\n");
$this->ignoreErrors( $ignore );
@@ -2088,34 +2099,28 @@
wfDebug( "getLag: fake slave lagged {$this->mFakeSlaveLag} seconds\n" );
return $this->mFakeSlaveLag;
}
- $res = $this->query( 'SHOW PROCESSLIST', __METHOD__ );
- # Find slave SQL thread
- while ( $row = $this->fetchObject( $res ) ) {
- /* This should work for most situations - when default db
- * for thread is not specified, it had no events executed,
- * and therefore it doesn't know yet how lagged it is.
- *
- * Relay log I/O thread does not select databases.
- */
- if ( $row->User == 'system user' &&
- $row->State != 'Waiting for master to send event' &&
- $row->State != 'Connecting to master' &&
- $row->State != 'Queueing master event to the relay log' &&
- $row->State != 'Waiting for master update' &&
- $row->State != 'Requesting binlog dump' &&
- $row->State != 'Waiting to reconnect after a failed master event read' &&
- $row->State != 'Reconnecting after a failed master event read' &&
- $row->State != 'Registering slave on master'
- ) {
- # This is it, return the time (except -ve)
- if ( $row->Time > 0x7fffffff ) {
+
+ /**
+ * @begin of wikia change by eloy, copied from mediawiki trunk
+ */
+
+ $res = $this->query( 'SHOW SLAVE STATUS', __METHOD__ );
+ if ( !$res ) {
return false;
- } else {
- return $row->Time;
- }
}
+ $row = $res->fetchObject();
+ if ( !$row ) {
+ return false;
}
+ if ( strval( $row->Seconds_Behind_Master ) === '' ) {
return false;
+ } else {
+ return intval( $row->Seconds_Behind_Master );
+ }
+
+ /**
+ * @end of wikia change
+ */
}
/**
@@ -2714,12 +2719,20 @@
}
function getSQL() {
- global $wgShowSQLErrors;
+ /* Wikia change begin - @author: Marooned */
+ /* add unique ID to query - useful for users reports to find proper query */
+ global $wgShowSQLErrors, $wgDBname;
+ $time = wfTimestamp( TS_MW );
+ $uri = $_SERVER[ 'SERVER_NAME' ] . $_SERVER[ 'REQUEST_URI' ];
+ $qry = $_SERVER[ 'QUERY_STRING' ];
+ error_log("DBQueryError: id=$time, errorNo={$this->errno}, errorMessage={$this->error}, SQL={$this->sql}");
+ error_log("DBQueryError: id=$time, errorNo={$this->errno}, NAME={$wgDBname}, functionName={$this->fname}, URI={$uri}, QUERY={$qry}");
if( !$wgShowSQLErrors ) {
- return $this->msg( 'sqlhidden', 'SQL hidden' );
+ return "/*id=$time*/ " . $this->msg( 'sqlhidden', 'SQL hidden' );
} else {
- return $this->sql;
+ return "/*id=$time*/ " . $this->sql;
}
+ /* Wikia change end */
}
function getLogMessage() {