Page MenuHomePhabricator

maintain-views halt with fatal error when dropping a view fails
Closed, ResolvedPublic

Description

Found while working on T211939: Drop several views from srwikinews:

$ sudo /usr/local/sbin/maintain-views --debug --clean --replace-all --database srwikinews
2018-12-13 22:22:28,223 DEBUG Removing 0 dbs as sensitive
...
2018-12-13 22:22:29,621 INFO cleanup is enabled
2018-12-13 22:22:29,623 INFO cleaning 13 tables
2018-12-13 22:22:29,623 INFO Dropping view srwikinews_p.flaggedrevs_stats2
2018-12-13 22:22:29,623 DEBUG SQL: drop view srwikinews_p.flaggedrevs_stats2
2018-12-13 22:22:29,626 INFO Dropping view srwikinews_p.flaggedpages
2018-12-13 22:22:29,626 DEBUG SQL: drop view srwikinews_p.flaggedpages
2018-12-13 22:22:29,628 INFO Dropping view srwikinews_p.flaggedrevs_stats
2018-12-13 22:22:29,628 DEBUG SQL: drop view srwikinews_p.flaggedrevs_stats
2018-12-13 22:22:29,631 INFO Dropping view srwikinews_p.flaggedpage_config
2018-12-13 22:22:29,631 DEBUG SQL: drop view srwikinews_p.flaggedpage_config
2018-12-13 22:22:29,634 INFO Dropping view srwikinews_p.flaggedimages           2018-12-13 22:22:29,634 DEBUG SQL: drop view srwikinews_p.flaggedimages
2018-12-13 22:22:29,636 INFO Dropping view srwikinews_p.comment_mat
2018-12-13 22:22:29,636 DEBUG SQL: drop view srwikinews_p.comment_mat
Traceback (most recent call last):
  File "/usr/local/sbin/maintain-views", line 594, in <module>
    main()
  File "/usr/local/sbin/maintain-views", line 590, in main
    ops.drop_view(dt)
  File "/usr/local/sbin/maintain-views", line 61, in drop_view
    self.write_execute("drop view {}.{}".format(self.db_p, view))
  File "/usr/local/sbin/maintain-views", line 54, in write_execute
    self.cursor.execute(query)
  File "/usr/lib/python3/dist-packages/pymysql/cursors.py", line 166, in execute
    result = self._query(query)
  File "/usr/lib/python3/dist-packages/pymysql/cursors.py", line 322, in _query
    conn.query(q)
  File "/usr/lib/python3/dist-packages/pymysql/connections.py", line 852, in que
ry
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "/usr/lib/python3/dist-packages/pymysql/connections.py", line 1053, in _r
ead_query_result
    result.read()
  File "/usr/lib/python3/dist-packages/pymysql/connections.py", line 1336, in re
ad
    first_packet = self.connection._read_packet()
  File "/usr/lib/python3/dist-packages/pymysql/connections.py", line 1010, in _r
ead_packet
    packet.check_error()
  File "/usr/lib/python3/dist-packages/pymysql/connections.py", line 393, in che
ck_error
    err.raise_mysql_exception(self._data)
  File "/usr/lib/python3/dist-packages/pymysql/err.py", line 107, in raise_mysql
_exception
    raise errorclass(errno, errval)
pymysql.err.InternalError: (1347, "'srwikinews_p.comment_mat' is not VIEW")

The thing I don't like about this is that the cleanup steps that could have worked beyond the unexpected physical table were skipped. Luckily repeated runs of the script with the same arguments eventually did remove all of the obsolete views, but this seems to have been an accident of the dictionary iteration order changing from run to run.

Event Timeline

Change 479576 had a related patch set uploaded (by BryanDavis; owner: Bryan Davis):
[operations/puppet@production] wmcs: catch and log view drop errors in maintain-views

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

Change 479576 merged by Bstorm:
[operations/puppet@production] wmcs: catch and log view drop errors in maintain-views

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

bd808 claimed this task.