diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2013-12-08 09:55:49 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2013-12-08 09:55:49 +0100 |
commit | 4ac9fa081a7c045f6a9f1cfc529d82423f485b2e (patch) | |
tree | af68743f2f4a47d13f2b0eb05f5c4aaf86d8ea37 /includes/objectcache | |
parent | af4da56f1ad4d3ef7b06557bae365da2ea27a897 (diff) |
Update to MediaWiki 1.22.0
Diffstat (limited to 'includes/objectcache')
-rw-r--r-- | includes/objectcache/BagOStuff.php | 8 | ||||
-rw-r--r-- | includes/objectcache/MemcachedBagOStuff.php | 2 | ||||
-rw-r--r-- | includes/objectcache/MemcachedClient.php | 24 | ||||
-rw-r--r-- | includes/objectcache/MemcachedPeclBagOStuff.php | 14 | ||||
-rw-r--r-- | includes/objectcache/MultiWriteBagOStuff.php | 2 | ||||
-rw-r--r-- | includes/objectcache/ObjectCache.php | 14 | ||||
-rw-r--r-- | includes/objectcache/ObjectCacheSessionHandler.php | 2 | ||||
-rw-r--r-- | includes/objectcache/RedisBagOStuff.php | 40 | ||||
-rw-r--r-- | includes/objectcache/SqlBagOStuff.php | 22 |
9 files changed, 56 insertions, 72 deletions
diff --git a/includes/objectcache/BagOStuff.php b/includes/objectcache/BagOStuff.php index dd744672..857943ee 100644 --- a/includes/objectcache/BagOStuff.php +++ b/includes/objectcache/BagOStuff.php @@ -170,12 +170,12 @@ abstract class BagOStuff { */ public function lock( $key, $timeout = 60 ) { $timestamp = microtime( true ); // starting UNIX timestamp - if ( $this->add( "{$key}:lock", $timeout ) ) { + if ( $this->add( "{$key}:lock", 1, $timeout ) ) { return true; } $uRTT = ceil( 1e6 * ( microtime( true ) - $timestamp ) ); // estimate RTT (us) - $sleep = 2*$uRTT; // rough time to do get()+set() + $sleep = 2 * $uRTT; // rough time to do get()+set() $locked = false; // lock acquired $attempts = 0; // failed attempts @@ -186,8 +186,8 @@ abstract class BagOStuff { $sleep *= 2; } usleep( $sleep ); // back off - $locked = $this->add( "{$key}:lock", $timeout ); - } while( !$locked ); + $locked = $this->add( "{$key}:lock", 1, $timeout ); + } while ( !$locked ); return $locked; } diff --git a/includes/objectcache/MemcachedBagOStuff.php b/includes/objectcache/MemcachedBagOStuff.php index 3f1fa3a0..f1644edb 100644 --- a/includes/objectcache/MemcachedBagOStuff.php +++ b/includes/objectcache/MemcachedBagOStuff.php @@ -43,7 +43,7 @@ class MemcachedBagOStuff extends BagOStuff { if ( !isset( $params['persistent'] ) ) { $params['persistent'] = $GLOBALS['wgMemCachedPersistent']; } - if ( !isset( $params['compress_threshold'] ) ) { + if ( !isset( $params['compress_threshold'] ) ) { $params['compress_threshold'] = 1500; } if ( !isset( $params['timeout'] ) ) { diff --git a/includes/objectcache/MemcachedClient.php b/includes/objectcache/MemcachedClient.php index 0d96ed6c..e5f60b55 100644 --- a/includes/objectcache/MemcachedClient.php +++ b/includes/objectcache/MemcachedClient.php @@ -55,9 +55,9 @@ * 'compress_threshold' => 10240, * 'persistent' => true)); * - * $mc->add('key', array('some', 'array')); - * $mc->replace('key', 'some random string'); - * $val = $mc->get('key'); + * $mc->add( 'key', array( 'some', 'array' ) ); + * $mc->replace( 'key', 'some random string' ); + * $val = $mc->get( 'key' ); * * @author Ryan T. Dean <rtdean@cytherianage.net> * @version 0.1.2 @@ -329,7 +329,7 @@ class MWMemcached { $this->stats['delete'] = 1; } $cmd = "delete $key $time\r\n"; - if( !$this->_fwrite( $sock, $cmd ) ) { + if ( !$this->_fwrite( $sock, $cmd ) ) { return false; } $res = $this->_fgets( $sock ); @@ -489,17 +489,17 @@ class MWMemcached { } $key = is_array( $key ) ? $key[1] : $key; if ( !isset( $sock_keys[$sock] ) ) { - $sock_keys[ intval( $sock ) ] = array(); + $sock_keys[intval( $sock )] = array(); $socks[] = $sock; } - $sock_keys[ intval( $sock ) ][] = $key; + $sock_keys[intval( $sock )][] = $key; } $gather = array(); // Send out the requests foreach ( $socks as $sock ) { $cmd = 'gets'; - foreach ( $sock_keys[ intval( $sock ) ] as $key ) { + foreach ( $sock_keys[intval( $sock )] as $key ) { $cmd .= ' ' . $key; } $cmd .= "\r\n"; @@ -733,7 +733,7 @@ class MWMemcached { $sock = false; $timeout = $this->_connect_timeout; $errno = $errstr = null; - for( $i = 0; !$sock && $i < $this->_connect_attempts; $i++ ) { + for ( $i = 0; !$sock && $i < $this->_connect_attempts; $i++ ) { wfSuppressWarnings(); if ( $this->_persistent == 1 ) { $sock = pfsockopen( $ip, $port, $errno, $errstr, $timeout ); @@ -810,7 +810,7 @@ class MWMemcached { $bu = array(); foreach ( $this->_servers as $v ) { if ( is_array( $v ) ) { - for( $i = 0; $i < $v[1]; $i++ ) { + for ( $i = 0; $i < $v[1]; $i++ ) { $bu[] = $v[0]; } } else { @@ -822,7 +822,7 @@ class MWMemcached { } $realkey = is_array( $key ) ? $key[1] : $key; - for( $tries = 0; $tries < 20; $tries++ ) { + for ( $tries = 0; $tries < 20; $tries++ ) { $host = $this->_buckets[$hv % $this->_bucketcount]; $sock = $this->sock_to_host( $host ); if ( is_resource( $sock ) ) { @@ -912,7 +912,7 @@ class MWMemcached { while ( 1 ) { $decl = $this->_fgets( $sock ); - if( $decl === false ) { + if ( $decl === false ) { /* * If nothing can be read, something is wrong because we know exactly when * to stop reading (right after "END") and we return right after that. @@ -1123,7 +1123,7 @@ class MWMemcached { function _fwrite( $sock, $buf ) { $bytesWritten = 0; $bufSize = strlen( $buf ); - while ( $bytesWritten < $bufSize ) { + while ( $bytesWritten < $bufSize ) { $result = fwrite( $sock, $buf ); $data = stream_get_meta_data( $sock ); if ( $data['timed_out'] ) { diff --git a/includes/objectcache/MemcachedPeclBagOStuff.php b/includes/objectcache/MemcachedPeclBagOStuff.php index 31924293..0c3b228f 100644 --- a/includes/objectcache/MemcachedPeclBagOStuff.php +++ b/includes/objectcache/MemcachedPeclBagOStuff.php @@ -37,6 +37,8 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff { * - compress_threshold: The minimum size an object must be before it is compressed * - timeout: The read timeout in microseconds * - connect_timeout: The connect timeout in seconds + * - retry_timeout: Time in seconds to wait before retrying a failed connect attempt + * - server_failure_limit: Limit for server connect failures before it is removed * - serializer: May be either "php" or "igbinary". Igbinary produces more compact * values, but serialization is much slower unless the php.ini option * igbinary.compact_strings is off. @@ -61,6 +63,14 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff { $params['serializer'] = 'php'; } + if ( isset( $params['retry_timeout'] ) ) { + $this->client->setOption( Memcached::OPT_RETRY_TIMEOUT, $params['retry_timeout'] ); + } + + if ( isset( $params['server_failure_limit'] ) ) { + $this->client->setOption( Memcached::OPT_SERVER_FAILURE_LIMIT, $params['server_failure_limit'] ); + } + // The compression threshold is an undocumented php.ini option for some // reason. There's probably not much harm in setting it globally, for // compatibility with the settings for the PHP client. @@ -87,13 +97,13 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff { break; case 'igbinary': if ( !Memcached::HAVE_IGBINARY ) { - throw new MWException( __CLASS__.': the igbinary extension is not available ' . + throw new MWException( __CLASS__ . ': the igbinary extension is not available ' . 'but igbinary serialization was requested.' ); } $this->client->setOption( Memcached::OPT_SERIALIZER, Memcached::SERIALIZER_IGBINARY ); break; default: - throw new MWException( __CLASS__.': invalid value for serializer parameter' ); + throw new MWException( __CLASS__ . ': invalid value for serializer parameter' ); } $servers = array(); foreach ( $params['servers'] as $host ) { diff --git a/includes/objectcache/MultiWriteBagOStuff.php b/includes/objectcache/MultiWriteBagOStuff.php index 92afaacd..e550c0d0 100644 --- a/includes/objectcache/MultiWriteBagOStuff.php +++ b/includes/objectcache/MultiWriteBagOStuff.php @@ -43,7 +43,7 @@ class MultiWriteBagOStuff extends BagOStuff { */ public function __construct( $params ) { if ( !isset( $params['caches'] ) ) { - throw new MWException( __METHOD__.': the caches parameter is required' ); + throw new MWException( __METHOD__ . ': the caches parameter is required' ); } $this->caches = array(); diff --git a/includes/objectcache/ObjectCache.php b/includes/objectcache/ObjectCache.php index eafa836a..6c1433a9 100644 --- a/includes/objectcache/ObjectCache.php +++ b/includes/objectcache/ObjectCache.php @@ -34,7 +34,7 @@ class ObjectCache { * * @param $id string * - * @return ObjectCache + * @return BagOStuff */ static function getInstance( $id ) { if ( isset( self::$instances[$id] ) ) { @@ -59,7 +59,7 @@ class ObjectCache { * @param $id string * * @throws MWException - * @return ObjectCache + * @return BagOStuff */ static function newFromId( $id ) { global $wgObjectCaches; @@ -78,7 +78,7 @@ class ObjectCache { * @param $params array * * @throws MWException - * @return ObjectCache + * @return BagOStuff */ static function newFromParams( $params ) { if ( isset( $params['factory'] ) ) { @@ -102,7 +102,7 @@ class ObjectCache { * If no cache choice is configured (by default $wgMainCacheType is CACHE_NONE), * then CACHE_ANYTHING will forward to CACHE_DB. * @param $params array - * @return ObjectCache + * @return BagOStuff */ static function newAnything( $params ) { global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType; @@ -120,14 +120,14 @@ class ObjectCache { * * @param $params array * @throws MWException - * @return ObjectCache + * @return BagOStuff */ static function newAccelerator( $params ) { if ( function_exists( 'apc_fetch' ) ) { $id = 'apc'; - } elseif( function_exists( 'xcache_get' ) && wfIniGetBool( 'xcache.var_size' ) ) { + } elseif ( function_exists( 'xcache_get' ) && wfIniGetBool( 'xcache.var_size' ) ) { $id = 'xcache'; - } elseif( function_exists( 'wincache_ucache_get' ) ) { + } elseif ( function_exists( 'wincache_ucache_get' ) ) { $id = 'wincache'; } else { throw new MWException( "CACHE_ACCEL requested but no suitable object " . diff --git a/includes/objectcache/ObjectCacheSessionHandler.php b/includes/objectcache/ObjectCacheSessionHandler.php index bc76294a..7cf960e7 100644 --- a/includes/objectcache/ObjectCacheSessionHandler.php +++ b/includes/objectcache/ObjectCacheSessionHandler.php @@ -94,7 +94,7 @@ class ObjectCacheSessionHandler { */ static function read( $id ) { $data = self::getCache()->get( self::getKey( $id ) ); - if( $data === false ) { + if ( $data === false ) { return ''; } return $data; diff --git a/includes/objectcache/RedisBagOStuff.php b/includes/objectcache/RedisBagOStuff.php index f9feaf9d..135e0e83 100644 --- a/includes/objectcache/RedisBagOStuff.php +++ b/includes/objectcache/RedisBagOStuff.php @@ -140,7 +140,13 @@ class RedisBagOStuff extends BagOStuff { $conn->setex( $key, $expiry, $value ); } - $result = $conn->exec(); + /* + * multi()/exec() (transactional mode) allows multiple values to + * be set/get at once and will return an array of results, in + * the order they were set/get. In this case, we only set 1 + * value, which should (in case of success) result in true. + */ + $result = ( $conn->exec() == array( true ) ); } catch ( RedisException $e ) { $result = false; $this->handleException( $server, $conn, $e ); @@ -268,38 +274,6 @@ class RedisBagOStuff extends BagOStuff { } /** - * Non-atomic implementation of incr(). - * - * Probably all callers actually want incr() to atomically initialise - * values to zero if they don't exist, as provided by the Redis INCR - * command. But we are constrained by the memcached-like interface to - * return null in that case. Once the key exists, further increments are - * atomic. - */ - public function incr( $key, $value = 1 ) { - wfProfileIn( __METHOD__ ); - list( $server, $conn ) = $this->getConnection( $key ); - if ( !$conn ) { - wfProfileOut( __METHOD__ ); - return false; - } - if ( !$conn->exists( $key ) ) { - wfProfileOut( __METHOD__ ); - return null; - } - try { - $result = $conn->incrBy( $key, $value ); - } catch ( RedisException $e ) { - $result = false; - $this->handleException( $server, $conn, $e ); - } - - $this->logRequest( 'incr', $key, $server, $result ); - wfProfileOut( __METHOD__ ); - return $result; - } - - /** * Get a Redis object with a connection suitable for fetching the specified key * @return Array (server, RedisConnRef) or (false, false) */ diff --git a/includes/objectcache/SqlBagOStuff.php b/includes/objectcache/SqlBagOStuff.php index 87f787d8..acf27036 100644 --- a/includes/objectcache/SqlBagOStuff.php +++ b/includes/objectcache/SqlBagOStuff.php @@ -222,8 +222,8 @@ class SqlBagOStuff extends BagOStuff { $dataRows = array(); foreach ( $keysByTable as $serverIndex => $serverKeys ) { - $db = $this->getDB( $serverIndex ); try { + $db = $this->getDB( $serverIndex ); foreach ( $serverKeys as $tableName => $tableKeys ) { $res = $db->select( $tableName, array( 'keyname', 'value', 'exptime' ), @@ -244,10 +244,10 @@ class SqlBagOStuff extends BagOStuff { if ( isset( $dataRows[$key] ) ) { // HIT? $row = $dataRows[$key]; $this->debug( "get: retrieved data; expiry time is " . $row->exptime ); - $db = $this->getDB( $row->serverIndex ); - if ( $this->isExpired( $db, $row->exptime ) ) { // MISS - $this->debug( "get: key has expired, deleting" ); - try { + try { + $db = $this->getDB( $row->serverIndex ); + if ( $this->isExpired( $db, $row->exptime ) ) { // MISS + $this->debug( "get: key has expired, deleting" ); $db->begin( __METHOD__ ); # Put the expiry time in the WHERE condition to avoid deleting a # newly-inserted value @@ -255,12 +255,12 @@ class SqlBagOStuff extends BagOStuff { array( 'keyname' => $key, 'exptime' => $row->exptime ), __METHOD__ ); $db->commit( __METHOD__ ); - } catch ( DBQueryError $e ) { - $this->handleWriteError( $e, $row->serverIndex ); + $values[$key] = false; + } else { // HIT + $values[$key] = $this->unserialize( $db->decodeBlob( $row->value ) ); } - $values[$key] = false; - } else { // HIT - $values[$key] = $this->unserialize( $db->decodeBlob( $row->value ) ); + } catch ( DBQueryError $e ) { + $this->handleWriteError( $e, $row->serverIndex ); } } else { // MISS $values[$key] = false; @@ -364,7 +364,7 @@ class SqlBagOStuff extends BagOStuff { return false; } - return (bool) $db->affectedRows(); + return (bool)$db->affectedRows(); } /** |