task_info FK error when running "glance-manage db purge"

Bug #1803643 reported by Liang Fang
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Glance
Fix Released
Medium
Liang Fang

Bug Description

"glance-manage db purge" failed when there're tasks in db, with state "deleted=1" and "deleted_at" one month ago.

Error logs
---------------------------------------------------------------

DBError detected when purging from tasks: (pymysql.err.IntegrityError) (1451, u'Cannot delete or update a parent row: a foreign key constraint fails (`glance`.`task_info`, CONSTRAINT `task_info_ibfk_1` FOREIGN KEY (`task_id`) REFERENCES `tasks` (`id`))') [SQL: u'DELETE FROM tasks WHERE tasks.id in (SELECT T1.id FROM (SELECT tasks.id \nFROM tasks \nWHERE tasks.deleted_at < %(deleted_at_1)s ORDER BY tasks.deleted_at \n LIMIT %(param_1)s) as T1)'] [parameters: {u'deleted_at_1': datetime.datetime(2018, 11, 14, 2, 28, 7, 645622), u'param_1': 100}] (Background on this error at: http://sqlalche.me/e/gkpj): DBReferenceError: (pymysql.err.IntegrityError) (1451, u'Cannot delete or update a parent row: a foreign key constraint fails (`glance`.`task_info`, CONSTRAINT `task_info_ibfk_1` FOREIGN KEY (`task_id`) REFERENCES `tasks` (`id`))') [SQL: u'DELETE FROM tasks WHERE tasks.id in (SELECT T1.id FROM (SELECT tasks.id \nFROM tasks \nWHERE tasks.deleted_at < %(deleted_at_1)s ORDER BY tasks.deleted_at \n LIMIT %(param_1)s) as T1)'] [parameters: {u'deleted_at_1': datetime.datetime(2018, 11, 14, 2, 28, 7, 645622), u'param_1': 100}] (Background on this error at: http://sqlalche.me/e/gkpj)
Purge command failed, check glance-manage logs for more details.

Steps to reproduce
---------------------------------------------------------------
1. create a task
glance task-create --type "import" --input '{"import_from": "/opt/stack/111.img"}'
glance task-create --type "import" --input '{"import_from": "/opt/stack/222.img"}'

2. update the db table "tasks", set deleted=1 and deleted_at a day one month ago
e.g.
update tasks set deleted=1, deleted_at='2018-10-10 03:18:50' where id='dc76da48-cace-47d4-bcfd-0b62254e52ed';

3. run "glance-manage db purge --age_in_days 2"

Database like:
mysql> select * from tasks;
+--------------------------------------+--------+---------+----------------------------------+------------+---------------------+---------------------+---------------------+---------+
| id | type | status | owner | expires_at | created_at | updated_at | deleted_at | deleted |
+--------------------------------------+--------+---------+----------------------------------+------------+---------------------+---------------------+---------------------+---------+
| dc76da48-cace-47d4-bcfd-0b62254e52ed | import | pending | 60a12b1788ad44468afd983f89a5f8dc | NULL | 2018-11-15 03:18:33 | 2018-11-15 03:18:33 | 2018-10-10 03:18:50 | 1 |
| fbd7e46a-0f33-4c98-be87-0ff7112561e1 | import | pending | 60a12b1788ad44468afd983f89a5f8dc | NULL | 2018-11-16 02:18:12 | 2018-11-16 02:18:12 | NULL | 0 |
+--------------------------------------+--------+---------+----------------------------------+------------+---------------------+---------------------+---------------------+---------+
2 rows in set (0.00 sec)

mysql> select * from task_info;
+--------------------------------------+---------------------------------------+--------+---------+
| task_id | input | result | message |
+--------------------------------------+---------------------------------------+--------+---------+
| dc76da48-cace-47d4-bcfd-0b62254e52ed | {"import_from": "/opt/stack/111.img"} | NULL | |
| fbd7e46a-0f33-4c98-be87-0ff7112561e1 | {"import_from": "/opt/stack/222.img"} | NULL | |
+--------------------------------------+---------------------------------------+--------+---------+

Revision history for this message
Abhishek Kekane (abhishek-kekane) wrote :
Changed in glance:
status: New → Confirmed
importance: Undecided → Medium
assignee: nobody → Liang Fang (liangfang)
Changed in glance:
status: Confirmed → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to glance (master)

Reviewed: https://review.openstack.org/617889
Committed: https://git.openstack.org/cgit/openstack/glance/commit/?id=72159a4a7b267bfe376e84ea754a42b372206325
Submitter: Zuul
Branch: master

commit 72159a4a7b267bfe376e84ea754a42b372206325
Author: Liang Fang <email address hidden>
Date: Wed Nov 14 14:18:54 2018 +0800

    Fix for FK constraint violation

    First force purging of records that are not soft deleted but are
    referencing soft deleted tasks/images records (e.g. task_info records).
    Then purge all soft deleted records in glance tables in the right order
    to avoid FK constraint violation.

    Closes-Bug: #1803643
    Change-Id: I1c471adce002545f8965a57ef78a57e1e3031ef0
    Co-authored-by: Tee Ngo <email address hidden>
    Signed-off-by: Liang Fang <email address hidden>

Changed in glance:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/glance 18.0.0.0b1

This issue was fixed in the openstack/glance 18.0.0.0b1 development milestone.

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.