DBDuplicateEntry: (IntegrityError) 500 after encryption-type-recreation

Bug #1316540 reported by Attila Fazekas
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Cinder
Fix Released
Low
Ivan Kolodyazhny

Bug Description

$ cinder type-create foo
$ cinder --debug encryption-type-create foo foobar
$ cinder --debug encryption-type-delete foo
$ cinder --debug encryption-type-create foo foobar

The above command sequence is rewarded by 500 and with the exception visible below:

2014-05-06 10:54:33.798 32003 ERROR cinder.api.middleware.fault [req-84b40273-9a16-4ab0-a521-c9aceb5f2021 8be40a280b234e8e84f9927ab1970477 f3910d12269f4a868adbca3e641b7038 - - -] Caught error: (IntegrityError) (1062, "Duplicate entry 'e1667fc3-8f19-4a83-b9cf-114d8ed297a1' for key 'PRIMARY'") 'INSERT INTO encryption (created_at, updated_at, deleted_at, deleted, cipher, key_size, provider, control_location, volume_type_id) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)' (datetime.datetime(2014, 5, 6, 10, 54, 33, 795603), None, None, 0, None, None, 'foobar', 'front-end', 'e1667fc3-8f19-4a83-b9cf-114d8ed297a1')
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault Traceback (most recent call last):
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault File "/opt/stack/new/cinder/cinder/api/middleware/fault.py", line 75, in __call__
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault return req.get_response(self.application)
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault File "/usr/lib/python2.7/site-packages/webob/request.py", line 1296, in send
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault application, catch_exc_info=False)
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault File "/usr/lib/python2.7/site-packages/webob/request.py", line 1260, in call_application
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault app_iter = application(self.environ, start_response)
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault File "/usr/lib/python2.7/site-packages/webob/dec.py", line 144, in __call__
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault return resp(environ, start_response)
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault File "/opt/stack/new/python-keystoneclient/keystoneclient/middleware/auth_token.py", line 632, in __call__
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault return self.app(env, start_response)
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault File "/usr/lib/python2.7/site-packages/webob/dec.py", line 144, in __call__
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault return resp(environ, start_response)
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault File "/usr/lib/python2.7/site-packages/webob/dec.py", line 144, in __call__
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault return resp(environ, start_response)
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault File "/usr/lib/python2.7/site-packages/routes/middleware.py", line 131, in __call__
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault response = self.app(environ, start_response)
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault File "/usr/lib/python2.7/site-packages/webob/dec.py", line 144, in __call__
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault return resp(environ, start_response)
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault File "/usr/lib/python2.7/site-packages/webob/dec.py", line 130, in __call__
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault resp = self.call_func(req, *args, **self.kwargs)
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault File "/usr/lib/python2.7/site-packages/webob/dec.py", line 195, in call_func
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault return self.func(req, *args, **kwargs)
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault File "/opt/stack/new/cinder/cinder/api/openstack/wsgi.py", line 895, in __call__
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault content_type, body, accept)
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault File "/opt/stack/new/cinder/cinder/api/openstack/wsgi.py", line 943, in _process_stack
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault action_result = self.dispatch(meth, request, action_args)
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault File "/opt/stack/new/cinder/cinder/api/openstack/wsgi.py", line 1019, in dispatch
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault return method(req=request, **action_args)
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault File "/opt/stack/new/cinder/cinder/api/contrib/volume_type_encryption.py", line 128, in create
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault db.volume_type_encryption_create(context, type_id, encryption_specs)
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault File "/opt/stack/new/cinder/cinder/db/api.py", line 455, in volume_type_encryption_create
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault encryption_specs)
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault File "/opt/stack/new/cinder/cinder/db/sqlalchemy/api.py", line 119, in wrapper
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault return f(*args, **kwargs)
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault File "/opt/stack/new/cinder/cinder/db/sqlalchemy/api.py", line 2321, in volume_type_encryption_create
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault encryption.save(session=session)
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault File "/opt/stack/new/cinder/cinder/openstack/common/db/sqlalchemy/models.py", line 51, in save
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault session.flush()
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault File "/opt/stack/new/cinder/cinder/openstack/common/db/sqlalchemy/session.py", line 484, in _wrap
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault _raise_if_duplicate_entry_error(e, get_engine().name)
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault File "/opt/stack/new/cinder/cinder/openstack/common/db/sqlalchemy/session.py", line 436, in _raise_if_duplicate_entry_error
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault raise exception.DBDuplicateEntry(columns, integrity_error)
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault DBDuplicateEntry: (IntegrityError) (1062, "Duplicate entry 'e1667fc3-8f19-4a83-b9cf-114d8ed297a1' for key 'PRIMARY'") 'INSERT INTO encryption (created_at, updated_at, deleted_at, deleted, cipher, key_size, provider, control_location, volume_type_id) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)' (datetime.datetime(2014, 5, 6, 10, 54, 33, 795603), None, None, 0, None, None, 'foobar', 'front-end', 'e1667fc3-8f19-4a83-b9cf-114d8ed297a1')
2014-05-06 10:54:33.798 32003 TRACE cinder.api.middleware.fault

Tags: api
Revision history for this message
John Griffith (john-griffith) wrote :

this is expected behavior for the most part.

We do soft-deletes for a number of reasons, I don't know that recreating types that you deleted with the same name is all that common, but....

This is a good reason to push back towards using UUID as the unique indicator and NOT the name. I proposed doing just that a while back and received a lot of push-back, maybe we should take another look at that?

I'd propose that volume-types should behave like everything else in OpenStack and use UUID as the unique identifier and not the name. If you want to keep the ability to specify by name that's fine, and you could even just limit the check for unique name to "active" entries.

Changed in cinder:
status: New → Triaged
importance: Undecided → Low
Changed in cinder:
assignee: nobody → Juan Manuel Ollé (juan-m-olle)
Changed in cinder:
assignee: Juan Manuel Ollé (juan-m-olle) → nobody
Mike Perez (thingee)
tags: added: api
Ivan Kolodyazhny (e0ne)
Changed in cinder:
assignee: nobody → Ivan Kolodyazhny (e0ne)
Revision history for this message
Ivan Kolodyazhny (e0ne) wrote :

As I understand, the problem is here: https://github.com/openstack/cinder/blob/master/cinder/db/sqlalchemy/models.py#L494
volume_type_id field is a primary key

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/119026

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

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

commit a21979c1230edb80a08b3bdd6083b2b088cc6aa1
Author: Ivan Kolodyazhny <email address hidden>
Date: Thu Sep 4 13:24:12 2014 +0300

    Added UUID as primary key for Encryption model

    volume_type_id could not be used as PK because
    soft deletes are using for Encryption

    Change-Id: I5c4423da4442f2458417dc3492750412a74ebe09
    Closes-Bug: #1316540

Changed in cinder:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in cinder:
milestone: none → kilo-1
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in cinder:
milestone: kilo-1 → 2015.1.0
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.