Aaron Schulz has uploaded a new change for review.
https://gerrit.wikimedia.org/r/243089
Change subject: Enforce the API maxlag logic automatically
......................................................................
Enforce the API maxlag logic automatically
* All users with the bot right sending requests to
write APIs will get 5XX responses if slave lag is too
high. The lag tolerance is configured server side.
The maxlag parameter was removed.
* The maxlag check in index.php was also removed,
as "good citizen" bots should be using the API
anyway and evil bots will probably not be logged
in with the bot right.
* With our decreasing tolerance for slave lag, it
makes little sense to keep a client specified
?maxlag parameter around with high values like
"5 seconds" being used and recommend on mw.org.
Bug: T95501
Change-Id: If9d8f4ef47258d5afb7a0e947c6e6f040cbc7e10
---
M RELEASE-NOTES-1.27
M includes/DefaultSettings.php
M includes/MediaWiki.php
M includes/api/ApiMain.php
4 files changed, 15 insertions(+), 31 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/89/243089/1
diff --git a/RELEASE-NOTES-1.27 b/RELEASE-NOTES-1.27
index 1670552..1c15993 100644
--- a/RELEASE-NOTES-1.27
+++ b/RELEASE-NOTES-1.27
@@ -19,12 +19,16 @@
* $wgDataCenterId and $wgDataCenterRoles where added, which will serve as
basic configuration settings needed for multi-datacenter setups.
$wgDataCenterUpdateStickTTL was also added.
+* $wgAPIMaxLagThreshold was added to limit bot changes when databases lag.
==== External libraries ====
=== Bug fixes in 1.27 ===
=== Action API changes in 1.27 ===
+* The 'maxlag' parameter was removed but the logic now enforced
+ automatically for all users with the 'bot' right when performing
+ requests to write APIs. The lag tolerance is $wgAPIMaxLagThreshold.
=== Action API internal changes in 1.27 ===
diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index 2793161..049dba3 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -7297,6 +7297,12 @@
$wgAPIMaxUncachedDiffs = 1;
/**
+ * Maximum amount of DB lag on the most lagged host to tolerate
+ * before forcing bots to retry any write requests via 5XX errors
+ */
+$wgAPIMaxLagThreshold = 3;
+
+/**
* Log file or URL (TCP or UDP) to log API requests to, or false to disable
* API request logging
*/
diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php
index f3fb158..e29319b 100644
--- a/includes/MediaWiki.php
+++ b/includes/MediaWiki.php
@@ -471,7 +471,6 @@
*/
public function run() {
try {
- $this->checkMaxLag();
try {
$this->main();
} catch ( ErrorPageError $e ) {
@@ -552,33 +551,6 @@
$callback();
}
- }
-
- /**
- * 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() {
diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php
index 8e0ba8b..f75ea7c 100644
--- a/includes/api/ApiMain.php
+++ b/includes/api/ApiMain.php
@@ -1001,9 +1001,11 @@
* @return bool True on success, false should exit immediately
*/
protected function checkMaxLag( $module, $params ) {
- if ( $module->shouldCheckMaxlag() && isset( $params['maxlag'] )
) {
- // Check for maxlag
- $maxLag = $params['maxlag'];
+ if ( $module->shouldCheckMaxlag()
+ && $module->isWriteMode()
+ && $this->getUser()->isAllowed( 'bot' )
+ ) {
+ $maxLag = $this->getConfig()->get( 'APIMaxLagThreshold'
);
list( $host, $lag ) = wfGetLB()->getMaxLag();
if ( $lag > $maxLag ) {
$response = $this->getRequest()->response();
--
To view, visit https://gerrit.wikimedia.org/r/243089
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If9d8f4ef47258d5afb7a0e947c6e6f040cbc7e10
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