From: jenkins-bot Date: Sat, 31 Mar 2018 08:31:10 +0000 (+0000) Subject: Merge "rdbms: avoid lag estimates in getLagFromPtHeartbeat ruined by snapshots" X-Git-Tag: 1.31.0-rc.0~237 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/password.php?a=commitdiff_plain;h=1314f667692ee768f5631f4c461d650f13bd4615;hp=f070e320f6c2700a01d2bf7cb004352e3070947a;p=lhc%2Fweb%2Fwiklou.git Merge "rdbms: avoid lag estimates in getLagFromPtHeartbeat ruined by snapshots" --- diff --git a/includes/libs/rdbms/database/Database.php b/includes/libs/rdbms/database/Database.php index 523f7cd462..699fee7e74 100644 --- a/includes/libs/rdbms/database/Database.php +++ b/includes/libs/rdbms/database/Database.php @@ -3680,7 +3680,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware * @return array|null ('lag': seconds or false on error, 'since': UNIX timestamp of BEGIN) * @since 1.27 */ - protected function getTransactionLagStatus() { + final protected function getTransactionLagStatus() { return $this->trxLevel ? [ 'lag' => $this->trxReplicaLag, 'since' => $this->trxTimestamp() ] : null; diff --git a/includes/libs/rdbms/database/DatabaseMysqlBase.php b/includes/libs/rdbms/database/DatabaseMysqlBase.php index b0fcade719..e6acaa9fa2 100644 --- a/includes/libs/rdbms/database/DatabaseMysqlBase.php +++ b/includes/libs/rdbms/database/DatabaseMysqlBase.php @@ -763,6 +763,17 @@ abstract class DatabaseMysqlBase extends Database { protected function getLagFromPtHeartbeat() { $options = $this->lagDetectionOptions; + if ( $this->trxLevel ) { + // Avoid returning higher and higher lag value due to snapshot age + // given that the isolation level will typically be REPEATABLE-READ + $this->queryLogger->warning( + "Using cached lag value for {db_server} due to active transaction", + $this->getLogContext( [ 'method' => __METHOD__ ] ) + ); + + return $this->getTransactionLagStatus()['lag']; + } + if ( isset( $options['conds'] ) ) { // Best method for multi-DC setups: use logical channel names $data = $this->getHeartbeatData( $options['conds'] ); diff --git a/includes/libs/rdbms/loadmonitor/LoadMonitor.php b/includes/libs/rdbms/loadmonitor/LoadMonitor.php index 50c878d06b..3372839648 100644 --- a/includes/libs/rdbms/loadmonitor/LoadMonitor.php +++ b/includes/libs/rdbms/loadmonitor/LoadMonitor.php @@ -157,7 +157,9 @@ class LoadMonitor implements ILoadMonitor { } $conn = $this->parent->getAnyOpenConnection( $i ); - if ( $conn ) { + if ( $conn && !$conn->trxLevel() ) { + # Handles with open transactions are avoided since they might be subject + # to REPEATABLE-READ snapshots, which could affect the lag estimate query. $close = false; // already open } else { $conn = $this->parent->openConnection( $i, '' );