Repository navigation
UCS/DATASTRUCT: Extract red-black tree core from interval tree - #11944
Conversation
Factor the balancing mechanics of ucs_interval_tree_t into a reusable intrusive red-black tree, ucs_rbtree_t, and port the interval tree onto it. The caller performs its own descent and hands the attachment point to ucs_rbtree_insert_at, so the ordering key stays in the embedding struct. An optional augmentation callback recomputes data a node derives from its subtrees, which the interval tree does not use and leaves NULL. The only behavior that changes is node identity on removal: the successor is relinked rather than having its interval copied into the removed node, so the node object a caller names is the one removed. Interval tree nodes are pool allocated and never referenced from outside, so this is not observable here; it is what lets a later user hold node pointers across unrelated removals.
|
🤖 Starting review — findings will be posted here when done. |
|
Residual coverage gaps: the relink-successor removal path ( |
|
🤖 CI Triage Agent — TL;DR: The Go binding test Full analysisSummary: Azure job "UCX PR (go gpu)" step "Run go tests" failed: Root cause: Log evidence:
So this is a hang, not a slow test. This is a pre-existing flaky test, not caused by this PR: Implicated commit: unknown for the failure trigger (flaky pre-existing test); the test code originates from File: Suggested fix:
var nevents int
for {
nevents, err = syscall.EpollWait(epfdLocal, events[:], -1)
if err != syscall.EINTR {
break
}
}
if err != nil {
t.Errorf("Failed to call epoll_wait %v", err)
close(eventsChan) // never leave the parent blocked
return
}
eventsChan <- nevents
Related: PR #11944 (build under test); no existing issue found tracking this |
|
🤖 Starting review — findings will be posted here when done. |
|
pls also reset the tree root here; otherwise |
The comment explaining why the augmentation walk starts at 'child_parent' was left behind when the hook was removed; there is no derived data to refresh here, and 'child_parent' is only the fixup start point.
Both changes alter behaviour only on a malformed tree, where the extracted code carried over defensive tests from ucs_interval_tree_delete_fixup(): - The removal fixup asserts that a double-black node has a sibling rather than testing for it. Removing a black node always leaves the opposite subtree non-empty, and a red sibling has two non-NIL black children, so the post-rotation sibling exists too. The tests were unreachable, and a tree that did violate them silently skipped the rebalance. - Cleanup resets the tree root, which previously kept pointing at nodes it had just freed while the node count read zero. Every caller either frees the containing object or re-initializes, so this was latent.
|
🤖 Starting review — findings will be posted here when done. |
|
Residual coverage gap: Residual coverage gap: no test inserts equal keys through |
|
🤖 Starting review — findings will be posted here when done. |
Deduplicate the ucs_derived_of cast: ucs_interval_tree_root() now returns ucs_interval_tree_node(tree->rb.root) instead of repeating it.
It is called once per tree lifetime, so there is nothing to gain from inlining it, and the other tree operations already live in rbtree.c.
|
🤖 Starting review — findings will be posted here when done. |
The remove fixup reaches those branches only when the sibling's other child is red, so the NULL checks were unreachable. Also document that ucs_interval_tree_root() returns NULL for an empty tree.
It also verifies the disjoint-with-a-gap property that coalescing provides, which is not a red-black invariant.
|
🤖 Starting review — findings will be posted here when done. |
The caller descends to the insertion point itself and passes (parent, link) as a pair. An inconsistent pair links the node under one node while setting its parent to another, which the existing *link == NULL check cannot catch.
|
🤖 Starting review — findings will be posted here when done. |
|
Residual coverage gaps (already reported in earlier rounds): the deep-successor relink path in |
|
🤖 Starting review — findings will be posted here when done. |
|
Residual coverage gap (already noted in earlier rounds, not re-posting): the deep-successor relink path of |
The file-level description sat above the node typedef, so doxygen attached it to ucs_rbtree_node_t; move it to ucs_rbtree_t and describe the node. Stop random_stress at the first failure instead of repeating it for every remaining iteration.
|
🤖 Starting review — findings will be posted here when done. |
|
🤖 Review complete — no issues found. |
|
🤖 CI Triage Agent — [incomplete: stop_reason=max_tokens] |
What?
Factor the balancing mechanics of ucs_interval_tree_t into a reusable intrusive red-black tree, ucs_rbtree_t, and port the interval tree onto it. The caller performs its own descent and hands the attachment point to ucs_rbtree_insert_at, so the ordering key stays in the embedding struct.
The only behavior that changes is node identity on removal: the successor is relinked rather than having its interval copied into the removed node, so the node object a caller names is the one removed. Interval tree nodes are pool allocated and never referenced from outside, so this is not observable here; it is what lets a later user hold node pointers across unrelated removals.
Why?
For later reuse of the rbtree in an interval_map structure