Aaron Schulz has uploaded a new change for review. https://gerrit.wikimedia.org/r/214107
Change subject: Added BagOStuff READ_LATEST flag for replicated stores ...................................................................... Added BagOStuff READ_LATEST flag for replicated stores Bug: T88493 Change-Id: I7ea050a2eabba635f2aadb4e33b6f8fbfb1b01a8 --- M includes/libs/objectcache/BagOStuff.php M includes/libs/objectcache/ReplicatedBagOStuff.php M includes/objectcache/ObjectCache.php 3 files changed, 22 insertions(+), 11 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/07/214107/1 diff --git a/includes/libs/objectcache/BagOStuff.php b/includes/libs/objectcache/BagOStuff.php index 65ff0ee..726c789 100644 --- a/includes/libs/objectcache/BagOStuff.php +++ b/includes/libs/objectcache/BagOStuff.php @@ -59,6 +59,9 @@ const ERR_UNREACHABLE = 2; // can't connect const ERR_UNEXPECTED = 3; // response gave some error + /** Bitfield constants for get()/getMulti() */ + const READ_LATEST = 1; // use latest data for replicated stores + public function __construct( array $params = array() ) { if ( isset( $params['logger'] ) ) { $this->setLogger( $params['logger'] ); @@ -86,9 +89,10 @@ * Get an item with the given key. Returns false if it does not exist. * @param string $key * @param mixed $casToken [optional] + * @param integer $flags Bitfield; supports READ_LATEST [optional] * @return mixed Returns false on failure */ - abstract public function get( $key, &$casToken = null ); + abstract public function get( $key, &$casToken = null, $flags = 0 ); /** * Set an item. @@ -262,14 +266,13 @@ return false; } - /* *** Emulated functions *** */ - /** * Get an associative array containing the item for each of the keys that have items. * @param array $keys List of strings + * @param integer $flags Bitfield; supports READ_LATEST [optional] * @return array */ - public function getMulti( array $keys ) { + public function getMulti( array $keys, $flags = 0 ) { $res = array(); foreach ( $keys as $key ) { $val = $this->get( $key ); diff --git a/includes/libs/objectcache/ReplicatedBagOStuff.php b/includes/libs/objectcache/ReplicatedBagOStuff.php index a263a3d..d0e1f84 100644 --- a/includes/libs/objectcache/ReplicatedBagOStuff.php +++ b/includes/libs/objectcache/ReplicatedBagOStuff.php @@ -71,12 +71,16 @@ $this->readStore->setDebug( $debug ); } - public function get( $key, &$casToken = null ) { - return $this->readStore->get( $key, $casToken ); + public function get( $key, &$casToken = null, $flags = 0 ) { + return ( $flags & self::READ_LATEST ) + ? $this->writeStore->get( $key, $casToken, $flags ) + : $this->readStore->get( $key, $casToken, $flags ); } - public function getMulti( $keys ) { - return $this->readStore->getMulti( $keys ); + public function getMulti( $keys, $flags = 0 ) { + return ( $flags & self::READ_LATEST ) + ? $this->writeStore->getMulti( $keys, $flags ) + : $this->readStore->getMulti( $keys, $flags ); } public function set( $key, $value, $exptime = 0 ) { diff --git a/includes/objectcache/ObjectCache.php b/includes/objectcache/ObjectCache.php index 7faf4bb..56d061c 100644 --- a/includes/objectcache/ObjectCache.php +++ b/includes/objectcache/ObjectCache.php @@ -29,9 +29,13 @@ * The word "cache" has two main dictionary meanings, and both * are used in this factory class. They are: * - a) A place to store copies or computations on existing data - * for higher access speeds (the computer science definition) + * for higher access speeds (the computer science definition) * - b) A place to store lightweight data that is not canonically - * stored anywhere else (e.g. a "hoard" of objects) + * stored anywhere else (e.g. a "hoard" of objects) + * + * The former should always use strongly consistent stores, so callers don't + * have to deal with stale reads. The later may be eventually consistent, but + * callers can use BagOStuff:READ_LATEST to see the latest available data. * * @ingroup Cache */ @@ -246,7 +250,7 @@ * In general, this means avoiding updates on idempotent HTTP requests and * avoiding an assumption of perfect serializability (or accepting anomalies). * Reads may be eventually consistent or data might rollback as nodes flap. - * + * Callers can use BagOStuff:READ_LATEST to see the latest available data. * * @return BagOStuff * @since 1.26 -- To view, visit https://gerrit.wikimedia.org/r/214107 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7ea050a2eabba635f2aadb4e33b6f8fbfb1b01a8 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits