wbc_entity_usage contains invalid entity ids (numeric parts to large)
Closed, ResolvedPublic

Description

Errors in jobs:

2016-10-06 14:41:01 [244478ea5b01dbb5fb34b0a9] mw1169 wikidatawiki 1.28.0-wmf.20 exception ERROR: [244478ea5b01dbb5fb34b0a9] /rpc/RunJobs.php?wiki=wikidatawiki&type=refreshLinks&maxtime=30&maxmem=300M   Wikibase\DataModel\Entity\EntityIdParsingException from line 54 of /srv/mediawiki/php-1.28.0-wmf.20/extensions/Wikidata/vendor/wikibase/data-model/src/Entity/DispatchingEntityIdParser.php: The serialization "Q10000000000" is not recognized by the configured id builders {"exception_id":"244478ea5b01dbb5fb34b0a9"}
[Exception Wikibase\DataModel\Entity\EntityIdParsingException] (/srv/mediawiki/php-1.28.0-wmf.20/extensions/Wikidata/vendor/wikibase/data-model/src/Entity/DispatchingEntityIdParser.php:54) The serialization "Q10000000000" is not recognized by the configured id builders
  #0 /srv/mediawiki/php-1.28.0-wmf.20/extensions/Wikidata/extensions/Wikibase/client/includes/Usage/Sql/EntityUsageTable.php(202): Wikibase\DataModel\Entity\DispatchingEntityIdParser->parse(string)
  #1 /srv/mediawiki/php-1.28.0-wmf.20/extensions/Wikidata/extensions/Wikibase/client/includes/Usage/Sql/EntityUsageTable.php(179): Wikibase\Client\Usage\Sql\EntityUsageTable->convertRowsToUsages(ResultWrapper)
  #2 /srv/mediawiki/php-1.28.0-wmf.20/extensions/Wikidata/extensions/Wikibase/client/includes/Usage/Sql/SqlUsageTracker.php(179): Wikibase\Client\Usage\Sql\EntityUsageTable->queryUsages(integer)
  #3 /srv/mediawiki/php-1.28.0-wmf.20/extensions/Wikidata/extensions/Wikibase/client/includes/Store/UsageUpdater.php(107): Wikibase\Client\Usage\Sql\SqlUsageTracker->replaceUsedEntities(integer, array)
  #4 /srv/mediawiki/php-1.28.0-wmf.20/extensions/Wikidata/extensions/Wikibase/client/includes/Hooks/DataUpdateHookHandlers.php(139): Wikibase\Client\Store\UsageUpdater->replaceUsagesForPage(integer, array)
  #5 /srv/mediawiki/php-1.28.0-wmf.20/extensions/Wikidata/extensions/Wikibase/client/includes/Hooks/DataUpdateHookHandlers.php(63): Wikibase\Client\Hooks\DataUpdateHookHandlers->doLinksUpdateComplete(LinksUpdate)
  #6 /srv/mediawiki/php-1.28.0-wmf.20/includes/Hooks.php(195): Wikibase\Client\Hooks\DataUpdateHookHandlers::onLinksUpdateComplete(LinksUpdate)
  #7 /srv/mediawiki/php-1.28.0-wmf.20/includes/deferred/LinksUpdate.php(179): Hooks::run(string, array)
  #8 /srv/mediawiki/php-1.28.0-wmf.20/includes/libs/rdbms/database/Database.php(2593): Closure$LinksUpdate::doUpdate(integer)
  #9 /srv/mediawiki/php-1.28.0-wmf.20/includes/libs/rdbms/loadbalancer/LoadBalancer.php(1133): Database->runOnTransactionIdleCallbacks(integer)
  #10 /srv/mediawiki/php-1.28.0-wmf.20/includes/libs/rdbms/loadbalancer/LoadBalancer.php(1357): Closure$LoadBalancer::runMasterPostTrxCallbacks(DatabaseMysqli)
  #11 /srv/mediawiki/php-1.28.0-wmf.20/includes/libs/rdbms/loadbalancer/LoadBalancer.php(1142): LoadBalancer->forEachOpenMasterConnection(Closure$LoadBalancer::runMasterPostTrxCallbacks;929355047)
  #12 /srv/mediawiki/php-1.28.0-wmf.20/includes/libs/rdbms/lbfactory/LBFactory.php(312): LoadBalancer->runMasterPostTrxCallbacks(integer)
  #13 /srv/mediawiki/php-1.28.0-wmf.20/includes/libs/rdbms/lbfactory/LBFactoryMulti.php(407): Closure$LBFactory::commitMasterChanges(LoadBalancer)
  #14 /srv/mediawiki/php-1.28.0-wmf.20/includes/libs/rdbms/lbfactory/LBFactory.php(314): LBFactoryMulti->forEachLB(Closure$LBFactory::commitMasterChanges;1602246427)
  #15 /srv/mediawiki/php-1.28.0-wmf.20/includes/jobqueue/JobRunner.php(526): LBFactory->commitMasterChanges(string)
  #16 /srv/mediawiki/php-1.28.0-wmf.20/includes/jobqueue/JobRunner.php(276): JobRunner->commitMasterChanges(LBFactoryMulti, RefreshLinksJob, string)
  #17 /srv/mediawiki/php-1.28.0-wmf.20/includes/jobqueue/JobRunner.php(184): JobRunner->executeJob(RefreshLinksJob, LBFactoryMulti, BufferingStatsdDataFactory, integer)
  #18 /srv/mediawiki/rpc/RunJobs.php(47): JobRunner->run(array)
  #19 {main}

The problem here is that the wbc_entity_usage table contains entity ids which are (no longer) valid. These can be identified by querying SELECT * FROM wbc_entity_usage WHERE LENGTH(eu_entity_id) > 10 AND REPLACE(REPLACE(eu_entity_id, 'Q', ''), 'P', '') > 2147483647;. EntityUsageTable is not able to purge these given it can't even construct entity id objects for them.

I suggest deleting these row manually (by primary key, given the above query is a little expensive). We could also look at making EntityUsageTable just purge rows it can't turn into entity ids.

hoo created this task.Oct 7 2016, 9:35 AM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptOct 7 2016, 9:35 AM

Mentioned in SAL (#wikimedia-operations) [2017-01-10T23:09:07Z] <hoo> Ran DELETE FROM wbc_entity_usage WHERE eu_row_id IN(1714177, 1714178, 1714179, 1714180, 1714181, 1714182, 1714183, 1714184, 3914375); on s5 master (T147630)

hoo closed this task as Resolved.Jan 10 2017, 11:09 PM
hoo claimed this task.

Query:

mysql:wikiadmin@db1045 [wikidatawiki]> SELECT * FROM wbc_entity_usage WHERE LENGTH(eu_entity_id) > 10 AND REPLACE(REPLACE(eu_entity_id, 'Q', ''), 'P', '') > 2147483647;
+-----------+--------------+-----------+------------+----------------+
| eu_row_id | eu_entity_id | eu_aspect | eu_page_id | eu_touched     |
+-----------+--------------+-----------+------------+----------------+
|   1714177 | Q3000000000  | X         |   18497544 | 20160409212853 |
|   1714178 | Q4000000000  | X         |   18497544 | 20160409212853 |
|   1714179 | Q5000000000  | X         |   18497544 | 20160409212853 |
|   1714180 | Q6000000000  | X         |   18497544 | 20160409212853 |
|   1714181 | Q7000000000  | X         |   18497544 | 20160409212853 |
|   1714182 | Q8000000000  | X         |   18497544 | 20160409212853 |
|   1714183 | Q9000000000  | X         |   18497544 | 20160409212853 |
|   1714184 | Q10000000000 | X         |   18497544 | 20160409212853 |
|   3914375 | Q4294967294  | X         |   23223110 | 20160412202754 |
+-----------+--------------+-----------+------------+----------------+
9 rows in set (12.00 sec)

Deleted on s5 master:

mysql:wikiadmin@db1049 [wikidatawiki]> BEGIN;
Query OK, 0 rows affected (0.00 sec)

mysql:wikiadmin@db1049 [wikidatawiki]> DELETE FROM wbc_entity_usage WHERE eu_row_id IN(1714177, 1714178, 1714179, 1714180, 1714181, 1714182, 1714183, 1714184, 3914375);
Query OK, 9 rows affected (0.00 sec)

mysql:wikiadmin@db1049 [wikidatawiki]> COMMIT;
Query OK, 0 rows affected (0.01 sec)

Query afterwards:

mysql:wikiadmin@db1045 [wikidatawiki]> SELECT * FROM wbc_entity_usage WHERE LENGTH(eu_entity_id) > 10 AND REPLACE(REPLACE(eu_entity_id, 'Q', ''), 'P', '') > 2147483647;
Empty set (0.87 sec)