'Wikimedia\\Rdbms\\DBExpectedError' => __DIR__ . '/includes/libs/rdbms/exception/DBExpectedError.php',
'Wikimedia\\Rdbms\\DBMasterPos' => __DIR__ . '/includes/libs/rdbms/database/position/DBMasterPos.php',
'Wikimedia\\Rdbms\\DBQueryError' => __DIR__ . '/includes/libs/rdbms/exception/DBQueryError.php',
+ 'Wikimedia\\Rdbms\\DBQueryTimeoutError' => __DIR__ . '/includes/libs/rdbms/exception/DBQueryTimeoutError.php',
'Wikimedia\\Rdbms\\DBReadOnlyError' => __DIR__ . '/includes/libs/rdbms/exception/DBReadOnlyError.php',
'Wikimedia\\Rdbms\\DBReplicationWaitError' => __DIR__ . '/includes/libs/rdbms/exception/DBReplicationWaitError.php',
'Wikimedia\\Rdbms\\DBTransactionError' => __DIR__ . '/includes/libs/rdbms/exception/DBTransactionError.php',
}
}
+ /**
+ * Checks whether the cause of the error is detected to be a timeout.
+ *
+ * It returns false by default, and not all engines support detecting this yet.
+ * If this returns false, it will be treated as a generic query error.
+ *
+ * @param string $error Error text
+ * @param int $errno Error number
+ */
+ protected function wasQueryTimeout( $error, $errno ) {
+ return false;
+ }
+
public function reportQueryError( $error, $errno, $sql, $fname, $tempIgnore = false ) {
if ( $this->ignoreErrors() || $tempIgnore ) {
$this->queryLogger->debug( "SQL ERROR (ignored): $error\n" );
] )
);
$this->queryLogger->debug( "SQL ERROR: " . $error . "\n" );
- throw new DBQueryError( $this, $error, $errno, $sql, $fname );
+ $wasQueryTimeout = $this->wasQueryTimeout( $error, $errno );
+ if ( $wasQueryTimeout ) {
+ throw new DBQueryTimeoutError( $this, $error, $errno, $sql, $fname );
+ } else {
+ throw new DBQueryError( $this, $error, $errno, $sql, $fname );
+ }
}
}
*/
abstract protected function mysqlError( $conn = null );
+ protected function wasQueryTimeout( $error, $errno ) {
+ return $errno == 2062;
+ }
+
/**
* @param string $table
* @param array $uniqueIndexes
* @param int|string $errno
* @param string $sql
* @param string $fname
+ * @param string $message Optional message, intended for subclases (optional)
*/
- public function __construct( IDatabase $db, $error, $errno, $sql, $fname ) {
- if ( $db instanceof Database && $db->wasConnectionError( $errno ) ) {
- $message = "A connection error occured. \n" .
- "Query: $sql\n" .
- "Function: $fname\n" .
- "Error: $errno $error\n";
- } else {
- $message = "A database query error has occurred. Did you forget to run " .
- "your application's database schema updater after upgrading? \n" .
- "Query: $sql\n" .
- "Function: $fname\n" .
- "Error: $errno $error\n";
+ public function __construct( IDatabase $db, $error, $errno, $sql, $fname, $message = null ) {
+ if ( $message === null ) {
+ if ( $db instanceof Database && $db->wasConnectionError( $errno ) ) {
+ $message = "A connection error occured. \n" .
+ "Query: $sql\n" .
+ "Function: $fname\n" .
+ "Error: $errno $error\n";
+ } else {
+ $message = "A database query error has occurred. Did you forget to run " .
+ "your application's database schema updater after upgrading? \n" .
+ "Query: $sql\n" .
+ "Function: $fname\n" .
+ "Error: $errno $error\n";
+ }
}
parent::__construct( $db, $message );
--- /dev/null
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Database
+ */
+
+namespace Wikimedia\Rdbms;
+
+/**
+ * Error thrown when a query times out
+ *
+ * @ingroup Database
+ */
+class DBQueryTimeoutError extends DBQueryError {
+ public function __construct( IDatabase $db, $error, $errno, $sql, $fname ) {
+ $message = "A database query timeout has occurred. \n" .
+ "Query: $sql\n" .
+ "Function: $fname\n" .
+ "Error: $errno $error\n";
+
+ parent::__construct( $db, $error, $errno, $sql, $fname, $message );
+ }
+}