Make LBFactory::waitForReplication() mask wait latency with callbacks
[lhc/web/wiklou.git] / includes / db / loadbalancer / LBFactory.php
index cd8dff3..4758cc7 100644 (file)
@@ -430,10 +430,6 @@ abstract class LBFactory implements DestructibleService {
                        'ifWritesSince' => null
                ];
 
-               foreach ( $this->replicationWaitCallbacks as $callback ) {
-                       $callback();
-               }
-
                // Figure out which clusters need to be checked
                /** @var LoadBalancer[] $lbs */
                $lbs = [];
@@ -467,6 +463,12 @@ abstract class LBFactory implements DestructibleService {
                        $masterPositions[$i] = $lb->getMasterPos();
                }
 
+               // Run any listener callbacks *after* getting the DB positions. The more
+               // time spent in the callbacks, the less time is spent in waitForAll().
+               foreach ( $this->replicationWaitCallbacks as $callback ) {
+                       $callback();
+               }
+
                $failed = [];
                foreach ( $lbs as $i => $lb ) {
                        if ( $masterPositions[$i] ) {