Bug 1306444 - DB Purge of raw_template fails on constraint from resources.current_template_id
Summary: DB Purge of raw_template fails on constraint from resources.current_template_id
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat OpenStack
Classification: Red Hat
Component: openstack-heat
Version: 7.0 (Kilo)
Hardware: Unspecified
OS: Unspecified
high
high
Target Milestone: z4
: 7.0 (Kilo)
Assignee: Crag Wolfe
QA Contact: Amit Ugol
URL:
Whiteboard:
Depends On:
Blocks: 1310890
TreeView+ depends on / blocked
 
Reported: 2016-02-10 21:37 UTC by Crag Wolfe
Modified: 2022-07-09 08:13 UTC (History)
7 users (show)

Fixed In Version: openstack-heat-2015.1.2-9.el7ost
Doc Type: Bug Fix
Doc Text:
Previously, the "heat-manage purge_delete" cron job on the undercloud failed when attempting to purge the raw_template table. This patch fixes raw_template purge query on MySQL, and handles stack tags before removing stacks which resolves the issue. This also removes a bunch of race conditions where incorrect data was being deleted.
Clone Of:
: 1310890 (view as bug list)
Environment:
Last Closed: 2016-02-18 16:43:40 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
OpenStack gerrit 278466 0 None MERGED Fix database purge query 2020-11-12 14:44:28 UTC
Red Hat Issue Tracker OSP-16732 0 None None None 2022-07-09 08:13:44 UTC
Red Hat Product Errata RHSA-2016:0266 0 normal SHIPPED_LIVE Moderate: openstack-heat bug fix and security advisory 2016-02-18 21:41:02 UTC

Description Crag Wolfe 2016-02-10 21:37:43 UTC
Description of problem:

The "heat-manage purge_delete" cron job on the undercloud fails when attempting to purge the raw_template table.

Version-Release number of selected component (if applicable):
openstack-heat-common-2015.1.2-4.el7ost.noarch

How reproducible:
Not clear.

Steps to Reproduce:
1. Run /bin/heat-manage purge_deleted manually

Actual results:
A stack trace and the raw_template table is left un-purged.

Expected results:
A purged raw_template table.

Comment 2 Zane Bitter 2016-02-11 17:53:48 UTC
Since DB migrations convergence were introduced in Kilo, we've been storing a reference to the raw_template for each resource in the current_template_id column of the resource table. It appears that prior to the fix for https://bugs.launchpad.net/heat/+bug/1524387 we were deleting too many raw_template entries - i.e. ones that might have been referenced by prev_raw_template_id in a stack, or current_template_id in a resource, resulting in this error:

ERROR: (_mysql_exceptions.IntegrityError) (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`heat`.`resource`, CONSTRAINT `current_template_fkey_ref` FOREIGN KEY (`current_template_id`) REFERENCES `raw_template` (`id`))') [SQL: u'DELETE FROM raw_template WHERE raw_template.id NOT IN (SELECT stack.raw_template_id \nFROM stack)']

The patch avoids deleting raw_template entries that are still referenced by prev_raw_template_id, but that field is not actually populated in Kilo (it was also introduced for convergence, although we also use it for other purposes in the legacy code path in Liberty). So it's unlikely this is having an effect.

I think the real reason it appears to work is that it now cleans up only raw_templates from the stacks that it had just deleted... and in this case all of the old *stacks* had already been removed by the previous command (which later failed attempting to clean up non-orphaned raw_templates). So we'll never be able to clean up those templates with this code.

Comment 3 Zane Bitter 2016-02-11 18:04:52 UTC
That said, the fact that we were trying to clean up all non-referenced raw_templates (not just the ones that were previously referenced by the stacks we just deleted) and doing an inadequate check for existing references was probably the reason for the error in the first place. So the check to only delete raw_templates associated with the stacks we just removed is probably a correct fix. But this at least explains why none of the old raw_templates were actually removed when purge_deleted was run with the patch, even though there was no more error.

Comment 5 Amit Ugol 2016-02-16 10:29:54 UTC
no issues running it manually now.

Comment 7 errata-xmlrpc 2016-02-18 16:43:40 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHSA-2016-0266.html


Note You need to log in before you can comment on or make changes to this bug.