From 14714b413539211f446dba0009b2aa1f78ede549 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sat, 10 Jul 2004 01:15:23 +0000 Subject: [PATCH] trying to work around memcached problems on the live site --- includes/MessageCache.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/includes/MessageCache.php b/includes/MessageCache.php index 4aee858313..9462a520ac 100755 --- a/includes/MessageCache.php +++ b/includes/MessageCache.php @@ -52,9 +52,12 @@ class MessageCache $this->mMemc->set( $this->mMemcKey, "loading", MSG_LOAD_TIMEOUT ); $this->loadFromDB(); # Save in memcached - if ( !$this->mMemc->set( $this->mMemcKey, $this->mCache, $this->mExpiry ) ) { - # Hack for slabs reassignment problem - $this->mMemc->set( $this->mMemcKey, "error" ); + # Keep trying if it fails, this is kind of important + for ( $i=0; $i<20 && !$this->mMemc->set( $this->mMemcKey, $this->mCache, $this->mExpiry ); $i++ ) { + usleep(mt_rand(500000,1500000)); + } + if ( $i == 20 ) { + $this->mMemc->set( $this->mMemcKey, "error", 86400 ); wfDebug( "MemCached set error in MessageCache: restart memcached server!\n" ); } $this->unlock(); @@ -62,6 +65,9 @@ class MessageCache if ( !is_array( $this->mCache ) ) { # If it is 'loading' or 'error', switch to individual message mode, otherwise disable + # Causing too much DB load, disabling -- TS + $this->mDisable = true; + /* if ( $this->mCache == "loading" ) { $this->mUseCache = false; } elseif ( $this->mCache == "error" ) { @@ -70,7 +76,7 @@ class MessageCache } else { $this->mDisable = true; $success = false; - } + }*/ $this->mCache = false; } } @@ -80,10 +86,12 @@ class MessageCache # Loads all cacheable messages from the database function loadFromDB() { - $fname = "MessageCache::loadFromDB"; + global $wgLoadBalancer; + $fname = "MessageCache::loadFromDB"; + $wgLoadBalancer->force(-1); $sql = "SELECT cur_title,cur_text FROM cur WHERE cur_is_redirect=0 AND cur_namespace=" . NS_MEDIAWIKI; $res = wfQuery( $sql, DB_READ, $fname ); - + $wgLoadBalancer->force(0); $this->mCache = array(); for ( $row = wfFetchObject( $res ); $row; $row = wfFetchObject( $res ) ) { $this->mCache[$row->cur_title] = $row->cur_text; -- 2.20.1