Commit graph

50 commits

Author SHA1 Message Date
Aaron Schulz
d2e1734390 rdbms: rename setDomainPrefix to setLocalDomainPrefix in ILoadBalancer
Update CloneDatabase and unit test callers, which are the only things
that are likely to call it.

Change-Id: Idbc6d2965cd3828c2c6d23012319bbf0fc3ffa4a
2018-11-26 10:38:15 -08:00
Aaron Schulz
1c205f1822 rdbms: add ILBFactory::redefineLocalDomain method
This is intended for use with scripts like addWiki.php to avoid mismatched domain errors.

Bug: T209483
Change-Id: Ie24f83f4e0fad7b01690d2055e1529a4cb0275b5
2018-11-22 23:51:44 -08:00
James D. Forrester
903e8b63de doc: Modernise parameter names and documentation for 'replica' DBs
Non-breaking change. Remaining uses are public interfaces (a constant, two
globals, a config sub-parameter, SQL queries, storage function names), one i18n
message key, and a whole lot of maintenance scripts with calls to the deprecated
function wfWaitForSlaves().

Change-Id: I6ee5ca92ccf6a80c08f53d9efe38ebb4b05064d7
2018-10-31 10:36:48 -07:00
Aaron Schulz
fe0af6cad5 rdbms: Database::selectDB() update the domain and handle failure better
LoadBalancer uses Database::getDomainId() for deciding which keys to use
in the foreign connection handle arrays. This method should reflect any
changes made to the DB selection.

If the query fails, then do not change domain field. This is the sort of
approach that LoadBalancer is expects in openForeignConnection(). Also,
throw an exception when selectDB() fails.

The db/schema/prefix fields of Database no longer exist in favor of just
using the newer currentDomain field.

Also:
* Add IDatabase::selectDomain() method and made selectDB() wrap it.
* Extract the DB name from sqlite files if not explicitly provided.
* Fix inconsistent open() return values from Database subclasses.
* Make a relationSchemaQualifier() method to handle the concern of
  omitting schema names in queries. The means that getDomainId() can
  still return the right value, rather than confusingly omitt the schema.
* Make RevisionStore::checkDatabaseWikiId() account for the domain schema.
  Unlike d2a4d614fc, this does not incorrectly assume the storage is
  always for the current wiki domain. Also, LBFactorySingle sets the local
  domain so it is defined even in install.php.
* Make RevisionStoreDbTestBase actually set the LoadBalancer local domain.
* Make RevisionTest::testLoadFromTitle() account for the domain schema.

Bug: T193565
Change-Id: I6e51cd54c6da78830b38906b8c46789c79498ab5
2018-10-10 12:03:30 -07:00
Reedy
71badb429e Remove global namespaced LBFactory
Change-Id: Ia87aa5c9426af83627a1bbc9bd914546c89c1e47
2018-09-21 15:42:42 +00:00
Reedy
1c5399b471 tests: Stop using deprecated LBFactory, use namespaced version
Change-Id: Ifbbbfe1bc58e57739b88588e3b6feb703f20534d
2018-09-21 02:37:12 +00:00
Kunal Mehta
b92565ca18 Disable PHPUnit tests that fail under sqlite
So we can make the job voting, preventing other tests from regressing.
These tests can be re-enabled whenever they're made to pass.

Change-Id: I959710138e1e1b37b6ba69561c2920a78208bf12
2018-08-01 00:19:43 -07:00
Aaron Schulz
2fd62f5dc9 rdbms: add resolveDomainID() method to LBFactory/LoadBalancer
Also add LBFactory::getLocalDomainID to match the one in LoadBalancer

Change-Id: Ia31f0800bd3b692194c08b1eab9cfb2f43679c7a
2018-07-05 14:07:04 +01:00
Aaron Schulz
44b47b43ee rdbms: make getCPInfoFromCookieValue() stricter about allowed values
All components, not just the write index, must now be present.

Bug: T194403
Change-Id: I279ba3e16d470aca09fdb74cec91d28efb5e2f95
2018-06-12 18:18:54 +00:00
Aaron Schulz
fb51330084 rdbms: include client ID hash in ChronologyProtector cookies
Previously, if an internal service forwarded the cookies for a
user (e.g. for permissions) but not the User-Agent header or not
the IP address (e.g. XFF), ChronologyProtector could timeout
waiting for a matching writeIndex to appear for the wrong key.

The cookie now tethers the client to the key that holds the
DB positions from their last state-changing request.

Bug: T194403
Bug: T190082
Change-Id: I84f2cbea82532d911cdfed14644008894498813a
2018-06-02 03:57:30 +00:00
Aaron Schulz
52af356cad Avoid unnecessary WaitConditionLoop delays in ChronologyProtector
Since it takes time for the agent to get the response and set the
cookie and, as well, the time into a request that a LoadBalancer is
initialized varies by many seconds (cookies loaded from the start),
give the cookie a much lower TTL than the DB positions in the stash.

This avoids having to wait for a position with a given cpPosIndex
value, when the position already expired from the store, which is
a waste of time.

Also include the timestamp in "cpPosIndex" cookies to implement
logical expiration in case clients do not expire them correctly.

Bug: T194403
Bug: T190082
Change-Id: I97d8f108dec59c5ccead66432a097cda8ef4a178
2018-05-18 13:43:05 -07:00
Aaron Schulz
86af2ef383 rdbms: fix callback stage errors in LBFactory::commitMasterChanges
Just like 082ed053b6 fixed pre-commit callback errors when new instances
of LoadBalancer are made during that step, do the same for post-commit
callbacks.

Bug: T194308
Change-Id: Ie79e0f22b3aced425cf067d0df6b67e368223e6c
2018-05-10 04:26:41 +00:00
Aaron Schulz
205cfc1854 rdbms: fix LBFactory::commitAll() round handling
This avoids "Transaction round stage must be approved (not cursory)".

Bug: T194308
Change-Id: I9dbfe9cede02b1b1904c1d5e5a9802306c2492a2
2018-05-09 14:51:18 -07:00
Aaron Schulz
082ed053b6 rdbms: fix finalization stage errors in LBFactory::commitMasterChanges
If a pre-commit callback caused a new LoadBalancer object to be created,
that object will be in the "cursory" state rather than the "finalized"
state. If any callbacks run on an LB instance, make LBFactory iterate
over them all again to finalize these new instances.

Make LoadBalancer::finializeMasterChanges allow calls to
already-finalized instances for simplicity.

Bug: T193668
Change-Id: I4493e9571625a350c0a102219081ce090967a4ac
2018-05-07 18:04:43 +00:00
Aaron Schulz
40b2e059c0 Reset table sequences and skip some test assertions for sqlite
Various revision storage tests assume the sequences are reset
and fail otherwise.

Also disable some failing tests that are not applicable to sqlite
as well as postgres.

Change-Id: Ibdb034121a44e16bb35059a92baafb1867951ea8
2018-04-13 10:36:08 +00:00
jenkins-bot
bed43f5255 Merge "rdbms: avoid "SHOW MASTER/SLAVE STATUS" queries in the GTID case" 2018-02-14 23:37:34 +00:00
Reedy
39f0f919c5 Update suppressWarning()/restoreWarning() calls
Bug: T182273
Change-Id: I9e1b628fe5949ca54258424c2e45b2fb6d491d0f
2018-02-10 08:50:12 +00:00
Aaron Schulz
e59b0556f4 rdbms: make DOMAIN_ANY ignore bogus MySQL DB names in config
This regressed in 14ee3f2, trying to select the server config
"dbname" value as the database on connect. If that config is
bogus, then the connection attempt would fail. Instead, always
pass null to the driver's connection function if the DB domain
doesn't matter.

This affected WMF sites during lag checks, on account of the
"serverTemplate" value in $wgLBFactoryConf always using the local
wiki domain (whether the cluster had such a database or not).

Use strlen() as mysqli sees null and "" as the same for $dbname.

Bug: T186764
Change-Id: I6699d17c0125a08415046211fee7906bbaf2c366
2018-02-09 06:43:24 +00:00
Aaron Schulz
a114bd9f4d rdbms: avoid "SHOW MASTER/SLAVE STATUS" queries in the GTID case
The binlog file/pos where only being used in __toString() for the GTID
case. Make that method use the GTID set instead and avoid querying the
old-fashioned binlog fields all together in that case. The STATUS
queries involve some global lock contention.

Bug: T180918
Change-Id: I18123a702e4f554b87bf5f90017b248062e73049
2018-02-08 09:26:48 -08:00
Umherirrender
45da581551 Use ::class to resolve class names in tests
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: Ie541a7baae10ab6f5c13f95ac2ff6598b8f8950c
2018-01-26 22:49:13 +01:00
Aaron Schulz
14ee3f2107 rdbms: specify DB name and table prefix even for the local domain
When LoadBalancer opens new local domain connections, it currently
assumes that the domain specified by the server info array is the
same. For sanity, make sure that the handle is set to the local
domain.

The main LBFactory/LoadBalancer use $wgDBname/$wgDBprefix as the
local domain, corresponding with wfWikiId(). This relation is set
automatically in MWLBFactory. If $wgLBFactoryConf/$wgDBservers is
manually configured in a way breaking this correspondance, then it
is misconfigured.

Fixes made to avoid test failure:
* Make sure LoadBalancer::setDomainPrefix() updates the local
  domain alias member. Also do not bother changing the domain of
  foreign connections.
* Use the right domain ID for the connection array key names in
  LoadBalancer::openForeignConnection().
* Now that JobQueueTest no longer mistakenly uses the non-test
  tables, force it to use the main DB_MASTER handle so that it can
  see the unit test tables even if they are TEMPORARY; such tables
  are tied to the TCP connection, so separate handles see different
  temporary tables.

Change-Id: I56f8b32fe957f984b8c9753e6db3b20abe96b038
2018-01-16 17:06:52 +00:00
Aaron Schulz
d5aa846d84 Replace cpPosTime cookie/parameter with cpPosIndex
This handles multi-DB transactions properly, instead of causing wait
timeouts in the WaitConditionLoop. It also is more correct in using
a counter instead of relying on wall clocks.

In addition:
* Refactor related code in MediaWiki.php to be comprehensible.
* Always send the cookie even the "remote wiki redirect" case.
* Renamed ChronologyProtector field and constant to avoid any
  confusion of "wait for server X to reach Y" with "wait for Y
  to show up in position store".
* Add an "asOfTime" field to the position keys for debugging.

Bug: T182322
Change-Id: I5c73cd07eaf664f02ba00c38fab9f49b609f4284
2018-01-02 17:00:32 -08:00
Kunal Mehta
9e7e12252a Add @covers tags to database tests
Change-Id: Ic46bb961b41856d390ffe0e3632790c506f5655b
2017-12-28 08:53:23 +00:00
Bartosz Dziewoński
8785e4a5b3 Replace remaining uses of deprecated DB_SLAVE with DB_REPLICA
Change 950cf6016c took care of the most,
but a few remain, either outside of includes/ and maintenance/
directories (which that change was limited to), or in code introduced
afterwards.

Change-Id: I9c363d0219ea7e71cde520faba39406949a36d27
2017-08-05 10:10:26 +00:00
Aaron Schulz
6793b60eca Fix some postgres test failures
Bug: T75174
Change-Id: If9812ae301f0af84fa012e2e980b92036c1b29b2
2017-05-10 01:59:47 +00:00
Bartosz Dziewoński
ecdef925bb Miscellaneous indentation tweaks
I was bored. What? Don't look at me that way.

I mostly targetted mixed tabs and spaces, but others were not spared.
Note that some of the whitespace changes are inside HTML output,
extended regexps or SQL snippets.

Change-Id: Ie206cc946459f6befcfc2d520e35ad3ea3c0f1e0
2017-02-27 19:23:54 +01:00
Aaron Schulz
864eab03e7 Move DBMasterPos to Rdbms namespace
Updated all callers

Change-Id: Iacd5d6f7f18d8b23df24637cda61592112490eb0
2017-02-10 02:38:56 -08:00
Aaron Schulz
4a177b34ef Move LBFactory to Rdbms namespace
Change-Id: I5ae10783228d0252284807c9562bc8e328d4becb
2017-02-03 17:24:03 -08:00
Aaron Schulz
59053a0716 Move ChronologyProtector/TransactionProfiler to Rdbms namespace
Change-Id: I37a655bd8bd267c9bc32028b55925b2dce527d33
2017-01-26 10:30:57 -08:00
Seb35
ec215d010c Replace mocks of DatabaseMysql by DatabaseMysqli
The class DatabaseMysql corresponds to the PHP extension 'mysql' which is
deprecated since PHP 5.5, and the class DatabaseMysqli corresponds to the
PHP extension 'mysqli' which is the current MySQL driver. Given the class
DatabaseMysql is likely to be removed in the future, this change is a
first step towards this.

Bug: T120333
Change-Id: I7b8363838449cae09b360221d8f50ace3a008f11
2016-12-31 12:52:16 +01:00
Hashar
4d487d1942 Revert "objectcache: detect default getWithSetCallback() set options"
Causes HHVM 3.12.7 to segfault and or:
Fatal error: Stack overflow in includes/libs/objectcache/BagOStuff.php on line 754

This reverts commit b47ce21cec.

Bug: T150833
Change-Id: Ia52fdf65f5e386c0eaa1046328680fb5c8a9081a
2016-11-16 10:35:27 +00:00
Aaron Schulz
b47ce21cec objectcache: detect default getWithSetCallback() set options
This works by setting a callback to return the cache set
options. The callback will watch DB reads and create a
merged result from said usage.

This handles callers that are missing getCacheSetOptions().

Change-Id: Ia264f011e45e8cf105480955dad7e2c4c2357b73
2016-11-16 04:53:53 +00:00
Aaron Schulz
8d61cf2793 Make LBFactoryTest.php pass for sqlite
Change-Id: I4fe929e82218231f6c8afa64da8c0ccb42d2c362
2016-10-28 22:56:39 -07:00
Timo Tijhof
6191314e58 database: Rename LBFactoryMW to MWLBFactory
It's no longer an LBFactory subclass (since 5d4b009cf), and the MW-prefix
seems more natural for this class.

The class has only existed since for about 2 weeks (since 0e5cd18b7) and
is not used outside MediaWiki core across Wikimedia Git.

Change-Id: I34be982b5d10ad03e062033da9c40b4a01665289
2016-09-30 22:06:02 +01:00
Aaron Schulz
5bbac35ed1 Replace DatabaseBase:: with Database:: and update type hints
Change-Id: I3919b04eb2de4fa0bf8a02239fb5bbf17d347511
2016-09-27 04:20:03 +00:00
Aaron Schulz
c36ef27c53 Add sanity check to LoadBalancer::setDomainPrefix()
Fixed some errors that popped up in CI:
* Also cleanup $domain handling in reuseConnection().
* Fix empty string handling in openForeignConnection() where
  the empty string check against $dbName failed since an empty
  string $domain results in $dbName being null.

Change-Id: Ie78fefa1acb401fe4e8bdc96b75053692aa0a925
2016-09-21 09:04:37 -07:00
Aaron Schulz
d175b391ae Move LBFactorySimple to /libs/rdbms
* Refactored LBFactory a bit to make this possible.
* Move newChronologyProtector() up to LBFactory and
  make a lazy-loading method instead.
* Move appendPreShutdownTimeAsQuery() up to LBFactory.
* Inject the web request values for LBFactory from Setup.php.
* Remove unused laggedSlaveUsed() method.

Change-Id: Ie8a38a6f4d6359680eb6a5be24a34e30b9816479
2016-09-17 23:13:00 +00:00
Aaron Schulz
847b91bf1f Make database classes handle hyphens in $wgDBname
* Add DatabaseDomain class to handle passing domains around.
It also can be cast to and from strings, which are of the same
format as wfWikiId() except with hyphens escaped.
* Make IDatabase::getDomainID() use these IDs so they can be
passed into LoadBalancer::getConnection() and friends without
breaking on sites with a hyphen in the DB name.
* Add more LBFactory unit tests for domains.

Bug: T145840
Change-Id: Icfed62b251af8cef706a899197c3ccdb730ef4d1
2016-09-17 15:29:21 -07:00
Aaron Schulz
0e5cd18b74 Rename LBFactory => LBFactoryMW and make LBFactory in /libs
The former extends the later with MW-specific logic.

Also removed a wf* method call from ChronologyProtector.

Change-Id: I325f59b7467ab9c2137731d1ce69816f5a020f03
2016-09-15 17:14:32 +00:00
Aaron Schulz
aeedfb8526 Remove unused LBFactoryFake class
Change-Id: I88acf72fc32c7e3c9bead81d11c5adfd8dff6151
2016-09-14 22:02:43 -07:00
Timo Tijhof
f6ce15ead3 phpunit: Simplify mock object syntax in includes/db/ tests
* Omit redundant `expects( $this->any() )`.
* Use willReturn() instead of `will( $this->returnValue() )`.

Change-Id: If90ac651748af8a78a720992240e40ba53cec79c
2016-09-15 01:47:18 +00:00
Aaron Schulz
6b8effebb3 Add LBFactory::getChronologyProtectorTouched() method
This lets callers check whether a user recently change a DB and
possibly try harder to reflect certain changes or refresh caches.

Also simplified some logging code a bit.

Change-Id: Ia1168cf0d46cfdee046838ce4c5a6294e4d81760
2016-09-11 20:07:43 +00:00
Aaron Schulz
af6efc3b06 Renamed "slave" internal LB/DB info field to "replica"
Change-Id: I46379013ddbdfdf03dbae0c6071e3dc0d960332d
2016-09-05 12:27:08 -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
Aaron Schulz
9c0b55d926 Make getLagFromPtHeartbeat() always use the LB cluster master entry
Before, it just used the immediate master entry, which could be another
slave. In that case, it may not even exists at all.

Bug: T119648
Change-Id: Iea970b81ad2c9855aafcccf0bb0662fc0b3a8d4d
2015-12-09 22:00:19 -08:00
Aaron Schulz
85c0f85e92 Decouple ChronologyProtector from user sessions
* It now works for users without using sessions.
  Sessions should not be cluttered with things
  unrelated to authentication and tokens.
* Public services doing api.php requests on behalf
  of a users only need to set XFF headers (as normal)
  for position wait logic to trigger. They can opt out
  of ChronologyProtector via a new HTTP header
  "ChronologyProtection: false".
* Requests across subdomains, such as the SUL2 handshake
  for CentralAuth on account creation, now have position
  wait logic applied. This helps avoid anomolies were a
  row just written in the last request may not be seen.
* Use merge() to avoid rolling back master positions if
  the user has multiple tabs open and doing writes at once.
* $_SESSION global state is gone from ChronologyProtector.
* Cleaned up post-send LBFactory::shutdown() logic for
  avoiding master position writes with an explicit flag.
* Use 'replication' debug log group in more places.

Bug: T111264
Change-Id: Ib25d05994d62b25c2f89e67b7f51009c54f4bca8
2015-11-12 23:11:18 +00:00
Aaron Schulz
ba00bd342b Made LBFactorySimple set "master" flags like LBFactoryMulti
* wfGetDB( DB_MASTER )->getLBInfo() now shows the master flag
* A corresponding slave flag was also added
* Added a few badly needed LBFactory/LoadBalancer tests

Change-Id: I9254b12cff63af7d754a3a14c5db44276f58d280
2015-10-01 05:11:14 +00:00
Timo Tijhof
ff6513f28b Remove '@section LICENSE'
This was used in 2 special classes, the logger classes and spread
to a few other random classes.

Afaik this has no meaning. Is for something we don't use, and
goes against the meaning of '@section' in Doxygen, which we do
use.

In Doxygen output, all LICENSE references became links to
ProfilerXhprof (the one Doxygen encoutered first).

Bug: T72328
Change-Id: Icc7c443245c70bc0f549bee7d105eef5691c864d
2014-11-26 02:20:55 +00:00
aude
1959b3eb5a Avoid interacting with LBFactory singleton in tests
Instead test that LBFactory::getLBFactoryClass() does the right thing.

In LBFactory::getLBFactoryClass(), the method now requires a configuration
array as a parameter, and returns the class name as a string.

LBFactory::singleton() now passes in $wgLBFactoryConf into getLBFactoryClass(),
while tests can use test configuration.

Only use of LBFactory::getLBFactoryClass() in core is in LBFactory::singleton().

No extension in gerrit uses getLBFactoryClass() and I can find no use of it
when searching places like Github and Google, so it should be safe to make
such change in LBFactory.

Bug: 59105
Change-Id: I71ae7df16bc5c214b9389125140bca5ce68d274c
2014-01-02 14:27:19 +01:00
Siebrand Mazeland
210edff11b Remove underscore from classes LBFactory_*, LoadBalancer_*, LoadMonitor_*
Part of program to remove underscores from class names. Checked core and
600+ extensions for occurrences. All uses are in core in core are updated
in this patch.

Patches for extensions:
* https://gerrit.wikimedia.org/r/#/c/96463/ CentralAuth
* https://gerrit.wikimedia.org/r/#/c/96460/ SimpleSecurity
* https://gerrit.wikimedia.org/r/#/c/96459/ WikiBase
* https://gerrit.wikimedia.org/r/#/c/96472/ Wikimedia configuration

Antoine added tests to test the back compatibility.

Change-Id: I507ba00a83bca8375a0215f00891b47e3c7afb9f
2013-12-26 16:30:15 -05:00