jenkins-bot has submitted this change and it was merged.
Change subject: Apply $wgReadOnly to all file backends
......................................................................
Apply $wgReadOnly to all file backends
* Also added a wfConfiguredReadOnly() method
to avoid DB_SLAVE connections
Change-Id: I9e7ec95c4b2f763505166d2345d27abaef6257a3
---
M includes/GlobalFunctions.php
M includes/filebackend/FileBackendGroup.php
2 files changed, 46 insertions(+), 17 deletions(-)
Approvals:
BryanDavis: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php
index 6fbc11d..496992b 100644
--- a/includes/GlobalFunctions.php
+++ b/includes/GlobalFunctions.php
@@ -1342,11 +1342,46 @@
}
/**
- * Get the value of $wgReadOnly or the contents of $wgReadOnlyFile.
+ * Check if the site is in read-only mode and return the message if so
+ *
+ * This checks wfConfiguredReadOnlyReason() and the main load balancer
+ * for slave lag. This may result in DB_SLAVE connection being made.
*
* @return string|bool String when in read-only mode; false otherwise
*/
function wfReadOnlyReason() {
+ $readOnly = wfConfiguredReadOnlyReason();
+ if ( $readOnly !== false ) {
+ return $readOnly;
+ }
+
+ static $autoReadOnly = null;
+ if ( $autoReadOnly === null ) {
+ // Callers use this method to be aware that data presented to a
user
+ // may be very stale and thus allowing submissions can be
problematic.
+ try {
+ if ( wfGetLB()->getLaggedSlaveMode() ) {
+ $autoReadOnly = 'The database has been
automatically locked ' .
+ 'while the slave database servers catch
up to the master';
+ } else {
+ $autoReadOnly = false;
+ }
+ } catch ( DBConnectionError $e ) {
+ $autoReadOnly = 'The database has been automatically
locked ' .
+ 'until the slave database servers become
available';
+ }
+ }
+
+ return $autoReadOnly;
+}
+
+/**
+ * Get the value of $wgReadOnly or the contents of $wgReadOnlyFile.
+ *
+ * @return string|bool String when in read-only mode; false otherwise
+ * @since 1.27
+ */
+function wfConfiguredReadOnlyReason() {
global $wgReadOnly, $wgReadOnlyFile;
if ( $wgReadOnly === null ) {
@@ -1355,17 +1390,6 @@
$wgReadOnly = file_get_contents( $wgReadOnlyFile );
} else {
$wgReadOnly = false;
- }
- // Callers use this method to be aware that data presented to a
user
- // may be very stale and thus allowing submissions can be
problematic.
- try {
- if ( $wgReadOnly === false &&
wfGetLB()->getLaggedSlaveMode() ) {
- $wgReadOnly = 'The database has been
automatically locked ' .
- 'while the slave database servers catch
up to the master';
- }
- } catch ( DBConnectionError $e ) {
- $wgReadOnly = 'The database has been automatically
locked ' .
- 'until the slave database servers become
available';
}
}
diff --git a/includes/filebackend/FileBackendGroup.php
b/includes/filebackend/FileBackendGroup.php
index 9bb1582..59b2fd6 100644
--- a/includes/filebackend/FileBackendGroup.php
+++ b/includes/filebackend/FileBackendGroup.php
@@ -63,9 +63,6 @@
protected function initFromGlobals() {
global $wgLocalFileRepo, $wgForeignFileRepos, $wgFileBackends;
- // Register explicitly defined backends
- $this->register( $wgFileBackends );
-
$autoBackends = array();
// Automatically create b/c backends for file repos...
$repos = array_merge( $wgForeignFileRepos, array(
$wgLocalFileRepo ) );
@@ -105,8 +102,16 @@
);
}
- // Register implicitly defined backends
- $this->register( $autoBackends );
+ $backends = array_merge( $autoBackends, $wgFileBackends );
+
+ // Apply $wgReadOnly to all backends if not already read-only
+ foreach ( $backends as &$backend ) {
+ $backend['readOnly'] = !empty( $backend['readOnly'] )
+ ? $backend['readOnly']
+ : wfConfiguredReadOnlyReason();
+ }
+
+ $this->register( $backends );
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/243054
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9e7ec95c4b2f763505166d2345d27abaef6257a3
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: BryanDavis <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits