From 7f30777b875e69151791d51ad69d2a665580e078 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Fri, 8 Aug 2008 11:20:38 +0000 Subject: [PATCH] noded: Add decorator for job queue lock The lock will also be needed by another function. Reviewed-by: iustinp --- daemons/ganeti-noded | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/daemons/ganeti-noded b/daemons/ganeti-noded index 79116ffa8..31a74d5e5 100755 --- a/daemons/ganeti-noded +++ b/daemons/ganeti-noded @@ -48,6 +48,22 @@ from ganeti import utils queue_lock = None +def _RequireJobQueueLock(fn): + """Decorator for job queue manipulating functions. + + """ + def wrapper(*args, **kwargs): + # Locking in exclusive, blocking mode because there could be several + # children running at the same time. + # TODO: Implement nonblocking locking with retries? + queue_lock.Exclusive(blocking=True) + try: + return fn(*args, **kwargs) + finally: + queue_lock.Unlock() + return wrapper + + class NodeDaemonRequestHandler(http.HTTPRequestHandler): """The server implementation. @@ -538,20 +554,13 @@ class NodeDaemonRequestHandler(http.HTTPRequestHandler): new_file_storage_dir) @staticmethod + @_RequireJobQueueLock def perspective_jobqueue_update(params): """Update job queue. """ (file_name, content) = params - - # Locking in exclusive, blocking mode because there could be several - # children running at the same time. - # TODO: Implement nonblocking locking with retries? - queue_lock.Exclusive(blocking=True) - try: - return backend.JobQueueUpdate(file_name, content) - finally: - queue_lock.Unlock() + return backend.JobQueueUpdate(file_name, content) @staticmethod def perspective_jobqueue_purge(params): -- GitLab