trying to work around memcached problems on the live site
authorTim Starling <tstarling@users.mediawiki.org>
Sat, 10 Jul 2004 01:15:23 +0000 (01:15 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sat, 10 Jul 2004 01:15:23 +0000 (01:15 +0000)
includes/MessageCache.php

index 4aee858..9462a52 100755 (executable)
@@ -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;