-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add a Redis based Read-Write Locker #1263
Conversation
Locally after setting the environment variable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not really sure about how to fit this into the
WrappedExpiringReadWriteLocker
.
Not sure what you mean. The WrappedExpiringReadWriteLocker
takes as input a ReadWriteLocker
so this should work fine with this new locker right?
I was under the impression that this was preferrable to allow for an external way to expire keys (e.g. with that WrappedExpiringReadWriteLocker).
That's fine for me.
As an aside, how much effort would it be to make the RedisResourceLocker
thread safe using the same method as is used here? Might it perhaps be possible to even merge these two into a single class that implements both ReadWriteLocker
and ResourceLocker
? Because it feels a bit much now that we have 2 different redis locker classes that are quite similar.
To be honest, the way RedisResourceLocker works, by using the redlock library and saving the returned Lock object in memory, it is hard to make it multi-process-safe. What I can do however is adapt my solution to also implement ResourceLocker. This has some implications:
|
Yes I meant removing the Redlock references and using Lua like you already do in the new solution. Which comes down to your suggestion of adapting your solution. |
@joachimvh Do you have any idea why the integration (linux) tests are not working on here? I can execute them in a WSL2 (ubuntu) shell with a redis docker service on my pc.. |
I have no idea tbh. Might be an issue with the redis instance set up by the github actions in that the latest It also seems that your new integration tests succeed and only the previous class fails, so maybe a Redlock case? But that class can be removed once Would also rename the class to |
Ok, that was my next plan. Getting the old one out and replacing with a RedisLocker. I will squash everything in one commit then and see if the intergration test is fixed. |
1bd56c8
to
b2a595b
Compare
I've merged the 2 Redis integration tests into 1. I also added a section that tests the lua scripts themselves. |
b8430da
to
121d612
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, I like the improvements. All comments are mostly minor/styling issues.
b68b45f
to
c937b96
Compare
c937b96
to
16631ab
Compare
refactor: more elegant way of providing default attemptSettings to constructor style(jsdoc): rewording of jsdoc comment fix: RegExp(/regex/) => /regex/ fix: Replace Error with InternalServerError docs: jsdoc for RedisReadWriteLocker class feat: make RedisReadWriteLocker a ResourceLocker too test: coverage back to 100% refactor: linting fix style(jsdoc): Add explanation to tryRedisFn() method refactor: remove RedisResourceLocker fix: bug in lua script chore(deps): update ioredis, remove redlock refactor: removed RedisResourceLocker in favor of generic RedisLocker class test: add redis lua scripts tests and integrate all 3 redis integration tests in 1 refactor: remove .vscode folder from index refactor: Add some typing and change redis references to Redis in comments refactor: more changes after PR review refactor: remove redis.json refactor: rename redis-rw.json to redis.json docs: added readme and release notes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
📁 Related issues
#325
✍️ Description
This PR introduces a Redis-based Locker that implements the Read Write locking algorithm. This implementation abides to the following rules:
Files
src/util/locking
src/util/locking/scripts
config/util/resource-locker
test/unit/util/locking
test/integration
test/integration/config
Remarks
I am not really sure about how to fit this into the
WrappedExpiringReadWriteLocker
. Right now the RedisReadWriteLocker is implemented with non-expiring keys (I can configure the lua scripts to make the keys auto-expire if needed, but they don't right now). I was under the impression that this was preferrable to allow for an external way to expire keys (e.g. with that WrappedExpiringReadWriteLocker). I might need to do more changes to support this though.I had to update the
ioredis
package, so that is way I made some small changes to the existing RedisResourceLocker class.✅ PR check list
Before this pull request can be merged, a core maintainer will check whether