Commit 6f2d7cbc authored by Edwin Zhai's avatar Edwin Zhai

Fix event_type creationg failure due to race condition

Race condition exists when 2 threads try to create same event_type, so
need detect it and load the event_type again.

Change-Id: If3439817cfbfef90daeb5975338909f8312864c4
Closes-Bug: #1254800
parent 477702dd
......@@ -155,14 +155,18 @@ class Connection(base.Connection):
If not, we create it and return the record. This may result in a flush.
"""
if session is None:
session = self._engine_facade.get_session()
with session.begin(subtransactions=True):
et = session.query(models.EventType).filter(
models.EventType.desc == event_type).first()
if not et:
et = models.EventType(event_type)
session.add(et)
try:
if session is None:
session = self._engine_facade.get_session()
with session.begin(subtransactions=True):
et = session.query(models.EventType).filter(
models.EventType.desc == event_type).first()
if not et:
et = models.EventType(event_type)
session.add(et)
except dbexc.DBDuplicateEntry:
et = self._get_or_create_event_type(event_type, session)
return et
def record_events(self, event_models):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment