Skip to content

Make redis-based locking mechanism fully multithreaded #325

Closed

Description

@jvherweg

We want to have a multithreaded locking mechanism based on a redis backend. redlock seems to be a good candidate for this.

UPDATE: see #325 (comment) below.

Activity

  1. self-assigned this
    on Mar 10, 2021
  2. BelgianNoise commented on Mar 10, 2021

    @BelgianNoise
    Member

    @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?

  3. RubenVerborgh commented on Mar 10, 2021

    @RubenVerborgh
    Member

    Do we want to spin up a Redis server every time we run the tests?

    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.)

  4. RubenVerborgh commented on Mar 10, 2021

    @RubenVerborgh
    Member

    Great news BTW 🥳

  5. BelgianNoise commented on Mar 10, 2021

    @BelgianNoise
    Member

    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?

  6. RubenVerborgh commented on Mar 10, 2021

    @RubenVerborgh
    Member

    How does this effect the test coverage?

    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.

  7. linked a pull request that will close this issuefeat: redis based locking mechanism #662on Mar 10, 2021
  8. BelgianNoise commented on Mar 12, 2021

    @BelgianNoise
    Member

    NOTE:

    3 main issues with Redlock:

    1. Redlock really wants to handle expiration of locks itself
    2. Locks can only be released by the instance that initially acquired/set the lock (feat: redis based locking mechanism #662 (comment))
    3. No easy/lightweight way to check if a lock has expired (feat: redis based locking mechanism #662 (comment))

    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() and releae()).

  9. RubenVerborgh commented on Mar 12, 2021

    @RubenVerborgh
    Member
  10. woutermont commented on Mar 13, 2021

    @woutermont
    Contributor

    @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.

  11. jvherweg commented on Mar 15, 2021

    @jvherweg
    MemberAuthor

    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).

  12. jvherweg commented on Apr 19, 2021

    @jvherweg
    MemberAuthor

    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.

  13. removed
    good first issue
    on Apr 19, 2021
  14. changed the title [-]Create redis-based multithreaded locking mechanism[/-] [+]Make redis-based locking mechanism fully multithreaded[/+] on Apr 19, 2021
  15. added
    🐜 worker threads
    on May 5, 2021
  16. self-assigned this
    on Mar 28, 2022
  17. jvherweg commented on Apr 19, 2022

    @jvherweg
    MemberAuthor

    Done in #1263

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🐜 worker threads➕ feature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions