Aaron Schulz has uploaded a new change for review.
https://gerrit.wikimedia.org/r/242812
Change subject: Lower CDN cache TTL when slave lag is high
......................................................................
Lower CDN cache TTL when slave lag is high
* $wgCdnMaxageLagged controls exactly what that TTL is
and the usual "max lag" settings determine what "high"
is for lag (which already makes the site read-only).
* This helps avoids stale content getting stuck in CDN
for a month just because a slave was lagged for a minute.
Of course race conditions with normal slave lag and WAN
cache relay purges can still lead to this problem, though
the scope of it is reduced.
Bug: T113204
Change-Id: I7ff0a8d88665f4e557566e7b412e75edee2627fe
---
M RELEASE-NOTES-1.27
M includes/DefaultSettings.php
M includes/MediaWiki.php
M includes/OutputPage.php
M includes/db/loadbalancer/LBFactory.php
M includes/db/loadbalancer/LoadBalancer.php
6 files changed, 56 insertions(+), 5 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/12/242812/1
diff --git a/RELEASE-NOTES-1.27 b/RELEASE-NOTES-1.27
index eb15439..27b31c0 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 ===
+* $wgCdnMaxageLagged was added, which limits the CDN cache TTL
+ when any load balancer uses a DB that is lagged beyond the 'max lag'
+ setting in the relevant section of $wgLBFactoryConf.
==== External libraries ====
diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index 69b4a24..bf48668 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -2541,15 +2541,22 @@
$wgInternalServer = false;
/**
- * Cache timeout for the squid, will be sent as s-maxage (without ESI) or
- * Surrogate-Control (with ESI). Without ESI, you should strip out s-maxage in
- * the Squid config.
+ * Cache TTL for the CDN sent as s-maxage (without ESI) or
+ * Surrogate-Control (with ESI). Without ESI, you should strip
+ * out s-maxage in the Squid config.
*
-* 18000 seconds = 5 hours, more cache hits with 2678400 = 31 days.
+ * 18000 seconds = 5 hours, more cache hits with 2678400 = 31 days.
*/
$wgSquidMaxage = 18000;
/**
+ * Cache timeout for the CDN when DB slave lag is high
+ * @see $wgSquidMaxage
+ * @since 1.27
+ */
+$wgCdnMaxageLagged = 30;
+
+/**
* Default maximum age for raw CSS/JS accesses
*
* 300 seconds = 5 minutes.
diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php
index fbacb25..887f877 100644
--- a/includes/MediaWiki.php
+++ b/includes/MediaWiki.php
@@ -504,6 +504,12 @@
$factory->shutdown();
wfDebug( __METHOD__ . ' completed; all transactions committed'
);
+
+ if ( $factory->laggedSlaveUsed() ) {
+ $maxAge = $this->config->get( 'CdnMaxageLagged' );
+ $this->context->getOutput()->lowerCdnMaxage( $maxAge );
+ wfDebugLog( 'caches', "Lagged DB used; CDN cache TTL
limited to $maxAge seconds" );
+ }
}
/**
diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index f680d45..9655f2d 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -1949,6 +1949,16 @@
}
/**
+ * Lower the value of the "s-maxage" part of the "Cache-control" HTTP
header
+ *
+ * @param int $maxage Maximum cache time on the Squid, in seconds
+ * @since 1.27
+ */
+ public function lowerCdnMaxage( $maxage ) {
+ $this->mSquidMaxage = min( $this->mSquidMaxage, $maxage );
+ }
+
+ /**
* Use enableClientCache(false) to force it to send nocache headers
*
* @param bool $state
diff --git a/includes/db/loadbalancer/LBFactory.php
b/includes/db/loadbalancer/LBFactory.php
index da0fe44..df3e693 100644
--- a/includes/db/loadbalancer/LBFactory.php
+++ b/includes/db/loadbalancer/LBFactory.php
@@ -202,7 +202,7 @@
}
/**
- * Detemine if any master connection has pending changes.
+ * Detemine if any master connection has pending changes
* @since 1.23
* @return bool
*/
@@ -211,6 +211,21 @@
$this->forEachLB( function ( LoadBalancer $lb ) use ( &$ret ) {
$ret = $ret || $lb->hasMasterChanges();
} );
+
+ return $ret;
+ }
+
+ /**
+ * Detemine if any lagged slave connection was used
+ * @since 1.27
+ * @return bool
+ */
+ public function laggedSlaveUsed() {
+ $ret = false;
+ $this->forEachLB( function ( LoadBalancer $lb ) use ( &$ret ) {
+ $ret = $ret || $lb->laggedSlaveUsed();
+ } );
+
return $ret;
}
}
diff --git a/includes/db/loadbalancer/LoadBalancer.php
b/includes/db/loadbalancer/LoadBalancer.php
index 3fcd349..60e154c 100644
--- a/includes/db/loadbalancer/LoadBalancer.php
+++ b/includes/db/loadbalancer/LoadBalancer.php
@@ -1131,6 +1131,7 @@
}
/**
+ * @note This method will trigger a DB connection if not yet done
* @return bool Whether the generic connection for reads is highly
"lagged"
*/
public function getLaggedSlaveMode() {
@@ -1141,6 +1142,15 @@
}
/**
+ * @note This method will never cause a new DB connection
+ * @return bool Whether any generic connection used for reads was
highly "lagged"
+ * @since 1.27
+ */
+ public function laggedSlaveUsed() {
+ return $this->mLaggedSlaveMode;
+ }
+
+ /**
* Disables/enables lag checks
* @param null|bool $mode
* @return bool
--
To view, visit https://gerrit.wikimedia.org/r/242812
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7ff0a8d88665f4e557566e7b412e75edee2627fe
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits