Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/95953


Change subject: Added fail-over support to JobQueueAggregatorRedis using 
"redisServers" option
......................................................................

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

* Also cleaned up various bits of documentation errors and cruft

Change-Id: Icccae5329941e4311fef02b6137a6b90f39f9046
---
M includes/clientpool/RedisConnectionPool.php
M includes/job/aggregator/JobQueueAggregatorRedis.php
2 files changed, 32 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/53/95953/1

diff --git a/includes/clientpool/RedisConnectionPool.php 
b/includes/clientpool/RedisConnectionPool.php
index 6cf7376..eb30a1d 100644
--- a/includes/clientpool/RedisConnectionPool.php
+++ b/includes/clientpool/RedisConnectionPool.php
@@ -314,6 +314,8 @@
 /**
  * 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 @@
                $this->conn = $conn;
        }
 
+       /**
+        * @return string
+        * @since 1.23
+        */
+       public function getServer() {
+               return $this->server;
+       }
+
        public function getLastError() {
                return $this->lastError;
        }
diff --git a/includes/job/aggregator/JobQueueAggregatorRedis.php 
b/includes/job/aggregator/JobQueueAggregatorRedis.php
index c6a799d..f1922a3 100644
--- a/includes/job/aggregator/JobQueueAggregatorRedis.php
+++ b/includes/job/aggregator/JobQueueAggregatorRedis.php
@@ -32,23 +32,27 @@
        /** @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 @@
                }
        }
 
-       /**
-        * @see JobQueueAggregator::doNotifyQueueNonEmpty()
-        */
        protected function doNotifyQueueNonEmpty( $wiki, $type ) {
                $conn = $this->getConnection();
                if ( !$conn ) {
@@ -80,9 +81,6 @@
                }
        }
 
-       /**
-        * @see JobQueueAggregator::doAllGetReadyWikiQueues()
-        */
        protected function doGetAllReadyWikiQueues() {
                $conn = $this->getConnection();
                if ( !$conn ) {
@@ -130,9 +128,6 @@
                }
        }
 
-       /**
-        * @see JobQueueAggregator::doPurge()
-        */
        protected function doPurge() {
                $conn = $this->getConnection();
                if ( !$conn ) {
@@ -150,11 +145,18 @@
        /**
         * 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 @@
         * @return void
         */
        protected function handleException( RedisConnRef $conn, $e ) {
-               $this->redisPool->handleException( $this->server, $conn, $e );
+               $this->redisPool->handleException( $conn->getServer(), $conn, 
$e );
        }
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/95953
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icccae5329941e4311fef02b6137a6b90f39f9046
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to