Page MenuHomePhabricator

[LIB] [TECH] Wikibase reads too many wb_property_info rows at once (expectation readQueryRows <= 10000 not met)
Open, Needs TriagePublicPRODUCTION ERROR

Description

Wikibase’s CachingPropertyInfoLookup loads and caches the whole wb_property_info table at once (via PropertyInfo::getAllPropertyInfo()). Since there are now more than 10k properties on Wikidata, this causes a log warning:

Error
normalized_message
Expectation (readQueryRows <= 10000) by ApiMain::setRequestExpectations not met (actual: {actualSeconds}) in trx #{trxId}:
{query}
exception.trace
from /srv/mediawiki/php-1.42.0-wmf.1/includes/libs/rdbms/TransactionProfiler.php(525)
#0 /srv/mediawiki/php-1.42.0-wmf.1/includes/libs/rdbms/TransactionProfiler.php(322): Wikimedia\Rdbms\TransactionProfiler->reportExpectationViolated(string, Wikimedia\Rdbms\GeneralizedSql, integer, string, string)
#1 /srv/mediawiki/php-1.42.0-wmf.1/includes/libs/rdbms/database/TransactionManager.php(615): Wikimedia\Rdbms\TransactionProfiler->recordQueryCompletion(Wikimedia\Rdbms\GeneralizedSql, double, boolean, integer, string, string)
#2 /srv/mediawiki/php-1.42.0-wmf.1/includes/libs/rdbms/database/Database.php(859): Wikimedia\Rdbms\TransactionManager->recordQueryCompletion(Wikimedia\Rdbms\GeneralizedSql, double, boolean, integer, string)
#3 /srv/mediawiki/php-1.42.0-wmf.1/includes/libs/rdbms/database/Database.php(749): Wikimedia\Rdbms\Database->attemptQuery(Wikimedia\Rdbms\Query, string, boolean)
#4 /srv/mediawiki/php-1.42.0-wmf.1/includes/libs/rdbms/database/Database.php(670): Wikimedia\Rdbms\Database->executeQuery(Wikimedia\Rdbms\Query, string, integer)
#5 /srv/mediawiki/php-1.42.0-wmf.1/includes/libs/rdbms/database/Database.php(1383): Wikimedia\Rdbms\Database->query(Wikimedia\Rdbms\Query, string)
#6 /srv/mediawiki/php-1.42.0-wmf.1/includes/libs/rdbms/database/DBConnRef.php(119): Wikimedia\Rdbms\Database->select(array, array, array, string, array, array)
#7 /srv/mediawiki/php-1.42.0-wmf.1/includes/libs/rdbms/database/DBConnRef.php(351): Wikimedia\Rdbms\DBConnRef->__call(string, array)
#8 /srv/mediawiki/php-1.42.0-wmf.1/includes/libs/rdbms/querybuilder/SelectQueryBuilder.php(708): Wikimedia\Rdbms\DBConnRef->select(array, array, array, string, array, array)
#9 /srv/mediawiki/php-1.42.0-wmf.1/extensions/Wikibase/lib/includes/Store/Sql/PropertyInfoTable.php(178): Wikimedia\Rdbms\SelectQueryBuilder->fetchResultSet()
#10 /srv/mediawiki/php-1.42.0-wmf.1/extensions/Wikibase/lib/includes/Store/CachingPropertyInfoLookup.php(172): Wikibase\Lib\Store\Sql\PropertyInfoTable->getAllPropertyInfo()
#11 /srv/mediawiki/php-1.42.0-wmf.1/includes/libs/objectcache/wancache/WANObjectCache.php(1726): Wikibase\Lib\Store\CachingPropertyInfoLookup->Wikibase\Lib\Store\{closure}(boolean, integer, array, NULL, array)
#12 /srv/mediawiki/php-1.42.0-wmf.1/includes/libs/objectcache/wancache/WANObjectCache.php(1556): WANObjectCache->fetchOrRegenerate(string, integer, Closure, array, array)
#13 /srv/mediawiki/php-1.42.0-wmf.1/extensions/Wikibase/lib/includes/Store/CachingPropertyInfoLookup.php(173): WANObjectCache->getWithSetCallback(string, integer, Closure)
#14 /srv/mediawiki/php-1.42.0-wmf.1/extensions/Wikibase/lib/includes/Store/CachingPropertyInfoLookup.php(172): Wikibase\Lib\Store\CachingPropertyInfoLookup->getAllPropertyInfo()
#15 /srv/mediawiki/php-1.42.0-wmf.1/includes/libs/objectcache/BagOStuff.php(206): Wikibase\Lib\Store\CachingPropertyInfoLookup->Wikibase\Lib\Store\{closure}(integer)
#16 /srv/mediawiki/php-1.42.0-wmf.1/extensions/Wikibase/lib/includes/Store/CachingPropertyInfoLookup.php(173): BagOStuff->getWithSetCallback(string, integer, Closure)
#17 /srv/mediawiki/php-1.42.0-wmf.1/extensions/Wikibase/lib/includes/Store/CachingPropertyInfoLookup.php(124): Wikibase\Lib\Store\CachingPropertyInfoLookup->getAllPropertyInfo()
#18 /srv/mediawiki/php-1.42.0-wmf.1/includes/libs/objectcache/BagOStuff.php(206): Wikibase\Lib\Store\CachingPropertyInfoLookup->Wikibase\Lib\Store\{closure}(integer)
#19 /srv/mediawiki/php-1.42.0-wmf.1/extensions/Wikibase/lib/includes/Store/CachingPropertyInfoLookup.php(129): BagOStuff->getWithSetCallback(string, integer, Closure)
#20 /srv/mediawiki/php-1.42.0-wmf.1/extensions/Wikibase/lib/includes/Store/CachingPropertyInfoLookup.php(109): Wikibase\Lib\Store\CachingPropertyInfoLookup->getPropertyInfoFromCache(Wikibase\DataModel\Entity\NumericPropertyId)
#21 /srv/mediawiki/php-1.42.0-wmf.1/extensions/Wikibase/lib/includes/PropertyInfoDataTypeLookup.php(58): Wikibase\Lib\Store\CachingPropertyInfoLookup->getPropertyInfo(Wikibase\DataModel\Entity\NumericPropertyId)
#22 /srv/mediawiki/php-1.42.0-wmf.1/extensions/Wikibase/lib/includes/SourceDispatchingPropertyDataTypeLookup.php(47): Wikibase\Lib\PropertyInfoDataTypeLookup->getDataTypeIdForProperty(Wikibase\DataModel\Entity\NumericPropertyId)
#23 /srv/mediawiki/php-1.42.0-wmf.1/extensions/Wikibase/lib/includes/Serialization/CallbackFactory.php(82): Wikibase\Lib\SourceDispatchingPropertyDataTypeLookup->getDataTypeIdForProperty(Wikibase\DataModel\Entity\NumericPropertyId)
#24 /srv/mediawiki/php-1.42.0-wmf.1/extensions/Wikibase/lib/includes/Serialization/SerializationModifier.php(70): Wikibase\Lib\Serialization\CallbackFactory->Wikibase\Lib\Serialization\{closure}(array)
#25 /srv/mediawiki/php-1.42.0-wmf.1/extensions/Wikibase/lib/includes/Serialization/SerializationModifier.php(63): Wikibase\Lib\Serialization\SerializationModifier->modifyUsingUnflattenedCallbacks(array, array)
#26 /srv/mediawiki/php-1.42.0-wmf.1/extensions/Wikibase/lib/includes/Serialization/SerializationModifier.php(58): Wikibase\Lib\Serialization\SerializationModifier->modifyUsingUnflattenedCallbacks(array, array)
#27 /srv/mediawiki/php-1.42.0-wmf.1/extensions/Wikibase/lib/includes/Serialization/SerializationModifier.php(58): Wikibase\Lib\Serialization\SerializationModifier->modifyUsingUnflattenedCallbacks(array, array)
#28 /srv/mediawiki/php-1.42.0-wmf.1/extensions/Wikibase/lib/includes/Serialization/SerializationModifier.php(33): Wikibase\Lib\Serialization\SerializationModifier->modifyUsingUnflattenedCallbacks(array, array)
#29 /srv/mediawiki/php-1.42.0-wmf.1/extensions/Wikibase/repo/includes/Api/ResultBuilder.php(921): Wikibase\Lib\Serialization\SerializationModifier->modifyUsingCallbacks(array, array)
#30 /srv/mediawiki/php-1.42.0-wmf.1/extensions/Wikibase/repo/includes/Api/ResultBuilder.php(854): Wikibase\Repo\Api\ResultBuilder->getArrayWithAlteredClaims(array, string)
#31 /srv/mediawiki/php-1.42.0-wmf.1/extensions/Wikibase/repo/includes/Api/GetClaims.php(136): Wikibase\Repo\Api\ResultBuilder->addStatements(Wikibase\DataModel\Statement\StatementList, NULL, array)
#32 /srv/mediawiki/php-1.42.0-wmf.1/includes/api/ApiMain.php(1931): Wikibase\Repo\Api\GetClaims->execute()
#33 /srv/mediawiki/php-1.42.0-wmf.1/includes/api/ApiMain.php(908): ApiMain->executeAction()
#34 /srv/mediawiki/php-1.42.0-wmf.1/includes/api/ApiMain.php(879): ApiMain->executeActionWithErrorHandling()
#35 /srv/mediawiki/php-1.42.0-wmf.1/api.php(95): ApiMain->execute()
#36 /srv/mediawiki/php-1.42.0-wmf.1/api.php(48): wfApiMain()
#37 /srv/mediawiki/w/api.php(3): require(string)
#38 {main}

Presumably, the problem is much worse on Test Wikidata, which has almost 90k properties. We probably need to rethink this caching.

Details

Request URL
https://www.wikidata.org/w/api.php?action=wbgetclaims&entity=*&errorformat=*&format=*&formatversion=*&property=*&props=*&uselang=*

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Some open questions I have:

  • If we decide that we still want to cache the whole data at once: would it be better to break the query into batches, so we get the same amount of data but spread over several queries? Or should we in that case rather seek to disable the warning and keep the one query with its big result set? (Probably a question for the DBAs.)
  • At what point (if at all) are we going to hit a limit when we store the whole data in the cache under a single key? (In the database, the objectcache.value is a mediumblob, i.e. 2^24-1 bytes; I have no idea about memcached.)
ItamarWMDE renamed this task from Wikibase reads too many wb_property_info rows at once (expectation readQueryRows <= 10000 not met) to [WikibaseLib] [TECH] Wikibase reads too many wb_property_info rows at once (expectation readQueryRows <= 10000 not met).Oct 24 2023, 1:33 PM

Presumably, the problem is much worse on Test Wikidata, which has almost 90k properties.

Indeed, the message is

Expectation (readQueryRows <= 10000) by ApiMain::setRequestExpectations not met (actual: 11319)

on normal wikis but

Expectation (readQueryRows <= 10000) by MediaWiki::restInPeace not met (actual: 89921)

on test wikis. (Emphasis added; disregard the different “set by” part.)

Task review notes:

  • Tagging Wikibase Reuse Team here, as this is a symptom apparent in Wikidata, but it will affect other Wikibases.
  • We are prioritizing this with the assumption that if and when we pick this up, we will try to collaborate with the Wikibase Product Platform Team on a solution.

Task Prio Notes:

  • Affects end users / production
  • Might affect monitoring
  • Does not affect development efforts
  • Does not affect onboarding efforts
  • Affects additional stakeholders (Logspam)
ItamarWMDE renamed this task from [WikibaseLib] [TECH] Wikibase reads too many wb_property_info rows at once (expectation readQueryRows <= 10000 not met) to [LIB] [TECH] Wikibase reads too many wb_property_info rows at once (expectation readQueryRows <= 10000 not met).Nov 8 2023, 10:54 AM

I also see Expectation (readQueryRows <= 10000) by MediaWiki\Actions\ActionEntryPoint::execute not met in the logs, with the trigger being the WikibaseMediaInfo BeforePageDisplay hook handler.

Some open questions I have:

  • If we decide that we still want to cache the whole data at once: would it be better to break the query into batches, so we get the same amount of data but spread over several queries? Or should we in that case rather seek to disable the warning and keep the one query with its big result set? (Probably a question for the DBAs.)

Answered by @Ladsgroup in IRC:

we could do two/three queries in a loop. That's fine from DB point of view, we reuse connections.

(That still leaves open the question if we want to cache the whole data at once at all, but at least this particular point is clarified now.)

We could also have multiple cache for thousands, so P1-P1000 will be one key and so on and then lazy load them. That way, let's say P10000-P11000 won't be used much and then it won't be loaded either.