cinder-manage db purge has issues with foreign keys

Bug #1489523 reported by Matt Fischer
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Cinder
Undecided
Jose Castro Leon

Bug Description

trying out db purge today on a kilo.0 database and it has errors with key constraints.

[DEV] root@bfd02-control-002:~# cinder-manage db purge 180
/usr/lib/python2.7/dist-packages/oslo_messaging/_drivers/base.py:20: DeprecationWarning: The oslo namespace package is deprecated. Please use oslo_config instead.
  from oslo.config import cfg
2015-08-27 15:44:02.480 24675 ERROR oslo_db.sqlalchemy.exc_filters [req-ad142b3c-a2a2-4171-a042-cd2d06c5f8a5 - - - - -] DBAPIError exception wrapped from (IntegrityError) (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`cinder`.`volume_glance_metadata`, CONSTRAINT `volume_glance_metadata_ibfk_2` FOREIGN KEY (`snapshot_id`) REFERENCES `snapshots` (`id`))') 'DELETE FROM snapshots WHERE snapshots.deleted_at < %s' (datetime.datetime(2015, 2, 28, 15, 44, 2, 473270),)
2015-08-27 15:44:02.480 24675 TRACE oslo_db.sqlalchemy.exc_filters Traceback (most recent call last):
2015-08-27 15:44:02.480 24675 TRACE oslo_db.sqlalchemy.exc_filters File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 951, in _execute_context
2015-08-27 15:44:02.480 24675 TRACE oslo_db.sqlalchemy.exc_filters context)
2015-08-27 15:44:02.480 24675 TRACE oslo_db.sqlalchemy.exc_filters File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/default.py", line 436, in do_execute
2015-08-27 15:44:02.480 24675 TRACE oslo_db.sqlalchemy.exc_filters cursor.execute(statement, parameters)
2015-08-27 15:44:02.480 24675 TRACE oslo_db.sqlalchemy.exc_filters File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 174, in execute
2015-08-27 15:44:02.480 24675 TRACE oslo_db.sqlalchemy.exc_filters self.errorhandler(self, exc, value)
2015-08-27 15:44:02.480 24675 TRACE oslo_db.sqlalchemy.exc_filters File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
2015-08-27 15:44:02.480 24675 TRACE oslo_db.sqlalchemy.exc_filters raise errorclass, errorvalue
2015-08-27 15:44:02.480 24675 TRACE oslo_db.sqlalchemy.exc_filters IntegrityError: (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`cinder`.`volume_glance_metadata`, CONSTRAINT `volume_glance_metadata_ibfk_2` FOREIGN KEY (`snapshot_id`) REFERENCES `snapshots` (`id`))')
2015-08-27 15:44:02.480 24675 TRACE oslo_db.sqlalchemy.exc_filters
2015-08-27 15:44:02.485 24675 CRITICAL cinder [req-ad142b3c-a2a2-4171-a042-cd2d06c5f8a5 - - - - -] DBError: (IntegrityError) (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`cinder`.`volume_glance_metadata`, CONSTRAINT `volume_glance_metadata_ibfk_2` FOREIGN KEY (`snapshot_id`) REFERENCES `snapshots` (`id`))') 'DELETE FROM snapshots WHERE snapshots.deleted_at < %s' (datetime.datetime(2015, 2, 28, 15, 44, 2, 473270),)
2015-08-27 15:44:02.485 24675 TRACE cinder Traceback (most recent call last):
2015-08-27 15:44:02.485 24675 TRACE cinder File "/usr/bin/cinder-manage", line 10, in <module>
2015-08-27 15:44:02.485 24675 TRACE cinder sys.exit(main())
2015-08-27 15:44:02.485 24675 TRACE cinder File "/usr/lib/python2.7/dist-packages/cinder/cmd/manage.py", line 565, in main
2015-08-27 15:44:02.485 24675 TRACE cinder fn(*fn_args)
2015-08-27 15:44:02.485 24675 TRACE cinder File "/usr/lib/python2.7/dist-packages/cinder/cmd/manage.py", line 248, in purge
2015-08-27 15:44:02.485 24675 TRACE cinder db.purge_deleted_rows(ctxt, age_in_days)
2015-08-27 15:44:02.485 24675 TRACE cinder File "/usr/lib/python2.7/dist-packages/cinder/db/api.py", line 965, in purge_deleted_rows
2015-08-27 15:44:02.485 24675 TRACE cinder return IMPL.purge_deleted_rows(context, age_in_days=age_in_days)
2015-08-27 15:44:02.485 24675 TRACE cinder File "/usr/lib/python2.7/dist-packages/cinder/db/sqlalchemy/api.py", line 163, in wrapper
2015-08-27 15:44:02.485 24675 TRACE cinder return f(*args, **kwargs)
2015-08-27 15:44:02.485 24675 TRACE cinder File "/usr/lib/python2.7/dist-packages/cinder/db/sqlalchemy/api.py", line 3597, in purge_deleted_rows
2015-08-27 15:44:02.485 24675 TRACE cinder .where(t.c.deleted_at < deleted_age))
2015-08-27 15:44:02.485 24675 TRACE cinder File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 991, in execute
2015-08-27 15:44:02.485 24675 TRACE cinder bind, close_with_result=True).execute(clause, params or {})
2015-08-27 15:44:02.485 24675 TRACE cinder File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 729, in execute
2015-08-27 15:44:02.485 24675 TRACE cinder return meth(self, multiparams, params)
2015-08-27 15:44:02.485 24675 TRACE cinder File "/usr/lib/python2.7/dist-packages/sqlalchemy/sql/elements.py", line 322, in _execute_on_connection
2015-08-27 15:44:02.485 24675 TRACE cinder return connection._execute_clauseelement(self, multiparams, params)
2015-08-27 15:44:02.485 24675 TRACE cinder File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 826, in _execute_clauseelement
2015-08-27 15:44:02.485 24675 TRACE cinder compiled_sql, distilled_params
2015-08-27 15:44:02.485 24675 TRACE cinder File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 958, in _execute_context
2015-08-27 15:44:02.485 24675 TRACE cinder context)
2015-08-27 15:44:02.485 24675 TRACE cinder File "/usr/lib/python2.7/dist-packages/oslo_db/sqlalchemy/compat/handle_error.py", line 261, in _handle_dbapi_exception
2015-08-27 15:44:02.485 24675 TRACE cinder e, statement, parameters, cursor, context)
2015-08-27 15:44:02.485 24675 TRACE cinder File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1155, in _handle_dbapi_exception
2015-08-27 15:44:02.485 24675 TRACE cinder util.raise_from_cause(newraise, exc_info)
2015-08-27 15:44:02.485 24675 TRACE cinder File "/usr/lib/python2.7/dist-packages/sqlalchemy/util/compat.py", line 199, in raise_from_cause
2015-08-27 15:44:02.485 24675 TRACE cinder reraise(type(exception), exception, tb=exc_tb)
2015-08-27 15:44:02.485 24675 TRACE cinder File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 951, in _execute_context
2015-08-27 15:44:02.485 24675 TRACE cinder context)
2015-08-27 15:44:02.485 24675 TRACE cinder File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/default.py", line 436, in do_execute
2015-08-27 15:44:02.485 24675 TRACE cinder cursor.execute(statement, parameters)
2015-08-27 15:44:02.485 24675 TRACE cinder File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 174, in execute
2015-08-27 15:44:02.485 24675 TRACE cinder self.errorhandler(self, exc, value)
2015-08-27 15:44:02.485 24675 TRACE cinder File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
2015-08-27 15:44:02.485 24675 TRACE cinder raise errorclass, errorvalue
2015-08-27 15:44:02.485 24675 TRACE cinder DBError: (IntegrityError) (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`cinder`.`volume_glance_metadata`, CONSTRAINT `volume_glance_metadata_ibfk_2` FOREIGN KEY (`snapshot_id`) REFERENCES `snapshots` (`id`))') 'DELETE FROM snapshots WHERE snapshots.deleted_at < %s' (datetime.datetime(2015, 2, 28, 15, 44, 2, 473270),)
2015-08-27 15:44:02.485 24675 TRACE cinder

Changed in cinder:
assignee: nobody → jelly (coding1314)
Revision history for this message
Sean McGinnis (sean-mcginnis) wrote : Owner Expired

Unassigning due to no activity.

Changed in cinder:
assignee: Kuo-tung Kao (jelly) (coding1314) → nobody
Changed in cinder:
assignee: nobody → Jose Castro Leon (jose-castro-leon)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to cinder (master)

Fix proposed to branch: master
Review: https://review.openstack.org/338228

Changed in cinder:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to cinder (master)

Reviewed: https://review.openstack.org/338228
Committed: https://git.openstack.org/cgit/openstack/cinder/commit/?id=b6d594898849c86bb3d5736a5b27f75fccf27066
Submitter: Jenkins
Branch: master

commit b6d594898849c86bb3d5736a5b27f75fccf27066
Author: Jose Castro Leon <email address hidden>
Date: Wed Jul 6 14:25:31 2016 +0200

    cinder-manage db purge has issues with foreign keys

    When executing purge on a database with snapshots created from volumes
    with glance metadata, it fails due to a foreign key exception.
    This patch adds the table at the end of the purge and forces the use of
    foreign key checks on the tests

    Change-Id: I67436a8319155bb47dfa67544ccae25f337ed246
    Closes-Bug: #1489523

Changed in cinder:
status: In Progress → Fix Released
Revision history for this message
Doug Hellmann (doug-hellmann) wrote : Fix included in openstack/cinder 9.0.0.0b2

This issue was fixed in the openstack/cinder 9.0.0.0b2 development milestone.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers