Merge "add IGNORE INDEX option to mysql database handler"
[lhc/web/wiklou.git] / includes / cache / MessageCache.php
index 0e566ea..d254d3d 100644 (file)
@@ -51,7 +51,7 @@ class MessageCache {
        protected $mCache;
 
        /**
-        * Should  mean that database cannot be used, but check
+        * Should mean that database cannot be used, but check
         * @var bool $mDisable
         */
        protected $mDisable;
@@ -302,7 +302,7 @@ class MessageCache {
                                                $where[] = 'global cache is expired';
                                                $staleCache = $cache;
                                        } elseif ( $hashVolatile ) {
-                                               # DB results are slave lag prone until the holdoff TTL passes.
+                                               # DB results are replica DB lag prone until the holdoff TTL passes.
                                                # By then, updates should be reflected in loadFromDBWithLock().
                                                # One thread renerates the cache while others use old values.
                                                $where[] = 'global cache is expired/volatile';
@@ -355,6 +355,7 @@ class MessageCache {
                        $where[] = 'loading FAILED - cache is disabled';
                        $this->mDisable = true;
                        $this->mCache = false;
+                       wfDebugLog( 'MessageCacheError', __METHOD__ . ": Failed to load $code\n" );
                        # This used to throw an exception, but that led to nasty side effects like
                        # the whole wiki being instantly down if the memcached server died
                } else {
@@ -441,7 +442,7 @@ class MessageCache {
        function loadFromDB( $code, $mode = null ) {
                global $wgMaxMsgCacheEntrySize, $wgLanguageCode, $wgAdaptiveMessageCache;
 
-               $dbr = wfGetDB( ( $mode == self::FOR_UPDATE ) ? DB_MASTER : DB_SLAVE );
+               $dbr = wfGetDB( ( $mode == self::FOR_UPDATE ) ? DB_MASTER : DB_REPLICA );
 
                $cache = [];
 
@@ -563,7 +564,7 @@ class MessageCache {
                }
 
                // Mark this cache as definitely "latest" (non-volatile) so
-               // load() calls do try to refresh the cache with slave data
+               // load() calls do try to refresh the cache with replica DB data
                $this->mCache[$code]['LATEST'] = time();
 
                // Update caches if the lock was acquired
@@ -1113,6 +1114,22 @@ class MessageCache {
                $this->mDisable = false;
        }
 
+       /**
+        * Whether DB/cache usage is disabled for determining messages
+        *
+        * If so, this typically indicates either:
+        *   - a) load() failed to find a cached copy nor query the DB
+        *   - b) we are in a special context or error mode that cannot use the DB
+        * If the DB is ignored, any derived HTML output or cached objects may be wrong.
+        * To avoid long-term cache pollution, TTLs can be adjusted accordingly.
+        *
+        * @return bool
+        * @since 1.27
+        */
+       public function isDisabled() {
+               return $this->mDisable;
+       }
+
        /**
         * Clear all stored messages. Mainly used after a mass rebuild.
         */