X-Git-Url: https://git.heureux-cyclage.org/w/index.php?a=blobdiff_plain;f=includes%2Fpoolcounter%2FPoolCounterRedis.php;h=5a15ddf6bb8dc38e236e3410dc48638f98e1f8e4;hb=53779578b44575ef91feb3fad488f09b52f737d7;hp=6dd0b353f5e0ab2375bdff8d0d37cf300904c409;hpb=cb2896f90ebef77c02c9da4067b0e56e37471092;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/poolcounter/PoolCounterRedis.php b/includes/poolcounter/PoolCounterRedis.php index 6dd0b353f5..5a15ddf6bb 100644 --- a/includes/poolcounter/PoolCounterRedis.php +++ b/includes/poolcounter/PoolCounterRedis.php @@ -18,6 +18,7 @@ * @file * @author Aaron Schulz */ +use Psr\Log\LoggerInterface; /** * Version of PoolCounter that uses Redis @@ -55,6 +56,8 @@ class PoolCounterRedis extends PoolCounter { protected $ring; /** @var RedisConnectionPool */ protected $pool; + /** @var LoggerInterface */ + protected $logger; /** @var array (server label => host) map */ protected $serversByLabel; /** @var string SHA-1 of the key */ @@ -87,14 +90,15 @@ class PoolCounterRedis extends PoolCounter { $conf['redisConfig']['serializer'] = 'none'; // for use with Lua $this->pool = RedisConnectionPool::singleton( $conf['redisConfig'] ); + $this->logger = \MediaWiki\Logger\LoggerFactory::getInstance( 'redis' ); $this->keySha1 = sha1( $this->key ); $met = ini_get( 'max_execution_time' ); // usually 0 in CLI mode $this->lockTTL = $met ? 2 * $met : 3600; if ( self::$active === null ) { - self::$active = array(); - register_shutdown_function( array( __CLASS__, 'releaseAll' ) ); + self::$active = []; + register_shutdown_function( [ __CLASS__, 'releaseAll' ] ); } } @@ -107,7 +111,7 @@ class PoolCounterRedis extends PoolCounter { $servers = $this->ring->getLocations( $this->key, 3 ); ArrayUtils::consistentHashSort( $servers, $this->key ); foreach ( $servers as $server ) { - $conn = $this->pool->getConnection( $this->serversByLabel[$server] ); + $conn = $this->pool->getConnection( $this->serversByLabel[$server], $this->logger ); if ( $conn ) { break; } @@ -151,6 +155,7 @@ class PoolCounterRedis extends PoolCounter { // @codingStandardsIgnoreStart Generic.Files.LineLength static $script = + /** @lang Lua */ <<luaEval( $script, - array( + [ $this->getSlotListKey(), $this->getSlotRTimeSetKey(), $this->getWakeupListKey(), @@ -202,7 +207,7 @@ LUA; $this->slotTime, // used for CAS-style sanity check ( $this->onRelease === self::AWAKE_ALL ) ? 1 : 0, microtime( true ) - ), + ], 4 # number of first argument(s) that are keys ); } catch ( RedisException $e ) { @@ -246,13 +251,13 @@ LUA; } elseif ( $slot === 'QUEUE_WAIT' ) { // This process is now registered as waiting $keys = ( $doWakeup == self::AWAKE_ALL ) - // Wait for an open slot or wake-up signal (preferring the later) - ? array( $this->getWakeupListKey(), $this->getSlotListKey() ) + // Wait for an open slot or wake-up signal (preferring the latter) + ? [ $this->getWakeupListKey(), $this->getSlotListKey() ] // Just wait for an actual pool slot - : array( $this->getSlotListKey() ); + : [ $this->getSlotListKey() ]; $res = $conn->blPop( $keys, $this->timeout ); - if ( $res === array() ) { + if ( $res === [] ) { $conn->zRem( $this->getWaitSetKey(), $this->session ); // no longer waiting return Status::newGood( PoolCounter::TIMEOUT ); } @@ -287,12 +292,13 @@ LUA; */ protected function initAndPopPoolSlotList( RedisConnRef $conn, $now ) { static $script = + /** @lang Lua */ <<luaEval( $script, - array( + [ $this->getSlotListKey(), $this->getSlotRTimeSetKey(), $this->getWaitSetKey(), @@ -342,7 +348,7 @@ LUA; $this->lockTTL, $this->session, $now - ), + ], 3 # number of first argument(s) that are keys ); } @@ -355,6 +361,7 @@ LUA; */ protected function registerAcquisitionTime( RedisConnRef $conn, $slot, $now ) { static $script = + /** @lang Lua */ <<luaEval( $script, - array( + [ $this->getSlotListKey(), $this->getSlotRTimeSetKey(), $this->getWaitSetKey(), @@ -379,7 +386,7 @@ LUA; $this->lockTTL, $this->session, $now - ), + ], 3 # number of first argument(s) that are keys ); }