Merge "objectcache: Add a clear() method to HashBagOStuff"
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 3 Nov 2015 10:16:19 +0000 (10:16 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 3 Nov 2015 10:16:19 +0000 (10:16 +0000)
RELEASE-NOTES-1.27
includes/OutputPage.php
includes/cache/LinkCache.php
includes/libs/objectcache/HashBagOStuff.php
includes/libs/objectcache/IExpiringStore.php
includes/libs/objectcache/WANObjectCache.php
includes/objectcache/SqlBagOStuff.php

index 4275921..f549620 100644 (file)
@@ -95,6 +95,7 @@ changes to languages because of Bugzilla reports.
   ignore the 2nd and 3rd arguments (formerly $id and $commit).
 * Removed "loaderScripts" option from ResourceLoaderFileModule class.
 * Removed ORM-like wrapper added in 1.20.
+* LinkCache::getGoodLinks and LinkCache::getBadLinks were removed (deprecated in 1.26).
 
 == Compatibility ==
 
index 726fec1..81724c5 100644 (file)
@@ -456,6 +456,8 @@ class OutputPage extends ContextSource {
 
        /**
         * Add raw HTML to the list of scripts (including \<script\> tag, etc.)
+        * Internal use only. Use OutputPage::addModules() or OutputPage::addJsConfigVars()
+        * if possible.
         *
         * @param string $script Raw HTML
         */
@@ -466,26 +468,31 @@ class OutputPage extends ContextSource {
        /**
         * Register and add a stylesheet from an extension directory.
         *
+        * @deprecated since 1.27 use addModuleStyles() or addStyle() instead
         * @param string $url Path to sheet.  Provide either a full url (beginning
         *             with 'http', etc) or a relative path from the document root
         *             (beginning with '/').  Otherwise it behaves identically to
         *             addStyle() and draws from the /skins folder.
         */
        public function addExtensionStyle( $url ) {
+               wfDeprecated( __METHOD__, '1.27' );
                array_push( $this->mExtStyles, $url );
        }
 
        /**
         * Get all styles added by extensions
         *
+        * @deprecated since 1.27
         * @return array
         */
        function getExtStyle() {
+               wfDeprecated( __METHOD__, '1.27' );
                return $this->mExtStyles;
        }
 
        /**
         * Add a JavaScript file out of skins/common, or a given relative path.
+        * Internal use only. Use OutputPage::addModules() if possible.
         *
         * @param string $file Filename in skins/common or complete on-server path
         *              (/foo/bar.js)
@@ -506,6 +513,7 @@ class OutputPage extends ContextSource {
 
        /**
         * Add a self-contained script tag with the given contents
+        * Internal use only. Use OutputPage::addModules() if possible.
         *
         * @param string $script JavaScript text, no "<script>" tags
         */
@@ -691,6 +699,12 @@ class OutputPage extends ContextSource {
        /**
         * Add or replace an header item to the output
         *
+        * Whenever possible, use more specific options like ResourceLoader modules,
+        * OutputPage::addLink(), OutputPage::addMetaLink() and OutputPage::addFeedLink()
+        * Fallback options for those are: OutputPage::addStyle, OutputPage::addScript(),
+        * OutputPage::addInlineScript() and OutputPage::addInlineStyle()
+        * This would be your very LAST fallback.
+        *
         * @param string $name Item name
         * @param string $value Raw HTML
         */
@@ -1025,6 +1039,7 @@ class OutputPage extends ContextSource {
         * @param string|Message $str String or Message to add to the subtitle
         */
        public function appendSubtitle( $str ) {
+               wfDeprecated( __METHOD__, '1.19' );
                $this->addSubtitle( $str );
        }
 
@@ -1748,6 +1763,7 @@ class OutputPage extends ContextSource {
         * @param ParserOutput $parserOutput
         */
        public function addParserOutputNoText( $parserOutput ) {
+               wfDeprecated( __METHOD__, '1.24' );
                $this->addParserOutputMetadata( $parserOutput );
        }
 
@@ -2328,6 +2344,7 @@ class OutputPage extends ContextSource {
         * @deprecated since 1.18
         */
        function blockedPage() {
+               wfDeprecated( __METHOD__, '1.18' );
                throw new UserBlockedError( $this->getUser()->mBlock );
        }
 
@@ -2479,6 +2496,7 @@ class OutputPage extends ContextSource {
         * @throws PermissionsError
         */
        public function permissionRequired( $permission ) {
+               wfDeprecated( __METHOD__, '1.18' );
                throw new PermissionsError( $permission );
        }
 
@@ -2488,6 +2506,7 @@ class OutputPage extends ContextSource {
         * @deprecated since 1.19; throw the exception directly
         */
        public function loginToUse() {
+               wfDeprecated( __METHOD__, '1.19' );
                throw new PermissionsError( 'read' );
        }
 
@@ -3601,7 +3620,7 @@ class OutputPage extends ContextSource {
 
        /**
         * Add a local or specified stylesheet, with the given media options.
-        * Meant primarily for internal use...
+        * Internal use only. Use OutputPage::addModuleStyles() if possible.
         *
         * @param string $style URL to the file
         * @param string $media To specify a media type, 'screen', 'printable', 'handheld' or any.
@@ -3626,6 +3645,8 @@ class OutputPage extends ContextSource {
 
        /**
         * Adds inline CSS styles
+        * Internal use only. Use OutputPage::addModuleStyles() if possible.
+        *
         * @param mixed $style_css Inline CSS
         * @param string $flip Set to 'flip' to flip the CSS if needed
         */
@@ -3940,6 +3961,7 @@ class OutputPage extends ContextSource {
         * @deprecated since 1.17
         */
        public function includeJQuery( array $modules = array() ) {
+               wfDeprecated( __METHOD__, '1.17' );
                return array();
        }
 
index 4c45686..93b4b57 100644 (file)
@@ -204,31 +204,6 @@ class LinkCache {
                $this->mGoodLinks->clear( array( $dbkey ) );
        }
 
-
-       /**
-        * @deprecated since 1.26
-        * @return array
-        */
-       public function getGoodLinks() {
-               wfDeprecated( __METHOD__, '1.26' );
-               $links = array();
-               foreach ( $this->mGoodLinks->getAllKeys() as $key ) {
-                       $info = $this->mGoodLinks->get( $key );
-                       $links[$key] = $info['id'];
-               }
-
-               return $links;
-       }
-
-       /**
-        * @deprecated since 1.26
-        * @return array
-        */
-       public function getBadLinks() {
-               wfDeprecated( __METHOD__, '1.26' );
-               return $this->mBadLinks->getAllKeys();
-       }
-
        /**
         * Add a title to the link cache, return the page_id or zero if non-existent
         *
index 6a43403..c1ee065 100644 (file)
@@ -51,7 +51,7 @@ class HashBagOStuff extends BagOStuff {
 
        protected function expire( $key ) {
                $et = $this->bag[$key][self::KEY_EXP];
-               if ( $et == 0 || $et > time() ) {
+               if ( $et == self::TTL_INDEFINITE || $et > time() ) {
                        return false;
                }
 
index b5ad702..fa465c7 100644 (file)
@@ -37,4 +37,6 @@ interface IExpiringStore {
        const TTL_WEEK = 604800; // 7 * 24 * 3600
        const TTL_MONTH = 2592000; // 30 * 24 * 3600
        const TTL_YEAR = 31536000; // 365 * 24 * 3600
+
+       const TTL_INDEFINITE = 0;
 }
index c04d4b6..7e3fa4f 100644 (file)
@@ -95,8 +95,6 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
        /** Default time-since-expiry on a miss that makes a key "hot" */
        const LOCK_TSE = 1;
 
-       /** Idiom for set()/getWithSetCallback() TTL being "forever" */
-       const TTL_INDEFINITE = 0;
        /** Idiom for getWithSetCallback() callbacks to avoid calling set() */
        const TTL_UNCACHEABLE = -1;
        /** Idiom for getWithSetCallback() callbacks to 'lockTSE' logic */
index 1f384c7..a6f2d37 100644 (file)
 class SqlBagOStuff extends BagOStuff {
        /** @var LoadBalancer */
        protected $lb;
-
        /** @var array */
        protected $serverInfos;
-
        /** @var array */
        protected $serverNames;
-
        /** @var int */
        protected $numServers;
-
-       /** @var array */
-       protected $conns;
-
        /** @var int */
        protected $lastExpireAll = 0;
-
        /** @var int */
        protected $purgePeriod = 100;
-
        /** @var int */
        protected $shards = 1;
-
        /** @var string */
        protected $tableName = 'objectcache';
-
        /** @var bool */
        protected $slaveOnly = false;
+       /** @var int */
+       protected $syncTimeout = 3;
 
+       /** @var array */
+       protected $conns;
        /** @var array UNIX timestamps */
        protected $connFailureTimes = array();
-
        /** @var array Exceptions */
        protected $connFailureErrors = array();
 
@@ -92,6 +84,7 @@ class SqlBagOStuff extends BagOStuff {
         *                  garbage collection logic of expired items. This only
         *                  makes sense if the primary DB is used and only if get()
         *                  calls will be used. This is used by ReplicatedBagOStuff.
+        *   - syncTimeout: Max seconds to wait for slaves to catch up for WRITE_SYNC.
         *
         * @param array $params
         */
@@ -120,6 +113,9 @@ class SqlBagOStuff extends BagOStuff {
                if ( isset( $params['shards'] ) ) {
                        $this->shards = intval( $params['shards'] );
                }
+               if ( isset( $params['syncTimeout'] ) ) {
+                       $this->syncTimeout = $params['syncTimeout'];
+               }
                $this->slaveOnly = !empty( $params['slaveOnly'] );
        }
 
@@ -349,7 +345,12 @@ class SqlBagOStuff extends BagOStuff {
        }
 
        public function set( $key, $value, $exptime = 0, $flags = 0 ) {
-               return $this->setMulti( array( $key => $value ), $exptime );
+               $ok = $this->setMulti( array( $key => $value ), $exptime );
+               if ( ( $flags & self::WRITE_SYNC ) == self::WRITE_SYNC ) {
+                       $ok = $ok && $this->waitForSlaves();
+               }
+
+               return $ok;
        }
 
        protected function cas( $casToken, $key, $value, $exptime = 0 ) {
@@ -457,7 +458,12 @@ class SqlBagOStuff extends BagOStuff {
                        throw new Exception( "Got invalid callback." );
                }
 
-               return $this->mergeViaCas( $key, $callback, $exptime, $attempts );
+               $ok = $this->mergeViaCas( $key, $callback, $exptime, $attempts );
+               if ( ( $flags & self::WRITE_SYNC ) == self::WRITE_SYNC ) {
+                       $ok = $ok && $this->waitForSlaves();
+               }
+
+               return $ok;
        }
 
        /**
@@ -729,4 +735,14 @@ class SqlBagOStuff extends BagOStuff {
                        }
                }
        }
+
+       protected function waitForSlaves() {
+               if ( !$this->serverInfos ) {
+                       // Main LB is used; wait for any slaves to catch up
+                       return wfWaitForSlaves( null, false, false, $this->syncTimeout );
+               } else {
+                       // Custom DB server list; probably doesn't use replication
+                       return true;
+               }
+       }
 }