Repository navigation
Stop node writers waiting for one node segment while holding another - #2968
Closed
miratepuffin wants to merge 1 commit into
Closed
miratepuffin wants to merge 1 commit into
miratepuffin wants to merge 1 commit into
Conversation
reserve_and_lock_segment held a full node segment while it blocked on the free segment (or the other way round). A reader holding the free segment that then reads a node in the full one deadlocked with it. The writer now only tries the second segment; when it is busy it releases the first, waits for the second holding nothing, and tries again. The in-memory node segment's locked() also took a fair read guard, so a reader already holding the segment queued behind a waiting writer. It now takes the same recursive guard as head_arc().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #2967: this PR's test also needs that fix, so it targets that branch.
What changes were proposed in this pull request?
Node writers no longer wait for one node segment while holding another, and in-memory node segments no longer hand out fair read guards.
reserve_and_lock_segmentlocks the free segment with a new helper,writer_beside. It holds the full segment and only tries the free one. If the free segment is busy, it releases the full segment, waits for the free one holding nothing, relocks the full one and tries again. This replaces the "lock in segment id order" scheme, which still blocked on the second segment while holding the first.NodeSegmentView::locked()took a fairread_arc(). It now useshead_arc(), the recursive read the edge segments already use.Why are the changes needed?
Two deadlocks between a reader and a node writer:
add_edgefrom an existing node in a full segment X to a new node holds X and blocks on the free segment F. A reader holding a node in F that reads its neighbour in X (a filtered neighbour walk, ornode_has_valid_edges) waits for X. Taking locks in id order doesn't prevent this, because readers take segments in any order.core_nodes()takeslocked()on X. With a fair read it queues behind a writer waiting on X, and that writer waits for the reader's entry.Does this PR introduce any user-facing change? If yes is this documented?
No.
How was this patch tested?
New test
graph_tests::test_node_lock_order::neighbour_walk_from_a_new_segment_does_not_deadlock_with_add_edge. On small node segments, four threads add edges from existing nodes to new ones while four threads takedegree()of the newest nodes through a node-filtered view. A watchdog fails the test if any thread hasn't finished 10 s after it is told to stop.db_v4it hangs in 5 of 5 runs.locked(), it hangs in 2 of 10 runs.The
db4-storage,raphtory-storageandraphtory-testssuites pass (release build).Are there any further changes required?
No.
Security implications if any