DB migration failure due to 006_mysql_downgrade script handled mysql reserved word as column name wrongly

Bug #1351413 reported by Zhi Yan Liu
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Glance
Fix Released
Low
Zhi Yan Liu

Bug Description

Because 006_mysql_downgrade didn't correctly quote 'key' column [0][1] of 'image_properties' table when creating index [2],
the index wasn't created as needed, and then operator could not run any upgrade script successfully since
006_mysql_upgrade script could not to handle this unexpected db status [3].

[0] http://dev.mysql.com/doc/mysqld-version-reference/en/mysqld-version-reference-reservedwords-5-5.html
[1] http://dev.mysql.com/doc/mysqld-version-reference/en/mysqld-version-reference-reservedwords-5-0.html
[2] https://github.com/openstack/glance/blob/master/glance/db/sqlalchemy/migrate_repo/versions/006_mysql_downgrade.sql#L11
[3] https://github.com/openstack/glance/blob/master/glance/db/sqlalchemy/migrate_repo/versions/006_mysql_upgrade.sql#L5

Note, this issue doesn't impact one-way upgrade migration operation, since bug existed in downgrade script. But once operator
do a reciprocating migration operation, this issue will rise up. When I open "snake walk" mode on migration test, this issue
could be triggered as well.

======================================================================
FAIL: glance.tests.unit.test_migrations.TestMigrations.test_walk_versions
tags: worker-0
----------------------------------------------------------------------
Traceback (most recent call last):
  File "glance/tests/unit/test_migrations.py", line 251, in test_walk_versions
    self._walk_versions(engine, self.snake_walk)
  File "glance/tests/unit/test_migrations.py", line 345, in _walk_versions
    self._migrate_up(engine, version)
  File "glance/tests/unit/test_migrations.py", line 394, in _migrate_up
    version)
  File "/home/lzy/workspace/openstack/glance/.tox/py27/local/lib/python2.7/site-packages/migrate/versioning/api.py", line 186, in upgrade
    return _migrate(url, repository, version, upgrade=True, err=err, **opts)
  File "<string>", line 2, in _migrate
  File "/home/lzy/workspace/openstack/glance/.tox/py27/local/lib/python2.7/site-packages/migrate/versioning/util/__init__.py", line 160, in with_engine
    return f(*a, **kw)
  File "/home/lzy/workspace/openstack/glance/.tox/py27/local/lib/python2.7/site-packages/migrate/versioning/api.py", line 366, in _migrate
    schema.runchange(ver, change, changeset.step)
  File "/home/lzy/workspace/openstack/glance/.tox/py27/local/lib/python2.7/site-packages/migrate/versioning/schema.py", line 93, in runchange
    change.run(self.engine, step)
  File "/home/lzy/workspace/openstack/glance/.tox/py27/local/lib/python2.7/site-packages/migrate/versioning/script/sql.py", line 43, in run
    conn.execute(text)
  File "/home/lzy/workspace/openstack/glance/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 721, in execute
    return self._execute_text(object, multiparams, params)
  File "/home/lzy/workspace/openstack/glance/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 870, in _execute_text
    statement, parameters
  File "/home/lzy/workspace/openstack/glance/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 958, in _execute_context
    context)
  File "/home/lzy/workspace/openstack/glance/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1160, in _handle_dbapi_exception
    exc_info
  File "/home/lzy/workspace/openstack/glance/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 199, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb)
  File "/home/lzy/workspace/openstack/glance/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 951, in _execute_context
    context)
  File "/home/lzy/workspace/openstack/glance/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 436, in do_execute
    cursor.execute(statement, parameters)
  File "/home/lzy/workspace/openstack/glance/.tox/py27/local/lib/python2.7/site-packages/MySQLdb/cursors.py", line 205, in execute
    self.errorhandler(self, exc, value)
  File "/home/lzy/workspace/openstack/glance/.tox/py27/local/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
OperationalError: (OperationalError) (1091, "Can't DROP 'ix_image_properties_image_id_key'; check that column/key exists") '/*\n * This file is necessary because MySQL does not support\n * renaming indexes.\n */\nDROP INDEX ix_image_properties_image_id_key ON image_properties;\n\n/* Rename the `key` column to `name` */\nALTER TABLE image_properties\nCHANGE COLUMN `key` name VARCHAR(255) NOT NULL;\n\nCREATE UNIQUE INDEX ix_image_properties_image_id_name ON image_properties (image_id, name);\n' ()

Tags: db
Zhi Yan Liu (lzy-dev)
tags: added: db
Revision history for this message
Zhi Yan Liu (lzy-dev) wrote :
Changed in glance:
assignee: nobody → Zhi Yan Liu (lzy-dev)
importance: Undecided → Low
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to glance (master)

Reviewed: https://review.openstack.org/111358
Committed: https://git.openstack.org/cgit/openstack/glance/commit/?id=579e0c18751216177c94d02f6488907165ce17ec
Submitter: Jenkins
Branch: master

commit 579e0c18751216177c94d02f6488907165ce17ec
Author: Zhi Yan Liu <email address hidden>
Date: Sat Aug 2 02:17:05 2014 +0800

    Quota column name 'key' in downgrade script

    006_mysql_downgrade didn't correctly quote 'key' column of
    'image_properties' table when creating index, the index wasn't created
    as needed, and then operator could not run any upgrade script
    successfully since 006_mysql_upgrade script could not to handle this
    unexpected db status.

    Note, this issue doesn't impact one-way upgrade migration operation,
    since bug existed in downgrade script. But once operator do a
    reciprocating migration operation, this issue will rise up as a blocker.

    Closes-bug: 1351413

    Change-Id: Ie1ed1b7f06b8a0aeede70c3d4dd061c857e448da
    Signed-off-by: Zhi Yan Liu <email address hidden>

Changed in glance:
status: Triaged → Fix Committed
Thierry Carrez (ttx)
Changed in glance:
milestone: none → juno-3
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in glance:
milestone: juno-3 → 2014.2
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.