Skip to content

Fix deadlock in proxy segment when propagating to write segment - #4206

Merged
timvisee merged 6 commits into
devfrom
fix-proxy-segment-propagate-deadlock
May 9, 2024
Merged

timvisee merged 6 commits into
devfrom
fix-proxy-segment-propagate-deadlock

Conversation

@timvisee

@timvisee timvisee commented May 9, 2024 •

Copy link
Copy Markdown
Member

Likely fixes: #4199

Fix a deadlock in the proxy segment. Locking in the propagate_to_wrapped() and search functions conflict.

The search function hold a lock on deleted_points after which it locked the wrapped segment. The propagation function did it the other way around.

I fixed this by not keeping a write lock on the write segment for the whole duration of the propagate_to_wrapped() function. Instead we now take an upgradable read lock and temporarily upgrade it on demand. An alternative would be to require mutable self on this function to ensure exclusive access to all locks, but I expect that to have a worse impact in terms of performance.

The last two days I managed to reproduce the problem very reliably. With this fix I've tested for another two hours, and I haven't seen it since.

For future reference, I've been testing like this getting a deadlock on the first snapshot request about 75% of the time:

# Qdrant with a flush interval of 0
QDRANT__STORAGE__OPTMIZERS__FLUSH_INTERVAL_SEC=0 ./qdrant

# Rapid upsertions
bfb -n 1000000 --create-if-missing --timeout 30

# A search/scroll job
bfb --skip-upload --skip-create --search -p 5 -t 5 --skip-wait-index
bfb --skip-upload --skip-create --scroll -p 5 -t 5 --skip-wait-index

# When all is running, create a snapshot
POST /collections/benchmark/snapshots

All Submissions:

  • Contributions should target the dev branch. Did you create your branch from dev?
  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  1. Does your submission pass tests?
  2. Have you formatted your code locally using cargo +nightly fmt --all command prior to submission?
  3. Have you checked your code using cargo clippy --all --all-features command?

@timvisee
timvisee merged commit a96d066 into dev May 9, 2024
@timvisee
timvisee deleted the fix-proxy-segment-propagate-deadlock branch May 9, 2024 12:20
timvisee added a commit that referenced this pull request May 9, 2024
* Don't keep wrapped segment lock when propagating proxy changes

This caused a deadlock when used in conjunction with searches through
the proxy, locking in a different order.

* When propagating, upgrade/downgrade wrapped segment lock back and forth

* Switch to upgrading the wrapped segment read lock on demand

* Annotate propagate function to prevent deadlocks in the future

* Minor log refactoring

* Add link to PR
@timvisee timvisee mentioned this pull request May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants