Queries fail while the vamana worker loads a large index, because the worker stops sending heartbeats during the load

Open
#110 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c, postgresql
Domain
backend, databases

Research direction

Start with vamanaworker.c around lines 1394 and 1851, then trace the index load path and VamanaWorkerWaitUntilAvailable() behavior. Reproduce with an index that takes more than three seconds to load and inspect how heartbeat age and svs.worker_startup_timeout_ms affect the second query. Done means queries wait through a live worker's load, and the worker state reports loading if that recommendation is included.

Written by the indexing model from the issue text.

Description

Problem

After a server restart, the vamana worker loads an index from disk the first time it is queried. The load runs synchronously inside the worker's main loop, and the heartbeat is only written at the top of that loop (vamanaworker.c ~line 1394), so no heartbeat is written for the duration of the load.

Before waiting for the worker, VamanaWorkerWaitUntilAvailable() checks the heartbeat. If the heartbeat is older than VAMANA_HEARTBEAT_STALE_MS (3000 ms, hard-coded), it raises an error immediately instead of waiting (vamanaworker.c ~line 1851). The worker is alive and busy, but backends treat it as hung.

As a result, any index whose load takes more than about 3 seconds is unavailable for the whole load:

  • Queries that arrive more than ~3 s after the load starts fail immediately with "vamana background worker unavailable … the worker's last heartbeat is older than 3000 ms".
  • Queries that arrive in the first ~3 s wait, but only up to svs.worker_startup_timeout_ms, and fail if the load takes longer.

svs.worker_startup_timeout_ms therefore doesn't help: the stale-heartbeat check fails a query before it ever reaches the wait. Large indexes easily take longer than 3 s to load.

Steps to reproduce

  1. Build a vamana index large enough that loading it takes more than a few seconds.
  2. Restart the server.
  3. Send one query against the index to trigger the load.
  4. While the load is still running, more than 3 s after it started, send another query from a different session.

The second query fails immediately with the stale-heartbeat error, and pg_stat_vamana_worker reports worker_state = 'unresponsive' until the load finishes. Once loaded, the index serves queries normally.

Environment: SVS-Extension-for-PostgreSQL 033cd2c, SVS C API 0.5.0, PostgreSQL 18.6.

Recommendations

  1. Keep the heartbeat alive during long operations. Update it periodically while an index loads, e.g. from the load path, or run the load outside the heartbeat loop.
  2. Don't treat "stale heartbeat, live worker" as fatal. If the worker's process is alive, keep waiting up to svs.worker_startup_timeout_ms, and reserve the immediate error for a worker that has exited.
  3. Report the loading state. Show it in pg_stat_vamana_worker (e.g. worker_state = 'loading'), so clients and monitoring can tell a busy worker from a hung one.
Dominant language
Perl
Stars
3
Forks
3
Avg merge
4d 19h
Merged PRs (30d)
5

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from intel/SVS-Extension-for-PostgreSQL

All issues in intel/SVS-Extension-for-PostgreSQL

Similar issues

More Perl issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.