Commit graph

82 commits

Author SHA1 Message Date
Brad Jorsch
d65e96b763 Use new externallinks.el_index_60 field
This adds a method to LinkFilter to build the query conditions necessary
to properly use it, and adjusts code to use it.

This also takes the opportunity to clean up the calculation of el_index:
IPs are handled more sensibly and IDNs are canonicalized.

Also weird edge cases for invalid hosts like "http://.example.com" and
corresponding searches like "http://*..example.com" are now handled more
regularly instead of being treated as if the extra dot were omitted,
while explicit specification of the DNS root like "http://example.com./"
is canonicalized to the usual implicit specification.

Note that this patch will break link searches for links where the host
is an IP or IDN until refreshExternallinksIndex.php is run.

Bug: T59176
Bug: T130482
Change-Id: I84d224ef23de22dfe179009ec3a11fd0e4b5f56d
2018-11-12 22:33:18 +00:00
Aaron Schulz
5c03b91e3b Add type hint to invalidateImageDescriptions()
Change-Id: Ie6322f25c959f5de4bbccd8f47d40f112817d00b
2018-10-01 23:20:10 -07:00
Timo Tijhof
3d758d7495 jobqueue: Use explicit retry when refreshLinks can't get a lock
While RefreshLinksJob is de-duplicated by page-id, it is possible
for two jobs to run for the same page ID if the second one was queued
after the first one started running. In that case they the newer
one must not be skipped or ignored because it will have newer
information to record to the database, but it also has no way
to stop the old one, and we can't run them concurrently.

Instead of letting the lock exception mark the job as error,
making it implicitly retry, do this more explicitly, which avoids
logspam.

Bug: T170596
Co-Authored-By: Aaron Schulz <aschulz@wikimedia.org>
Change-Id: Id2852d73d00daf83f72cf5ff778c638083f5fc73
2018-08-28 22:39:01 +01:00
Umherirrender
40d3ce8d17 Reduce calls to MediaWikiServices::getInstance()
In some functions MediaWikiServices::getInstance() was called twices or
in loops. Extract the variable to reduce calls.

Change-Id: I2705db11d7a9ea73efb9b5a5c40747ab0b3ea36f
2018-08-18 06:02:39 +02:00
Aryeh Gregor
90d4f56fe4 Mass conversion of $wgContLang to service
Brought to you by vim macros.

Bug: T200246
Change-Id: I79e919f4553e3bd3eb714073fed7a43051b4fb2a
2018-08-11 22:44:29 -06:00
Bartosz Dziewoński
62f7cdc331 Use multibyte-aware truncation to avoid invalid UTF-8 in cl_sortkey_prefix
The invalid UTF-8 could cause incorrect sorting of affected pages in
category lists on wikis using UCA collations. On my local testing
wiki, the generated cl_sortkey was just 0x30 regardless of the value
of cl_sortkey_prefix.

This doesn't fix existing bad data in the database. It will only be
updated when the affected page is edited (or null-edited).

The cl_timestamp field will also be updated when that happens, which
apparently may affect Wikinews' DynamicPageList extension, according
to comments on T27254. This is not easily avoidable.

Bug: T200623
Change-Id: I4baa9ea3c7f831ff3c9c51e6b8e5d66e7da42a91
2018-07-30 21:52:38 +02:00
Reedy
a075271157 Update composer/spdx-licenses to 1.4.0 and mediawiki/mediawiki-codesniffer to 21.0.0
https://github.com/composer/spdx-licenses/compare/1.3.0...1.4.0

Change-Id: I39f7a1310455159866bfed5224536e800befec0d
2018-07-26 17:44:28 +00:00
Kevin Israel
a50f61009d MWNamespace: Add getCategoryLinkType() method
This method returns the value used as cl_type for category links that
are "from" pages within the namespace, and is added to avoid duplication
of code across a few classes.

Change-Id: I4e55932a5a27858cfedb12009b455fcd02f9b5df
2018-06-29 15:37:11 +00:00
Brad Jorsch
aef72c5cf6 Populate externallinks.el_index_60 and drop default
Adds a maintenance script to populate the field, has that be
automatically run during update.php, and drops the no-longer-needed
default value on the column (where possible: mssql has some sort of
constraint thing going on that I have no idea how it works).

Bug: T59176
Change-Id: I971edf013a1a39466aca3b6e34c915cb24fd3aa7
2018-05-15 12:08:35 -04:00
Aaron Schulz
8659c59dcf Use AutoCommitUpdate in LinksUpdate::doUpdate
The hook handlers are likely to write to secondary databases, in which
case it is better to wrap the callback in its own transaction round.

This lowers the chance of pending write warnings happening in
runMasterTransactionIdleCallbacks() as well as DBTransactionError
exceptions in LBFactory due to recursion during commit.

Bug: T191282
Bug: T193668
Change-Id: Ie207ca312888b6bb076f783d41f05b701f70a52e
2018-05-03 23:47:17 +00:00
Aaron Schulz
3247bae0e7 Add action/user tracking to html cache purge jobs
Change-Id: Ic7155a7303debfaf26b13cb836497ccbc89ea238
2017-10-30 10:47:30 -07:00
Aaron Schulz
8f829de5f0 Add action/user tracking to link refresh jobs
Change-Id: Ie7261eacddb869988b005ba2f17968df88c7003e
2017-10-23 11:06:16 -07:00
Aaron Schulz
a005f1de98 Clean up wiki ID and DB domain ID handling
Bug: T174017
Change-Id: I42299a393c6691d39817db1d83a176a17df2474b
2017-09-30 10:25:03 +00:00
Brad Jorsch
01a10dba5a Remove reference to deprecated IDatabase->nextSequenceValue()
The method was deprecated and made unnecessary in Ib308190c.

Change-Id: I1729ac0b3a88270a4c2f064187a2472112aaeb1e
2017-09-01 12:28:39 -04: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
Thiemo Mättig
91a920fd85 Remove auto-generated "Constructor" documentation on constructors
Having such comments is worse than not having them. They add zero
information. But you must read the text to understand there is
nothing you don't already know from the class and the method name.

This is similar to I994d11e. Even more trivial, because this here is
about comments that don't say anything but "constructor".

Change-Id: I474dcdb5997bea3aafd11c0760ee072dfaff124c
2017-07-21 12:19:30 +02:00
Aaron Schulz
869bea9c59 Release prior row locks beforehand in LinksUpdate::updateCategoryCounts
Bug: T163801
Change-Id: I6a026ee9a249da5a8fd9ceb216416340a9188d3f
2017-04-26 22:33:56 -07:00
Fomafix
464f0c72a5 Remove multiple spaces in PHP files
Change-Id: Id9c26ec5ca730a9536f8fdccb8853eb03cbe87a4
2017-04-12 17:27:19 +02:00
Aaron Schulz
488a647831 Move IDatabase/IMaintainableDatabase to Rdbms namespace
Change-Id: If7e8a8ff574661fd827de8bcec11d2c39a687300
2017-03-28 15:32:38 -07:00
James D. Forrester
9635dda73a includes: Replace implicit Bugzilla bug numbers with Phab ones
It's unreasonable to expect newbies to know that "bug 12345" means "Task T14345"
except where it doesn't, so let's just standardise on the real numbers.

Change-Id: I6f59febaf8fc96e80f8cfc11f4356283f461142a
2017-02-21 18:13:24 +00:00
Brad Jorsch
fb3ae6fbe3 Replace use of &$this
Use of &$this doesn't work in PHP 7.1. For callbacks to methods like
array_map() it's completely unnecessary, while for hooks we still need
to pass a reference and so we need to copy $this into a local variable.

Bug: T153505
Change-Id: I8bbb26e248cd6f213fd0e7460d6d6935a3f9e468
2017-01-31 23:01:54 -05:00
Aaron Schulz
e3b7bf4d0a Make updateCategoryCounts() have better lag checks
* Add the lag checks to LinksUpdate. Previously, only
  LinksDeletionUpdate had any such checks.
* Remove the transaction hook usage, since the only two callers are
  already lag/contention aware. Deferring them just makes the wait
  checks pointless and they might end up happening all at once.
* Also set the visibility on some neigboring methods.
* Clean up LinksUpdate $existing variables in passing. Instead of
  overriding the same variable, use a differently named variable
  to avoid mistakes.

Bug: T95501
Change-Id: I43e3af17399417cbf0ab4e5e7d1f2bd518fa7e90
2016-10-20 15:33:18 -07:00
Kunal Mehta
61adc1e146 Use namespaced ScopedCallback
The un-namespaced \ScopedCallback is deprecated.

Change-Id: Ie014d5a775ead66335a24acac9d339915884d1a4
2016-10-17 15:46:05 -07:00
Aaron Schulz
d31ecefc1c Add transaction ticket to LinksUpdateComplete hook
This lets callers use commitAndWaitForReplication() more easily.

Change-Id: I743bd1f989b8fb3b7ba3e5cc8ce1bb44c00f99af
2016-09-23 02:37:03 +00:00
Aaron Schulz
a2790b1b80 Remove wfGetCaller() dependency from DatabaseBase
Change-Id: I3e240b2eb5c1f6a21f1bc974c3d28f5755c7451a
2016-09-15 14:40:00 -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
ef1c17b77d Remove unused custom transaction logic from DataUpdate
Change-Id: Ife65e4e90a35395e87f4f487f1cb871b67d92aa1
2016-09-01 15:03:16 -07:00
Aaron Schulz
a438b12b8b Links update class cleanups
* Avoid using deprecated functions.
* Switch to DataUpdate as the direct parent class as
  no benefit was provided from SqlDataUpdate (which
  should be deprecated soon).

Change-Id: I0f1c77128f3df658e6a0eaf4471ca48ac536c643
2016-08-31 17:11:51 -07:00
cenarium
d88d902735 LinksUpdate: Add functions returning changed page properties
This adds getAddedProperties and getRemovedProperties functions
to LinksUpdate. They are available only after the update, so for
extensions in the LinksUpdateComplete hook. This is useful for
example if an extension caches a page property; if the property
gets changed it may want to purge the cache.

This is similar to the getAddedLinks and getRemovedLinks
functions.

Change-Id: I0c73b3d181f32502da75687857ae9aeff731f559
2016-08-29 16:45:05 -07:00
Aaron Schulz
f16eb73ecf Move invalidatePages() to new PurgeJobUtils class
This does not really belong in SqlDataUpdate.

Change-Id: I7166e50696483371f95db3a8b6bce44b0f866ccd
2016-08-23 01:09:08 +00:00
Aaron Schulz
21ddcf1592 Add convenience commitAndWaitForReplication() method
This also does sanity checks to avoid breaking transactions

Change-Id: I7453c245eee25a26243e606970ef5f79b21a8141
2016-08-16 22:09:17 +00:00
Aaron Schulz
4bcfe7d0ad Database transaction flushing cleanups
* Do not commit() inside masterPosWait(). This could happen
  inside JobRunner::commitMasterChanges, resulting in
  one DB committing while the others may or may not later commit.
* Migrate some commit() callers to commitMasterChanges().
* Removed unsafe upload class commit() which could break
  outer transactions.
* Also cleaned up the "flush" flag to make it harder to misuse.

Change-Id: I75193baaed979100c5338abe0c0899abba3444cb
2016-08-16 20:34:54 +00:00
Aaron Schulz
63a3911a67 Improvements to RefreshLinksJob/DeleteLinksJob locking
* Removed the lockAndGetLatest() call which caused contention problems.
  Previously, job #2 could block on job #1 in that method, then job #1
  yields the row lock to job #2 in LinksUpdate::acquirePageLock() by
  committing, then job #1 blocks on job #2 in updateLinksTimestamp().
  This caused timeout errors. It also is not fully safe ever since
  batching and acquirePageLock() was added.
* Add an outer getScopedLockAndFlush() call to runForTitle() which
  avoids this contention (as well as contention with page edits)
  but still prevents older jobs from clobbering newer jobs. Edits
  can happen concurrently, since they will enqueue a job post-commit
  that will block on the lock.
* Use the same lock in DeleteLinksJob to edit/deletion races.

Change-Id: I9e2d1eefd7cbb3d2f333c595361d070527d6f0c5
2016-07-19 13:04:21 -07:00
Aaron Schulz
473ab6e80e Avoid contention in updateLinksTimestamp()
Since LinksUpdate::doUpdate() already flushes the transaction,
go ahead and flush before other DataUpdates might run (e.g.
from RefreshLinksJob). Also release the lock before running
the LinksUpdateComplete handlers, as the lock is just to keep
LinksUpdate instances from racing with each other.

Change-Id: Ied97fa36fbca0203123e9fc966d2e23bfd621c0e
2016-06-07 05:15:42 -07:00
jenkins-bot
b746001c66 Merge "Add LinksUpdate::getRevision()" 2016-05-26 23:12:12 +00:00
Roan Kattouw
01b2516175 Add LinksUpdate::getRevision()
Similar to getTriggeringUser(). Also propagate it
to subjobs similarly.

Bug: T135959
Change-Id: I3d894acaf3d85b790e5034c7d9f76bf94672f445
2016-05-26 15:43:22 -07:00
Aaron Schulz
d14d322612 Lowered incrTableUpdate() batch size to $wgUpdateRowsPerQuery
Change-Id: I05787b6e9ace26e7a20c228fbc3502983dfed777
2016-05-19 20:59:55 -07:00
Aaron Schulz
7ee9645c1e Make LinksUpdate only wait on the DB with the link tables
Bug: T135690

Change-Id: If79ca385884f422e5ed11e77b29033c8cabf494c
2016-05-18 22:07:58 +00:00
Aaron Schulz
4a67b170fc Batch links updates performed by refreshLinks jobs
This should avoid erratic lag spikes that happen as many links are
added and removed via new pages (sometimes bot generated) and edits
that blank pages as well as their reversions.

In the common cases of a modest number of link changes, the entire
update will still happen in one transaction. In any case, link updates
now use a lock to avoid clobbering each other on the same page.

Bug: T109943
Change-Id: Icd453fcc3d28342065893260ad327eae11870245
2016-05-13 18:31:51 +00:00
Aaron Schulz
0097e00050 Document mInterwikis in LinksUpdate
Change-Id: If10840c5df849455027b5a497097e583fb982a65
2016-05-02 16:53:20 -07: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
Ricordisamoa
f76275febc Stop doing $that = $this in includes/deferred
Closures support $this as of PHP 5.4

Change-Id: I2632d0c2bdc9e2fec72f1c64c3868dcb442ba871
2016-02-10 17:53:29 +00:00
Aaron Schulz
8d17ad6b22 Use GAID_FOR_UPDATE for getArticleID() in LinksUpdate
Bug: T121228
Change-Id: I33addea4261d58cc93ab739621481065eb9c908d
2015-12-11 15:05:59 -08:00
Aaron Schulz
22476baa85 Remove obsolete category links code
* These calls and methods should no longer be needed
* Follow-up to 6dedffc2d7

Change-Id: Iff121263610117112c84edb5e575f039456d1ac8
2015-12-05 16:07:59 -08:00
Aaron Schulz
6dedffc2d7 Move category membership RC updates to CategoryMembershipChangeJob
* Recursive link updates no longer mention an category changes.
  It's hard to avoid either duplicate mentioning of changes or
  confusing explicit and automatic category changes.
* LinksUpdate no longer handles this logic, but rather WikiPage
  decides to spawn this update when needed in doEditUpdates().
* Fix race conditions with calculating category deltas. Do not
  rely on the link tables for the read used to determine these
  writes, as they may be out-of-date due to slave lag. Using the
  master would still not be good enough since that would assume
  FIFO and serialized job execution, which is not garaunteed.
  Use the parser output of the relevant revisions to determine
  the RC rows. If 3 users quickly edit a page's categories, the
  old way could misattribute who actually changed what.
* Make sure RC rows are inserted in an order that matches that
  of the corresponding revisions.
* Better avoid mentioning time-based (parser functions) category
  changes so they don't get attributed to the next editor.
* Also wait for slaves between RC row insertions if there where
  many category changes (it theory it could well over 10K rows).
* Using a separate job better separates concerns as LinksUpdate
  should not have to care about recent changes updates.
* Added more docs to $wgRCWatchCategoryMembership.

Bug: T95501
Change-Id: I5863e7d7483a4fd1fa633597af66a0088ace4c68
2015-12-03 11:28:05 +00:00
Aaron Schulz
27f5abac54 Make HTMLCacheUpdate callers more consistent
A few random callers were calling doUpdate() themselves
instead of using DeferredUpdates

Change-Id: If121e6afab9899dae92f0bf831b0b0c9967deeb5
2015-12-01 01:00:01 +00:00
Aaron Schulz
af5f784868 Reduce updateLinksTimestamp() DB contention
Do the LinksUpdateComplete hook updates in a separate
transaction as they may do slow SELECTs and updates.

A large amount of DBPerformance warnings were triggered
by such cases.

Bug: T95501
Change-Id: Ie4e6b7f6aefc21bafba270282c55571ff5385fe0
2015-11-17 02:36:37 +00:00
addshore
6a65ce223f Add triggeringRevisionId to LinksUpdate JobSpec
Bug: T117860
Change-Id: I8c730a434b8bdda7664fd1e3bb3fbc8840804950
2015-11-05 12:07:01 +00:00
Kunal Mehta
c52e5a21f6 LinksUpdate: Keep track of the triggering User
So extensions like Echo are able to attribute post-edit link updates to
specific the users who triggered them.

Bug: T116485
Change-Id: I083736a174b6bc15e3ce60b2b107c697d0ac13da
2015-10-27 17:10:19 -07:00
Aaron Schulz
d705ae970a Fixes related to WikiPage::triggerOpportunisticLinksUpdate()
* Focus on updating links that would *not* already be updated
  by jobs, not those that already *will* be updated.
* Place the jobs into a dedicated queue so they don't wait
  behind jobs that actually have to parse every time. This
  helps avoid queue buildup.
* Make Job::factory() set the command field to match the value
  it had when enqueued. This makes it easier to have the same
  job class used for multiple queues.
* Given the above, remove the RefreshLinksJob 'prioritize' flag.
  This worked by overriding getType() so that the job went to a
  different queue. This required both the special type *and* the
  flag to be set if using JobSpecification or either ack() would
  route to the wrong queue and fail or the job would go in the
  regular queue. This was too messy and error prone. Cirrus jobs
  using the same pattern also had ack() failures for example.

Change-Id: I5941cb62cdafde203fdee7e106894322ba87b48a
2015-10-24 00:10:12 +00:00