jenkins-bot has submitted this change and it was merged.

Change subject: Allow tag names for SqlBagOStuff consistent hashing
......................................................................


Allow tag names for SqlBagOStuff consistent hashing

This is needed to avoid poor hit rates in multi-DC setups

Change-Id: I8830bd6bffa4619e31609676527282ef9af0c76c
---
M includes/libs/ArrayUtils.php
M includes/objectcache/SqlBagOStuff.php
2 files changed, 23 insertions(+), 13 deletions(-)

Approvals:
  Ori.livneh: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/libs/ArrayUtils.php b/includes/libs/ArrayUtils.php
index fb35801..2156bd7 100644
--- a/includes/libs/ArrayUtils.php
+++ b/includes/libs/ArrayUtils.php
@@ -28,7 +28,7 @@
 class ArrayUtils {
        /**
         * Sort the given array in a pseudo-random order which depends only on 
the
-        * given key and each element value. This is typically used for load
+        * given key and each element value in $array. This is typically used 
for load
         * balancing between servers each with a local cache.
         *
         * Keys are preserved. The input array is modified in place.
diff --git a/includes/objectcache/SqlBagOStuff.php 
b/includes/objectcache/SqlBagOStuff.php
index 3945094..a1394c1 100644
--- a/includes/objectcache/SqlBagOStuff.php
+++ b/includes/objectcache/SqlBagOStuff.php
@@ -27,10 +27,10 @@
  * @ingroup Cache
  */
 class SqlBagOStuff extends BagOStuff {
-       /** @var array */
+       /** @var array[] (server index => server config) */
        protected $serverInfos;
-       /** @var array */
-       protected $serverNames;
+       /** @var string[] (server index => tag/host name) */
+       protected $serverTags;
        /** @var int */
        protected $numServers;
        /** @var int */
@@ -58,9 +58,12 @@
         *   - server:      A server info structure in the format required by 
each
         *                  element in $wgDBServers.
         *
-        *   - servers:     An array of server info structures describing a set 
of
-        *                  database servers to distribute keys to. If this is
-        *                  specified, the "server" option will be ignored.
+        *   - servers:     An array of server info structures describing a set 
of database servers
+        *                  to distribute keys to. If this is specified, the 
"server" option will be
+        *                  ignored. If string keys are used, then they will be 
used for consistent
+        *                  hashing *instead* of the host name (from the server 
config). This is useful
+        *                  when a cluster is replicated to another site (with 
different host names)
+        *                  but each server has a corresponding replica in the 
other cluster.
         *
         *   - purgePeriod: The average number of object cache requests in 
between
         *                  garbage collection operations, where expired entries
@@ -89,11 +92,18 @@
        public function __construct( $params ) {
                parent::__construct( $params );
                if ( isset( $params['servers'] ) ) {
-                       $this->serverInfos = $params['servers'];
-                       $this->numServers = count( $this->serverInfos );
-                       $this->serverNames = [];
-                       foreach ( $this->serverInfos as $i => $info ) {
-                               $this->serverNames[$i] = isset( $info['host'] ) 
? $info['host'] : "#$i";
+                       $this->serverInfos = [];
+                       $this->serverTags = [];
+                       $this->numServers = count( $params['servers'] );
+                       $index = 0;
+                       foreach ( $params['servers'] as $tag => $info ) {
+                               $this->serverInfos[$index] = $info;
+                               if ( is_string( $tag ) ) {
+                                       $this->serverTags[$index] = $tag;
+                               } else {
+                                       $this->serverTags[$index] = isset( 
$info['host'] ) ? $info['host'] : "#$index";
+                               }
+                               ++$index;
                        }
                } elseif ( isset( $params['server'] ) ) {
                        $this->serverInfos = [ $params['server'] ];
@@ -180,7 +190,7 @@
                        $tableIndex = 0;
                }
                if ( $this->numServers > 1 ) {
-                       $sortedServers = $this->serverNames;
+                       $sortedServers = $this->serverTags;
                        ArrayUtils::consistentHashSort( $sortedServers, $key );
                        reset( $sortedServers );
                        $serverIndex = key( $sortedServers );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I8830bd6bffa4619e31609676527282ef9af0c76c
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Ori.livneh <o...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to