*/
public function run() {
try {
- $this->checkMaxLag();
try {
$this->main();
} catch ( ErrorPageError $e ) {
$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 );
+ }
+
+ // Avoid letting a few seconds of slave lag cause a month of stale data
+ if ( $factory->laggedSlaveUsed() ) {
+ $maxAge = $this->config->get( 'CdnMaxageLagged' );
+ $this->context->getOutput()->lowerCdnMaxage( $maxAge );
+ wfDebugLog( 'replication', "Lagged DB used; CDN cache TTL limited to $maxAge seconds" );
+ }
}
/**
}
}
- /**
- * Checks if the request should abort due to a lagged server,
- * for given maxlag parameter.
- * @return bool
- */
- private function checkMaxLag() {
- $maxLag = $this->context->getRequest()->getVal( 'maxlag' );
- if ( !is_null( $maxLag ) ) {
- list( $host, $lag ) = wfGetLB()->getMaxLag();
- if ( $lag > $maxLag ) {
- $resp = $this->context->getRequest()->response();
- $resp->statusHeader( 503 );
- $resp->header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) );
- $resp->header( 'X-Database-Lag: ' . intval( $lag ) );
- $resp->header( 'Content-Type: text/plain' );
- if ( $this->config->get( 'ShowHostnames' ) ) {
- echo "Waiting for $host: $lag seconds lagged\n";
- } else {
- echo "Waiting for a database server: $lag seconds lagged\n";
- }
-
- exit;
- }
- }
- return true;
- }
-
private function main() {
global $wgTitle, $wgTrxProfilerLimits;
Profiler::instance()->getTransactionProfiler()->resetExpectations();
// Do any deferred jobs
- DeferredUpdates::doUpdates( 'commit' );
+ DeferredUpdates::doUpdates( 'commit', 'enqueue' );
// Make sure any lazy jobs are pushed
JobQueueGroup::pushLazyJobs();