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 ====
*/
$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
*/
return $bits;
}
+/**
+ * @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.
*
$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 );
+ }
}
/**
}
/**
- * 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;
} );
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;
+ }
}
/**