Page MenuHomePhabricator

Database updater fails
Closed, ResolvedPublic

Description

Master is currently broken, because it needs a schema change, but applying the schema change doesn't work:

Adding ug_expiry field to table user_groups ...
Fatal error: Uncaught exception 'DBQueryError' with message 'A database query error has occurred. Did you forget to run your application's database schema updater after upgrading? 
Query: ALTER TABLE `bw_user_groups`
 DROP INDEX ug_user_group,
 ADD PRIMARY KEY (ug_user, ug_group),
 ADD COLUMN ug_expiry varbinary(14) NULL default NULL,
 ADD INDEX ug_expiry (ug_expiry)

Function: Database::sourceFile( /srv/mediawiki/workdir/maintenance/archives/patch-user_groups-ug_expiry.sql )
Error: 1091 Can't DROP 'ug_user_group'; check that column/key exists (127.0.0.1:3306)
' in /srv/mediawiki/workdir/includes/libs/rdbms/database/Database.php:1055
Stack trace:
#0 /srv/mediawiki/workdir/includes/libs/rdbms/database/Database.php(913): Database->reportQueryError()
#1 /srv/mediawiki/workdir/includes/libs/rdbms/database/Database.php(3121): Database->query()
#2 /srv/mediawiki/workdir/includes/libs/rdbms/database/Database.php(3070): Database->sourceStream()
#3 /srv/mediawiki/workdir/includes/installer/DatabaseUpdater.php(666): Database->sourceFile()
#4 /srv/mediawiki/workdir/includes/installer/DatabaseUpdater.php(734): DatabaseUpdater->applyPatch()
#5 /srv/mediawiki/workdir/includes/installer/DatabaseUpdater.php(465): DatabaseUpdater->addField()
#6 /srv/mediawiki/workdir/includes/installer/DatabaseUpdater.php(429): DatabaseUpdater->runUpdates()
#7 /srv/mediawiki/workdir/maintenance/update.php(172): DatabaseUpdater->doUpdates()
#8 /srv/mediawiki/workdir/maintenance/doMaintenance.php(119): UpdateMediaWiki->execute()
#9 /srv/mediawiki/workdir/maintenance/update.php(217): include()
#10 {main}

Related Objects

View Standalone Graph
This task is connected to more than 200 other tasks. Only direct parents and subtasks are shown here. Use View Standalone Graph to show more of the graph.
StatusAssignedTask
OpenNone
ResolvedNikerabbit

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptFeb 1 2017, 9:21 AM
Nikerabbit triaged this task as Unbreak Now! priority.Feb 1 2017, 9:21 AM
Restricted Application added subscribers: Jay8g, TerraCodes. · View Herald TranscriptFeb 1 2017, 9:21 AM
TTO added a comment.Feb 1 2017, 9:27 AM

The ug_user_group index was in MediaWiki tables.sql from 2008 until recently: https://phabricator.wikimedia.org/source/mediawiki/browse/REL1_28/maintenance/tables.sql;bd2f326a46ebdf9fcdbc21066e44a5969bb316f6$166

Unfortuantely MySQL doesn't have DROP INDEX IF EXISTS, which would be really nice to prevent this sort of issue.

I'm not so sure that this is UBN! - is this affecting anyone else?

I am sure I am not the only one who has installed MediaWiki before 2008 and still running. If it breaks a production size, I consider it UBN!.

It wouldn't be the first time there hasn't been proper updates, the last one I reported resulted in a data loss for truncating ipv6 addresses.

TTO added a comment.Feb 1 2017, 9:51 AM

I can't find a patch in maintenance/archives to add this index. I'm not sure how MW schema updates were done ten years ago - if they were done manually, I guess some people might have missed this particular update, or skipped over it if they thought it was unnecessary.

Looks like we might need some custom logic in MysqlUpdater...

Reedy added a subscriber: Reedy.Feb 1 2017, 9:51 AM

I guess twn didn't have that index for some reason (lack of addition previously as no updater changed?)

Easiest fix...

https://github.com/wikimedia/mediawiki/blob/master/includes/installer/MysqlUpdater.php#L297

Split that line and the DB patch into two db patches? The second, with a dropIndex, should do an indexExists check... And then only drop it if it needs to be

Slightly less performant maybe, but should fix this sort of issue

Change 335414 had a related patch set uploaded (by TTO):
Don't try to drop ug_user_group index if it doesn't exist

https://gerrit.wikimedia.org/r/335414

Change 335414 merged by jenkins-bot:
Don't try to drop ug_user_group index if it doesn't exist

https://gerrit.wikimedia.org/r/335414

TTO added a comment.Feb 2 2017, 12:00 AM

Should be fixed now. @Nikerabbit: Please confirm.

Nikerabbit closed this task as Resolved.Feb 2 2017, 7:46 AM
Nikerabbit claimed this task.

Can confirm, but unfortunately I am now having troubles with T156996: Various PHP warnings are breaking FormattedRCFeed