jenkins-bot has submitted this change and it was merged.
Change subject: Make RedisBagOStuff support tag name hashing
......................................................................
Make RedisBagOStuff support tag name hashing
Bug: T95126
Change-Id: I266dd30c93cfc44395eba5bca64f451ca77c23a4
---
M includes/objectcache/RedisBagOStuff.php
1 file changed, 15 insertions(+), 6 deletions(-)
Approvals:
Chad: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/objectcache/RedisBagOStuff.php
b/includes/objectcache/RedisBagOStuff.php
index de3511d..23c8b6d 100644
--- a/includes/objectcache/RedisBagOStuff.php
+++ b/includes/objectcache/RedisBagOStuff.php
@@ -25,6 +25,8 @@
protected $redisPool;
/** @var array List of server names */
protected $servers;
+ /** @var array Map of (tag => server name) */
+ protected $serverTagMap;
/** @var bool */
protected $automaticFailover;
@@ -34,7 +36,8 @@
* - servers: An array of server names. A server name may be a
hostname,
* 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.
+ * 6379 will be used. Arrays keys can be used to specify the tag to
+ * hash on in place of the host/port. Required.
*
* - connectTimeout: The timeout for new connections, in seconds.
Optional,
* default is 1 second.
@@ -66,6 +69,10 @@
$this->redisPool = RedisConnectionPool::singleton( $redisConf );
$this->servers = $params['servers'];
+ foreach ( $this->servers as $key => $server ) {
+ $this->serverTagMap[is_int( $key ) ? $server : $key] =
$server;
+ }
+
if ( isset( $params['automaticFailover'] ) ) {
$this->automaticFailover = $params['automaticFailover'];
} else {
@@ -348,23 +355,25 @@
* @return array (server, RedisConnRef) or (false, false)
*/
protected function getConnection( $key ) {
- if ( count( $this->servers ) === 1 ) {
- $candidates = $this->servers;
- } else {
- $candidates = $this->servers;
+ $candidates = array_keys( $this->serverTagMap );
+
+ if ( count( $this->servers ) > 1 ) {
ArrayUtils::consistentHashSort( $candidates, $key, '/'
);
if ( !$this->automaticFailover ) {
$candidates = array_slice( $candidates, 0, 1 );
}
}
- foreach ( $candidates as $server ) {
+ foreach ( $candidates as $tag ) {
+ $server = $this->serverTagMap[$tag];
$conn = $this->redisPool->getConnection( $server );
if ( $conn ) {
return array( $server, $conn );
}
}
+
$this->setLastError( BagOStuff::ERR_UNREACHABLE );
+
return array( false, false );
}
--
To view, visit https://gerrit.wikimedia.org/r/202329
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I266dd30c93cfc44395eba5bca64f451ca77c23a4
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Chad <[email protected]>
Gerrit-Reviewer: Gilles <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits