Commit graph

78 commits

Author SHA1 Message Date
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
Aaron Schulz
3496f0fca3 Make sure that each DataUpdate still has outer transaction scope
Bug: T221577
Change-Id: I620e461d791416ca37fa9ca4fca501e28d778cf5
2019-05-30 20:53:18 +00:00
Aaron Schulz
ef949d79d2 Introduce TransactionRoundAwareUpdate interface
Refactor the deferred update transaction round handling code to use
a new TransactionRoundAwareUpdate interface. Also, rename a few
DeferredUpdates methods so they do not give the impression that
doUpdates() is always called.

Change-Id: Idc4c6d81c4e2ca0ce41bca1e7800f797fa7e37f6
2019-05-25 02:33:05 +00:00
Aaron Schulz
1f628f0dc7 Update DeferredUpdates::enqueueUpdates() to look for the DB domain
Change-Id: I2c786eba61ff36a9e0e2d605aa3108c9c8569063
2019-03-29 04:04:05 +00:00
Aaron Schulz
09240a268f Make EnqueueableDataUpdate use DB domain IDs
This makes it consistent with what JobQueueGroup actually expects.

Change-Id: Id6c6b3bf19fb1e85a2e3e231d216974d831a2f7c
2019-03-27 17:40:30 +00:00
Timo Tijhof
6b7ddf9c9b Revert "Split out new RefreshSecondaryDataUpdate class"
This reverts commits a1f7fd3ada, 0ef02cd018.

Bug: T218456
Change-Id: I9bbea3d13460ed44755d77fc61ff23fb906cf71e
2019-03-19 14:51:27 +00:00
Aaron Schulz
0ef02cd018 Make DeferredUpdates enqueue updates that failed to run when possible
Bug: T206288
Bug: T206283
Change-Id: I6025bcc7d68cf214d291191d4044a66cdeff108b
2019-03-15 19:14:07 +00:00
Aaron Schulz
d92024053b Add more documentation to DeferredUpdates::doUpdates
Change-Id: Id2f1fb624d03943e5eb4bed49d3435cf9c99fc25
2019-03-06 00:04:12 -08:00
jenkins-bot
4ddc1da854 Merge "Make MergeableUpdate jobs avoid the sub-queue so they can always merge" 2018-10-12 01:13:29 +00:00
Aaron Schulz
f61868f13d Make MergeableUpdate jobs avoid the sub-queue so they can always merge
Change-Id: I5b100fae29b785ab4524d165dad2e8ee46406b0c
2018-10-12 00:36:39 +00:00
Aaron Schulz
9fb67b9a41 Make merged MergeableUpdate items always go to the end of the queue
Change-Id: I2e8aa28f7426470d9b8b9e11b902deea793069b3
2018-10-11 14:51:36 -07:00
James D. Forrester
054d5ff1a1 Drop DeferredUpdates::setImmediateMode(), deprecated since 1.29
Change-Id: I8ae7dedf956034981081d2bcec630d6724921269
2018-10-10 15:30:00 -07:00
Aaron Schulz
a79b9737f1 Make DeferredUpdates avoid running during LBFactory::commitMasterChanges
Bug: T193668
Change-Id: I50890ef17ea72481a14c4abcd93ae58b93f15d28
2018-05-03 15:11:38 -07:00
daniel
a430307fad Make DeferredUpdates re-throw exceptions during testing.
This is a stop-gap solution for the problem described in T190178.
A better solution would probably include changing the behavior
of LegacyLogger.

Bug: T190178
Change-Id: I433be04b8ee725becd174e567270aa674d2661df
2018-05-02 21:16:05 +00:00
Stephane Bisson
b5ea51dce6 Fix typehint for multiple dbs in addCallableUpdate
Change-Id: Ic4fe6c529d9394cfd0c8c8652a28f47973342096
Follow-up: I0371ecd20101c5e622497e5912676300b040865e
2018-02-13 15:50:49 -05:00
Timo Tijhof
6b2f8639b6 deferred: Introduce TransactionRoundDefiningUpdate
This allows scheduling of updates that need to start their own
transaction round. Specifically for cases where the ability to
commit early is not enough (which is already possible via LBFactory
getEmptyTransactionTicket and commitAndWaitForReplication).

Change-Id: I0910587b61c8ddf825f91e92c2f93582cc7ebd80
2017-10-13 21:24:11 +00:00
Kunal Mehta
0cb2a09b6d Always put type information before variable name for @var tags
Like other tags, @var should have the type information before the
variable name.

<https://docs.phpdoc.org/references/phpdoc/tags/var.html>

Change-Id: I9eca6957b1990fa8cc687103dc02ee38af5f9086
2017-09-04 11:06:51 -07:00
Umherirrender
3f1a52805e Use short type bool/int in param documentation
Enable the phpcs sniffs for this and used phpcbf

Change-Id: Iaa36687154ddd2bf663b9dd519f5c99409d37925
2017-08-20 13:20:59 +02:00
Aaron Schulz
3daad1264b Push all DeferredUpdates to POSTSEND queue when running that queue
This avoids putting updates in the PRESEND queue at a point where they
may never get run later in the request. The peculiarity lead to a
regression in 24842cfac.

Move "enqueue" logic to runUpdate() to simplify execute(). If job
insertion batching is strongly desired for a class, then it can use
MergeableUpdate.

Removed unused "update" field in $executeContext.

Bug: T168723
Change-Id: I40d16f6cd0adc8583797b99d859b76a836d362a8
2017-07-06 14:10:17 -07:00
Aaron Schulz
95fdff36c2 Make DeferredUpdates detect LBFactory transaction rounds
Previously, tryOpportunisticExecute() tried to nest transaction rounds,
which would fail. Added LBFactory::hasTransactionRound() as needed.

Also cleaned up some unqualified class names in callbacks and set the
PRESEND flag for the JobQueueDB AutoCommitUpdate callback. Use the
proper getMasterDB() method while at it. These follow up 24842cfac.

Bug: T154425
Change-Id: Ib1d38f68bd217903d1a7d46fb15b7d7d9620daa6
2017-06-10 15:22:32 +00:00
Aaron Schulz
c769e3f3e4 Add missing return value to getPendingUpdates() docs
Change-Id: I917a2eb97e6e99ccc895245b84717ba40b0c88f6
2017-06-01 21:10:44 -07:00
Seb35
d80fca05e1 Better handling of jobs execution in post-connection shutdown
In the postprocessing, some jobs can be executed but given the deferred
updates were already "closed", any new DeferredUpdate were directly called
(as explained by Krinkle on T165714), and the transactions opened by
classical jobs are badly mixed with transactions (directly) executed by
DeferredUpdates jobs, issuing a DBError, avoiding the job, which stays
in a 'claimed' status even if failed.

Quite similarly, some DeferredUpdates callables use JobQueueGroup::lazyPush
so it is needed to really push the generated jobs.

This change removes the run-immediately-deferred-updates behaviour even
in the post-connection shutdown, and given there is a call to
DeferredUpdates::doUpdates in JobRunner::execute it is not necessary to
add another one and hence execution of Web jobs is more similar to execution
of CLI jobs. In the same spirit to reconcile Web jobs and CLI jobs, the
call to JobQueueGroup::pushLazyJobs is done in JobRunner::execute.

Bug: T165714
Bug: T100085
Change-Id: I721e7167eca5b0b6227234fe516005243ab22388
2017-06-01 13:16:08 +02:00
Aaron Schulz
488a647831 Move IDatabase/IMaintainableDatabase to Rdbms namespace
Change-Id: If7e8a8ff574661fd827de8bcec11d2c39a687300
2017-03-28 15:32:38 -07:00
Antoine Musso
8357fe9e98 Add accessor to DeferredUpdates
Updates are stored in private variables which is not convenient when
testing deferred updates.  Add a getPendingUpdates() accessor. The stage
can be specified to only retrieve PRE or POST ones.

Change-Id: I1af730ec5e48bc0be555a8db4611a76eb9332444
2017-03-03 13:32:05 +00:00
Aaron Schulz
64df456b39 Move remaining LoadBalancer classes to Rdbms
The old names are left as aliases.

Change-Id: I52a327f2463a2ba7437324047b5b00d28cd1d758
2017-02-23 20:38:31 -08:00
Aaron Schulz
4a177b34ef Move LBFactory to Rdbms namespace
Change-Id: I5ae10783228d0252284807c9562bc8e328d4becb
2017-02-03 17:24:03 -08:00
Aaron Schulz
4a2085523f Make SessionBackend::save() update the user post-send
Bug: T92357
Change-Id: Id4f4991aca1ceeb74b59e980f09863041246a4fc
2016-10-12 11:14:45 -07:00
Aaron Schulz
c5cba0ea15 Call setTransactionTicket() on DeferredUpdates sub-queue items too
This should lower the rate of "does not have outer scope" log
warnings in DBPerformance.

Also add traces to such logs.

Change-Id: I7d21ea745cae07e0fbbe4cd8de82e93f1d10e0a5
2016-09-22 17:03:56 -07:00
Aaron Schulz
d1e15787bd Make DeferredUpdates call setTransactionTicket() on all DataUpdate tasks
This assues that things like LinksUpdate/LinksDeletionUpdate will
have a proper ticket for commitAndWaitForReplication()

Change-Id: I8234510efb706394c39c4027ddf54ace76983aa9
2016-09-12 21:48:51 -07:00
Aaron Schulz
148f7bf0d1 Make DeferredUpdates::execute() protected
Update the only caller, which is a deprecated wrapper method.
Locking down this internal method makes it secure against
misuse with regards to recursion checks.

Change-Id: I3ed52dbe4c0ad52c7b5de92e81bfdc98a1737bcf
2016-09-13 04:11:24 +00:00
jenkins-bot
f9676b1950 Merge "Clarify and update DeferredUpdates docs" 2016-09-07 06:56:40 +00:00
Aaron Schulz
3642142dd0 Clarify and update DeferredUpdates docs
Follows-up dc0cdc8a4d

Change-Id: Ib70585d9d10f6f6493a625697243e0a67796c272
2016-09-07 06:48:49 +00:00
Aaron Schulz
b8b4f12663 Make deferred updates fully own their transaction rounds
This will matter when commitMasterChanges() enforcement is tighter.
For now, any thing can still call that method anytime.

Change-Id: I0b08e9e9118a6c6118c117e3856d0a8e0ca3d457
2016-09-03 06:44:31 -07:00
Aaron Schulz
dc0cdc8a4d Make DeferredUpdates able to run DataUpdates
* Also make ErrorPageError exceptions display themselves
  in PRESEND mode. Before they were always suppressed.
* Make DataUpdate::runUpdates() simply wrap
  DeferredUpdates::execute().
* Remove unused installDBListener() method, which was
  basically moved to Maintenance.
* Enable DBO_TRX for DeferredUpdates::execute() in CLI mode
* Also perform sub-DeferrableUpdate jobs right after their
  parent for better transaction locality.
* Made rollbackMasterChangesAndLog() clear all master
  transactions/rounds, even if there are no changes yet.
  This keeps the state cleaner for continuing.
* For sanity, avoid calling acquirePageLock() in link updates
  unless the transaction ticket is set. These locks are
  already redundant and weaker in range than the locks the
  Job classes that run them get. This helps guard against
  DBTransactionError.
* Renamed $type to $stage to be more clear about the order.

Change-Id: I1e90b56cc80041d70fb9158ac4f027285ad0f2c9
2016-09-02 04:12:50 +00:00
Aaron Schulz
ce504f2d19 Move run-on-add logic in DeferredUpdates to addUpdate()
Change-Id: I1b3ec21e07549f7250fa497f352fe1c131ddc88a
2016-09-02 00:02:53 +00:00
Aaron Schulz
c1ebcb0ee2 Remove $recursionGuard var from tryOpportunisticExecute()
Aside from there being no idle callback setting here, the
old addUpdate() code that runs updates allows nesting updates.
Make this support that for a few transitional commits. It will
be changed later to simply order the sub-updates after their
parent updates, keeping both outer scope for all updates and
locality of related updates.

Change-Id: I0ad4e9713a7893b981b7bb013e9db803eed663b2
2016-09-01 22:56:45 +00:00
Aaron Schulz
44f486ffac Use transaction listener to run DeferredUpdates in CLI mode
This sets triggers on master position waits typically called
after commitMasterChanges() or in commitAndWaitForReplication().

Change-Id: I127a8fe3cfc319abfa84fcd221ee2dae191c6d3b
2016-09-01 03:30:00 +00:00
Aaron Schulz
32a8eb1822 Make various MWCallableUpdate usages rollback-safe
Support for this added to MWCallableUpdate and its helper method
in DeferredUpdates.

Bug: T141988
Change-Id: Ief150ea655036e2708557dd8ae847379edf21933
2016-08-15 00:47:42 -07:00