#6960·dragonfly

Background vector indexing correctness

Author: dranikpgCreated Mar 24, 2026Updated Sep 30, 2026
Labelsstale
  1. Previosuly all indexing was synchronous under a transaction lock.
cpp
void FtCreate() {
  Hop({
    for (key : table->traverse())
      Add(key)
  })
}
  1. 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
cpp

Fiber({
  for (key : table->traverse()) {
    Add(key)
    ThisFiber::Sleep(x ms); // keeps dragonfly operational even when building a many gigabyte index
  }
);
  1. 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:

  1. 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