Merge "Change 'history-show-deleted' message to 'Revision deleted only' for clarity"
[lhc/web/wiklou.git] / includes / libs / rdbms / database / DatabaseMysqlBase.php
index 668443b..e900027 100644 (file)
  * @file
  * @ingroup Database
  */
+use Wikimedia\Rdbms\DBMasterPos;
+use Wikimedia\Rdbms\MySQLMasterPos;
+use Wikimedia\Rdbms\MySQLField;
+use Wikimedia\Rdbms\ResultWrapper;
 
 /**
  * Database abstraction object for MySQL.
@@ -756,14 +760,20 @@ abstract class DatabaseMysqlBase extends Database {
         * @see https://www.percona.com/doc/percona-toolkit/2.1/pt-heartbeat.html
         */
        protected function getHeartbeatData( array $conds ) {
-               $whereSQL = $this->makeList( $conds, self::LIST_AND );
-               // Use ORDER BY for channel based queries since that field might not be UNIQUE.
-               // Note: this would use "TIMESTAMPDIFF(MICROSECOND,ts,UTC_TIMESTAMP(6))" but the
-               // percision field is not supported in MySQL <= 5.5.
-               $res = $this->query(
-                       "SELECT ts FROM heartbeat.heartbeat WHERE $whereSQL ORDER BY ts DESC LIMIT 1"
-               );
-               $row = $res ? $res->fetchObject() : false;
+               // Do not bother starting implicit transactions here
+               $this->clearFlag( self::DBO_TRX, self::REMEMBER_PRIOR );
+               try {
+                       $whereSQL = $this->makeList( $conds, self::LIST_AND );
+                       // Use ORDER BY for channel based queries since that field might not be UNIQUE.
+                       // Note: this would use "TIMESTAMPDIFF(MICROSECOND,ts,UTC_TIMESTAMP(6))" but the
+                       // percision field is not supported in MySQL <= 5.5.
+                       $res = $this->query(
+                               "SELECT ts FROM heartbeat.heartbeat WHERE $whereSQL ORDER BY ts DESC LIMIT 1"
+                       );
+                       $row = $res ? $res->fetchObject() : false;
+               } finally {
+                       $this->restoreFlags();
+               }
 
                return [ $row ? $row->ts : null, microtime( true ) ];
        }
@@ -811,7 +821,8 @@ abstract class DatabaseMysqlBase extends Database {
 
                $row = $res ? $this->fetchRow( $res ) : false;
                if ( !$row ) {
-                       throw new DBExpectedError( $this, "Failed to query MASTER_POS_WAIT()" );
+                       throw new DBExpectedError( $this,
+                               "MASTER_POS_WAIT() or MASTER_GTID_WAIT() failed: {$this->lastError()}" );
                }
 
                // Result can be NULL (error), -1 (timeout), or 0+ per the MySQL manual
@@ -1325,4 +1336,3 @@ abstract class DatabaseMysqlBase extends Database {
                return in_array( $name, $this->listViews( $prefix ) );
        }
 }
-