Few sanity things for database activity:
authorDomas Mituzas <midom@users.mediawiki.org>
Sat, 12 Jan 2008 22:51:16 +0000 (22:51 +0000)
committerDomas Mituzas <midom@users.mediawiki.org>
Sat, 12 Jan 2008 22:51:16 +0000 (22:51 +0000)
* Provide function to COMMIT master connection in case there were any changes
* Use it at cleanup, instead of sending too many COMMITs to all slaves
* Don't acquire master connection, if no updates are to be done
* Don't care about closing database connections, let PHP do that (would close HTTP socket few nanoseconds earlier)

includes/LoadBalancer.php
includes/Wiki.php

index b10c2a5..6efcbdd 100644 (file)
@@ -552,6 +552,17 @@ class LoadBalancer {
                        }
                }
        }
+       
+       /* Issue COMMIT only on master, only if queries were done on connection */
+       function commitMasterChanges() {
+               // Always 0, but who knows.. :)
+               $i = $this->getWriterIndex;
+               if (array_key_exists($i,$this->mConnections)) {
+                       if ($this->mConnections[$i]->lastQuery != '') {
+                               $this->mConnections[$i]->immediateCommit();
+                       }
+               }
+       }
 
        function waitTimeout( $value = NULL ) {
                return wfSetVar( $this->mWaitTimeout, $value );
index 4920ff2..e1a3c5f 100644 (file)
@@ -289,7 +289,7 @@ class MediaWiki {
                $this->doJobs();
                $loadBalancer->saveMasterPos();
                # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
-               $loadBalancer->commitAll();
+               $loadBalancer->commitMasterChanges();
                $output->output();
                wfProfileOut( 'MediaWiki::finalCleanup' );
        }
@@ -301,6 +301,12 @@ class MediaWiki {
         */
        function doUpdates ( &$updates ) {
                wfProfileIn( 'MediaWiki::doUpdates' );
+               /* No need to get master connections in case of empty updates array */
+               if (!$updates) {
+                       wfProfileOut('MediaWiki::doUpdates');
+                       return;
+               }
+               
                $dbw = wfGetDB( DB_MASTER );
                foreach( $updates as $up ) {
                        $up->doUpdate();
@@ -352,7 +358,6 @@ class MediaWiki {
         */
        function restInPeace ( &$loadBalancer ) {
                wfLogProfilingData();
-               $loadBalancer->closeAll();
                wfDebug( "Request ended normally\n" );
        }