You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make redis-based locking mechanism fully multithreaded #325
@joachimvh I have implemented the Redis locking mechanism and am now trying to write tests for this class.
I was trying to mock a Redlock instance to not need a running Redis server.
I found this issue: mike-marcacci/node-redlock#54
Do we want to spin up a Redis server every time we run the tests?
I added the describeIf('docker'.. as you suggested.
How does this effect the test coverage? How do i tell jest to not care about coverage for that file when the tests don't run?
It should not; the unit test should not use Redis (use Jest mocks), and it's only the unit tests that count for 100% coverage.
The integration test should use Redis, and that doesn't count for coverage.
@RubenVerborgh, which of the three issues would atomicity address? The lock check? Trying to acquire a lock should be a good enough indication for all practical purposes (since only the availability of the lock is of real interest to a process).
As for the second point (releasing locks acquired by other processes), I can't image the scenario there.
The first issue is therefore the only problem i.m.o, and can probably be solved by implementing it similar to the ExpiringReadWriteLocker.
For the multiple process I refer to my comment at #662 (comment)
The problem is that the current locking interfaces were written with the idea that a ResourceLocker would be a simple implementation which could then be used by a ReadWriteLocker implementation for an actual read/write algorithm. And then we could wrap it in an ExpiringReadWriteLocker if we want the locks to expire. So if a ResourceLocker on its own already starts to expire some changes would be needed there.
One solution could be to simply expect all our locks to support expiration. It would narrow some of the possibilities but perhaps it's not bad to always have expiring locks. There might be better solutions though. But even then we still would really like to know when a lock expires (since that usually means something went wrong).
We now have a Redis-based solution as made in #662. As seen from the comments above this partially works in a multithreaded environment: multiple threads can't lock the same resource, but thread A can't unlock a lock made in thread B. This means we can't use an actual read/write locking algorithm with this implementation. We can use the EqualReadWriteLocker with it though.
If we want a fully multithreaded solution in the future we might have to look into writing our own "redlock" library.
Activity
BelgianNoise commentedon Mar 10, 2021
@joachimvh I have implemented the Redis locking mechanism and am now trying to write tests for this class.
I was trying to mock a Redlock instance to not need a running Redis server.
I found this issue: mike-marcacci/node-redlock#54
Do we want to spin up a Redis server every time we run the tests?
RubenVerborgh commentedon Mar 10, 2021
No, let's do the same a we do for the SPARQL endpoint integration tests.
(Skip them unless a flag is set; run on Docker in CI.)
RubenVerborgh commentedon Mar 10, 2021
Great news BTW 🥳
BelgianNoise commentedon Mar 10, 2021
I added the describeIf('docker'.. as you suggested.
How does this effect the test coverage? How do i tell jest to not care about coverage for that file when the tests don't run?
RubenVerborgh commentedon Mar 10, 2021
It should not; the unit test should not use Redis (use Jest mocks), and it's only the unit tests that count for 100% coverage.
The integration test should use Redis, and that doesn't count for coverage.
BelgianNoise commentedon Mar 12, 2021
NOTE:
3 main issues with Redlock:
Minor remark: Saving a Lock locally to release it later is not the way it was intended to be used(This is needed to work with
acquire()andreleae()).RubenVerborgh commentedon Mar 12, 2021
Redis itself does support atomicity though. So it should be possible.
https://www.npmjs.com/package/redis#optimistic-locks
woutermont commentedon Mar 13, 2021
@RubenVerborgh, which of the three issues would atomicity address? The lock check? Trying to acquire a lock should be a good enough indication for all practical purposes (since only the availability of the lock is of real interest to a process).
As for the second point (releasing locks acquired by other processes), I can't image the scenario there.
The first issue is therefore the only problem i.m.o, and can probably be solved by implementing it similar to the
ExpiringReadWriteLocker.jvherweg commentedon Mar 15, 2021
For the multiple process I refer to my comment at #662 (comment)
The problem is that the current locking interfaces were written with the idea that a
ResourceLockerwould be a simple implementation which could then be used by aReadWriteLockerimplementation for an actual read/write algorithm. And then we could wrap it in anExpiringReadWriteLockerif we want the locks to expire. So if aResourceLockeron its own already starts to expire some changes would be needed there.One solution could be to simply expect all our locks to support expiration. It would narrow some of the possibilities but perhaps it's not bad to always have expiring locks. There might be better solutions though. But even then we still would really like to know when a lock expires (since that usually means something went wrong).
jvherweg commentedon Apr 19, 2021
We now have a Redis-based solution as made in #662. As seen from the comments above this partially works in a multithreaded environment: multiple threads can't lock the same resource, but thread A can't unlock a lock made in thread B. This means we can't use an actual read/write locking algorithm with this implementation. We can use the
EqualReadWriteLockerwith it though.If we want a fully multithreaded solution in the future we might have to look into writing our own "redlock" library.
[-]Create redis-based multithreaded locking mechanism[/-][+]Make redis-based locking mechanism fully multithreaded[/+]jvherweg commentedon Apr 19, 2022
Done in #1263