Page MenuHomePhabricator

patch-drop-ct_tag.sql causes duplicate entries for key change_tag_rc_tag_id
Closed, InvalidPublic

Description

When upgrading from 1.31 to 1.33 the patch-drop-ct_tag.sql patch fails due to it attempting to create duplicate unique keys in the change_tag_rc_tag_id unique index by converting all NULL to 0. MobileFrontend creates two change tags per mobile web edit and MediaWiki itself creates two change tags during an undo was a redirect.

PHP 7.2+, Aurora MySQL, Ubuntu/Debian

Table change_tag contains ct_tag field. Dropping ...General exception while running update: A database query error has occurred. Did you forget to run your application's database schema updater after upgrading? 
Query: ALTER TABLE `change_tag` MODIFY ct_tag_id int unsigned NOT NULL

Function: Wikimedia\Rdbms\Database::sourceFile( maintenance/archives/patch-drop-ct_tag.sql )
Error: 1062 Duplicate entry '170920-0' for key 'change_tag_rc_tag_id' (****:3306)

Example data:

+-------+----------+-----------+-----------+----------------------------+-----------+-----------+
| ct_id | ct_rc_id | ct_log_id | ct_rev_id | ct_tag                     | ct_params | ct_tag_id |
+-------+----------+-----------+-----------+----------------------------+-----------+-----------+
|   185 |   217216 |      NULL |    525456 | mobile edit                | NULL      |      NULL |
|   186 |   217216 |      NULL |    525456 | mobile web edit            | NULL      |      NULL |
|   656 |   242085 |      NULL |    546513 | mw-changed-redirect-target | NULL      |      NULL |
|   657 |   242085 |      NULL |    546513 | mw-undo                    | NULL      |      NULL |

SHOW CREATE TABLE change_tag;

CREATE TABLE `change_tag` (
  `ct_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `ct_rc_id` int(11) DEFAULT NULL,
  `ct_log_id` int(10) unsigned DEFAULT NULL,
  `ct_rev_id` int(10) unsigned DEFAULT NULL,
  `ct_tag` varbinary(255) NOT NULL DEFAULT '',
  `ct_params` blob,
  `ct_tag_id` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`ct_id`),
  UNIQUE KEY `change_tag_rc_tag_id` (`ct_rc_id`,`ct_tag_id`),
  UNIQUE KEY `change_tag_log_tag_id` (`ct_log_id`,`ct_tag_id`),
  UNIQUE KEY `change_tag_rev_tag_id` (`ct_rev_id`,`ct_tag_id`),
  KEY `change_tag_tag_id` (`ct_tag`,`ct_rc_id`,`ct_rev_id`,`ct_log_id`),
  KEY `change_tag_tag_id_id` (`ct_tag_id`,`ct_rc_id`,`ct_rev_id`,`ct_log_id`),
  KEY `change_tag_rc_tag_nonuniq` (`ct_rc_id`,`ct_tag`),
  KEY `change_tag_log_tag_nonuniq` (`ct_log_id`,`ct_tag`),
  KEY `change_tag_rev_tag_nonuniq` (`ct_rev_id`,`ct_tag`)
) ENGINE=InnoDB AUTO_INCREMENT=11416 DEFAULT CHARSET=binary

Related Objects

Event Timeline

The error is caused because the maintenance script mentioned in the update.php is not ran (PopulateChangeTagDef) otherwise your ct_tag_id column would have not been NULL, and indeed patch-drop-ct_tag.sql is after the maintenance script. So either somehow updater skipped running the maintenance script or failed to do anything there. I have no idea how I can check this for you. Can you do it?

Also can you try running maintenance/populateChangeTagDef.php and then try again?

The maintenance script did run though:

Running maintenance/populateChangeTagDef.php...
done.
Adding index change_tag_rc_tag_id to table change_tag ...done.
Adding ipb_sitewide field to table ipblocks ...done.
Creating ipblocks_restrictions table ...done.
Merging image_comment_temp into the image table
Merging image_comment_temp into the image table...
Completed merge of image_comment_temp into the image table, 0 image rows updated, 0 image_comment_temp rows deleted.
done.
Dropping table image_comment_temp ...done.
Table change_tag contains ct_tag field. Dropping ...General exception while running update: A database query error has occurred. Did you forget to run your application's database schema updater after upgrading? 
Query: ALTER TABLE `change_tag` MODIFY ct_tag_id int unsigned NOT NULL

Function: Wikimedia\Rdbms\Database::sourceFile( /home/hydra/public_html/maintenance/archives/patch-drop-ct_tag.sql )
Error: 1062 Duplicate entry '170920-0' for key 'change_tag_rc_tag_id' (****:3306)

Running it manually:

...Update 'PopulateChangeTagDef' already logged as completed.

I deleted the updatelog entry and ran it manually. This time around it actually did the task. This is consistent behavior across every wiki that is being upgraded. It fails during update.php with a successful message, is logged as completed, but did not actually do anything. I am going to do tests against the MW 1.31 version of the database with debugging to see what is happening.

I am closing this as invalid. There is a context issue with the DynamicSettings FarmInstaller that is causing this maintenance script to run against the wrong database. We will fix that on our end.