Fix check+set race condition in APIv1/Sink
Change-Id: I02d22212511246f0c1b8138fa3413770cd5810a1
Closes-Bug: 1454262
(cherry picked from commit ef769bf960
)
This commit is contained in:
parent
05f6d2a45f
commit
219aa4bee5
|
@ -46,9 +46,7 @@ def _find_or_create_recordset(context, domain_id, name, type, ttl):
|
|||
central_api.find_domain(context, criterion=criterion)
|
||||
|
||||
try:
|
||||
recordset = _find_recordset(context, domain_id, name, type)
|
||||
except exceptions.RecordSetNotFound:
|
||||
# Create an empty recordset
|
||||
# Attempt to create an empty recordset
|
||||
values = {
|
||||
'name': name,
|
||||
'type': type,
|
||||
|
@ -58,6 +56,10 @@ def _find_or_create_recordset(context, domain_id, name, type, ttl):
|
|||
recordset = central_api.create_recordset(
|
||||
context, domain_id, objects.RecordSet(**values))
|
||||
|
||||
except exceptions.DuplicateRecordSet:
|
||||
# Fetch the existing recordset
|
||||
recordset = _find_recordset(context, domain_id, name, type)
|
||||
|
||||
return recordset
|
||||
|
||||
|
||||
|
|
|
@ -84,12 +84,7 @@ class NotificationHandler(ExtensionPlugin):
|
|||
def _find_or_create_recordset(self, context, domain_id, name, type,
|
||||
ttl=None):
|
||||
try:
|
||||
recordset = self.central_api.find_recordset(context, {
|
||||
'domain_id': domain_id,
|
||||
'name': name,
|
||||
'type': type,
|
||||
})
|
||||
except exceptions.RecordSetNotFound:
|
||||
# Attempt to create an empty recordset
|
||||
values = {
|
||||
'name': name,
|
||||
'type': type,
|
||||
|
@ -98,6 +93,14 @@ class NotificationHandler(ExtensionPlugin):
|
|||
recordset = self.central_api.create_recordset(
|
||||
context, domain_id, RecordSet(**values))
|
||||
|
||||
except exceptions.DuplicateRecordSet:
|
||||
# Fetch the existing recordset
|
||||
recordset = self.central_api.find_recordset(context, {
|
||||
'domain_id': domain_id,
|
||||
'name': name,
|
||||
'type': type,
|
||||
})
|
||||
|
||||
return recordset
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue