Closed p4u closed 4 years ago
Hello! Thanks for giving us a heads up on this. We'll take a look ASAP.
Thanks for the quick reply @tessr
That could be a data race in our side. We are investigating it... we'll report more information once available.
Yeah, I don't believe IAVL is concurrency-safe (although I'm not 100% sure), so if the application is making concurrent accesses - in particular writes - then I believe you'd see problems like this under load. Are you using IAVL concurrently? Do you see the same problems if you put an RWMutex
around it?
We are using a RWMutex already:
However we suspect that the fact that we do use pointers
app.State.IAppTree = app.State.AppTree.ImmutableTree
Could raise a data race when app.State.AppTree changes.
Ah - yes, I think that might be a cause. Let us know what you find, and if there's a problem with IAVL itself it would be very helpful with a minimal reproducible case.
@erikgrinaker just to double check - if one is running write operations on the mutable tree, such as tree.Set
, it's not safe to concurrently call read operations on its immutable tree, such as tree.ImmutableTree.Get
. I assume this is the case because, from reading your code, I can see that a mutable tree operation can modify the immutable tree, such as modifying the immutable tree's root node.
If the above is correct, then it's very probably a data race on our side. We do have a mutex guarding the immutable tree, like @p4u mentioned, but the write operations on the mutable tree aren't guarded by the same mutex. So we might end up calling tree.Set
and tree.ImmutableTree.Get
concurrently.
I'm not too familiar with the details here, but that would not surprise me - for example when removing orphan nodes or pruning old versions. To be safe, I would use a mutex for all operations against the entire IAVL store.
We should really specify the exact concurrency semantics for IAVL, and maybe down the line implement some form of concurrency control.
Thanks - sounds good with me. I was going to suggest that the docs be clarified a bit, for now. The immutable tree does say Note that this tree is not thread-safe.
, but we didn't understand that to also mean operations on the parent mutable tree.
For sure, we should clarify what the intended behavior here is. It is sort of unintuitive that an immutable tree is, well, mutable.
Yes, that's a good point. I think that's what caused confusion for us - the ImmutableTree name seems to imply that it's a completely immutable and static snapshot of a tree, when it's not. It's meant for immutable use, but it itself is not immutable.
I'll close this for now, but do let us know if you still see problems even with a mutex around all operations.
So I can confirm that the issue was in our side due a data race.
It's also fixed in our side and after running several benchmarks, no Panic found.
Thanks for your time and help @erikgrinaker
When performing a benchmark under high load operation, IAVL panics. We have seen this error on different servers and many times already. Looks like there is something missing on the IAVL tree, but not sure what. After re-launching the program everything goes back to normal and IAVL works fine.