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 : [];
}
// 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(