Nir Soffer has uploaded a new change for review.
Change subject: rwlock: Support non-blocking acquire ......................................................................
rwlock: Support non-blocking acquire
This patch adds non-blocking acquire suggested in https://gerrit.ovirt.org/42773. This is a simpler alternative to timed acquire, suggested in https://gerrit.ovirt.org/42909.
Change-Id: Iec721a07087349050bfe9aa11aacf3be9695fb85 Signed-off-by: Nir Soffer nsoffer@redhat.com --- M lib/vdsm/rwlock.py M tests/rwlock_test.py 2 files changed, 30 insertions(+), 48 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/28/42928/1
diff --git a/lib/vdsm/rwlock.py b/lib/vdsm/rwlock.py index c6ce1ea..2281851 100644 --- a/lib/vdsm/rwlock.py +++ b/lib/vdsm/rwlock.py @@ -32,17 +32,23 @@ self._readers = set() self._writer = None
- def acquireWrite(self): + def acquireWrite(self, block=True): with self._lock: if self._writer or self._readers or self._waiters: + if not block: + return False self._wait(True) self._writer = threading.current_thread() + return True
- def acquireRead(self): + def acquireRead(self, block=True): with self._lock: if self._writer or self._waiters: + if not block: + return False self._wait(False) self._readers.add(threading.current_thread()) + return True
def release(self): me = threading.current_thread() diff --git a/tests/rwlock_test.py b/tests/rwlock_test.py index 1c28f26..7ef5aa6 100644 --- a/tests/rwlock_test.py +++ b/tests/rwlock_test.py @@ -121,54 +121,30 @@ for t in threads: t.stop()
- @slowtest - def test_shared_context_blocks_writer(self): - lock = RWLock() - writer = RWThread(lock.exclusive) - try: - with lock.shared: - writer.start() - if not writer.ready.wait(2): - raise RuntimeError("Timeout waiting for writer thread") - # Writer must block - self.assertFalse(writer.acquired.wait(1)) - finally: - writer.stop() - - def test_shared_context_allows_reader(self): - lock = RWLock() - with lock.shared: - reader = RWThread(lock.shared) - with utils.running(reader): - self.assertTrue(reader.acquired.wait(1)) - - @slowtest - def test_exclusive_context_blocks_writer(self): - lock = RWLock() - writer = RWThread(lock.exclusive) - try: - with lock.exclusive: - writer.start() - if not writer.ready.wait(2): - raise RuntimeError("Timeout waiting for writer thread") - # Reader must block - self.assertFalse(writer.acquired.wait(1)) - finally: - writer.stop() - - @slowtest - def test_exclusive_context_blocks_reader(self): + def test_reader_blocks_writer(self): lock = RWLock() reader = RWThread(lock.shared) - try: - with lock.exclusive: - reader.start() - if not reader.ready.wait(2): - raise RuntimeError("Timeout waiting for reader thread") - # Reader must block - self.assertFalse(reader.acquired.wait(1)) - finally: - reader.stop() + with utils.running(reader): + if not reader.acquired.wait(2): + raise RuntimeError("Timeout waiting for reader thread") + self.assertFalse(lock.acquireWrite(block=False)) + + def test_writer_blocks_writer(self): + lock = RWLock() + writer = RWThread(lock.exclusive) + with utils.running(writer): + if not writer.acquired.wait(2): + raise RuntimeError("Timeout waiting for writer thread") + self.assertFalse(lock.acquireWrite(block=False)) + + + def test_writer_blocks_reader(self): + lock = RWLock() + writer = RWThread(lock.exclusive) + with utils.running(writer): + if not writer.acquired.wait(2): + raise RuntimeError("Timeout waiting for writer thread") + self.assertFalse(lock.acquireRead(block=False))
@expandPermutations
automation@ovirt.org has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 1:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
automation@ovirt.org has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 2:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
automation@ovirt.org has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 3:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
automation@ovirt.org has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 4:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
Nir Soffer has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 4:
Manual rebase, no change in behavior.
automation@ovirt.org has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 5:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
automation@ovirt.org has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 6:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
Nir Soffer has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 6:
This version add the missing documentation.
automation@ovirt.org has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 7:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
automation@ovirt.org has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 8:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
automation@ovirt.org has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 9:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
Adam Litke has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 9:
(2 comments)
https://gerrit.ovirt.org/#/c/42928/9/lib/vdsm/rwlock.py File lib/vdsm/rwlock.py:
Line 91 Line 92 Line 93 Line 94 Line 95 return True?
https://gerrit.ovirt.org/#/c/42928/9/tests/rwlock_test.py File tests/rwlock_test.py:
Line 200 Line 201 Line 202 Line 203 Line 204 Maybe test the positive flow to catch the bug I mentioned in my other comment. Make sure non-blocking acquire returns true.
automation@ovirt.org has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 10:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
Nir Soffer has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 9:
(2 comments)
https://gerrit.ovirt.org/#/c/42928/9/lib/vdsm/rwlock.py File lib/vdsm/rwlock.py:
Line 91 Line 92 Line 93 Line 94 Line 95
return True?
Look in line 115 (the diff is confusing).
https://gerrit.ovirt.org/#/c/42928/9/tests/rwlock_test.py File tests/rwlock_test.py:
Line 200 Line 201 Line 202 Line 203 Line 204
Maybe test the positive flow to catch the bug I mentioned in my other comme
I don't think here is a bug, but test for True is required.
Nir Soffer has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 10: Verified+1
Adam Litke has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 9:
(2 comments)
https://gerrit.ovirt.org/#/c/42928/9/lib/vdsm/rwlock.py File lib/vdsm/rwlock.py:
Line 91 Line 92 Line 93 Line 94 Line 95
Look in line 115 (the diff is confusing).
ahh, indeed.
https://gerrit.ovirt.org/#/c/42928/9/tests/rwlock_test.py File tests/rwlock_test.py:
Line 200 Line 201 Line 202 Line 203 Line 204
I don't think here is a bug, but test for True is required.
Agreed: No bug, but a test would be appropriate.
automation@ovirt.org has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 11:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
Nir Soffer has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 11: Verified+1
Nir Soffer has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 9:
(1 comment)
https://gerrit.ovirt.org/#/c/42928/9/tests/rwlock_test.py File tests/rwlock_test.py:
Line 200 Line 201 Line 202 Line 203 Line 204
Agreed: No bug, but a test would be appropriate.
Added in version 11
automation@ovirt.org has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 12:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
automation@ovirt.org has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 13:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
automation@ovirt.org has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 14:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
Nir Soffer has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 14: Verified+1
automation@ovirt.org has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 15:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
automation@ovirt.org has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 16:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
Nir Soffer has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 16: Code-Review+1
Nir Soffer has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 16: -Code-Review
Adam Litke has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 16: Code-Review+1
automation@ovirt.org has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 17:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
Nir Soffer has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 17: Verified+1
automation@ovirt.org has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 18:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
automation@ovirt.org has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 19:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
Nir Soffer has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 19: Verified+1
automation@ovirt.org has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 20:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
Ido Barkan has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 20: Code-Review+1
Ido Barkan has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 20:
can we just drop this patch and use the next one?
automation@ovirt.org has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 21:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
automation@ovirt.org has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 22:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
automation@ovirt.org has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 23:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
automation@ovirt.org has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 24:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
Nir Soffer has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 24:
Manual rebase, no code change.
Nir Soffer has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 24: Verified+1
gerrit-hooks has posted comments on this change.
Change subject: rwlock: Support non-blocking acquire ......................................................................
Patch Set 25:
* Update tracker: IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.6', 'ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
vdsm-patches@lists.fedorahosted.org