From: Aaron Schulz Date: Thu, 25 Oct 2018 15:34:39 +0000 (-0700) Subject: rdbms: avoid transaction status errors from ping() in rollback() X-Git-Tag: 1.34.0-rc.0~3658 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=59573879f13f8004f5eab910f19eb7ad25a39275 rdbms: avoid transaction status errors from ping() in rollback() Change-Id: I38658cbf90518d9818824674da371637db15e156 --- diff --git a/includes/libs/rdbms/database/Database.php b/includes/libs/rdbms/database/Database.php index c436b640c1..16e8d8b37c 100644 --- a/includes/libs/rdbms/database/Database.php +++ b/includes/libs/rdbms/database/Database.php @@ -719,19 +719,27 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware switch ( $type ) { case self::ESTIMATE_DB_APPLY: - $this->ping( $rtt ); - $rttAdjTotal = $this->trxWriteAdjQueryCount * $rtt; - $applyTime = max( $this->trxWriteAdjDuration - $rttAdjTotal, 0 ); - // For omitted queries, make them count as something at least - $omitted = $this->trxWriteQueryCount - $this->trxWriteAdjQueryCount; - $applyTime += self::TINY_WRITE_SEC * $omitted; - - return $applyTime; + return $this->pingAndCalculateLastTrxApplyTime(); default: // everything return $this->trxWriteDuration; } } + /** + * @return float Time to apply writes to replicas based on trxWrite* fields + */ + private function pingAndCalculateLastTrxApplyTime() { + $this->ping( $rtt ); + + $rttAdjTotal = $this->trxWriteAdjQueryCount * $rtt; + $applyTime = max( $this->trxWriteAdjDuration - $rttAdjTotal, 0 ); + // For omitted queries, make them count as something at least + $omitted = $this->trxWriteQueryCount - $this->trxWriteAdjQueryCount; + $applyTime += self::TINY_WRITE_SEC * $omitted; + + return $applyTime; + } + public function pendingWriteCallers() { return $this->trxLevel ? $this->trxWriteCallers : []; } @@ -3972,10 +3980,11 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware // Avoid fatals if close() was called $this->assertOpen(); - $writeTime = $this->pendingWriteQueryDuration( self::ESTIMATE_DB_APPLY ); $this->doRollback( $fname ); $this->trxStatus = self::STATUS_TRX_NONE; $this->trxAtomicLevels = []; + // Estimate the RTT via a query now that trxStatus is OK + $writeTime = $this->pingAndCalculateLastTrxApplyTime(); if ( $this->trxDoneWrites ) { $this->trxProfiler->transactionWritingOut(