Merge "Unbreak the DB updater by removing transaction from doUpdates()"
[lhc/web/wiklou.git] / includes / db / loadbalancer / LoadBalancer.php
index 5578099..d9a7381 100644 (file)
@@ -1115,6 +1115,28 @@ class LoadBalancer {
                }
        }
 
+       /**
+        * Call runOnTransactionPreCommitCallbacks() on all DB handles
+        *
+        * This method should not be used outside of LBFactory/LoadBalancer
+        *
+        * @since 1.28
+        */
+       public function runPreCommitCallbacks() {
+               $masterIndex = $this->getWriterIndex();
+               foreach ( $this->mConns as $conns2 ) {
+                       if ( empty( $conns2[$masterIndex] ) ) {
+                               continue;
+                       }
+                       /** @var DatabaseBase $conn */
+                       foreach ( $conns2[$masterIndex] as $conn ) {
+                               if ( $conn->trxLevel() && $conn->writesOrCallbacksPending() ) {
+                                       $conn->runOnTransactionPreCommitCallbacks();
+                               }
+                       }
+               }
+       }
+
        /**
         * @return bool Whether a master connection is already open
         * @since 1.24
@@ -1334,7 +1356,7 @@ class LoadBalancer {
 
                $lagTimes = $this->getLagTimes( $wiki );
                foreach ( $lagTimes as $i => $lag ) {
-                       if ( $lag > $maxLag ) {
+                       if ( $this->mLoads[$i] > 0 && $lag > $maxLag ) {
                                $maxLag = $lag;
                                $host = $this->mServers[$i]['host'];
                                $maxIndex = $i;
@@ -1402,7 +1424,7 @@ class LoadBalancer {
                }
 
                $pos = $pos ?: $this->getConnection( DB_MASTER )->getMasterPos();
-               if ( !$pos ) {
+               if ( !( $pos instanceof DBMasterPos ) ) {
                        return false; // something is misconfigured
                }