From 40e749598bbd504f018d56e6773d80eaff5a3624 Mon Sep 17 00:00:00 2001 From: zhangsong Date: Thu, 16 Mar 2017 13:00:02 +0800 Subject: [PATCH] FileDriver:Support multiple processes The interprocess file-lock is not really released when user call FileLock.release() method. So the second process will be blocked when it try to acquire a lock which has been 'released' by the first process until the first process is exited. This lead to current filelock don't support multiple processes. This patch fixed this problem. Closes-Bug: #1665897 Change-Id: I3d4331a400dd551fa97cada2d7af9415fda720da --- tooz/drivers/file.py | 1 + tooz/tests/test_coordination.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/tooz/drivers/file.py b/tooz/drivers/file.py index e28c7e62..96333c11 100644 --- a/tooz/drivers/file.py +++ b/tooz/drivers/file.py @@ -155,6 +155,7 @@ class FileLock(locking.Lock): with self._barrier.cond: self.acquired = False self._barrier.owner = None + self._lock.release() self._barrier.cond.notify_all() return True diff --git a/tooz/tests/test_coordination.py b/tooz/tests/test_coordination.py index a45c0dc6..74a74b17 100644 --- a/tooz/tests/test_coordination.py +++ b/tooz/tests/test_coordination.py @@ -743,10 +743,26 @@ class TestAPI(tests.TestWithCoordinator): tests.get_random_uuid()) self.assertFalse(f.result()) + def _do_test_get_lock_serial_locking_two_lock(self, executor, + use_same_coord): + name = tests.get_random_uuid() + lock1 = self._coord.get_lock(name) + lock1.acquire() + lock1.release() + with executor(max_workers=1) as e: + coord = self._coord if use_same_coord else None + f = e.submit(try_to_lock_job, name, coord, self.url, + tests.get_random_uuid()) + self.assertTrue(f.result()) + def test_get_lock_concurrency_locking_two_lock_process(self): self._do_test_get_lock_concurrency_locking_two_lock( futures.ProcessPoolExecutor, False) + def test_get_lock_serial_locking_two_lock_process(self): + self._do_test_get_lock_serial_locking_two_lock( + futures.ProcessPoolExecutor, False) + def test_get_lock_concurrency_locking_two_lock_thread1(self): self._do_test_get_lock_concurrency_locking_two_lock( futures.ThreadPoolExecutor, False)