Commit graph

507 commits

Author SHA1 Message Date
Umherirrender
fe48e1223a cache: Fix various scalar and null types to match documentation
Adding float as type when INF is used as argument

Found by phan strict checks

Change-Id: I7e19cd0d9b09bf685e4e8387c900f303b669ad54
2022-03-14 17:36:04 +00:00
jenkins-bot
6fd4c95f5e Merge "Use updated ObjectFactory namespace" 2022-03-12 00:19:53 +00:00
Alexander Vorwerk
9b09bf3112 Use updated ObjectFactory namespace
Depends-On: I99c5e5664d2401c36a9890f148eba7c25e6e8324
Depends-On: I48ab818b2965da14af15ef370aa83ad9455badd9
Depends-On: I018371e4b77911e56152ca7b2df734afc73f58a5
Change-Id: I04ebdb52102f6191d49a9cc70b1f98308299e72f
2022-03-09 23:04:51 +00:00
jenkins-bot
0200221a93 Merge "Fix various documentation related to null types (part II)" 2022-03-09 22:42:42 +00:00
Umherirrender
e4829c6ea3 SQLBagOStuff: Fix dbdomain argument in getConnectionViaLoadBalancer
getMaintenanceConnectionRef second parameter is the group,
not the domain
Break another line to make the argument order more visible

Follow-Up: 618b61a4c6
Change-Id: Id6dd0c2f8e5aded759fe403f8435ee7251a46b8c
2022-03-09 20:36:34 +00:00
Umherirrender
d7248d63fb Fix various documentation related to null types (part II)
The functions returning null or the class property is set explict null.
Some function should not accept null or return null.

Found by phan strict checks

Change-Id: Ie50f23249282cdb18caa332f562a3945a58d86ff
2022-03-08 23:45:31 +00:00
Umherirrender
9ed1ed185f Fix various documentation related to false
Some function already document "False on failure", but does not document
it on the used type

Found by phan strict checks

Change-Id: I12eb8bbc99179833ee3e42c1a7d1dc1443682ca6
2022-03-03 21:33:31 +01:00
Umherirrender
9efd9ca45e Add explicit casts between scalar types
* Some functions accept only string, cast ints and floats to string
* After preg_matches or explode() casts numbers to int to do maths
* Cast unix timestamps to int to do maths
* Cast return values from timestamp format function to int
* Cast bitwise operator to bool when needed as bool

* php internal functions like floor/round/ceil documented to return
  float, most cases the result is used as int, added casts

Found by phan strict checks

Change-Id: Icb2de32107f43817acc45fe296fb77acf65c1786
2022-03-01 18:19:33 +01:00
daniel
a5277ce87f Avoid references to DefaultSettings.
This replaces references to DefaultSettings with
references to config-schema.yaml where appropriate.

NOTE: this does not yet change Setup.php. DefaultSettings.php
remains intact and is still being used.

NOTE: this does not remove usages in the installer, see I5d8843a1062fbf
for that.

Bug: T300129
Change-Id: Ie6152cf510c3be61bc22167ca6d90dfc28910a45
2022-02-22 19:43:50 +01:00
Aaron Schulz
bc79ce7fb7 objectcache: deprecate BagOStuff incr() and decr() methods
All callers in Wikimedia gerrit repos have since been migrated to
incrWithInit(), which is usually what is desired and is easier to
implement in various backends. Newer memcached versions of the
memcached protocol even support auto-initializing increments
(including an initial TTL) via the 'ma' command. The incr()/decr()
methods currently bloat the interface and subclasses (often with
slow and buggy implementations). These methods are also hard to
implement in a multi-DC store (either extremely slow or racey)
even though callers might assume they handle high concurrency.

Also, force each MediumSpecificBagOStuff subclass to implement
incrWithInit() instead of having some rely on the base method

In mcc.php, add incrWithInit() and simplify parameters, making
it possible to test non-memcached backends.

Change-Id: I53c9c2c839a1e71d5c104913fea0680c30d11108
2022-02-18 11:15:27 +11:00
Aaron Schulz
618b61a4c6 objectcache: add "globalKeyLbDomain" option to use with "globalKeyLB"
Previously, "globalKeyLB" was generally useless for sharing keys since
the LoadBalancer would still use the default domain.

This does not effect configuration using "server"/"servers".

Follow-up to 6a8943d8c5.

Bug: T212129
Change-Id: I5b20c9d3f153650d6e03581fd523cba4961f664f
2022-01-31 19:14:04 +00:00
Siddharth VP
804dcac8a3 Fix typos in comments (S)
Change-Id: Id86769ca81ff65707edde520585aa9ea117123e1
2022-01-09 23:28:53 +05:30
Umherirrender
fe7bd754ee objectcache: Change variable name from master to primary
Change-Id: I3574ea348f32ccd289a0b4158fe93b5cb48ddffa
2021-10-14 19:40:01 +00:00
Umherirrender
2e4ee47c3d Cleanup mixed space/tab line indent
Change-Id: I833052a656b1ce419c0929f6f0514f2a33c2c4cc
2021-09-04 00:52:31 +02:00
Aaron Schulz
7e12163708 objectcache: simplify BagOStuff::ATTR_* flags and set them for backends
* Remove unused ATTR_SYNCWRITES/QOS_SYNCWRITES_* constants
* Remove unused ATTR_LOCALITY/QOS_LOCALITY_* constants

Bug: T279977
Change-Id: I5ada228fbd504f8e94833df8a8414ed8da0bce4b
2021-08-31 11:23:28 -07:00
jenkins-bot
5f83cbffa4 Merge "objectcache: call silenceTransactionProfiler() in SqlBagOStuff::fetchBlobs()" 2021-08-28 23:16:06 +00:00
Aaron Schulz
411878214d objectcache: call silenceTransactionProfiler() in SqlBagOStuff::fetchBlobs()
This avoids any warnings about DB_PRIMARY connections.

Folllows-up 719bfa8977, which handled the writes, but we still
emitted warnings about connections.

Change-Id: I1f82af996ba179890d159e4ca307424b46ff6bfa
2021-08-28 22:57:52 +00:00
Aaron Schulz
6894873abe objectcache: cleanup config injection and method names in SqlBagOStuff
Dependency inject the write batch size into SqlBagOStuff.

Clean up SqlBagOStuff method names and comments.

Renamed getServerIndexByTag() to getShardServerIndexForTag() and
getServerShardIndexes() to getShardServerIndexes(). Since each of these
servers manages one of the shards, it makes sense to call them "shard
servers".

Change-Id: I9af1f64602dabe85288937ab52c08470138f4c91
2021-08-28 22:52:04 +00:00
Aaron Schulz
2947b099db objectcache: make use of new modtoken field in SqlBagOStuff (ii)
Add a multi-primary mode option that supports MySQL DB setups
that use circular replication with STATEMENT formatted binlogs.
The `modtoken` column is only used when multi-primary mode is
explicitly enabled in configuration. The column is used by write
queries to determine the "winning" version of keys, with the goal
of approximating "Last-Write-Wins" eventual consistency.

Writes with different timestamps can be handled by picking the
one with the highest timestamp as the "winner". Writes with the
same timestamp, from different primary DBs, can be handled by
picking the one from the primary DB with the highest server_id.
Writes with the same token timestamp from the same primary DB can
be handled by picking the last write to appear in the binlog.
The delete() operation uses tombstones in multi-primary mode,
since there must be a key version to actually compare with the
versions from other operations.

Also:
* Remove "LOCK IN SHARE MODE" that was made obsolete by the
  CONN_TRX_AUTOCOMMIT flag. For the SQLite transaction case,
  it is serializable anyway.
* Simplified handleWriteError() to match handleReadError()
  and merged them into handleDBError().

Changes from d56a686f83:
* Keep using replace() for set() in non-multi-primary mode.
* Fix old encoding issues when incrementing keys with postgres.

Bug: T274174
Change-Id: I25b1278586f99fdace8f2a081f6f460f734e5d83
2021-08-20 19:23:39 -07:00
Ladsgroup
0bd5cf3910 Revert "objectcache: make use of new modtoken field in SqlBagOStuff"
This reverts commit d56a686f83.

Reason for revert: T288998#7287717

Bug: T288998
Change-Id: Ia05b00a345335fe8bdd6041323c3abfa79ded169
2021-08-17 15:29:32 +00:00
Aaron Schulz
d56a686f83 objectcache: make use of new modtoken field in SqlBagOStuff
Add a multi-primary mode option that supports MySQL DB setups
that use circular replication with STATEMENT formatted binlogs.
The `modtoken` column is only used when multi-primary mode is
explicitly enabled in configuration. The column is used by write
queries to determine the "winning" version of keys, with the goal
of approximating "Last-Write-Wins" eventual consistency.

Writes with different timestamps can be handled by picking the
one with the highest timestamp as the "winner". Writes with the
same timestamp, from different primary DBs, can be handled by
picking the one from the primary DB with the highest server_id.
Writes with the same token timestamp from the same primary DB can
be handled by picking the last write to appear in the binlog.
The delete() operation uses tombstones in multi-primary mode,
since there must be a key version to actually compare with the
versions from other operations.

Also:
* Remove "LOCK IN SHARE MODE" that was made obsolete by the
  CONN_TRX_AUTOCOMMIT flag. For the SQLite transaction case,
  it is serializable anyway.
* Simplified handleWriteError() to match handleReadError()
  and merged them into handleDBError().

Bug: T274174
Change-Id: Icc5eff9a032dd3403b5718058f20e38f8ea84af5
2021-08-05 02:33:00 +01:00
James D. Forrester
1d71fd91d6 ILoadBalancer and IDatabase: Rename getMasterPos to getPrimaryPos
Bug: T282894
Change-Id: I30a600335af735a13a6ad2d3df56a5f17e05bfab
2021-08-02 18:14:41 +00:00
libraryupgrader
5357695270 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0
  The following sniffs now pass and were enabled:
  * Generic.ControlStructures.InlineControlStructure
  * MediaWiki.PHPUnit.AssertCount.NotUsed

npm:
* svgo: 2.3.0 → 2.3.1
  * https://npmjs.com/advisories/1754 (CVE-2021-33587)

Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
2021-07-22 03:36:05 +00:00
Aaron Schulz
dd97395104 objectcache: make BagOStuff::lock/unlock easier to override
Avoid the duplication of the reentrant lock logic in subclasses.

Move "lock already expired" logic from getScopedLock() to unlock()
so that it applies more generally. Warn when unlock() is called on
a key that is not even locked as well.

Also:
* Rename lock() $expiry argument to $exptime for consistency
* Fix return types for serialize()/unserialize()

Bug: T274174
Change-Id: I211536e616cf7f1cc60181c378bbf9b35ffa40a4
2021-07-19 19:40:17 +00:00
James D. Forrester
719cf161f2 More master -> primary documentation and internal var renaming
Bug: T254646
Change-Id: I63cc8895033714bdfbf09aee933a8f0a43b387f3
2021-07-15 11:20:20 +01:00
jenkins-bot
2740bc941e Merge "objectcache: Remove internal 'numServerShards' field in SqlBagOStuff" 2021-07-02 20:22:45 +00:00
jenkins-bot
bb70a93778 Merge "objectcache: Fix SqlBagOStuff progress printing to account for server tags" 2021-07-02 01:10:23 +00:00
jenkins-bot
405ec97225 Merge "objectcache: Refactor deleteServerObjectsExpiringBefore() to combine progress args" 2021-07-02 01:10:17 +00:00
Timo Tijhof
8f1bc8d13a objectcache: Remove internal 'numServerShards' field in SqlBagOStuff
Only used in one plac (getServerShardIndexes), where a simpler solution
can (and arguably should) be taken instead, based on the indexes
of the array rather than assuming/re-creating them on the spot.

Change-Id: I807f53fd4f47237e9192bb1ad004b901ecbaa5d6
2021-07-01 22:05:09 +01:00
Timo Tijhof
91785d1979 objectcache: Fix SqlBagOStuff progress printing to account for server tags
Follows-up 0545fdc3af, which added `--tag` to purgeParserCache.php
to purge only one of the server shards (by its tag).

However, the percentage printing was still based on the total count
instead of on the count of the local $shardIndexes array, thus the
progress reported was artifically slowed down to a low percentage (
e.g. 33.3% if there are three shards), and then it stops, with 100.0%
added to the end by the CLI script:

```
... 0.0%
[…]
... 33.3%
... 100.0%
```

Fix this to only count the servers being iterated.

Bug: T282761
Change-Id: Id87868ceb9b7980442d57551e728d9f0d2784e01
2021-07-01 20:22:32 +01:00
Timo Tijhof
f0011cf605 objectcache: Refactor deleteServerObjectsExpiringBefore() to combine progress args
This is preparation for Id87868ceb9b7, as otherwise this internal
signature is getting increasingly messy and awkward to use for the
occasionallyGarbageCollect() callsite where would effectively have
to pass non-sensical values that are never used just to satisfy the
contract.

Change-Id: Ic8d925110a0826811c7e8d3d7bc5077d03f38085
2021-07-01 20:22:03 +01:00
DannyS712
4f9970f30b Fix a bunch of random typos
* yeild -> yield
* paramter -> parameter
* seperator -> separator
* neccesary -> necessary
* inital -> initial
* intial -> initial
* repsonse -> response
* retreived -> retrieved

Bug: T201491
Change-Id: I461941b027590997448f3bdd8a137a48bb338beb
2021-06-29 11:32:04 +00:00
Timo Tijhof
0545fdc3af purgeParserCache.php: Implement --tag for purging one server only
Large wiki farms may have to purge servers concurrently (instead of
one at a time) in order to keep up with new writes and delete expired
rows faster than new rows are written.

The parameter for this uses server tags for three reasons:

* Maintenance risk and complexity.
  This requires the least information about MW configuration to be
  hardcoded in the scheduled maintenance cronjob (compared to: server
  indexes which are a runtime concept, or specific hostnames/IP/
  tableprefixes which may change and should not require
  coordinating changes elsewhere).

* Operational convenience.
  By using server tags, the parameters don't have to vary between
  data centers.

* Code complexity.
  The current code for obtaining connections is based on server indexes,
  which are easy to mapped at runtime from server tags. Other ways
  of identifying shard like hostnames are either an awkward fit (as
  they don't uniquely identify a shard per-se, with multiple instances
  on the same hardware at WMF), or require SqlBagOStuff to store and
  maintain more information about connections than it currently has
  readily available.

Bug: T282761
Change-Id: I618bc1e8ca3008a4dd54778ac24aa5948f27c52e
2021-06-24 18:01:27 +01:00
Timo Tijhof
fef7e282eb SqlBagOStuff: Fix incorrect numServerShards for default CACHE_DB
As part of working on I, I noticed that, despite there being only
one shard on my localhost (getServerShardIndexes: ["local"]), only one
table index ([0]), and no data in them at all, purgeParserCache.php was
still, incorrectly, reporting the (only) progress callback from SqlBag
as being at 50%, with the final 100% only being printed due to the
CLI script forcing it so at the end - if not already done by SqlBag.

The following diff helped me understand this:

```
@@ -813,6 +814,10 @@ class SqlBagOStuff extends MediumSpecificBagOStuff {
+					echo json_encode( [
+						"tablesDoneRatio" => $tablesDoneRatio,
+						"numServerShards" => $this->numServerShards,
+					], JSON_PRETTY_PRINT );
 					call_user_func( $progressCallback, $overallRatio * 100 );
```

This should have printed 1 and 1, but printed 1 and 2. Thus the reason
it was only able to go upto 50% was because it wrongly thought there
was a second shard.

Change-Id: I9500a40d5c2a18750f043e33d825d748b79ae202
2021-06-23 16:41:39 +01:00
Aaron Schulz
12923c1cd5 objectcache: add last-modified token field to objectcache table
Also added token and flags fields. The token field can
be used as a tie-breaker for modtime and also for faster
cas() operations. The flags field makes serialization and
compression format changes easier in the future.

Bug: T274174
Change-Id: I45731a877b21835652993c2d285165a76eeae3e9
2021-05-18 20:06:37 -07:00
Gergő Tisza
8925ba9c50 Add TransactionProfiler::silenceForScope()
Add a helper method for the common use case of temporarily silencing
transaction profiler warnings.

Change-Id: I40de4daf8756da693de969e5526b471b624b2cee
2021-05-16 18:19:53 +02:00
Timo Tijhof
e556a7ea99 purgeParserCache.php: Remove carriage return printer, minor cleanup
* There was a carriage return, as part of a self-overwriting progress
  bar. While nice for humans running the script by hand, this made
  the script difficult to understand in WMF production where the logs
  go to syslog/journalctl, which doesn't like \r and thus showed only
  `[2KB blob]` instead of the actual output. This can bypassed with
  `journalctl -u … --all`, but that still leaves one with a sea of
  misaligned progress bars, concatenated as one long "line".

  It seems most of our maintenance scripts nowadays just keep printing
  lines to notify of progress made, so change the script to that,
  by just printing a boring "... % done\n" line (at most) every 0.1%.

* Change hardcoded batch size of 100 to use $wgUpdateRowsPerQuery.
  This is generally a no-op as this configuration defaults to 100 in
  DefaultSettings.php, and is not overridden in WMF production.

* Add a "--dry-run" option to allow for last-minute verification of
  the age and date calculation which is rather non-trivial given that
  we don't index creation time and assume $wgParserCacheExpireTime
  is constant and unchanged, which in practice, when this script is
  considered for running, tends not to be the case, making it hard to
  be sure exactly what it will do.

Minor stuff:

* Make the ORDER BY clause explicitly use ascending order.

* Try to retroactively document why we use a --msleep parameter
  instead of waiting for replication.

* Revert some of the variable name changes of I723e6377c26750ff9
  which imho made the code harder to understand.

* Flip order of $overallRatio additions to match the order of
  $tablesDoneRatio (e.g. high level + current thing).

* Remove use of Language->timeanddate() in favour of native
  date formatting, mainly to include seconds and timezone,
  but also because its simpler not to bring in all of Language
  and LocalisationCache into the script.

* Pass unix time directly to SqlBagOStuff::deleteObjectsExpiringBefore,
  as other callers do, instead of TS_MW-formatting first. There is
  also additional casting to TS_UNIX within the method.

Before:

> Deleting objects expiring before 21:43, 7 May 2021
> [**************************************************] 100.00%
> Done

After:

> Deleting objects expiring before Fri, 07 May 2021 21:43:52 GMT
> ... 50.0% done
> ... 100.0% done
> Done

Bug: T280605
Bug: T282761
Change-Id: I563886be0b3aeb187c274c0de4549374e0ff18f0
2021-05-13 02:42:29 +00:00
James D. Forrester
df5eb22f83 Replace uses of DB_MASTER with DB_PRIMARY
Just an auto-replace from codesniffer for now.

Change-Id: I5240dc9ac5929d291b0ef1c743ea2bfd3f428266
2021-04-29 09:24:31 -07:00
Aaron Schulz
5115449259 objectcache: reorganize method order in SqlBagOStuff
Make public methods and methods defining abstract parent methods first.
This also matches the order of BagOStuff.

Change-Id: If609f5c88fefa9afaa1027555cb42eec7361e223
2021-04-26 17:12:23 -07:00
Aaron Schulz
fc3d7ffd04 objectcache: fix TTL_INDEFINITE placeholder DB timestamp
Always use "99991231235959" instead of using either 0x7fffffff
or (1 << 62), depending on the current timestamp. The bit shifted
case always returned false, and thus did not work.

Refactor DB timestamp logic into encodeDbExpiry()/decodeDbExpiry().

Change-Id: Ic78bca1fa0234468c30e17ec603565636348b0de
2021-04-20 20:01:49 +00:00
Aaron Schulz
0f930f6f8f objectcache: switch static vars to constants in SqlBagOStuff
Also, make serialize method parameter names consistent with
the base class.

Change-Id: I938d84458adbdc3a4ecf979b01caf8b17aa790ea
2021-04-19 18:42:37 +00:00
Aaron Schulz
af916aad81 objectcache: Switch SqlBlobStore to using ATTR_DURABILITY
ATTR_EMULATION will soon be deprecated.

Bug: T279977
Change-Id: I2e6d214f0af2a037b5bded3801f848109c2b6dde
2021-04-13 01:36:15 +00:00
jenkins-bot
0aa2c00fde Merge "objectcache: remove ObjectCache::detectLocalServerCache() method" 2021-03-08 05:57:14 +00:00
Aaron Schulz
bd7cf4dce9 Add $wgChronologyProtectorStash and improve $wgMainStash comments
Remove WRITE_SYNC flag from ChronologyProtector since the current
plan is to simply use a datacenter-local storage cluster.

Move the touched timestamps into the same stash key that holds the
replication positions. Update the ChronologyProtector::getTouched()
comments.

Also:
* Use $wgMainCacheType as a $wgChronologyProtectorStash fallback
  since the main stash will be 'db-replicated' for most sites.
* Remove HashBagOStuff default for position store since that can
  result in timeouts waiting on a write position index to appear
  since the data does not actually persist accress requests.
* Rename ChronologyProtector::saveSessionReplicationPosition()
  since it does not actually save replication positions to storage.
* Make ChronologyProtector::getTouched() check the "enabled" field.
* Allow mocking the current time in ChronologyProtector.
* Mark some internal methods with @internal.
* Migrate various comments from $wgMainStash to BagOStuff.
* Update some other ObjectCache related comments.

Bug: T254634
Change-Id: I0456f5d40a558122a1b50baf4ab400c5cf0b623d
2021-03-01 20:34:34 +00:00
Aaron Schulz
05a1a44f86 objectcache: remove ObjectCache::detectLocalServerCache() method
Change-Id: I322e4e8d3117d33a5456c6c4161014c5f3589dd1
2021-02-25 16:29:47 -08:00
Aaron Schulz
8dd4bd0fe0 objectcache: make SqlBagOStuff use getSerialized()
This makes use of any values prepared in setNewPreparedValues()

Change-Id: I2c9ec7d1f9183e060cda81de009e4bdfc889faf6
2021-02-19 02:13:45 +00:00
Aaron Schulz
2757a31674 objectcache: make MediumSpecificBagOStuff::updateOpStats more robust
Make the method accept either an integer-indexed list of keys or a map
of keys to the send/receive payload size information tuple.

Make sure that no BagOStuff subclasses are passing in $keys directly
from the call to the public BagOStuff methods; these allow keys in the
form of a list or a map of arbitrary strings to keys.

Change-Id: I9687d25a4dd1c7b4b304f9fd543cc0a26a595962
2021-02-18 04:20:24 +00:00
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
Aaron Schulz
57325ba3bd objectcache: add statsd key metrics to BagOStuff classes
Update SQL, REST, and redis subclasses to emit call count and
payload size metrics for cache key operations. These metrics
are bucketed by cache key collection (similar to WANCache).

Bug: T235705
Change-Id: Icaa3fa1ae9c8b0f664c26ce70b7e1c4fc5f92767
2021-01-25 14:36:29 -08:00
Ammar Abdulhamid
20d1849b53 Migrate objectcache to abstract schema
For Postgres:
 - Drop Unique constraint on `keyname` and make primary key
 - Change type of `value` from BYTEA to TEXT and drop its default
 - Make `value` nullable to sync with MySQL/SQLite

MySQL:
 - Change exptime from DATETIME to TIMESTAMP

MySQL/SQLite:
 - Make 'exptime' not nullable

Bug: T230428
Bug: T164898
Change-Id: Iab9de8a1bb2cb01b6e3e69e66f1bbe089d53d0a7
2021-01-20 13:50:28 +01:00