}
if ( $this->debug() ) {
- wfDebugLog( 'queries', sprintf( "%s: %s", $this->mDBname, $sql ) );
+ wfDebugLog( 'queries', sprintf( "%s: %s", $this->mDBname, $commentedSql ) );
}
$queryId = MWDebug::query( $sql, $fname, $isMaster );
MWExceptionHandler::logException( $ePrior );
}
$ePrior = $e;
+ // Some callbacks may use startAtomic/endAtomic, so make sure
+ // their transactions are ended so other callbacks don't fail
+ if ( $this->trxLevel() ) {
+ $this->rollback( __METHOD__ );
+ }
}
}
} while ( count( $this->mTrxIdleCallbacks ) );
$levels = implode( ', ', $this->mTrxAtomicLevels );
throw new DBUnexpectedError(
$this,
- "Got explicit BEGIN while atomic sections $levels are still open."
+ "Got explicit BEGIN from $fname while atomic section(s) $levels are open."
);
} elseif ( !$this->mTrxAutomatic ) {
// We want to warn about inadvertently nested begin/commit pairs, but not about
return true;
}
- /**
- * Get the slave lag when the current transaction started
- * or a general lag estimate if not transaction is active
- *
- * This is useful when transactions might use snapshot isolation
- * (e.g. REPEATABLE-READ in innodb), so the "real" lag of that data
- * is this lag plus transaction duration. If they don't, it is still
- * safe to be pessimistic. In AUTO-COMMIT mode, this still gives an
- * indication of the staleness of subsequent reads.
- *
- * @return array ('lag': seconds, 'since': UNIX timestamp of BEGIN)
- * @since 1.27
- */
public function getSessionLagStatus() {
return $this->getTransactionLagStatus() ?: $this->getApproximateLagStatus();
}
* is this lag plus transaction duration. If they don't, it is still
* safe to be pessimistic. This returns null if there is no transaction.
*
- * @return array|null ('lag': seconds, 'since': UNIX timestamp of BEGIN)
+ * @return array|null ('lag': seconds or false on error, 'since': UNIX timestamp of BEGIN)
* @since 1.27
*/
public function getTransactionLagStatus() {
/**
* Get a slave lag estimate for this server
*
- * @return array ('lag': seconds, 'since': UNIX timestamp of estimate)
+ * @return array ('lag': seconds or false on error, 'since': UNIX timestamp of estimate)
* @since 1.27
*/
public function getApproximateLagStatus() {
* @param IDatabase $db1
* @param IDatabase ...
* @return array Map of values:
- * - lag: highest lag of any of the DBs
+ * - lag: highest lag of any of the DBs or false on error (e.g. replication stopped)
* - since: oldest UNIX timestamp of any of the DB lag estimates
* - pending: whether any of the DBs have uncommitted changes
* @since 1.27
foreach ( func_get_args() as $db ) {
/** @var IDatabase $db */
$status = $db->getSessionLagStatus();
- $res['lag'] = max( $res['lag'], $status['lag'] );
+ if ( $status['lag'] === false ) {
+ $res['lag'] = false;
+ } elseif ( $res['lag'] !== false ) {
+ $res['lag'] = max( $res['lag'], $status['lag'] );
+ }
$res['since'] = min( $res['since'], $status['since'] );
$res['pending'] = $res['pending'] ?: $db->writesPending();
}
return $res;
}
- /**
- * Get slave lag. Currently supported only by MySQL.
- *
- * Note that this function will generate a fatal error on many
- * installations. Most callers should use LoadBalancer::safeGetLag()
- * instead.
- *
- * @return int Database replication lag in seconds
- */
public function getLag() {
return 0;
}