-
Notifications
You must be signed in to change notification settings - Fork 81
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
repository.createIndex is not safe for concurrent use #254
Comments
This makes sense. Redis itself creates the indices asynchronously. If you call FT.CREATE in rapid succession from Node Redis, or perhaps even from redis-cli itself, I would expect the same error. I can code around this, but it will require me to ask Redis before each index creation if the index creation is already in progress or not. So, I'll need to think about how to do it in a way that doesn't negatively impact performance. |
I think it can be solved by rewriting redis-om-node/lib/repository/repository.ts Lines 66 to 103 in 6f08d02
|
Scripts can get messy when we start dealing with clustered environments. Here's what I'm thinking:
The flaw here is that if two bits of code are changing the same index with different schemas, then Redis could get into a weird state where the hash and the index don't match. This should be exceedingly rare and would be easy to fix by deleting the hash in Redis and calling createIndex again. It might even be worthwhile to add a flag to createIndex that allows you to force this behavior. |
When repository.createIndex is called multiple times concurrently, it might throw an exception
[ErrorReply: Index already exists]
. This happens when test runner run app init code concurrently.Another problem is that the thrown exception should be an
Error
.Reproduction:
The text was updated successfully, but these errors were encountered: