Commit graph

115 commits

Author SHA1 Message Date
James D. Forrester
8e940c4f21 Standardise all our class alias deprecation comments for ease of grepping
Change-Id: I7f85d931d3b79da23e87b4e5692b2e14be8fcaa0
2024-03-19 20:11:29 +00:00
Gergő Tisza
353b37b4e0
DeferredUpdates: normalize logging
Change-Id: I1fd5d897c947dd407aa04b72e11c2ce9f5ef900d
2024-01-14 00:44:49 -08:00
Gergő Tisza
dd85bcb519
DeferredUpdates: Only log enqueueing updates when it does happen
Follows up I1f68be0991f1865edca5d4b41745f3b37db8d630.

Change-Id: I1d5169a61c751be3790e5e710192d6f4b3499369
2023-12-19 20:00:08 -08:00
Gergő Tisza
73668612d4
DeferredUpdates: Fix logging for opportunistic enqueue
Bug: T351729
Change-Id: I1f68be0991f1865edca5d4b41745f3b37db8d630
2023-12-06 14:19:54 -08:00
Gergő Tisza
dc03ae088a
DeferredUpates: Mention it in the logs when enqueuing deferreds
Bug: T351729
Change-Id: Ieb6d222c6c96a005daca1505453e70b55c6915d5
2023-11-29 21:26:00 -08:00
James D. Forrester
67217d08df Namespace remaining files under includes/deferred
Bug: T166010
Change-Id: Ibd40734b96fd2900e3ce12239d09becfb4150059
2023-11-22 10:08:53 -05:00
Timo Tijhof
e56552557f deferred: Decouple DeferredUpdates from MediaWikiServices
* Create task-specific methods with simple defaults that require no
  mocking or stubbing of any kind, as used by the pure unit tests
  where service container (and by extent, storage services) are
  disabled.

* Remove all use of global variables, LBFactory, JobQueue,
  StatsdFactory, and RequestContext.

Bug: T265749
Change-Id: If85c448d2d1b806e70f641f06263680d49c6eeec
2023-09-09 20:42:02 +01:00
Timo Tijhof
aca3c8203a deferred: Make DeferredUpdates docs more accessible
In prep for the next decoupling commit:

* Rephrase introduction to state what its actually for in practice.

* Remove mentions of implementation details in favour of inline
  comments, especially stuff relating to databases.
  Except for 1 thing, every integration with databases is already
  fully decoupled.

  Automatic cancellation on rollback works by having the caller pass
  on an IDatabase object to addCallableUpdate() for that specific
  update, which works even if it came from an unknown LBFactory
  or unknown service containter.

  Oppertunistic execution is triggered by service wiring, where
  MWLBFactory takes responsibility for having LBFactory notify the
  DeferredUpdates singleton; not the other way around.

Bug: T265749
Change-Id: I048d22ffe2fa3838d9a5f4aa4128c756185a6b2e
2023-08-25 01:16:17 +01:00
Derick Alangi
407d82100b deferred: Move DeferredUpdates away from DUManager service approach
DU is a PHP process level mechanism to finish things related to a MW
request (which is possible to context changes). By request, meaning it's
stateful and a lot of things can be altered before the response gets to
the client or completes.

Services on the other hand are by design stateless meaning that making
DU stateless is approaching things from a contrary perspective. This means
when an update is deferred, nothing can change anymore as it's now done
so via a DUManager but that's the opposite of what we want becuase an
update (whether presend or postsend) should be able to do other things
in the background (perform changes to the DB, change an article's rendering
etc).

This patch is an attempt to move DU away from being a service class.

Bug: T265749
Depends-On: I2b0e80bdd92a5fd4d7c325fc8792df45e0776c30
Depends-On: I8126cc76440724753c356c48ba4e0fcc9be5b41a
Depends-On: Ia2fa060237c4e9d328d1b2b9622a65fcca97b854
Change-Id: Ifbfb0442bf6264d0bf786334416c5d99c0dd4699
2023-08-21 22:56:10 +00:00
DannyS712
07af42e199 Add DeferredUpdatesManager service to replace DeferredUpdates
This patch doesn't deal with the injection of dependencies
and removal of the global state, but rather moves the code
from DeferredUpdates to the new service essentially as-is,
to simplify review. The changes to inject the various
services needed and make DeferredUpdatesManager a proper
service will be done in follow-ups, to make them easier
to follow.

While almost everything is changed from static to non-static,
DeferredUpdates::$scopeStack remains static as
DeferredUpdatesManager::$scopeStack, just in case multiple
versions of the service are created, to ensure that no
updates are missed.

Bug: T265749
Change-Id: I7f07eddf2fc399b15db4fe9be4c792ef8eb0747b
2023-05-29 03:59:03 +00:00
Matěj Suchánek
c231736471 Fix some typos
Bug: T201491
Change-Id: I5c9408c262f09c936525f35abfacfa92a193b791
2023-03-21 15:58:09 +01:00
Timo Tijhof
ec293a0889 deferred: Remove internal DeferredUpdates::doUpdates parameter
Unused as of June 2022 with e802062e11 (I0089fa01524924).

Change-Id: I51a30d7bc1550880cd44c1f1d4e104d0e9e7c2c0
2023-01-06 23:39:19 +00:00
Thiemo Kreuz
67c56155c7 Replace trivial usages of code in strings with concatenation
This is really hard to read. What is code, what is string? These
places are so simple, they really don't need the "{$var}" syntax.

Change-Id: I589dedb8c0193eec4eef500bbb896b5b790b727b
2022-08-26 12:26:44 +00:00
Timo Tijhof
50d069826b deferred: Remove unused $mode and jobify() from internal doUpdates
Keep the $unused for now since, while it is internal, there are
actually callers in test suites of various extensions.

Change-Id: Ib56298c98b26b22568abcd71bc844651b120fe01
2022-06-21 23:03:39 +00:00
Timo Tijhof
e802062e11 deferred: Remove unused $mode of internal tryOpportunisticExecute
Has not been used for a while.

Change-Id: I0089fa01524924a092a616ebfa190a360ff957b3
2022-06-17 18:57:52 +01:00
Tim Starling
8632b5920a Replace LoadBalancer/LBFactory callback iteration with generators
Callback style iteration made sense before generators existed, but
generators make for simpler code. The "call method" variants made
sense before closures existed but defeat static analysis.

So, in LBFactory:

* Add ILBFactory::getAllLBs()
* Deprecate ILBFactory::forEachLB()
* Remove LBFactory::forEachLBCallMethod(), was protected.
* Add LBFactory::getLBsForOwner(), which is protected and has the
  internal interface in @return. Adding a new abstract method breaks
  Wikibase tests despite LBFactory not being stable to extend.
* Migrate callers. Generators allow you to return/break from the middle
  of the loop, which implies a little rearrangement for some callers.

In LoadBalancer, connections supposedly of type IDatabase were
routinely type-hinted as Database in closure parameters so that methods
could be called that were not in the interface. So it's convenient to
get rid of public iteration methods entirely in favour of private
methods returning Database[].

* Hard-deprecate ILoadBalancerForOwner::forEachOpenConnection()
  and replace it with a private generator method since nothing called
  it externally except for core tests.
* Hard-deprecate ILoadBalancerForOwner::forEachOpenPrimaryConnection()
  and replace it with a private generator. DeferredUpdates needed it for
  iterating over IDatabase::explicitTrxActive(), so add
  ILoadBalancer::explicitTrxActive() as a replacement.
* Replace private method LoadBalancer::forEachOpenReplicaConnection()
  with a generator.

Depends-On: If0b382231e27d6d1197fb7b6aef6ab50335df4e5
Change-Id: I64514e77b9bfe737be5b12e1d3c9c49976bb522f
2022-04-29 08:58:17 +10:00
Umherirrender
68808e5832 Replace deprecated JobQueueGroup::singleton()
Change-Id: Icdb301d352d302f70fefba9b40df2368cb217fd2
2022-01-27 21:37:50 +01:00
Tim Starling
84f0876b83 Add regression test for LinksDeletionUpdate loss of page_id
Bug: T299244
Change-Id: Ica31000df693ff6a4ab2c54c88b6cbdc7e70d6d0
2022-01-17 12:10:57 +11:00
TChin
47adb6d65a Refactor global variables to use MediaWikiServices instead
Automatically refactors wg prefixed globals to use MediaWikiServices config using Rector. Doesn't include files that set globals or files that fail CI.

Rector Gist: https://gist.github.com/tchin25/7cc54f6d23aedef010b22e4dfbead228

* This patch uses a modified source code rector library for our specific use case and the rector will have different effects without it.

A writeup for future reference is here: https://meta.wikimedia.org/wiki/User:TChin_(WMF)/Using_Rector_On_MediaWiki

Change-Id: I1a691f01cd82e60bf41207d32501edb4b9835e37
2022-01-10 13:55:53 -05:00
Aaron Schulz
672c646d22 deferred: make DeferredUpdates::run() logic more readable
Change-Id: I620895d6f21d8e84b74ed4ad268a668cc0ac9c4b
2021-11-17 16:39:34 -08:00
James D. Forrester
3983572c49 ILoadBalancer: Rename forEachOpenMasterConnection to forEachOpenPrimaryConnection
Bug: T282894
Change-Id: I4892084aba6c7fdfbeccec42de88b9f23490b61c
2021-09-03 13:05:23 -07:00
James D. Forrester
10324c232a ILoadBalancer/ILBFactory: Rename rollbackMasterChanges to rollbackPrimaryChanges
Bug: T282894
Change-Id: I31794e052d71160195dd3b6c29fea24bc98b356b
2021-09-02 12:50:52 -07:00
jenkins-bot
9957bc2f84 Merge "ILoadBalancer/ILBFactory: Rename commitMasterChanges() to commitPrimaryChanges()" 2021-09-02 18:50:43 +00:00
jenkins-bot
5f30d77f4d Merge "ILoadBalancer/ILBFactory: Rename beginMasterChanges() to beginPrimaryChanges()" 2021-09-02 18:30:07 +00:00
James D. Forrester
5ad7ca7eba ILoadBalancer/ILBFactory: Rename commitMasterChanges() to commitPrimaryChanges()
Bug: T282894
Change-Id: I0d80be56e683924254c4e38d05e1109ea74eeab5
2021-09-02 11:27:10 -07:00
James D. Forrester
577e1c3710 ILoadBalancer/ILBFactory: Rename beginMasterChanges() to beginPrimaryChanges()
Bug: T282894
Change-Id: I10e607215e6772c48670659719948f7135472a7f
2021-09-01 22:15:45 +00:00
Umherirrender
4d42b5e86e docs: Change wording master to primary in comments and log text
Bug: T254646
Change-Id: I5379dc79be60c99f0a30f74e5d624f81fe6f921b
2021-09-01 23:04:40 +02:00
libraryupgrader
5357695270 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0
  The following sniffs now pass and were enabled:
  * Generic.ControlStructures.InlineControlStructure
  * MediaWiki.PHPUnit.AssertCount.NotUsed

npm:
* svgo: 2.3.0 → 2.3.1
  * https://npmjs.com/advisories/1754 (CVE-2021-33587)

Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
2021-07-22 03:36:05 +00:00
Kosta Harlan
20422d9324 DeferredUpdates: Log execution time for updates
Doesn't cost anything to compute and include in logs, and would be
useful for understanding serial processing of DeferredUpdates
(basically, non-deferred deferred updates) in CI are slowing down
browser tests.

Bug: T225968
Change-Id: Id55bde5d8f4e465723d8db6df29b4c554fc1bc9c
2021-06-09 19:00:39 +00:00
Timo Tijhof
e9051b2b99 rdbms: Move setLBFactoryTriggers from doMaintenance to service wiring
This logic is not needed to run on every PHP process and was making
it difficult to run offline maintenance scripts without additional
complexity based on Maintenance::getDbType and DB_NONE.

Instead of skipping this only for DB_NONE, and establishing a pattern
that may spread to other ad-hoc places throughout the codebase, instead
remove this entirely from the eager set up code for all PHP processes
and move it to the service wiring and dependency injection.

That way, it naturally doesn't happen until and unless the DB service
is actually called upon. Scripts and entry point that need to disable
the DB service, can continue to use
MediaWikiServices::disableStorageBackend.

== Impact on SiteStatsUpdate ==

With wgCommandLineMode no longer being read at run-time from a global,
but in service wiring, this means SiteStatsUpdateTest can't change
the behaviour between CLI-like and Web-like, unless it e.g. resets
the 'DBLoadBalancerFactory' service first. Unfortunately, while most
any reset is supported, a reset of the 'DBLoadBalancerFactory' would
be unsupported as that would lose the temporary db clone context and
such, bringing us to either the developer's live db, or a broken set
up altogether. If there is a strong need for toggling oppertunistic
updates off and on at run-time, this could be supported in the
DeferredUpdates class perhaps, but we already have numerous methods
there (incl db begin/commit being a good proxy already), which this
test already used, so for now I've just removed the extra assertion
for this as it wasn't essential to that test.

Bug: T228895
Bug: T238436
Change-Id: Icf29bc484c155f52b6d8f61e5902233a15ba0c6d
2021-04-27 23:35:20 +01:00
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
Aaron Schulz
4b7ddd3c67 deferred: make DeferredUpdates::doUpdates() recursion more uniform
Follow-up ba6490aa1e.

That patch worked around $executeContext iteration errors due to the
lack of recursion support in doUpdates()/handleUpdateQueue(). Errors
were triggered by MediaWiki::schedulePostSendJobs() enqueueing deferred
updates that invoke JobRunner::run(), which, in turn, invoke doUpdates()
for each job via JobRunner:: doExecuteJob(). The doUpdates() method was
changed to operate on the sub-queue for the in-progress DeferrableUpdate.

Further improve the recursion logic:
* Use classes for the scope stack and scope queues.
* Put *all* updates added during a DeferrableUpdate::doUpdate() call into
  the subqueue, regardless of "defer until" stage or whether it implements
  MergeableUpdate. Now, doUpdate() can run *everything* it enqueued instead
  of a non-obvious subset. Note that the TransactionRoundDefiningUpdate
  that invokes JobRunner was already a POSTSEND update before ba6490aa1eb;
  the only effect of this change is that MergeableUpdate instances from jobs
  will once again run in doExecuteJob().
* Make recursive DeferredUpdates::doUpdate() calls error out immediately
  unless the DeferrableUpdate responsible is a TransactionRoundAwareUpdate
  with the TRX_ROUND_ABSENT flag. This covers the schedulePostSendJobs()
  scenario and only prohibits insane call patterns. Failing early avoids
  the risk of handleUpdateQueue() dropping all the updates due to the same
  DBTransactionError error in DeferredUpdates::attemptUpdate().
* Avoid recursion loop in tryOpportunisticExecute() when JobQueueDB is in
  use and a large number of tasks are pending. This happened due to methods
  like onTransactionPreCommitOrIdle() being used within JobQueueDB.

Mark DeferredUpdates::doUpdates()/tryOpportunisticExecute() as @internal
and create a Maintenance::shutdown() method to avoid a direct call in the
doMaintenance.php file.

Bug: T249069
Bug: T268840
Change-Id: Ib369f0e74243a48ababdb9cd83b155c9a0f5e741
2021-01-14 15:37:58 -08:00
Umherirrender
bc5cb7ae64 phan: Enable redundant_condition_detection
Remove duplicate casts
Suppress false positives

Bug: T248438
Change-Id: I2f89664a4bcd3b39b15e7cf850adda2f0c90ae6f
2020-07-01 20:13:07 +00:00
Reedy
c50ba9b190 Fix more PSR12.Properties.ConstantVisibility.NotFound
Change-Id: I0ccda3d1de29b1044f74ef0972949eb8fbcb707d
2020-05-15 00:32:23 +01:00
jenkins-bot
e17780ebcf Merge "deferred: add turnstile debug logging to DeferredUpdates::attemptUpdate()" 2020-05-11 17:16:27 +00:00
Aaron Schulz
ba6490aa1e deferredupdates: support limited DeferredUpdates::doUpdates()
Bug: T249069
Change-Id: I8b9ce062764c7993bf47aeb15f995b4257f24ee0
2020-05-07 02:17:21 -07:00
Aaron Schulz
8e2ce21223 deferred: add turnstile debug logging to DeferredUpdates::attemptUpdate()
Bug: T249069
Change-Id: Ia191b82a1f7a1f917a61c77c17cf882a19cd3d37
2020-04-21 15:07:07 -07:00
Timo Tijhof
14a8713e93 exception,deferred: Standardise on 'exception' for uncaughts and fatals
Bug: T247113
Change-Id: Id72cae0672169e8d2622bbc67c3c0b59e7c8ad54
2020-03-06 20:16:22 +00:00
Ricordisamoa
1b3bc281ac Clean up redundant Exception|Throwable union type
PHP 7.0 makes many error conditions throw instances of the new Error class
which does not extend the known Exception.
The Throwable interface provides a concise and type-safe way of handling
either, e.g. for logging purposes, but HHVM did not support it, requiring
tedious fallback checks.

This commit replaces occurrences of Exception in code paths equally
covered by Throwable, like Exception|Throwable parameter and return types
(also nullable), instanceof guards, duplicated `catch` blocks, as well as
related comments and documentation blocks, with the exception of $previous
parameter descriptions consistent with the manual at
https://www.php.net/manual/en/exception.construct.php

Proper type declarations have been added or reinstated where possible.

Change-Id: I5d3920d3cc66936a350314e2f19c4f6faeffd7c0
2020-02-12 20:28:40 +00:00
James D. Forrester
4f2d1efdda Coding style: Auto-fix MediaWiki.Classes.UnsortedUseStatements.UnsortedUse
Change-Id: I94a0ae83c65e8ee419bbd1ae1e86ab21ed4d8210
2020-01-10 09:32:25 -08:00
jenkins-bot
278cdf9607 Merge "deferred: Log trace as 'exception.trace' instead of 'trace'" 2019-12-19 17:38:33 +00:00
Umherirrender
c7ad21c25f Improve param docs
Change-Id: I746a69f6ed01c3ff000da125457df62b02d13b34
2019-11-28 19:08:59 +01:00
Timo Tijhof
c643e47248 deferred: Log trace as 'exception.trace' instead of 'trace'
This way most existing Logstash dashboards looking for traces
can pick this up without requiring the filter to be duplicated
or written as a custom Query DSL entry.

Also:

* Fix the broken logger from the jobify() method which did not
  define the "{type}" or "{exception_message}" keys at all.

* Fix the over-normalized logging of all fatal errors from deferred
  updates as "Error from {type}: {exception}" which isn't useful to
  aggregate (we can already get an overall count for
  channel:DeferredUpdates, level:error). The normalized aggregate
  is meant to uniquely identify specific errors that have a common
  cause. For other fatal exceptions we leave the keep the cause
  and exception message in the raw message and only add the request
  context and trace into placeholder fields (MWExceptionHandler.php).
  Apply the same principal here as well.

* Field 'exception.class' will now be available. This was previously
  missing (e.g. what exception is being thrown). It would log
  "The given Title does not belong" instead of
  "InvalidArgumentException: The given Title…".

Bug: T233342
Change-Id: I9b15658c97e3bfcc2ce8b234d1c0d47c9c294fb7
2019-11-26 20:40:08 +00:00
Aaron Schulz
d0b7a1b4f3 Clean up DeferredUpdates transactions and push failed updates as jobs
Bail out in attemptUpdate() if the transaction state is dirty rather
that failing at some later point. Also, flush implicit transaction
rounds before calling DeferrableUpdate::doUpdate() for fresher data.

Note that only instances of EnqueueableDataUpdate can become jobs.
Make handleUpdateQueue() defer throwing the exception until every task
was attempted for the special unit test logic.

Clean up some of the logging from 34427e7d7b.

Bug: T206283
Change-Id: I84ba1f2f8c4bf7c8ef21a907f73ad1065dd8f330
2019-11-14 13:24:53 +00:00
Daimona Eaytoy
d3252fc870 Fix new phan errors, part 5
Some of the errors are suppressed because they're phan false positives.
The idea behind this is that they'll be fixed in a future version of
phan, and we'll just have to remove the suppressions.

Note: I'm disabling UnusedPluginSuppression so that we can start suppressing
issues even if they're still disabled. The sniff should be re-enabled
as soon as we upgrade phan.

Bug: T231636
Change-Id: I0f7fa06a9e03fbb86c7a5eb6e50a850bb258a7f7
2019-10-18 20:45:53 +00:00
Daimona Eaytoy
95dc119527 Fix new phan errors, part 2
Still mostly doc-only.

Bug: T231636
Change-Id: I65cec6c716ce6859e14da00a12ef71e03603e59a
2019-10-12 10:35:09 +00:00
Daimona Eaytoy
c659bc6308 Unsuppress another phan issue (part 7)
Bug: T231636
Depends-On: I2cd24e73726394e3200a570c45d5e86b6849bfa9
Depends-On: I4fa3e6aad872434ca397325ed7a83f94973661d0
Change-Id: Ie6233561de78457cae5e4e44e220feec2d1272d8
2019-09-03 17:19:21 +00:00
Aaron Schulz
182256c572 deferred: make DeferredUpdates::attemptUpdate() use callback owners for $fnameTrxOwner
This only applies for instances of DeferrableCallback

Bug: T229694
Change-Id: I57fe351041c87342bd5774e333fcde4ae15059df
2019-08-03 05:48:02 +00:00
Aaron Schulz
b39f8289ff Clean up DeferredUpdates transaction handling
Bail out in attemptUpdate() if the transaction state is dirty rather
that failing at some later point. Also, flush implicit transaction
rounds before calling DeferrableUpdate::doUpdate() for fresher data.

Bug: T225103
Change-Id: I4f5d2f9814a562069619f05e003663fcedbd3f64
2019-07-18 13:16:28 -07:00
Aaron Schulz
dce07b4c21 Log errors in DeferredUpdates::handleUpdateQueue()
Other cleanups and fixes:
* Split up handleUpdate() method into run() and jobify()
* Handle Throwable errors
* Use 'cli' in stats keys in CLI mode instead of "get"
* Tweak some code comments

Change-Id: I7749465df2d7b58e66ee5ebdd3c3d25aea52eeb3
2019-07-11 22:04:55 +00:00