From 8b7c41171e0d323c415f2f47bc220bd63f709f86 Mon Sep 17 00:00:00 2001 From: Duc Truong Date: Tue, 29 Jan 2019 22:52:06 +0000 Subject: [PATCH] Catch DBDuplicateEntry when locking cluster Catch and log DBDuplicateEntry exception when acquiring cluster lock. This exception is not fatal so we should let the engine try to acquire the lock again at a later time. Change-Id: I7a2923cb1bd18812991a310084b1b35592767b9c --- senlin/engine/senlin_lock.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/senlin/engine/senlin_lock.py b/senlin/engine/senlin_lock.py index 23d1eb422..3657483e6 100644 --- a/senlin/engine/senlin_lock.py +++ b/senlin/engine/senlin_lock.py @@ -15,6 +15,7 @@ import random import time from oslo_config import cfg +from oslo_db import exception from oslo_log import log as logging from senlin.common.i18n import _ @@ -56,9 +57,14 @@ def cluster_lock_acquire(context, cluster_id, action_id, engine=None, # Step 1: try lock the cluster - if the returned owner_id is the # action id, it was a success for retries in range(3): - owners = cl_obj.ClusterLock.acquire(cluster_id, action_id, scope) - if action_id in owners: - return True + try: + owners = cl_obj.ClusterLock.acquire(cluster_id, action_id, scope) + if action_id in owners: + return True + except exception.DBDuplicateEntry: + LOG.info('Duplicate entry in cluster_lock table for %(c)s. ' + 'Retrying cluster lock.', + {'c': cluster_id}) eventlet.sleep(random.randrange(1, 3)) # Step 2: Last resort is 'forced locking', only needed when retry failed