From 01ccf55545c5393413d27eb27317de49da2f5c06 Mon Sep 17 00:00:00 2001 From: Domas Mituzas Date: Sat, 12 Jan 2008 22:51:16 +0000 Subject: [PATCH] Few sanity things for database activity: * 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 | 11 +++++++++++ includes/Wiki.php | 9 +++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/includes/LoadBalancer.php b/includes/LoadBalancer.php index b10c2a5ebe..6efcbdded7 100644 --- a/includes/LoadBalancer.php +++ b/includes/LoadBalancer.php @@ -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 ); diff --git a/includes/Wiki.php b/includes/Wiki.php index 4920ff2b21..e1a3c5ff9c 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -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" ); } -- 2.20.1