rdbms: avoid incorrect warnings in getLagFromPtHeartbeat()
authorAaron Schulz <aschulz@wikimedia.org>
Mon, 2 Apr 2018 19:56:11 +0000 (12:56 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Mon, 2 Apr 2018 19:56:11 +0000 (12:56 -0700)
Change-Id: I4c0d42be0ee0c518d7bacdae0f76feb53007861e

includes/libs/rdbms/database/DatabaseMysqlBase.php

index e6acaa9..0a63bdc 100644 (file)
@@ -73,6 +73,9 @@ abstract class DatabaseMysqlBase extends Database {
        // Cache getServerId() for 24 hours
        const SERVER_ID_CACHE_TTL = 86400;
 
+       /** @var float Warn if lag estimates are made for transactions older than this many seconds */
+       const LAG_STALE_WARN_THRESHOLD = 0.100;
+
        /**
         * Additional $params include:
         *   - lagDetectionMethod : set to one of (Seconds_Behind_Master,pt-heartbeat).
@@ -763,7 +766,10 @@ abstract class DatabaseMysqlBase extends Database {
        protected function getLagFromPtHeartbeat() {
                $options = $this->lagDetectionOptions;
 
-               if ( $this->trxLevel ) {
+               $staleness = $this->trxLevel
+                       ? microtime( true ) - $this->trxTimestamp()
+                       : 0;
+               if ( $staleness > self::LAG_STALE_WARN_THRESHOLD ) {
                        // Avoid returning higher and higher lag value due to snapshot age
                        // given that the isolation level will typically be REPEATABLE-READ
                        $this->queryLogger->warning(