Merge "Hard deprecate $wgTidyConfig['driver'] = 'disabled'"
[lhc/web/wiklou.git] / includes / libs / rdbms / database / Database.php
index 3d23a83..83b9660 100644 (file)
@@ -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 : [];
        }
@@ -1544,14 +1552,14 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                        $options = [ $options ];
                }
 
-               $res = $this->select( $table, $var, $cond, $fname, $options, $join_conds );
+               $res = $this->select( $table, [ 'value' => $var ], $cond, $fname, $options, $join_conds );
                if ( $res === false ) {
                        return false;
                }
 
                $values = [];
                foreach ( $res as $row ) {
-                       $values[] = $row->$var;
+                       $values[] = $row->value;
                }
 
                return $values;
@@ -2030,10 +2038,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                        $options = [ $options ];
                }
 
-               $fh = null;
-               if ( isset( $options['fileHandle'] ) ) {
-                       $fh = $options['fileHandle'];
-               }
+               $fh = $options['fileHandle'] ?? null;
                $options = $this->makeInsertOptions( $options );
 
                if ( isset( $a[0] ) && is_array( $a[0] ) ) {
@@ -3972,10 +3977,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(