alarm creation with sqlalchemy fails with intermittent IntegrityError

Bug #1255107 reported by Eoghan Glynn
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Ceilometer
Fix Released
High
Eoghan Glynn
Havana
Fix Released
High
Eoghan Glynn

Bug Description

Alarm creation fails intermittently when the sqlalchemy driver is used:

(IntegrityError) (1452, 'Cannot add or update a child row: a foreign key constraint fails (`ceilometer`.`alarm`, CONSTRAINT `fk_alarm_project_id` FOREIGN KEY (`project_id`) REFERENCES `project` (`id`))') 'INSERT INTO alarm (id, enabled, name, type, description, timestamp, user_id, project_id, state, state_timestamp, ok_actions, alarm_actions, insufficient_data_actions, repeat_actions, rule) VALUES ...

This appears to be an artifact of how the alarm creation logic was added to the sqlalchemy driver in such a way as to rely on sqlalchemy session merge to create the corresponding entries in the project & user tables[1].

Then subsequently a *later* migration[2] was added to assert foreign key constraints for those project & user IDs.

I don't think session merge is a reliable way to ensure creation of the corresponding rows in the related tables in order to satisfy the foreign key constraints. Instead we should create the project & user IDs explicitly.

[1] https://github.com/openstack/ceilometer/commit/2c84007b
[2] https://github.com/openstack/ceilometer/commit/fa6f9807

Eoghan Glynn (eglynn)
Changed in ceilometer:
assignee: nobody → Eoghan Glynn (eglynn)
status: New → In Progress
importance: Undecided → High
Eoghan Glynn (eglynn)
Changed in ceilometer:
milestone: none → icehouse-1
Eoghan Glynn (eglynn)
tags: added: havana-backport-potential
Eoghan Glynn (eglynn)
summary: - alarm creation with sqlalchemy fails with IntegrityError due to
- ForeignKey constraint on project ID
+ alarm creation with sqlalchemy fails with intermittent IntegrityError
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to ceilometer (master)

Reviewed: https://review.openstack.org/58587
Committed: http://github.com/openstack/ceilometer/commit/b2b500c83cf5a81269c84a16f9a30ab7fa4c8ee6
Submitter: Jenkins
Branch: master

commit b2b500c83cf5a81269c84a16f9a30ab7fa4c8ee6
Author: Eoghan Glynn <email address hidden>
Date: Tue Nov 26 16:35:36 2013 +0000

    Avoid intermittent integrity error on alarm creation

    Fixes bug 1255107

    Previously, alarm creation failed intermittently with the
    sqlalchemy driver, due to the reliance on session merge to create
    the project & user IDs if not already encountered. This approach
    conflicted with the strict foreign key constraints that were
    added to the alarms table as an after-thought.

    Now, we avoid the potential problem by explicitly creating the
    project and user IDs if necessary.

    Unfortunately, this cannot be tested via the scenario tests,
    as there we use sqlite (the problematic migration does not
    apply the foreign key constraints for that engine).

    Change-Id: Ieaed676a0a68725242fadbf658646b874d6851ce

Changed in ceilometer:
status: In Progress → Fix Committed
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to ceilometer (stable/havana)

Fix proposed to branch: stable/havana
Review: https://review.openstack.org/58818

Thierry Carrez (ttx)
Changed in ceilometer:
status: Fix Committed → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to ceilometer (stable/havana)

Reviewed: https://review.openstack.org/58818
Committed: http://github.com/openstack/ceilometer/commit/59f25a4f062a6e9d3a75baf38400ea5fc41c0a68
Submitter: Jenkins
Branch: stable/havana

commit 59f25a4f062a6e9d3a75baf38400ea5fc41c0a68
Author: Eoghan Glynn <email address hidden>
Date: Tue Nov 26 16:35:36 2013 +0000

    Avoid intermittent integrity error on alarm creation

    Fixes bug 1255107

    Previously, alarm created failed intermittently with the
    sqlalchemy driver, due to the reliance on session merge to create
    the project & user IDs if not already encountered. This approach
    conflicted with the strict foreign key constraints that were
    added to the alarms table as an after-thought.

    Now, we avoid the potential problem by creating the project and
    user IDs explicitly.

    Unfortunately, this cannot be tested via the scenario tests,
    as there we use sqlite (the problematic migration does not
    apply the foreign key constraints for that engine).

    Change-Id: Ieaed676a0a68725242fadbf658646b874d6851ce
    (cherry picked from commit b2b500c83cf5a81269c84a16f9a30ab7fa4c8ee6)

Alan Pevec (apevec)
tags: removed: havana-backport-potential
Thierry Carrez (ttx)
Changed in ceilometer:
milestone: icehouse-1 → 2014.1
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.