Added fail-over support to JobQueueAggregatorRedis using "redisServers" option

* Also cleaned up various bits of documentation errors and cruft

Change-Id: Icccae5329941e4311fef02b6137a6b90f39f9046
This commit is contained in:
Aaron Schulz 2013-11-17 14:04:04 -08:00 committed by BryanDavis
parent 295c9f93e9
commit 8c1a12677c
2 changed files with 32 additions and 20 deletions

View file

@ -314,6 +314,8 @@ class RedisConnectionPool {
/**
* Helper class to handle automatically marking connectons as reusable (via RAII pattern)
*
* This class simply wraps the Redis class and can be used the same way
*
* @ingroup Redis
* @since 1.21
*/
@ -337,6 +339,14 @@ class RedisConnRef {
$this->conn = $conn;
}
/**
* @return string
* @since 1.23
*/
public function getServer() {
return $this->server;
}
public function getLastError() {
return $this->lastError;
}

View file

@ -32,23 +32,27 @@ class JobQueueAggregatorRedis extends JobQueueAggregator {
/** @var RedisConnectionPool */
protected $redisPool;
/** @var Array List of Redis server addresses */
protected $servers;
/**
* @params include:
* - redisConfig : An array of parameters to RedisConnectionPool::__construct().
* - redisServer : A hostname/port combination or the absolute path of a UNIX socket.
* If a hostname is specified but no port, the standard port number
* 6379 will be used. Required.
* - redisConfig : An array of parameters to RedisConnectionPool::__construct().
* - redisServers : Array of server entries, the first being the primary and the
* others being fallback servers. Each entry is either a hostname/port
* combination or the absolute path of a UNIX socket.
* If a hostname is specified but no port, the standard port number
* 6379 will be used. Required.
* @param array $params
*/
protected function __construct( array $params ) {
parent::__construct( $params );
$this->server = $params['redisServer'];
$this->servers = isset( $params['redisServers'] )
? $params['redisServers']
: array( $params['redisServer'] ); // b/c
$this->redisPool = RedisConnectionPool::singleton( $params['redisConfig'] );
}
/**
* @see JobQueueAggregator::doNotifyQueueEmpty()
*/
protected function doNotifyQueueEmpty( $wiki, $type ) {
$conn = $this->getConnection();
if ( !$conn ) {
@ -63,9 +67,6 @@ class JobQueueAggregatorRedis extends JobQueueAggregator {
}
}
/**
* @see JobQueueAggregator::doNotifyQueueNonEmpty()
*/
protected function doNotifyQueueNonEmpty( $wiki, $type ) {
$conn = $this->getConnection();
if ( !$conn ) {
@ -80,9 +81,6 @@ class JobQueueAggregatorRedis extends JobQueueAggregator {
}
}
/**
* @see JobQueueAggregator::doAllGetReadyWikiQueues()
*/
protected function doGetAllReadyWikiQueues() {
$conn = $this->getConnection();
if ( !$conn ) {
@ -130,9 +128,6 @@ class JobQueueAggregatorRedis extends JobQueueAggregator {
}
}
/**
* @see JobQueueAggregator::doPurge()
*/
protected function doPurge() {
$conn = $this->getConnection();
if ( !$conn ) {
@ -150,11 +145,18 @@ class JobQueueAggregatorRedis extends JobQueueAggregator {
/**
* Get a connection to the server that handles all sub-queues for this queue
*
* @return Array (server name, Redis instance)
* @return RedisConnRef|bool Returns false on failure
* @throws MWException
*/
protected function getConnection() {
return $this->redisPool->getConnection( $this->server );
$conn = false;
foreach ( $this->servers as $server ) {
$conn = $this->redisPool->getConnection( $server );
if ( $conn ) {
break;
}
}
return $conn;
}
/**
@ -163,7 +165,7 @@ class JobQueueAggregatorRedis extends JobQueueAggregator {
* @return void
*/
protected function handleException( RedisConnRef $conn, $e ) {
$this->redisPool->handleException( $this->server, $conn, $e );
$this->redisPool->handleException( $conn->getServer(), $conn, $e );
}
/**