designate/designate
Takahito Hirose f828654a3d Fix DBDeadLock error resulting into 500
When user requests the record registration request continuously,
sometimes designate hits DBDeadLock resuting into 500 InternalServerError.

We get below error:

2019-02-21 21:30:39.925 49752 ERROR designate.api.middleware RemoteError:
Remote error: DBDeadlock (pymysql.err.InternalError)
(1213, u'Deadlock found when trying to get lock; try restarting transaction')
[SQL: u'UPDATE records SET version=(records.version + %(version_1)s),
updated_at=%(updated_at)s, data=%(data)s, hash=%(hash)s, status=%(status)s,
action=%(action)s, serial=%(serial)s WHERE records.id = %(id_1)s']
[parameters: {'status': 'PENDING', 'hash': '39795ee18c6e3c9ad1c0190c6a3d8d4f',
'updated_at': datetime.datetime(2019, 2, 21, 12, 30, 39, 909846), u'version_1': 1,
u'id_1': '7a655eeda4d446cdaa81caf19ab55fcc', 'action': 'UPDATE',
'serial': 1550752338,
'data': u'ns2.example.jp. domain.example.com. 1550752338 3552 600 86400 3600'}]

In the process of record registeration, designate first tried to update
the reocrd and then update the zone status.

Updating the zone_status and registering the record process[1] and after synced
update record_status and zone_status process[2] are in reverse order. So If user
request the registering record many time and same time, Designate will get the
DBDeadLock, when these processes run the same time.

We observed that changing the order of the operations solves this issue.

[1] https://github.com/openstack/designate/blob/master/designate/central/service.py#L1292-L1320
[2] https://github.com/openstack/designate/blob/master/designate/central/service.py#L2310-L2322

1. transaction [1]-1 updating zone status process <- run    ---> table_name-zone
2. transaction [2]-1 updating record status process <- run  ---> table_name-record
3. transaction [1]-2 registering record process <- run and wait  ---> table_name-record
4. transaction [2]-2 updating zone process <-deadlock!           ---> table_name-zone

Change-Id: Icd6e690ac84a2fe0db0f4a8a513de47f7916f5ea
Related-Bug: #1785459
2019-03-27 20:27:30 +09:00
..
agent Fixing Python 3.x issues introduced with eventlet update 2018-09-15 05:51:03 +00:00
api Use oslo_serialization instead of the json module directly 2019-01-18 14:22:04 -08:00
backend Allow pdns4 backend to select tsigkey 2019-03-22 09:11:41 +00:00
central Fix DBDeadLock error resulting into 500 2019-03-27 20:27:30 +09:00
cmd Add designate-status command for upgrade checks 2018-12-07 21:53:17 +00:00
common Verify project-id when setting quota 2018-07-05 08:46:37 +00:00
hacking Remove Hacking check for log translation 2018-02-15 15:31:34 +00:00
locale/en_GB/LC_MESSAGES Imported Translations from Zanata 2018-09-12 07:46:55 +00:00
manage Merge "Remove translation of log messages" 2018-03-20 20:01:50 +00:00
mdns Modernized RPC impl and fixed service tests 2019-03-09 13:54:58 -08:00
metrics_client Remove translation of log messages 2018-03-14 12:54:05 -07:00
network_api Fixing Python 3.x issues introduced with eventlet update 2018-09-15 05:51:03 +00:00
notification_handler Removed deprecated managed option in notification handler 2018-07-21 23:33:41 -07:00
objects CAA DNS records 2018-11-07 16:08:01 +00:00
pool_manager Remove translation of log messages 2018-03-14 12:54:05 -07:00
producer Replace StopIteration with return for PEP 0479 2018-07-17 12:07:57 -04:00
quota Remove translation of log messages 2018-03-14 12:54:05 -07:00
resources Remove v1 API 2018-01-11 14:13:43 +00:00
scheduler Merge "Remove translation of log messages" 2018-03-20 20:01:50 +00:00
schema Remove v1 API 2018-01-11 14:13:43 +00:00
sink Modernized RPC impl and fixed service tests 2019-03-09 13:54:58 -08:00
sqlalchemy Remove translation of log messages 2018-03-14 12:54:05 -07:00
storage nit: remove downgrade methods and add release note 2019-01-17 16:14:26 +00:00
tests Fix DBDeadLock error resulting into 500 2019-03-27 20:27:30 +09:00
worker Set worker model to be the default 2019-03-06 12:37:16 +00:00
__init__.py CAA DNS records 2018-11-07 16:08:01 +00:00
context.py Verify project-id when setting quota 2018-07-05 08:46:37 +00:00
coordination.py Remove translation of log messages 2018-03-14 12:54:05 -07:00
debug.py Update email addresses hp.com to hpe.com 2016-01-11 14:29:33 +00:00
dnsutils.py Modernized RPC impl and fixed service tests 2019-03-09 13:54:58 -08:00
exceptions.py Modernized RPC impl and fixed service tests 2019-03-09 13:54:58 -08:00
hookpoints.py Trivial fix pep8 and typos 2017-05-06 03:30:23 +07:00
i18n.py Update email addresses hp.com to hpe.com 2016-01-11 14:29:33 +00:00
loggingutils.py Add Decorator to log RPCAPI Calls 2016-04-21 14:11:35 +01:00
metrics.py Remove translation of log messages 2018-03-14 12:54:05 -07:00
notifications.py Remove translation of log messages 2018-03-14 12:54:05 -07:00
opts.py Verify project-id when setting quota 2018-07-05 08:46:37 +00:00
plugin.py Remove translation of log messages 2018-03-14 12:54:05 -07:00
policy.py Remove translation of log messages 2018-03-14 12:54:05 -07:00
rpc.py Modernized RPC impl and fixed service tests 2019-03-09 13:54:58 -08:00
service.py Enable mutable config in designate 2018-07-26 02:08:17 +05:30
service_status.py Auto-generate designate.conf.sample via genconfig testenv 2017-07-01 21:32:16 +07:00
utils.py Use oslo_serialization instead of the json module directly 2019-01-18 14:22:04 -08:00
version.py Switch to oslo.reports 2015-11-05 10:55:29 +01:00