Red Hat Bugzilla – Bug 1306444
DB Purge of raw_template fails on constraint from resources.current_template_id
Last modified: 2016-04-26 14:00:57 EDT
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):
Steps to Reproduce:
1. Run /bin/heat-manage purge_deleted manually
A stack trace and the raw_template table is left un-purged.
A purged raw_template table.
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.
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.
no issues running it manually now.
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.