Skip to content

Stop node writers waiting for one node segment while holding another - #2968

Closed
miratepuffin wants to merge 1 commit into
fix/filtered-walk-edge-node-deadlockfrom
fix/reserve-segment-deadlock
Closed

miratepuffin wants to merge 1 commit into
fix/filtered-walk-edge-node-deadlockfrom
fix/reserve-segment-deadlock

Conversation

@miratepuffin

Copy link
Copy Markdown
Collaborator

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_segment locks 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 fair read_arc(). It now uses head_arc(), the recursive read the edge segments already use.

Why are the changes needed?

Two deadlocks between a reader and a node writer:

  1. Lock order. add_edge from 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, or node_has_valid_edges) waits for X. Taking locks in id order doesn't prevent this, because readers take segments in any order.
  2. Fair read. A reader that already holds a node entry in segment X and then calls core_nodes() takes locked() 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 take degree() 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.

  • On db_v4 it hangs in 5 of 5 runs.
  • With only the edge-segment fix from the base PR it still hangs in 3 of 3 runs.
  • With the lock-order change but the old fair locked(), it hangs in 2 of 10 runs.
  • With this PR it passes in 20 of 20 runs, and the test from the base PR passes in 10 of 10.

The db4-storage, raphtory-storage and raphtory-tests suites pass (release build).

Are there any further changes required?

No.

Security implications if any

  • I have considered the security impact of this change (secrets, dependencies, access, data handling)

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().
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.

1 participant