Let LBFactory/LoadBalancer transaction methods take __METHOD__
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 22 Dec 2015 11:05:45 +0000 (03:05 -0800)
committerUmherirrender <umherirrender_de.wp@web.de>
Tue, 22 Dec 2015 20:08:48 +0000 (20:08 +0000)
Also send commitAll() times to statsd like commitMasterChanges().

Change-Id: I261ca89f00e40b35f2ddeef6845b111720e7e43c

includes/db/loadbalancer/LBFactory.php
includes/db/loadbalancer/LoadBalancer.php

index eeeca62..4aed718 100644 (file)
@@ -190,36 +190,47 @@ abstract class LBFactory {
         * @param array $args
         */
        private function forEachLBCallMethod( $methodName, array $args = array() ) {
         * @param array $args
         */
        private function forEachLBCallMethod( $methodName, array $args = array() ) {
-               $this->forEachLB( function ( LoadBalancer $loadBalancer, $methodName, array $args ) {
-                       call_user_func_array( array( $loadBalancer, $methodName ), $args );
-               }, array( $methodName, $args ) );
+               $this->forEachLB(
+                       function ( LoadBalancer $loadBalancer, $methodName, array $args ) {
+                               call_user_func_array( array( $loadBalancer, $methodName ), $args );
+                       },
+                       array( $methodName, $args )
+               );
        }
 
        /**
         * Commit on all connections. Done for two reasons:
         * 1. To commit changes to the masters.
         * 2. To release the snapshot on all connections, master and slave.
        }
 
        /**
         * Commit on all connections. Done for two reasons:
         * 1. To commit changes to the masters.
         * 2. To release the snapshot on all connections, master and slave.
+        * @param string $fname Caller name
         */
         */
-       public function commitAll() {
-               $this->forEachLBCallMethod( 'commitAll' );
+       public function commitAll( $fname = __METHOD__ ) {
+               $start = microtime( true );
+               $this->forEachLBCallMethod( 'commitAll', array( $fname ) );
+               $timeMs = 1000 * ( microtime( true ) - $start );
+
+               RequestContext::getMain()->getStats()->timing( "db.commit-all", $timeMs );
        }
 
        /**
         * Commit changes on all master connections
        }
 
        /**
         * Commit changes on all master connections
+        * @param string $fname Caller name
         */
         */
-       public function commitMasterChanges() {
+       public function commitMasterChanges( $fname = __METHOD__ ) {
                $start = microtime( true );
                $start = microtime( true );
-               $this->forEachLBCallMethod( 'commitMasterChanges' );
+               $this->forEachLBCallMethod( 'commitMasterChanges', array( $fname ) );
                $timeMs = 1000 * ( microtime( true ) - $start );
                $timeMs = 1000 * ( microtime( true ) - $start );
+
                RequestContext::getMain()->getStats()->timing( "db.commit-masters", $timeMs );
        }
 
        /**
         * Rollback changes on all master connections
                RequestContext::getMain()->getStats()->timing( "db.commit-masters", $timeMs );
        }
 
        /**
         * Rollback changes on all master connections
+        * @param string $fname Caller name
         * @since 1.23
         */
         * @since 1.23
         */
-       public function rollbackMasterChanges() {
-               $this->forEachLBCallMethod( 'rollbackMasterChanges' );
+       public function rollbackMasterChanges( $fname = __METHOD__ ) {
+               $this->forEachLBCallMethod( 'rollbackMasterChanges', array( $fname ) );
        }
 
        /**
        }
 
        /**
index 19b2d1c..4ff400c 100644 (file)
@@ -1021,14 +1021,15 @@ class LoadBalancer {
 
        /**
         * Commit transactions on all open connections
 
        /**
         * Commit transactions on all open connections
+        * @param string $fname Caller name
         */
         */
-       public function commitAll() {
+       public function commitAll( $fname = __METHOD__ ) {
                foreach ( $this->mConns as $conns2 ) {
                        foreach ( $conns2 as $conns3 ) {
                                /** @var DatabaseBase[] $conns3 */
                                foreach ( $conns3 as $conn ) {
                                        if ( $conn->trxLevel() ) {
                foreach ( $this->mConns as $conns2 ) {
                        foreach ( $conns2 as $conns3 ) {
                                /** @var DatabaseBase[] $conns3 */
                                foreach ( $conns3 as $conn ) {
                                        if ( $conn->trxLevel() ) {
-                                               $conn->commit( __METHOD__, 'flush' );
+                                               $conn->commit( $fname, 'flush' );
                                        }
                                }
                        }
                                        }
                                }
                        }
@@ -1036,9 +1037,10 @@ class LoadBalancer {
        }
 
        /**
        }
 
        /**
-        *  Issue COMMIT only on master, only if queries were done on connection
+        * Issue COMMIT only on master, only if queries were done on connection
+        * @param string $fname Caller name
         */
         */
-       public function commitMasterChanges() {
+       public function commitMasterChanges( $fname = __METHOD__ ) {
                $masterIndex = $this->getWriterIndex();
                foreach ( $this->mConns as $conns2 ) {
                        if ( empty( $conns2[$masterIndex] ) ) {
                $masterIndex = $this->getWriterIndex();
                foreach ( $this->mConns as $conns2 ) {
                        if ( empty( $conns2[$masterIndex] ) ) {
@@ -1047,7 +1049,7 @@ class LoadBalancer {
                        /** @var DatabaseBase $conn */
                        foreach ( $conns2[$masterIndex] as $conn ) {
                                if ( $conn->trxLevel() && $conn->writesOrCallbacksPending() ) {
                        /** @var DatabaseBase $conn */
                        foreach ( $conns2[$masterIndex] as $conn ) {
                                if ( $conn->trxLevel() && $conn->writesOrCallbacksPending() ) {
-                                       $conn->commit( __METHOD__, 'flush' );
+                                       $conn->commit( $fname, 'flush' );
                                }
                        }
                }
                                }
                        }
                }
@@ -1055,9 +1057,11 @@ class LoadBalancer {
 
        /**
         * Issue ROLLBACK only on master, only if queries were done on connection
 
        /**
         * Issue ROLLBACK only on master, only if queries were done on connection
+        * @param string $fname Caller name
+        * @throws DBExpectedError
         * @since 1.23
         */
         * @since 1.23
         */
-       public function rollbackMasterChanges() {
+       public function rollbackMasterChanges( $fname = __METHOD__ ) {
                $failedServers = array();
 
                $masterIndex = $this->getWriterIndex();
                $failedServers = array();
 
                $masterIndex = $this->getWriterIndex();
@@ -1069,7 +1073,7 @@ class LoadBalancer {
                        foreach ( $conns2[$masterIndex] as $conn ) {
                                if ( $conn->trxLevel() && $conn->writesOrCallbacksPending() ) {
                                        try {
                        foreach ( $conns2[$masterIndex] as $conn ) {
                                if ( $conn->trxLevel() && $conn->writesOrCallbacksPending() ) {
                                        try {
-                                               $conn->rollback( __METHOD__, 'flush' );
+                                               $conn->rollback( $fname, 'flush' );
                                        } catch ( DBError $e ) {
                                                MWExceptionHandler::logException( $e );
                                                $failedServers[] = $conn->getServer();
                                        } catch ( DBError $e ) {
                                                MWExceptionHandler::logException( $e );
                                                $failedServers[] = $conn->getServer();