Merge "Add flushReplicaSnapshots() method for just clearing snapshots"
[lhc/web/wiklou.git] / includes / db / loadbalancer / LoadBalancer.php
index 8f0a021..8db1085 100644 (file)
@@ -1316,6 +1316,18 @@ class LoadBalancer {
                }
        }
 
+       /**
+        * Commit all replica DB transactions so as to flush any REPEATABLE-READ or SSI snapshot
+        *
+        * @param string $fname Caller name
+        * @since 1.28
+        */
+       public function flushReplicaSnapshots( $fname = __METHOD__ ) {
+               $this->forEachOpenReplicaConnection( function ( DatabaseBase $conn ) {
+                       $conn->clearSnapshot( __METHOD__ );
+               } );
+       }
+
        /**
         * @return bool Whether a master connection is already open
         * @since 1.24
@@ -1558,6 +1570,26 @@ class LoadBalancer {
                }
        }
 
+       /**
+        * Call a function with each open replica DB connection object
+        * @param callable $callback
+        * @param array $params
+        * @since 1.28
+        */
+       public function forEachOpenReplicaConnection( $callback, array $params = [] ) {
+               foreach ( $this->mConns as $connsByServer ) {
+                       foreach ( $connsByServer as $i => $serverConns ) {
+                               if ( $i === $this->getWriterIndex() ) {
+                                       continue; // skip master
+                               }
+                               foreach ( $serverConns as $conn ) {
+                                       $mergedParams = array_merge( [ $conn ], $params );
+                                       call_user_func_array( $callback, $mergedParams );
+                               }
+                       }
+               }
+       }
+
        /**
         * Get the hostname and lag time of the most-lagged slave
         *