summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2022-03-23 01:00:03 +0000
committerGerrit Code Review <review@openstack.org>2022-03-23 01:00:03 +0000
commit91ee8776f0de6940581d0027e10d88a5a315fb5b (patch)
treeb86e933e01599667e2e5bda681d1586b3f0f2257
parenta72c661eb031ab9eb880c36a792be003e6a5c193 (diff)
parenta03d9fc3970a4812ac2e1c2c3f4d4cdf41ff9825 (diff)
downloadzuul-91ee8776f0de6940581d0027e10d88a5a315fb5b.tar.gz
Merge "Perform per tenant locking in getStatus"
-rwxr-xr-xzuul/web/__init__.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/zuul/web/__init__.py b/zuul/web/__init__.py
index d12f8835e..7281f3b42 100755
--- a/zuul/web/__init__.py
+++ b/zuul/web/__init__.py
@@ -364,7 +364,7 @@ class ZuulWebAPI(object):
self.cache_time = {}
self.cache_expiry = 1
self.static_cache_expiry = zuulweb.static_cache_expiry
- self.status_lock = threading.Lock()
+ self.status_lock = defaultdict(threading.Lock)
@property
def log(self):
@@ -991,12 +991,21 @@ class ZuulWebAPI(object):
def _getStatus(self, tenant_name):
tenant = self._getTenantOrRaise(tenant_name)
- with self.status_lock:
- if tenant not in self.cache or \
- (time.time() - self.cache_time[tenant]) > self.cache_expiry:
- self.cache[tenant_name] = self.formatStatus(tenant)
- self.cache_time[tenant_name] = time.time()
-
+ if tenant_name not in self.cache or \
+ (time.time() - self.cache_time[tenant_name]) > self.cache_expiry:
+ if self.status_lock[tenant_name].acquire(blocking=False):
+ try:
+ self.cache[tenant_name] = self.formatStatus(tenant)
+ self.cache_time[tenant_name] = time.time()
+ finally:
+ self.status_lock[tenant_name].release()
+ if not self.cache.get(tenant_name):
+ # If the cache is empty at this point it means that we didn't
+ # get the lock but another thread is initializing the cache
+ # for the first time. In this case we just wait for the lock
+ # to wait for it to finish.
+ with self.status_lock[tenant_name]:
+ pass
payload = self.cache[tenant_name]
resp = cherrypy.response
resp.headers["Cache-Control"] = f"public, max-age={self.cache_expiry}"