Commit graph

516 commits

Author SHA1 Message Date
Aaron Schulz
611e2d5596 objectcache: move version numbers to the main wrapper in WANObjectCache
Add FLD_VALUE_VERSION key to the value wrapper array to hold the version
number used in getWithSetCallback(). Remove the VFLD_* wrapper array from
FLD_VALUE for versioned values.

Keys stored with the old VFLD_VERSION and VFLD_DATA fields will be seen as
having the wrong version. The previous WAN cache code will see the new keys
that use FLD_VALUE_VERSION as having the wrong version too. In either case,
the usual variant key logic applies, so there should not be any issues.

This means that moving from a non-versioned to a versioned cache key is no
longer a breaking change when, for the same key, some code passes a version
number to getWithSetCallback() while other code does not.

Also:
* Make "pcTTL" respect the version number for sanity
* Make sure set() respects TTL_UNCACHEABLE for completeness
* Track slow regeneration callback runtime in FLD_GENERATION_TIME
* Remove is_callable() check overhead and rely on PHP Error instances
* Refactor unwrap() to return a more immediately useful value
* Simplify getNonProcessCachedKeys() signature by using $opts
* Split out PURGE_* constants for purge entries since those keys are
  never stored in any serialize value but are only in PHP arrays
* Rename doGetWithSetCallback() to be more succinct
* Rename and reorganize some variables for clarity

Change-Id: I4060b19583cdfd9fa36c91d7014441eeef4b3609
2019-07-11 18:04:50 -07:00
jenkins-bot
5be1301617 Merge "Make MapCacheLRU::get() accept a default value and improve $maxAge default" 2019-07-11 21:16:28 +00:00
Aaron Schulz
1f76570c46 Add ResultWrapper/FakeResultWrapper tests
Bug: T227665
Change-Id: I0709d0fb55640756b19614552b42b6b8341959f4
2019-07-11 19:57:14 +00:00
Aaron Schulz
69ad84cf36 Make MapCacheLRU::get() accept a default value and improve $maxAge default
Change-Id: If562e1745ffed37b0f1ed5382a5a397fc68aac8e
2019-07-10 22:27:51 +00:00
Aaron Schulz
20a9c8d24e bagostuff: optimize SqlBagOStuff and fix failing segmentation tests
In SqlBagOStuff:
* Add modifyMulti() helper method to reduce code duplication
* Improve atomicity of add(), cas(), and changeTTL() queries
* Avoid integer serialization and improve atomicity of incr()
* Optimize new BagOStuff::changeTTLMulti() method

In BagOStuff:
* Add changeTTLMulti() method for subclasses to optimize
* Make set() ignore WRITE_ALLOW_SEGMENTS for integers so incr() works
* Strip WRITE_ALLOW_SEGMENTS flag from the setMulti() call in set() to
  avoid triggering bogus sanity check exceptions
* Fix BagOStuffTest::testSetSegmentable failures via the above changes
* Enforce WRITE_ALLOW_SEGMENTS sanity check in setMulti() for all the
  subclasses by using a final wrapper method
* Add WRITE_ALLOW_SEGMENTS sanity check to deleteMulti()

Bug: T113916
Change-Id: I25d1790fa9b0d1837643efccfa94a12043cfbf42
2019-07-09 22:53:18 -07:00
Antoine Musso
c40d76e23b Recognizes Open Document Database
Mediawiki does not recognizes the mime type of an OpenOffice / Libre
Office Database Frontend Document and thus uses application/zip.

Our MimeAnalyzer::detectZipType() looks at the Zip files to detect known
signatures, however it is based on a reference from 2005 which did not
have the Database type yet.

OASIS Open Document Format v1.2 specify non normative MIME types, the
reference supposedly being the ones registered with the IANA, but we
have some dispredancy: ODF recommends 'base' while the IANA got
'database' registered: https://www.iana.org/assignments/media-types/

I supposed the format got approved as is, the Database mime type being
'recommended' probably because the IANA registration was pending.

Add the 'base' type which is being used by OpenOffice 3.x and later as
well as at least Libre Office 5.x.
Document my findings in code comments.
Add a test.

Bug: T35515
Change-Id: If0210a87067358612ecb8b3edd001fb05d01653d
2019-07-09 13:42:07 +02:00
jenkins-bot
14d8b187f3 Merge "rdbms: normalize Database/LBFactory logging and add snapshot flushing warnings" 2019-07-08 18:53:38 +00:00
Máté Szabó
6c462836a7 Make MSCompoundFileReader::readFile platform-agnostic
MSCompoundFileReader::readFile uses iconv to convert information
given in UTF-16 character set with little-endian byte order to
the UTF-8 character set. The input string has no BOM and the byte order
is not explicitly given, causing iconv to try to guess the byte order
based on the host operating system. This causes the method to return
different results for the same file in different environments.

This patch explicitly provides the byte order for the input to be
converted (UTF-16LE) to ensure portability and predictability.

As part of this, move MSCompoundFileReaderTest into the unit test tree.

Bug: T225019
Change-Id: I62154897d303b28c288c3a4f2f5456bedcc81852
2019-07-08 10:45:42 -07:00
Aaron Schulz
04d591935c rdbms: normalize Database/LBFactory logging and add snapshot flushing warnings
Make flushSnapshot() logging more detailed and check for explicit transaction
rounds. Also removing periods and trailing newlines from log/exception messages.

Change-Id: I0f6520f563680ab3a65b6338ced59ba25a2ec7b5
2019-07-06 13:10:24 -07:00
jenkins-bot
2b4c62b597 Merge "rdbms: make implement IResultWrapper directly instead of via inheritence" 2019-07-04 13:58:16 +00:00
Aaron Schulz
a830c14d0b rdbms: make implement IResultWrapper directly instead of via inheritence
Change-Id: If1b15c0c21d0ee336025fb99f47fc19ddf1d5435
2019-07-04 13:42:53 +00:00
Aaron Schulz
1b031cbf3f rdbms: make temp table tracking in Database more robust
Do not register table changes until query success

Change-Id: I8c0eeb510d15e2f4cc014f62b7a0f146e31b6613
2019-07-04 13:36:30 +00:00
Máté Szabó
344481f60d Move trivially compatible tests to the unit tests suite
This changeset resumes work on T89432 and related tickets
by porting an initial set of tests to the new unit test suite
separated out in I69b92db3e70093570e05cc0a64c7780a278b321a.
The tests were only ported if they worked immediately without
requiring any changes other than changing the test case class
to MediaWikiUnitTestCase and moving the test to the new suite.
If a test failed for any reason (even trivial misconfiguration),
it was NOT ported.

With this change, the unit tests suite now consits of a total
of 455 tests. As before, you can run these tests via the following
command:
$ composer phpunit:unit

Bug: T84948
Bug: T89432
Bug: T87781
Change-Id: Ibb8175981092d7f41864e641cc3c118af70a5c76
2019-06-30 15:23:53 +02:00
Brad Jorsch
f8b48c99bf rdbms: Add callback for atomic section cancellation
The callback will be called immediately when the section is cancelled,
whether that occurs directly, or via cancelling of an outer section, or
via rollback of the entire transaction.

Change-Id: Id05296948b52b95544547bd38c4387496b6c83b9
2019-06-27 20:09:42 -07:00
jenkins-bot
20d290b883 Merge "Replace very trivial mock builders with createMock()" 2019-06-24 17:15:17 +00:00
Thiemo Kreuz
005dd91276 Replace very trivial mock builders with createMock()
It does the exact same before and after. createMock() always disables
the default constructor.

Change-Id: I7b294cc3ee7f245f0aec55d12f1277fca5d39bce
2019-06-24 08:36:16 +00:00
Brad Jorsch
002f409a0b
API: Abstract out parameter validation
With the introduction of a REST API into MediaWiki core, we're going to
want to share parameter validation logic rather than having similar code
in both the Action API and the REST API. This abstracts out parameter
validation logic as a library.

There will be at least two follow-up patches:
* One to add calls in the REST API, plus the interface for the REST API
  to do body validation. Should be reasonably straightforward.
* One to adjust the Action API to use this. That'll be much less
  straightforward, as the Action API needs some MediaWiki-specific types
  (which the REST API might use too in the future) and needs to override
  the defaults on some of the library's checks (to maintain back-compat).

Bug: T142080
Bug: T223239
Change-Id: I5c0cc3a8d686ace97596df5832c450a6a50f902c
Depends-On: Iea05dc439688871c574c639e617765ae88a75ff7
2019-06-23 10:58:44 +02:00
Umherirrender
725a59f0c7 rdbms: Document varargs for IDatabase::buildLike
This is needed in order for Phan not to consider calls to
IDatabase::buildLike as invalid. Interestingly, it does not
consider calls to Database::buildLike invalid.

Bug: T191668
Change-Id: I0e027f5ec66d20b1d11e3441086001f6a751e1f5
2019-06-18 14:11:15 +00:00
Fomafix
110a5877e9 Use [...] instead of array(...) in PHP comments and documentation
Change-Id: I0c83783051bf35fe785bc01644eeb2946902b6b2
2019-06-17 21:15:09 +02:00
Aaron Schulz
f18cb061c7 Reduce HashRing test load to avoid several seconds of CPU
Bug: T225719
Change-Id: I358383e99d7950c4747b48583dc8faf00b3deeab
2019-06-14 12:57:12 +01:00
Legoktm
4e35134f7a Revert "Separate MediaWiki unit and integration tests"
This reverts commit 0a2b996278.

Reason for revert: Broke postgres tests.

Change-Id: I27d8e0c807ad5f0748b9611a4f3df84cc213fbe1
2019-06-13 23:00:08 +00:00
Máté Szabó
0a2b996278 Separate MediaWiki unit and integration tests
This changeset implements T89432 and related tickets and is based on exploration
done at the Prague Hackathon. The goal is to identify tests in MediaWiki core
that can be run without having to install & configure MediaWiki and its dependencies,
and provide a way to execute these tests via the standard phpunit entry point,
allowing for faster development and integration with existing tooling like IDEs.

The initial set of tests that met these criteria were identified using the work Amir did in
I88822667693d9e00ac3d4639c87bc24e5083e5e8. These tests were then moved into a new subdirectory
under phpunit/ and organized into a separate test suite. The environment for this suite
is set up via a PHPUnit bootstrap file without a custom entry point.

You can execute these tests by running:
$ vendor/bin/phpunit -d memory_limit=512M -c tests/phpunit/unit-tests.xml

Bug: T89432
Bug: T87781
Bug: T84948
Change-Id: Iad01033a0548afd4d2a6f2c1ef6fcc9debf72c0d
2019-06-13 22:56:31 +02:00
jenkins-bot
699920cc66 Merge "objectcache: add object segmentation support to BagOStuff" 2019-06-13 18:19:17 +00:00
Aaron Schulz
b09b3980f9 objectcache: add object segmentation support to BagOStuff
Use it for ApiStashEdit so that large PaserOutput can be stored.

Add flag to allow for value segmentation on set() in BagOStuff.
Also add a flag for immediate deletion of segments on delete().

BagOStuff now has base serialize()/unserialize() methods.

Bug: T204742
Change-Id: I0667a02612526d8ddfd91d5de48b6faa78bd1ab5
2019-06-11 16:14:17 +01:00
Aaron Schulz
2866c9b7d4 rdbms: add Database::executeQuery() method for internal use
This shares reconnection and retry logic but lacks some of the
restrictions applied to queries that go through the public query()
interface.

Use this in a few places such as doSelectDomain() for mysql/mssql.

Bug: T212284
Change-Id: Ie7341a0e6c4149fc375cc357877486efe9e56eb9
2019-06-11 14:00:41 +00:00
Thiemo Kreuz
8a4e15db7f Add missing newline between <?php and namespace/use section
The rest of the codebase is using this code formatting standard.

Change-Id: I4d2ba61757a7e28d40096d9dc5915005c340d4f2
2019-06-03 13:36:48 +00:00
Aaron Schulz
17de186917 rdbms: fix ChronologyProtector client IDs to not be empty
Follow up to 8107fddd8f

Also improve debug logging and add some unit tests

Bug: T223310
Bug: T223978
Change-Id: I35484385e4da2912bc10f5e8d2fb07cb1097347e
2019-05-24 23:42:32 -07:00
Thiemo Kreuz
e9044fe58d Remove covers validator trait where it is not needed
MediaWikiTestCase already contains this trait.

Change-Id: I08224ac12a58b41121697ab71d5c54ddbdd060ec
2019-05-17 16:49:31 +02:00
daniel
49d20b5095 Add tests for HttpRequestFactoryTest.
This also moves several tests out of HttpTest, so they are not lost when
the deprecated Http class is removed.

Bug: T222935
Change-Id: Ib4aac96ba1a978e8b6738ed446663afc3cc8c792
2019-05-13 14:32:23 +02:00
Derick Alangi
5b2d38c750 MWMessagePack: Deprecate MWMessagePack class and its method
Usage
=====

https://codesearch.wmflabs.org/search/?q=%5CbMWMessagePack%5Cb&i=nope&files=&repos=

Bug: T220313
Change-Id: I3648f8c14116f924d835f68077f46333d892a038
2019-05-09 22:40:03 +01:00
Timo Tijhof
4938038175 tests: Remove use of wfRandomString() for test fixtures
This reduces confidence in the test. There is no guruantee that
it won't return the same value twice during the duration of a full
PHPUnit run of all test suites, whether twice in a row or 20 minutes
apart.

For a test that needs a string of any kind, use an explicit, consinstent
and cheap literal value.

For a test that specifically needs some kind of uniqueness compared to
something else within the same test case, do so explicitly.

Tests that require something globally unique (for some undefined/vague
definition of "global") were not found, and should not exist anyway.

Also, in libs/objectcache tests, fix order of parameters in some
assertions (expected first, then actual), and use assertFalse/assertSame
instead of assertEqual for cases where false is expected to remove
tolerance of other loosely equal values.

Change-Id: Ifc60e88178da471330b94bfbf12e2731d2efc77d
2019-05-06 17:22:03 +00:00
Timo Tijhof
2bcd74d968 tests: Use standard utilities for temporary file names
Change-Id: Iff28c27990a81b02a92148a88256b9a25518f496
2019-05-06 17:21:45 +00:00
Aryeh Gregor
7b4489e019 Get rid of unnecessary func_get_args() and friends
HHVM does not support variadic arguments with type hints.  This is
mostly not a big problem, because we can just drop the type hint, but
for some reason PHPUnit adds a type hint of "array" when it creates
mocks, so a class with a variadic method can't be mocked (at least in
some cases).  As such, I left alone all the classes that seem like
someone might like to mock them, like Title and User.  If anyone wants
to mock them in the future, they'll have to switch back to
func_get_args().  Some of the changes are definitely safe, like
functions and test classes.

In most cases, func_get_args() (and/or func_get_arg(), func_num_args() )
were only present because the code was written before we required PHP
5.6, and writing them as variadic functions is strictly superior. In
some cases I left them alone, aside from HHVM compatibility:

* Forwarding all arguments to another function. It's useful to keep
  func_get_args() here where we want to keep the list of expected
  arguments and their meanings in the function signature line for
  documentation purposes, but don't want to copy-paste a long line of
  argument names.
* Handling deprecated calling conventions.
* One or two miscellaneous cases where we're basically using the
  arguments individually but want to use them as an array as well for
  some reason.

Change-Id: I066ec95a7beb7c0665146195a08e7cce1222c788
2019-04-12 20:17:01 +00:00
Aaron Schulz
eb603040de rdbms: add and enforce DB_REPLICA/DB_MASTER roles in DBConnRef
Even if there is only one database, if a DB_REPLICA connection
reference is obtained and an attempt is made to write it then
it will still fail. This can make it easier to spot incorrect
database usage even in a simple vanilla developer environment.

Note that methods like ILoadBalancer::getConnectionRef() can
be used for local connections as well as foreign ones.

Change-Id: I5523daad1bdd64624d3e0dd41bfd8d078b1078b0
2019-04-05 09:03:50 +00:00
jenkins-bot
962eec295d Merge "objectcache: Remove hacky testMerge_fork() method in BagOStuffTest" 2019-03-29 17:32:14 +00:00
Aaron Schulz
7ff911ba11 objectcache: Remove hacky testMerge_fork() method in BagOStuffTest
This method easily fails due to use of the same resource in each
thread after calling pcntl_fork(). This can cause thread-safety
problems like mysqli errors, which in turn make tests fail.

Change-Id: I4ff3657940c1d1cdad58bafb7449bdd0182cbe56
2019-03-28 19:39:05 -07:00
Aaron Schulz
b5c0e927a4 rdbms: add another null db/schema sanity check to DatabaseDomain
Change-Id: Id75a47a3dee97b43c586faf06208dffcc30c9e6e
2019-03-28 19:18:56 -07:00
jenkins-bot
046b9d7158 Merge "objectcache: merge getWithToken() into doGet() for simplicity" 2019-03-27 20:58:25 +00:00
Aaron Schulz
962495b17a objectcache: merge getWithToken() into doGet() for simplicity
Change-Id: I581f866521e1086ca350973d9cdeff6656f48fe8
2019-03-27 13:03:25 -07:00
jenkins-bot
970fbf54ab Merge "rdbms: add ATTR_SCHEMAS_AS_TABLE_GROUPS attribute" 2019-03-27 19:22:07 +00:00
jenkins-bot
0fd9e748cc Merge "objectcache: defined some missing methods in MultiWriteBagOStuff" 2019-03-27 18:34:30 +00:00
Aaron Schulz
25fd7dbc7b objectcache: defined some missing methods in MultiWriteBagOStuff
Also, reorder some method definitions to match the base class.
This makes it easier to compare the two. In addition, refactor
the doWrite() method to make the calls clearer.

Change-Id: I795b395b9c54645f62962461a28067ae38b291ed
2019-03-27 17:26:43 +00:00
Aaron Schulz
861683b722 objectcache: fix race condition in SqlBagOStuff::changeTTL
Also fix --use-bagostuff parameter when given 0

Change-Id: I64971d4ccad2c856cc7688577ae564c8db068819
2019-03-26 17:06:21 -07:00
jenkins-bot
1a62e51a00 Merge "rdbms: treat cloned temporary tables as "effective write" targets" 2019-03-26 22:02:10 +00:00
Aaron Schulz
314968036b rdbms: add ATTR_SCHEMAS_AS_TABLE_GROUPS attribute
Change-Id: Ia12a00c30039acd6c59726f35d03cc76aa957902
2019-03-26 14:37:27 -07:00
Aaron Schulz
108fd8b18c rdbms: treat cloned temporary tables as "effective write" targets
Make IDatabase::lastDoneWrites() reflect creation and changes to
the cloned temporary unit test tables but not other temporary tables.
This effects the LB method hasOrMadeRecentMasterChanges(). Other tables
are assumpted to really just be there for temporary calculations rather
acting as test-only ephemeral versions of permanent tables. Treating
writes to the "fake permanent" temp tables more like real permanent
tables means that the tests better align with production.

At the moment, temporary tables still have to use DB_MASTER, given
the assertIsWritableMaster() check in query(). This restriction
can be lifted at some point, when RDBMs compatibility is robust.

Bug: T218388
Change-Id: I4c0d629da254ac2aaf31aae35bd2efc7bc064ac6
2019-03-26 14:24:42 -07:00
Aaron Schulz
c4e284f113 rdbms: codify DatabaseDomain table "_" prefix convention
Alos simplify isCompatible() slightly and make the string
case in convertToString() explicit.

Change-Id: Ifb61bb5fb012491520525bbebfbde2269fa55b52
2019-03-26 21:04:51 +00:00
Aaron Schulz
e626d014ac objectcache: remove BagOStuff::mergeViaLock() and update RESTBagOStuff
All subclasses are now using the CAS variant, which respects $attempts.

Change-Id: Ia7ec6a7f3337cabe95c54c1142c3c5464c1794e7
2019-03-24 00:35:23 -07:00
Aaron Schulz
4118762bbe rdbms: avoid connections on more lazy DBConnRef methods
Also:
* Fixed LoadBalancer::getAnyOpenConnection for both
  DB_MASTER and DB_REPLICA, which are not real indexes.
* Lock down DBConnRef::close since it can only cause trouble.
* Relax DBConnRef restrictions on tablePrefix()/dbSchema()
  for the harmless "getter" mode case.
* Remove redundant DatabasePostgres::getServer definition.

Change-Id: Ia855d901cc3c28147e52284fdabb1645805d4466
2019-03-21 17:35:27 -07:00
Aaron Schulz
e2b03d5d30 objectcache: add BagOStuff::deleteMulti() method for consistency
Also:
* Make the BagOStuff tests actually pass for memcached and sql
* Add more unit tests for BagOStuff
* Make SqlBagOStuff::add() more atomic

Change-Id: Ic1eec0990a66b595b57c646498c3bd229442230c
2019-03-14 23:12:30 +00:00