pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
[pgvector/pgvector] issue #637: Update neighbors tuple atomically
3+ messages / 2 participants
[nested] [flat]

* [pgvector/pgvector] issue #637: Update neighbors tuple atomically
@ 2024-08-06 12:09 "ron-marcus (@ron-marcus)" <noreply+ron-marcus@github.com>
  0 siblings, 0 replies; 3+ messages in thread

From: ron-marcus (@ron-marcus) @ 2024-08-06 12:09 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi,

I would like to inquire about a potential concurrency issue in hnswUpdateNeighborsOnDisk().

From my understanding, updating an adjacency list should be an atomic read-modify-write (RMW) operation performed under a lock. However, I noticed that the current implementation reads the list, updates it locally, and only then acquires a lock to update on disk. The list is read under a lock, but the lock is released once the read is done.

In a scenario where two new vectors are added concurrently and both processes attempt to modify the same neighbor tuple, it appears that both may read the same original neighbor tuple when calling hnswUpdateNeighborsOnDisk(). This could result in only one update being stored on disk, potentially overwriting the other.

There is a comment stating, "Do not lock yet since selecting neighbors can take time." Could you please explain why it is acceptable not to acquire the lock immediately? Am I missing something? Is this a tradeoff between correctness and performance?

Thanks!

^ permalink  raw  [nested|flat] 3+ messages in thread

* Re: [pgvector/pgvector] issue #637: Update neighbors tuple atomically
@ 2024-08-06 17:11 ` "ankane (@ankane)" <noreply+ankane@github.com>
  1 sibling, 0 replies; 3+ messages in thread

From: ankane (@ankane) @ 2024-08-06 17:11 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @ron-marcus, this was a design decision. Locking immediately would block page reads for longer during all updates (which blocks index scans and other inserts trying to access the page), with the only benefit of preventing the scenario described above (which is uncommon and has limited impact when it occurs).

Edit: This could be a good place for optimistic locking, but it's not clear it's worth the complexity / performance impact.

^ permalink  raw  [nested|flat] 3+ messages in thread

* Re: [pgvector/pgvector] issue #637: Update neighbors tuple atomically
@ 2024-08-06 17:11 ` "ankane (@ankane)" <noreply+ankane@github.com>
  1 sibling, 0 replies; 3+ messages in thread

From: ankane (@ankane) @ 2024-08-06 17:11 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@ankane closed this.

^ permalink  raw  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2024-08-06 17:11 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-08-06 12:09 [pgvector/pgvector] issue #637: Update neighbors tuple atomically "ron-marcus (@ron-marcus)" <noreply+ron-marcus@github.com>
2024-08-06 17:11 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-08-06 17:11 ` "ankane (@ankane)" <noreply+ankane@github.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox