Commit graph

29 commits

Author SHA1 Message Date
Umherirrender
c8ec25a961 maintenance: Add missing documentation to class properties
Add doc-typehints to class properties found by the PropertyDocumentation
sniff to improve the documentation.

Once the sniff is enabled it avoids that new code is missing type
declarations. This is focused on documentation and does not change code.

Change-Id: I7dec01892a987a87b1b79374a1c28f97d055e8fa
2024-09-13 19:29:24 +02:00
Dreamy Jazz
e7393b3cc7 Exclude boilerplate maintenance code from code coverage reports
Why:
* Maintenance scripts in core have bolierplate code that is
  added before and after the class to allow directly running
  the maintenance script.
* Running the maintenance script directly has been deprecated
  since 1.40, so this boilerplate code is only to support a now
  deprecated method of running maintenance scripts.
* This code cannot also be marked as covered, due to PHPUnit
  not recognising code coverage for files.
* Therefore, it is best to ignore this boilerplate code in code
  coverage reports as it cannot be marked as covered and also
  is for deprecated code.

What:
* Wrap the boilerplate code (requiring Maintenance.php and then
  later defining the maintenance script class and running if the
  maintenance script was called directly) with @codeCoverageIgnore
  comments.
* Some files use a different boilerplate code, however, these
  should also be marked as ignored for coverage for the same
  reason that coverage is not properly reported for files.

Bug: T371167
Change-Id: I32f5c6362dfb354149a48ce9c28da9a7fc494f7c
2024-08-27 13:22:29 +01:00
Derick Alangi
74033c50cd maintenance: Begin using Maintenance::getServiceContainer()
Maintenance class provides a method for getting a fresh reference
of the MW services container instance. Let's make use of these in
maintenance scripts now that we have it.

NOTE: There are still some static methods like in refreshLinks.php
that makes use of services that we can't use this method for now.

Change-Id: Idba744057577896fc97c9ecf4724db27542bf01c
2023-09-04 10:39:58 +00:00
Timo Tijhof
24509f97c0 ParserCache: Improve docs for cache type and purgeParserCache.php
Change-Id: I3301ff90a135bd0103c1dfc7e86f1dd1ba245a5a
2023-01-30 20:49:52 +00:00
Ferran Tufan
cd99df60ed Maintenance scripts: replace most globals with Config
Bug: T72673
Change-Id: Idc46e88756b1aa20f5dccbe7ab3e661b2b102964
2022-07-12 21:13:19 +02:00
Umherirrender
a7bb7cc5c5 Remove unreachable code after exception/die/exit
Change-Id: Ia81903fb2a8157625fbe63115097eccc1161b5db
2021-09-03 23:14:28 +00:00
Timo Tijhof
0545fdc3af purgeParserCache.php: Implement --tag for purging one server only
Large wiki farms may have to purge servers concurrently (instead of
one at a time) in order to keep up with new writes and delete expired
rows faster than new rows are written.

The parameter for this uses server tags for three reasons:

* Maintenance risk and complexity.
  This requires the least information about MW configuration to be
  hardcoded in the scheduled maintenance cronjob (compared to: server
  indexes which are a runtime concept, or specific hostnames/IP/
  tableprefixes which may change and should not require
  coordinating changes elsewhere).

* Operational convenience.
  By using server tags, the parameters don't have to vary between
  data centers.

* Code complexity.
  The current code for obtaining connections is based on server indexes,
  which are easy to mapped at runtime from server tags. Other ways
  of identifying shard like hostnames are either an awkward fit (as
  they don't uniquely identify a shard per-se, with multiple instances
  on the same hardware at WMF), or require SqlBagOStuff to store and
  maintain more information about connections than it currently has
  readily available.

Bug: T282761
Change-Id: I618bc1e8ca3008a4dd54778ac24aa5948f27c52e
2021-06-24 18:01:27 +01:00
Timo Tijhof
d192e0a8a9 purgeParserCache.php: Print stats for time and iterations
This emperical data will help confirm and gain confidence in our
understanding of how much time is spent in the delete operations under
various conditions, and by extent whether it'll be worth converting
the sleep duration logic to an interval that includes the time spent
in the delete operation itself.

Bug: T282761
Change-Id: I0406d9c0807bb9722623f3ec61f1e559dbe14aa9
2021-06-23 16:41:39 +01:00
Timo Tijhof
e556a7ea99 purgeParserCache.php: Remove carriage return printer, minor cleanup
* There was a carriage return, as part of a self-overwriting progress
  bar. While nice for humans running the script by hand, this made
  the script difficult to understand in WMF production where the logs
  go to syslog/journalctl, which doesn't like \r and thus showed only
  `[2KB blob]` instead of the actual output. This can bypassed with
  `journalctl -u … --all`, but that still leaves one with a sea of
  misaligned progress bars, concatenated as one long "line".

  It seems most of our maintenance scripts nowadays just keep printing
  lines to notify of progress made, so change the script to that,
  by just printing a boring "... % done\n" line (at most) every 0.1%.

* Change hardcoded batch size of 100 to use $wgUpdateRowsPerQuery.
  This is generally a no-op as this configuration defaults to 100 in
  DefaultSettings.php, and is not overridden in WMF production.

* Add a "--dry-run" option to allow for last-minute verification of
  the age and date calculation which is rather non-trivial given that
  we don't index creation time and assume $wgParserCacheExpireTime
  is constant and unchanged, which in practice, when this script is
  considered for running, tends not to be the case, making it hard to
  be sure exactly what it will do.

Minor stuff:

* Make the ORDER BY clause explicitly use ascending order.

* Try to retroactively document why we use a --msleep parameter
  instead of waiting for replication.

* Revert some of the variable name changes of I723e6377c26750ff9
  which imho made the code harder to understand.

* Flip order of $overallRatio additions to match the order of
  $tablesDoneRatio (e.g. high level + current thing).

* Remove use of Language->timeanddate() in favour of native
  date formatting, mainly to include seconds and timezone,
  but also because its simpler not to bring in all of Language
  and LocalisationCache into the script.

* Pass unix time directly to SqlBagOStuff::deleteObjectsExpiringBefore,
  as other callers do, instead of TS_MW-formatting first. There is
  also additional casting to TS_UNIX within the method.

Before:

> Deleting objects expiring before 21:43, 7 May 2021
> [**************************************************] 100.00%
> Done

After:

> Deleting objects expiring before Fri, 07 May 2021 21:43:52 GMT
> ... 50.0% done
> ... 100.0% done
> Done

Bug: T280605
Bug: T282761
Change-Id: I563886be0b3aeb187c274c0de4549374e0ff18f0
2021-05-13 02:42:29 +00:00
Tim Starling
20d06b34bb Safer autoloading with respect to file-scope code
Many files were in the autoloader despite having potentially harmful
file-scope code.

* Exclude all CommandLineInc maintenance scripts from the autoloader.
* Introduce  "NO_AUTOLOAD" tag which excludes the file containing it
  from the autoloader. Use it on CommandLineInc.php and a few
  suspicious-looking files without classes in case they are refactored
  to add classes in the future.
* Add a test which parses all non-PSR4 class files and confirms that
  they do not contain dangerous file-scope code. It's slow (15s) but
  its results were enlightening.
* Several maintenance scripts define constants in the file scope,
  intending to modify the behaviour of MediaWiki. Either move the
  define() to a later setup function, or protect with NO_AUTOLOAD.
* Use require_once consistently with Maintenance.php and
  doMaintenance.php, per the original convention which is supposed to
  allow one maintenance script to use the class of another maintenance
  script. Using require breaks autoloading of these maintenance class
  files.
* When Maintenance.php is included, check if MediaWiki has already
  started, and if so, return early. Revert the fix for T250003 which
  is incompatible with this safety measure. Hopefully it was superseded
  by splitting out the class file.
* In runScript.php add a redundant PHP_SAPI check since it does some
  things in file-scope code before any other check will be run.
* Change the if(false) class_alias(...) to something more hackish and
  more compatible with the new test.
* Some site-related scripts found Maintenance.php in a non-standard way.
  Use the standard way.
* fileOpPerfTest.php called error_reporting(). Probably debugging code
  left in; removed.
* Moved mediawiki.compress.7z registration from the class file to the
  caller.

Change-Id: I1b1be90343a5ab678df6f1b1bdd03319dcf6537f
2021-01-11 11:59:36 +11:00
Reedy
c7eb28aac9 Fix various MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment
Change-Id: I50c7c93f1534e966224f98a835ca01f93eb9416d
2020-05-21 01:06:05 +00:00
Aryeh Gregor
0de9c47b50 Remove Language::factory and getParentLanguage use
Change-Id: I11f8801ef47ec1a1f63d840116e69667e6f3ae3c
2019-10-27 12:34:28 +02:00
Umherirrender
7363e38ddf Set public for override of Maintenance functions
The following function are set to public in the parent class and cannot
have another visibility in subclasses
Maintenance::__construct
Maintenance::execute
Maintenance::getDbType
Maintenance::validateParamsAndArgs
Maintenance::setDB

Change-Id: I0cd6514642d479aca20f1221bf673b0713c21631
2019-10-09 20:41:33 +02:00
Umherirrender
ad776c7d5f Use ::class to resolve class names in maintenance scripts
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: I1d4567f47f93eb1436cb98558388e48d35258666
2018-01-23 17:40:16 +00:00
Bryan Davis
9e34eeff23 Maintenance: add fatalError() method
Deprecate the second argument to Maintenance::error() in favor of a new
Maintenance::fatalError() method. This is intended to make it easier to
review flow control in maintenance scripts.

Change-Id: I75699008638f7e99b11210c7bb9e2e131fca7c9e
2017-11-21 21:34:16 -07:00
Kunal Mehta
399adec9ad Turn ParserCache into a service, deprecate $parserMemc
ParserCache is already a singleton, making it a good candidate for a
service. $parserMemc is an odd global (it lacks the "wg" prefix) and is
ripe for deprecation.

The following are now deprecated:
* $parserMemc global
* ParserCache::singleton()
* wfGetParserCacheStorage()

A ParserCache::getCacheStorage() method was added for cases where direct
access to the underlying BagOStuff object is necessary.

Usage of $parserMemc will emit deprecation warnings through the
DeprecatedGlobal class mechanism. All usage in core was migrated.

Also take this opportunity to inject the $wgCacheEpoch global value into
ParserCache. This will require an update to the FlaggedRevs extension.

Change-Id: I2ac7afff0d8522214329248c3d1cdccd0f72bbd4
2017-07-05 19:56:49 -07:00
Aaron Schulz
c8375f708b Add --msleep option to purgeParserCache.php
Bug: T150124
Change-Id: I22be4ab67b6f9b0adb5cb62dd54b1139ee29739a
2016-11-10 13:58:22 -08:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Siebrand Mazeland
606c680b21 Update formatting in maintenance/ (4/4)
Change-Id: I6b58d014a4bfd6600e4e6f80188fdcfce18482ca
2014-04-23 20:09:26 +02:00
Timo Tijhof
beb1c4a0ec phpcs: More require/include is not a function
Follows-up I1343872de7, Ia533aedf63 and I2df2f80b81.

Also updated usage in text in documentation and the
installer LocalSettingsGenerator.

Most of them were handled by this regex:
- find: (require|include|require_once|include_once)\s*\(\s*(.+?)\s*\)\s*;$
- replace: $1 $2;

Change-Id: I6b38aad9a5149c9c43ce18bd8edbab14b8ce43fa
2013-05-21 23:26:28 +02:00
Timo Tijhof
50e7985d4d phpcs: Fix WhiteSpace.LanguageConstructSpacing warnings
Squiz.WhiteSpace.LanguageConstructSpacing:
   Language constructs must be followed by a single space;
   expected "require_once expression" but found
   "require_once(expression)"

It is a keyword (e.g. like `new`, `return` and `print`). As
such the parentheses don't make sense.

Per our code conventions, we use a space after keywords like
these. We appeared to have an unwritten exception for `require`
that doesn't make sense. About 60% of require/include usage
was missing the space and/or had superfluous parentheses.

It is as silly as print("foo") or return("foo"), it works
because keywords have no significance for whitespace between
it and the expression that follows, and since experessions can
be wrapped in parentheses for clarity (e.g. when doing string
concatenation or mathematical operations) the parenthesis
before and after basiclaly just ignored.

Change-Id: I2df2f80b8123714bea7e0771bf94b51ad5bb4b87
2013-05-09 05:56:26 +02:00
Reedy
81a6294f9a Use output/error maintenance functions
Change-Id: I9f9ebee9e577ab3cc7a042e5280161d2b2bad57a
2013-03-08 02:40:07 +00:00
Marius Hoch
652c4be7c2 Clean up: Declare variables with public instead of var
Variables in classes should be declared using public $foo
instead of var $foo for various reasons. As we require PHP 5.3
we don't have to take care about that PHP4 left over, but can
get rid of it in favour of the more clear and better readable
public.
See also: http://php.net/manual/en/language.oop5.visibility.php
(Divided into several commits to keep reviewable)

Change-Id: Ic723d0347ab2e3c78bc0097345c68bbee3dc035a
2012-09-14 21:00:00 +02:00
jeroendedauw
38c7f444e1 Use __DIR__ instead of dirname( __FILE__ )
We can now do this since we finally switched to PHP 5.3 for MW 1.20 and get rid of the silly dirname(__FILE__) stuff :)

Change-Id: Id9b2c9cd2e678197aa81c78adced5d1d31ff57b1
2012-08-27 21:45:00 +02:00
Alexandre Emsenhuber
73ae67c6ed Improve documentation of maintenance scripts.
Change-Id: I557f85e8526a3e4b48107fbf299ff39f6af1ac12
2012-08-05 12:00:37 +02:00
Alexandre Emsenhuber
9fc3afc6cd Added missing GPLv2 headers in some places.
Also made file/class documentation more consistent.

Change-Id: I8ee0861bfc2e9ff6511ad61175f1f1273739816c
2012-06-14 14:26:37 +02:00
Antoine Musso
46546f0519 Fix doc for maintenance/ 2012-02-08 16:55:54 +00:00
Tim Starling
53d267b3dc purgeParserCache.php improvements:
* Do queries in batches of 100 rows instead of all at once. Note that if there are a lot of objects with the exact same expiry time, it might take multiple runs of the script to delete them all.
* Progress meter.
2011-12-02 02:59:11 +00:00
Tim Starling
cac02778e4 * Added a script to reduce disk space on a MySQL parser cache setup such as the one at Wikimedia at the moment, by removing all objects which expire before a given time.
* Fixed unintentional shortcut evaluation in MultiWriteBagOStuff::doWrite(). It would have caused writes to be skipped on the second cache if the first cache failed, now writes should be attempted on all caches.
2011-09-09 03:51:45 +00:00