Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/260552

Change subject: Let LBFactory/LoadBalancer transaction methods take __METHOD__
......................................................................

Let LBFactory/LoadBalancer transaction methods take __METHOD__

Also send commitAll() times to statsd like commitMasterChanges().

Change-Id: I261ca89f00e40b35f2ddeef6845b111720e7e43c
---
M includes/db/loadbalancer/LBFactory.php
M includes/db/loadbalancer/LoadBalancer.php
2 files changed, 31 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/52/260552/1

diff --git a/includes/db/loadbalancer/LBFactory.php 
b/includes/db/loadbalancer/LBFactory.php
index eeeca62..4aed718 100644
--- a/includes/db/loadbalancer/LBFactory.php
+++ b/includes/db/loadbalancer/LBFactory.php
@@ -190,36 +190,47 @@
         * @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.
+        * @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
+        * @param string $fname Caller name
         */
-       public function commitMasterChanges() {
+       public function commitMasterChanges( $fname = __METHOD__ ) {
                $start = microtime( true );
-               $this->forEachLBCallMethod( 'commitMasterChanges' );
+               $this->forEachLBCallMethod( 'commitMasterChanges', array( 
$fname ) );
                $timeMs = 1000 * ( microtime( true ) - $start );
+
                RequestContext::getMain()->getStats()->timing( 
"db.commit-masters", $timeMs );
        }
 
        /**
         * Rollback changes on all master connections
+        * @param string $fname Caller name
         * @since 1.23
         */
-       public function rollbackMasterChanges() {
-               $this->forEachLBCallMethod( 'rollbackMasterChanges' );
+       public function rollbackMasterChanges( $fname = __METHOD__ ) {
+               $this->forEachLBCallMethod( 'rollbackMasterChanges', array( 
$fname ) );
        }
 
        /**
diff --git a/includes/db/loadbalancer/LoadBalancer.php 
b/includes/db/loadbalancer/LoadBalancer.php
index 19b2d1c..4ff400c 100644
--- a/includes/db/loadbalancer/LoadBalancer.php
+++ b/includes/db/loadbalancer/LoadBalancer.php
@@ -1021,14 +1021,15 @@
 
        /**
         * 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() ) {
-                                               $conn->commit( __METHOD__, 
'flush' );
+                                               $conn->commit( $fname, 'flush' 
);
                                        }
                                }
                        }
@@ -1036,9 +1037,10 @@
        }
 
        /**
-        *  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] ) ) {
@@ -1047,7 +1049,7 @@
                        /** @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 @@
 
        /**
         * Issue ROLLBACK only on master, only if queries were done on 
connection
+        * @param string $fname Caller name
+        * @throws DBExpectedError
         * @since 1.23
         */
-       public function rollbackMasterChanges() {
+       public function rollbackMasterChanges( $fname = __METHOD__ ) {
                $failedServers = array();
 
                $masterIndex = $this->getWriterIndex();
@@ -1069,7 +1073,7 @@
                        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();

-- 
To view, visit https://gerrit.wikimedia.org/r/260552
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I261ca89f00e40b35f2ddeef6845b111720e7e43c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to