Commit graph

399 commits

Author SHA1 Message Date
jenkins-bot
285080c311 Merge "objectcache: make RedisBagOStuff pass all tests" 2018-06-02 01:35:26 +00:00
jenkins-bot
966e34619b Merge "objectcache: add setMockTime() method to BagOStuff/WANObjectCache" 2018-06-01 13:19:24 +00:00
Aaron Schulz
acace9a049 objectcache: add setMockTime() method to BagOStuff/WANObjectCache
Change-Id: I3e5760814fb7dbe628eb0d979d690c3275fc3c15
2018-06-01 03:46:58 +00:00
Aaron Schulz
13f7232bf4 objectcache: make RedisBagOStuff pass all tests
* Provide a default lock-based BagOStuff::cas implementation
* Make RedisBagOStuff::merge() use mergeViaCas()
* Use the raw unserialized string as the redis CAS token to
  avoid any bad interaction with __wakeup() methods changing
  field values every time
* Make RedisBagOStuff::incr() return false when there is no
  such key, not null
* Rewrite merge() test to make the order of write/cas phase
  of the parent and child merge() calls well defined instead
  of arbitrary usleep() calls
* Avoid cache key reuse in test runs

Change-Id: I388ec173cf3858bb2fc7a8c8a00cda68703074ce
2018-05-31 20:43:10 -07:00
Kunal Mehta
2ecb2c944f Use wikimedia/xmp-reader library
Bug: T100922
Depends-On: I9bec4e03c49baafda30fb44cc793fa31b36e400d
Change-Id: Ic9044bf3260d1a474a6c74844949602441ffc865
2018-05-31 19:24:39 -07:00
Bartosz Dziewoński
485f66f174 Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
Find: /isset\(\s*([^()]+?)\s*\)\s*\?\s*\1\s*:\s*/
Replace with: '\1 ?? '

(Everywhere except includes/PHPVersionCheck.php)
(Then, manually fix some line length and indentation issues)

Then manually reviewed the replacements for cases where confusing
operator precedence would result in incorrect results
(fixing those in I478db046a1cc162c6767003ce45c9b56270f3372).

Change-Id: I33b421c8cb11cdd4ce896488c9ff5313f03a38cf
2018-05-30 18:06:13 -07:00
jenkins-bot
b6e8e6b832 Merge "rdbms: make runOnTransactionIdleCallbacks() reset DBO_TRX on exceptions" 2018-05-30 21:47:27 +00:00
Aaron Schulz
0b5ed025e9 rdbms: do not silently rollback empty transactions on error
Since there might be important view snapshots, temp tables, or effects
from SET statements or the like, go into TRX_ERROR state for "possible
transaction level errors" even if no recognized writes took place and
the transaction was not explicit.

Change-Id: I32c34bc28b845e343d0167a220412824838eaed8
2018-05-30 03:10:02 +00:00
Aaron Schulz
8880a25112 rdbms: make runOnTransactionIdleCallbacks() reset DBO_TRX on exceptions
Change-Id: Ibbb2a3ebf9dd970772ee704aa643a3843f20a3b5
2018-05-25 23:40:47 +00:00
Brad Jorsch
57445f0425 IP: Fix sanitization of IPv4 ranges
'000.000.000.000/24' should sanitize to '0.0.0.0/24', not
'0.0.0.000/24'.

Change-Id: I9364cb268dcc9b9b24aa1c627a87482978c4cf34
2018-05-23 10:34:20 -04:00
jenkins-bot
fd3f586dbb Merge "resourceloader: Make various CSSMin performance optimizations and cleanups" 2018-05-17 18:50:45 +00:00
Thiemo Kreuz
ff84fbe8a0 resourceloader: Make various CSSMin performance optimizations and cleanups
This is called relatively often. Even small improvements might have an
impact.

I'm intentionally replacing method_exists with class_exists because the
old check looked like it was done for backwards compatibility (MediaWiki
before 1.27 did not contained the method), while in reality this code is
meant to run without MediaWiki. This is much better reflected with a
straight "if this class doesn't exist, there is no MediaWiki".

I'm intentionally using the …::class feature. Yes, this works, even if the
class is not there.

Change-Id: I7f250a7cb000105bb751f68f25c6cc1c44c8f221
2018-05-17 18:34:41 +00:00
Fomafix
a9c11c473b CSSMin: Do not escape U+FFFD as code point
The current editors draft from 23 April 2018 does not require to escape
the REPLACEMENT CHARACTER (U+FFFD) as code point anymore.

https://drafts.csswg.org/cssom/#serialize-a-string
  If the character is NULL (U+0000), then the REPLACEMENT CHARACTER
  (U+FFFD).

https://www.w3.org/TR/2016/WD-cssom-1-20160317/#serialize-a-string
  If the character is NULL (U+0000), then the REPLACEMENT CHARACTER
  (U+FFFD) escaped as code point.

Change-Id: Ia67e89b3c9561ca29e133d61a2eca8f3db306d8c
2018-05-17 12:22:59 +02:00
Aaron Schulz
b6cd5421b9 rdbms: rename onTransactionIdle() to onTransactionCommitOrIdle()
This is clearer and is consistent with onTransactionPreCommitOrIdle()

Change-Id: I3a34a0e9adea69ec55ed6ddfef47703e31e7c3b5
2018-05-09 21:07:06 +00:00
Thiemo Kreuz
49216d9c3b CSSMin: Add more edge cases with spaces to CSSMinTest
Change-Id: Id5e884711ab69615273dd050d83c65a385aaa817
2018-05-02 17:03:57 +00:00
Aaron Schulz
5bfa77f8d9 rdbms: enforce and improve LBFactory/LoadBalancer callback handling
* Handle the case where an onTransaction* callback for one handle
  adds more onTransaction* callbacks to a different handle. Instead
  of supporting only a short chain of such callbacks, try to resolve
  the whole chain by using a loop in LoadBalancer and LBFactory.
* Add sanity checks to enforce the proper call order of LoadBalancer
  transaction methods, such as those that execute callbacks. This is
  the order that LBFactory already uses. Use ROUND_ERROR for problems
  that can ruin the instance state. Such problems require rollback.
* Correct setTrxEndCallbackSuppression() calls in beginMasterChanges()
  that were making tests fail.
* Make Database handle callback suppression for FLUSHING_ALL_PEERS
  instead of making LoadBalancer/LBFactory have to manage it.
* Simplify finalizeMasterChanges() given that suppression does not
  actually effect runOnTransactionPreCommitCallbacks().
* Make dangling callback warning in Database::close work properly.
* Actually use $fname in flushReplicaSnapshots().
* Use DBTransactionError instead of DBExpectedError in some places
  where stages fail.
* Fix failing testGetScopedLock() unit tests so everything passes.

Add more comments to setTransactionListener and onTransactionIdle.

Change-Id: I6a25a6e4e5ba666e0da065a24846cbab7e786c7b
2018-04-30 21:55:25 +00:00
Aaron Schulz
c8085ad43f rdbms: make IDatabase::onTransaction* methods pass the DB handle for convenience
Change-Id: Ia45a26830d62326b103593268fbf34c907783c90
2018-04-24 16:45:11 -07:00
jenkins-bot
984381d6d9 Merge "rdbms: make select() warn when FOR UPDATE is used with aggregation" 2018-04-23 20:01:13 +00:00
jenkins-bot
ec72c55954 Merge "CSSMin: Fix breaking of quoted urls with outer spacing" 2018-04-20 19:24:15 +00:00
Aaron Schulz
b992b3aea5 rdbms: make select() warn when FOR UPDATE is used with aggregation
Using FOR UPDATE or LOCK IN SHARE MODE with aggregation leads to
query errors with PostgreSQL.

Bug: T160910
Change-Id: Iaed964e7e59468365cbc62cb4bfd3ad44b898452
2018-04-20 03:42:26 +00:00
jenkins-bot
a7c2042234 Merge "rdbms: make cancelAtomic() handle callbacks and work with DBO_TRX" 2018-04-19 20:14:21 +00:00
Aaron Schulz
20777d7399 rdbms: make cancelAtomic() handle callbacks and work with DBO_TRX
Make transaction callbacks aware of cancelled sections. If the
statements of a section are reverted via cancelAtomic(), then the
dependant callbacks are now cancelled as well. Any callbacks for
onTransactionResolution(), which does not depend on COMMIT, will
see the triggering event as a ROLLBACK, since the unit of work it
was part of was rolled back.

Also fix the handling of topmost atomic sections with DBO_TRX.
These still need their own savepoint to make cancelAtomic() work.

Follow-up to 52aeaa7a5.

Change-Id: If4d455c98155283797678cfb9df31d5317dd91a2
2018-04-19 12:43:01 -07:00
Timo Tijhof
5333d63cbc CSSMin: Fix breaking of quoted urls with outer spacing
Bug:  T189375
Change-Id: I9226ec9bd21d7dedc964fbc1dc1f0914abe458d5
2018-04-18 18:24:07 +00:00
Timo Tijhof
cb2ab955f1 resourceloader: Clean up CSSMinTest
* Consistently name data providers as "provide.." and make them
  static.

* Document why wgServer is being mocked.

* Use TestingAccessWrapper instead of ad-hoc sub class for
  accessing protected methods.

Change-Id: Ife2d98091200bbc8fb16b7ac6eafd3f2c22c1463
2018-04-16 23:05:46 +01:00
jenkins-bot
046250bfc3 Merge "CSSMin::serializeStringValue: Update implementation to new specification" 2018-04-13 12:30:30 +00:00
Fomafix
d37c017994 CSSMin::serializeStringValue: Update implementation to new specification
The current version of https://www.w3.org/TR/cssom/ is
https://www.w3.org/TR/2016/WD-cssom-1-20160317/

The new specification for CSS string serialization
https://www.w3.org/TR/2016/WD-cssom-1-20160317/#serialize-a-string
has some changes compared to the old specification
https://www.w3.org/TR/2013/WD-cssom-20131205/#serialize-a-string
* U+0000 get replaced by the REPLACEMENT CHARACTER (U+FFFD) instead of
  throwing an exception.
* U+0080 to U+009F are not escaped.

The old implementation has a bug because it selects the byte range
[\x7f-\x9f] and not unicode codepoint range [\u007f-\u009f]. This
breaks the encoding because CSS is in UTF-8 not in ISO 8859-x.

Also add tests to cover CSSMin::serializeStringValue.

Bug: T192048
Change-Id: I894824c216b95dbba461308488fba33121ffea54
2018-04-13 05:58:25 +02:00
jenkins-bot
6a3aadf097 Merge "rdbms: rename CONN_TRX_AUTO constant to CONN_TRX_AUTOCOMMIT" 2018-04-12 20:38:58 +00:00
Aaron Schulz
f8c2486d15 rdbms: rename CONN_TRX_AUTO constant to CONN_TRX_AUTOCOMMIT
The "AUTO" means AUTOCOMMIT, not "automatic transactions"/DBO_TRX,
which is basically the opposite concept. The new name does not
suffer from that ambiguity.

Keep the old constant as an alias for backwards compatibility.

Also remove LoadBalancer comment about non-existing field

Change-Id: I63beeb061fc9be73f320308e4d6393b58628b8c8
2018-04-12 13:01:52 -07:00
jenkins-bot
296fe3b900 Merge "rdbms: ignore inactive mysql GTIDs in replication position methods" 2018-04-12 01:03:15 +00:00
jenkins-bot
2d030f4576 Merge "rdbms: allow cancelation of dangling nested atomic sections" 2018-04-11 19:48:00 +00:00
Aaron Schulz
f9d10f9e03 rdbms: fix transaction flushing in Database::close
Use the right IDatabase constants for the $flush parameter to
the commit() and rollback() calls.

This fixes a regression from 3975e04cf4.

Also validate the mode/flush parameters to begin() and commit().

Bug: T191916
Change-Id: I0992f9a87f2add303ed309efcc1adb781baecfdc
2018-04-10 22:31:31 -07:00
Aaron Schulz
477b835945 rdbms: allow cancelation of dangling nested atomic sections
* Make startAtomic() return a token that can be used with cancelAtomic()
  cancel any nested atomic sections that have not yet been ended.
* Make doAtomicSection() clear dangling nested sections by default.
* Also give doAtomicSection() a $cancelable parameter, having the
  same default as startAtomic().

Change-Id: I75fa234cb1dcfef17dc9a973a3b02d2607efa98e
2018-04-10 16:34:31 -07:00
Brad Jorsch
0618227f7f rdbms: Issue a deprecation warning if errors are ignored
I532bc5201 added code to put the Database into an error state on error,
to prevent callers from catching and ignoring exceptions without rolling
back. But to avoid breaking everything relying on the ability to do so,
it didn't set the error state for certain types of errors.

To allow those broken callers to be cleaned up, log a deprecation
warning when we detect that someone has indeed ignored one of these
errors.

Bug: T189999
Change-Id: Ib7aca59639f30959e106fd4f1a1209e28bad2857
2018-04-10 02:06:44 +00:00
Kunal Mehta
b4925e34d0 tests: Enable PHPUnit 4/6 compat layer in some tests that need it
Change-Id: I27a21fa9e97414fae02acbefb28011f0275cba63
2018-04-07 19:31:24 -07:00
Brad Jorsch
395462b7d5 rdbms: Roll back empty implicit transaction on error
If we're not going to set trxStatus to an error state in this case, we
need to issue a rollback to be sure the database (i.e. PostgreSQL) isn't
still in an error state too.

Bug: T189999
Change-Id: Id6e203b216fff937b6a97d779b36c278e3366409
2018-04-05 14:45:18 -04:00
jenkins-bot
5211d2ab68 Merge "Fix SamplingStatsdClient for PHP 7.1+" 2018-04-05 18:10:06 +00:00
jenkins-bot
671e5b4d81 Merge "rdbms: make Database query error handling more strict" 2018-04-05 15:29:20 +00:00
Gergő Tisza
9e9a696492
Fix SamplingStatsdClient for PHP 7.1+
Bug: T182380
Change-Id: I74a8aef1230c56d0c6a7856f8397e657fc6d1c40
2018-04-05 11:51:00 +02:00
Aaron Schulz
315ffb840b rdbms: ignore inactive mysql GTIDs in replication position methods
If it is known that master writes will use GTIDs with a certain
domain and server ID, ignore other ones on masterPosWait().

This restores ceb7d61ee except it uses the same server variables
and MySQLMasterPos preserves the active server/domain information
across serialization.

Change-Id: I1a4f143adcbec642966d7d1a55edb0f414a7f0c4
2018-04-04 21:58:03 -07:00
Aaron Schulz
3975e04cf4 rdbms: make Database query error handling more strict
Handle all errors in query() that might have caused rollback by
putting the Database handle into an error state that can only be
resolved by cancelAtomic() or rollback(). Other queries will be
rejected until then.

This results in more immediate exceptions in some cases where
atomic section mismatch errors would have been thrown, such as a
an error bubbling up from a child atomic section. Most cases were
a try/catch block assumes that only the statement was rolled back
now result in an error and rollback.

Callers using try/catch to handle key conflicts should instead use
SELECT FOR UPDATE to find conflicts beforehand, or use IGNORE, or
the upsert()/replace() methods. The try/catch pattern is unsafe and
no longer allowed, except for some common errors known to just
rollback the statement. Even then, such statements can come from
child atomic sections, so committing would be unsafe. Luckily, in
such cases, there will be a mismatch detected on endAtomic() or a
dangling section detected in close(), resulting in rollback.

Remove caching from DatabaseMyslBase::getServerVariableSettings
in case some SET query changes the values.

Bug: T189999
Change-Id: I532bc5201681a915d0c8aa7a3b1c143b040b142e
2018-04-04 21:26:11 -07:00
jenkins-bot
456729e8d2 Merge "CSSMin: Don't match empty string as remappable url" 2018-04-04 22:54:00 +00:00
Timo Tijhof
5385f56e96 CSSMin: Don't match empty string as remappable url
The empty string being matched causes an undefined array index
notice in production, seen from various random gadgets, but spiked
after a change in MonoBook from last week that introduced a
broken background-image rule with empty string as url.

In browsers, that is actually interpreted as valid and "expands"
to the current url and re-fetches as Accept:image/*, silly, but
still broken. The broken icon was fixed in MonoBook, but we still
need to avoid trying to remap empty string as url.

Two changes:

1. Fix regex used by remap() to not match empty string.
   This was already fixed for the 'url()' case without the
   optional quotes, but with quotes, it was being matched as
   non-empty. This is now fixed by using '+' instead of '*'.
   Added tests to confirm they produce output, and PHPUnit
   is configured to also assert no Notices are emitted (which
   it converts to fatal exceptions).

2. Fix processUrlMatch() as sanity check to throw if the key
   is missing.

Bug: T191237
Change-Id: I0ada337b0b4ab73c80236367ff79c31bcd13aa7d
2018-04-04 21:17:35 +01:00
jenkins-bot
6c169ee1fd Merge "rdbms: clean up DBO_TRX behavior for onTransaction* callbacks" 2018-04-04 16:18:14 +00:00
Aaron Schulz
d4c31cf841 rdbms: clean up DBO_TRX behavior for onTransaction* callbacks
* Make onTransactionIdle() wait until any transaction round
  is gone, even if there is no SQL transaction active. This
  is what onTransactionPreCommitOrIdle() already does.
* Decouple "transaction round mode" (DBO_TRX) from whether a
  round is active via a 'trxRoundId' LB info field. If rounds
  are enabled, but not is started, then the transaction state
  should be interpreted as "idle".
* Improve related documentation.
* Add more related unit tests.

Change-Id: I3ab18f577ec0375897fcb63f18f4ee2deeb436e9
2018-04-03 23:16:45 -07:00
Antoine Musso
bb683d5176 tests: fix PHPUnit @requires for APCU
@requires is an annotation used by PHPUnit to flag a test as requiring a
PHP function or extension. c214c9a95 changed it to list two functions
separated by a slash:

   @requires function apc_store/apcu_store

However that is not recognized by PHPUnit and the test is always
skipped.

Change the @requires to require the APCU extension.

Repro case:

  phpunit.php --verbose includes/libs/MemoizedCallableTest.php

Follow-up c214c9a952

Bug: T140587
Change-Id: I1fdd52c8fc8ca1c7c0c7f914e6da8774799ba5d8
2018-04-03 12:21:55 +00:00
Aaron Schulz
9ce9f5c4e4 Revert "rdbms: make getMasterPos() ignore GTIDs outside of gtid_domain_id"
This had a noticeable increase in LoadBalancer::doWait timeouts.

This reverts commit ceb7d61ee7.

Change-Id: I7004d55a05c20f646f70d778d7b6496123e270a4
2018-04-02 14:02:47 -07:00
jenkins-bot
0b2b8e94cd Merge "tests: Remove some unused stuff in phpunit tests" 2018-03-26 22:59:06 +00:00
Max Semenik
aa9bbe6051 tests: Remove some unused stuff in phpunit tests
Change-Id: Ica20e4f4ac0887b7cac12700ffcd15f587b3ba01
2018-03-26 22:45:29 +00:00
Aaron Schulz
ceb7d61ee7 rdbms: make getMasterPos() ignore GTIDs outside of gtid_domain_id
* Filter out GTIDs with a domain that is not the one binlog
  events would be written to if the Database handle was given
  write queries. Likewise for the MariaDB server_id component.
* Also improve MySQL GTID support to better match that of MariaDB.
  This covers position retrieval, replication waiting, and ranges
  in GTIDs (which are almost always present).
* Make some MySQLMasterPos variables private by making use of
  accesors instead.
* Store the gtids array keyed by domain ID for convenience.
* Clean up dynamic call to static method.

Change-Id: Ic6ab517bc8f200c968ff892ade69ad1b9394ab21
2018-03-22 23:53:05 +00:00
Brad Jorsch
3365e83d96 rdbms: Add ATOMIC_CANCELABLE flag for micro-optimization
Aaron is concerned about the extra time added to atomic sections within
an outer transaction if we do a SAVEPOINT and RELEASE. He wants a flag
so callers have to specifically opt-in to use of savepoints.

Change-Id: I64cf5033ced464863d28dd49d9173856a9c1e1c0
2018-03-22 07:20:54 +00:00