Open golopot opened 2 weeks ago
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 createIndex
as a Lua script. When running concurrently, a latter call will early return at the compare hash step.
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: