Background vector indexing correctness
Author: dranikpgCreated Mar 24, 2026Updated Sep 30, 2026
Labelsstale
- Previosuly all indexing was synchronous under a transaction lock.
void FtCreate() {
Hop({
for (key : table->traverse())
Add(key)
})
}- I introduced IndexBuilder https://github.com/dragonflydb/dragonfly/pull/6504 that allows indexing in the background by iterating with Traverse in a separate fiber. It doesn't use transactional locking and relies on the fact that adding to the classic index is a non-suspendable operation
Fiber({
for (key : table->traverse()) {
Add(key)
ThisFiber::Sleep(x ms); // keeps dragonfly operational even when building a many gigabyte index
}
);- However, access to a global vector index requires locking a mutex, breaking the assumption of (2). Currently, the global vector index is a regular std::mutex suspending full thread execution, making this operation safe.
This issue prevents us from adopting a fiber-aware mutex for global hnsw indices
Suggested workarounds:
- Use a "quiescence" concept where a given "period" is safe for performing modifications, during which indexing can't run. An instance will juggle between those two modes
Source: dragonflydb/dragonfly