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

Change subject: Added $wgDataCenterId/$wgDataCenterRoles
......................................................................


Added $wgDataCenterId/$wgDataCenterRoles

* This is used to set sticky DC cookies to avoid
  session replication lag (which also makes sure
  ChronologyProtector works)

Bug: T91816
Change-Id: I7bc2f8185a3c05cb3ca5ccc42d300eccffae48e1
---
M RELEASE-NOTES-1.27
M includes/DefaultSettings.php
M includes/GlobalFunctions.php
M includes/MediaWiki.php
M includes/db/loadbalancer/LBFactory.php
5 files changed, 74 insertions(+), 2 deletions(-)

Approvals:
  Gilles: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/RELEASE-NOTES-1.27 b/RELEASE-NOTES-1.27
index eb15439..1670552 100644
--- a/RELEASE-NOTES-1.27
+++ b/RELEASE-NOTES-1.27
@@ -16,6 +16,9 @@
   1000 for the latter) are now hard-coded.
 
 === New features in 1.27 ===
+* $wgDataCenterId and $wgDataCenterRoles where added, which will serve as
+  basic configuration settings needed for multi-datacenter setups.
+  $wgDataCenterUpdateStickTTL was also added.
 
 ==== External libraries ====
 
diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index 69b4a24..2793161 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -1869,6 +1869,32 @@
 $wgLBFactoryConf = array( 'class' => 'LBFactorySimple' );
 
 /**
+ * The ID of the current data center
+ * @since 1.27
+ */
+$wgDataCenterId = 'default';
+
+/**
+ * Map of data center IDs to their role ("master" or "slave")
+ *
+ * Multiple data centers can be setup to handle MediaWiki, with HTTP
+ * POSTs routed to the master data center and GET/HEAD/OPTION routed to
+ * any data center (usually the closest to the end user). In such setups,
+ * this setting should be set to the appropriate value in the site
+ * config for each data center.
+ * @since 1.27
+ */
+$wgDataCenterRoles = array( 'default' => 'master' );
+
+/**
+ * After a state-changing request is done by a client, this determines
+ * how many seconds that client should keep using the master datacenter.
+ * This avoids unexpected stale or 404 responses due to replication lag.
+ * @since 1.27
+ */
+$wgDataCenterUpdateStickTTL = 10;
+
+/**
  * File to log database errors to
  */
 $wgDBerrorLog = false;
diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php
index 6fbc11d..3b9a882 100644
--- a/includes/GlobalFunctions.php
+++ b/includes/GlobalFunctions.php
@@ -3606,6 +3606,28 @@
 }
 
 /**
+ * @see $wgDataCenterRoles
+ * @return string The current cluster ID
+ * @since 1.27
+ */
+function wfDataCenter() {
+       global $wgDataCenterId;
+
+       return $wgDataCenterId;
+}
+
+/**
+ * @see $wgDataCenterRoles
+ * @return string The current cluster role; one of (master/slave)
+ * @since 1.27
+ */
+function wfDataCenterRole() {
+       global $wgDataCenterId, $wgDataCenterRoles;
+
+       return $wgDataCenterRoles[$wgDataCenterId];
+}
+
+/**
  * Get a Database object.
  *
  * @param int $db Index of the connection to get. May be DB_MASTER for the
diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php
index fbacb25..f3fb158 100644
--- a/includes/MediaWiki.php
+++ b/includes/MediaWiki.php
@@ -504,6 +504,14 @@
                $factory->shutdown();
 
                wfDebug( __METHOD__ . ' completed; all transactions committed' 
);
+
+               // Set a cookie to tell all CDN edge nodes to "stick" the user 
to the
+               // DC that handles this POST request (e.g. the "master" data 
center)
+               $request = $this->context->getRequest();
+               if ( $request->wasPosted() && 
$factory->hasOrMadeRecentMasterChanges() ) {
+                       $expires = time() + $this->config->get( 
'DataCenterUpdateStickTTL' );
+                       $request->response()->setCookie( 'UseDC', 'master', 
$expires );
+               }
        }
 
        /**
diff --git a/includes/db/loadbalancer/LBFactory.php 
b/includes/db/loadbalancer/LBFactory.php
index da0fe44..e5fb094 100644
--- a/includes/db/loadbalancer/LBFactory.php
+++ b/includes/db/loadbalancer/LBFactory.php
@@ -202,9 +202,9 @@
        }
 
        /**
-        * Detemine if any master connection has pending changes.
-        * @since 1.23
+        * Determine if any master connection has pending changes
         * @return bool
+        * @since 1.23
         */
        public function hasMasterChanges() {
                $ret = false;
@@ -213,6 +213,19 @@
                } );
                return $ret;
        }
+
+       /**
+        * Determine if any master connection has pending/written changes from 
this request
+        * @return bool
+        * @since 1.27
+        */
+       public function hasOrMadeRecentMasterChanges() {
+               $ret = false;
+               $this->forEachLB( function ( LoadBalancer $lb ) use ( &$ret ) {
+                       $ret = $ret || $lb->hasOrMadeRecentMasterChanges();
+               } );
+               return $ret;
+       }
 }
 
 /**

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I7bc2f8185a3c05cb3ca5ccc42d300eccffae48e1
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: BBlack <[email protected]>
Gerrit-Reviewer: Cscott <[email protected]>
Gerrit-Reviewer: Gilles <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to