Page MenuHomePhabricator

Queries to externallinks table fail following schema changes
Closed, ResolvedPublicBUG REPORT

Description

First reported on IRC by @Danny_B.

$ sql cswikinews
> select * from externallinks limit 1;
ERROR 1356 (HY000): View 'cswikinews_p.externallinks' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
> show create view externallinks\G
*************************** 1. row ***************************
                View: externallinks
         Create View: CREATE ALGORITHM=UNDEFINED DEFINER=`viewmaster`@`%` SQL SECURITY DEFINER VIEW `externallinks` AS select `cswikinews`.`externallinks`.`el_id` AS `el_id`,`cswikinews`.`externallinks`.`el_from` AS `el_from`,`cswikinews`.`externallinks`.`el_to` AS `el_to`,`cswikinews`.`externallinks`.`el_index` AS `el_index`,`cswikinews`.`externallinks`.`el_index_60` AS `el_index_60`,`cswikinews`.`externallinks`.`el_to_domain_index` AS `el_to_domain_index`,`cswikinews`.`externallinks`.`el_to_path` AS `el_to_path` from `cswikinews`.`externallinks`
character_set_client: utf8
collation_connection: utf8_general_ci
1 row in set, 1 warning (0.002 sec)

I think this is triggered by actions on T343718: Drop old columns of externallinks.

Event Timeline

Externallinks is marked as a "fullview" in maintain-views.yaml. This means that the view for it is generated by code that looks something like:

CREATE OR REPLACE
DEFINER=viewmaster
VIEW externallinks
AS SELECT * FROM externallinks;

That select is done as the view is created and it embeds the columns at that point in time into the view's code. This fundamentally means that dropping columns from externallinks as is being done in T343718 will break the view as soon as the drop happens.

bd808 triaged this task as High priority.Aug 23 2023, 10:29 PM

This fix should be running sudo maintain-views --table externallinks --all-databases --replace-all --debug on each wiki replica backend server. This will need to be done and redone as columns are dropped from each replica.

Alternately someone could update maintain-view.yaml to define an explicit table structure for externallinks that only includes the columns that will remain after T343718 is finished and rebuild all of the views once for that set of columns.

This fix should be running sudo maintain-views --table externallinks --all-databases --replace-all --debug on each wiki replica backend server. This will need to be done and redone as columns are dropped from each replica.

I just did this task across clouddb1013,clouddb1014,clouddb1015,clouddb1016,clouddb1017,clouddb1018,clouddb1019,clouddb1020. The change applied everywhere but clouddb1019 where the commonswiki_p.externallinks view is being actively used too heavily for the script to acquire a write lock. Depooling the instance to fix that is something that needs global root powers that I do not have.

@Ladsgroup it would be most excellent if you could add the needed view rebuild to the process you are following to drop the old columns. If that is not reasonably possible the next best thing would be finding a way to poke someone to do the needful after the drop has happened. Who to poke is a question that I'm not 100% certain of today. Once I would have said @BTullis, but I'm not sure if he is still actively working on Wiki Replica maintenance tasks.

Someone just needs to run sudo maintain-views --replace-all --all-databases --table externallinks on cloud replicas of the section after the bot is run. I ran it for s5, doing it for s3 now.

Who to poke is a question that I'm not 100% certain of today. Once I would have said @BTullis, but I'm not sure if he is still actively working on Wiki Replica maintenance tasks.

Just for the record, am still working on wikireplica view maintenance, but I also really appreciate the help, so thanks @Ladsgroup and @bd808.

I think we would try to encourage you to tag Data-Platform-SRE as a general rule, so that it doesn't have to be an individual and so that we get more people versed in the practices of wikireplica view maintenance.

If it's a more involved change to the views definition, then it should fall to the Data-Engineering to review. Hope that helps.

Can someone run maintain-views for s2?

Could not get links for wikimap.toolforge.org: Database(Database(MySqlDatabaseError { code: Some("HY000"), number: 1356, message: "View 'enwiktionary_p.externallinks' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them" }))

The schema change is now run on every section and I ran the maintain-views afterwards. So this should be done now.

Ladsgroup claimed this task.