[feat][core] Add try_relink repair primitive - #102
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a repair-oriented atomic primitive, try_relink, to the LookupTable API (with RelinkOutcome) and implements it for ArrayLookupTable using a single write-lock critical section, mirroring the existing try_link atomicity guarantees. It also adds targeted unit tests that cover all acceptance-criteria outcomes and updates re-exports / test mocks to compile with the expanded trait.
Changes:
- Add
RelinkOutcomeandLookupTable::try_relink(repair counterpart totry_link) to the core lookup API. - Implement
try_relinkinArrayLookupTableusing a singleinner.write()guard and return the evicted neighbor when replacing. - Add unit tests covering AlreadyConsistent, Forward, Relinked (with/without eviction), and out-of-range errors.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/node/core_test.rs | Updates a test mock LookupTable impl to include the new try_relink method. |
| src/core/mod.rs | Re-exports RelinkOutcome from the core module. |
| src/core/lookup/mod.rs | Adds RelinkOutcome and extends the LookupTable trait with try_relink + documentation. |
| src/core/lookup/array_lookup_table.rs | Implements try_relink under a single write lock and logs the decision. |
| src/core/lookup/array_lookup_table_test.rs | Adds tests for all try_relink outcomes and bounds-check errors. |
Comments suppressed due to low confidence (1)
src/core/lookup/mod.rs:134
- The
try_relinkdocs describe the "otherwise" case as an occupant being "farther fromclaimantthan this node is", but the implementation (andtry_linkdocs) are based on the strictly-between comparison (existing.id() < claimant.id() for Right, > for Left). Rewording this avoids implying a distance metric that isn’t enforced.
/// - **otherwise** (the slot is empty, or its occupant sits on the wrong side, farther from
/// `claimant` than this node is) — `claimant` is installed as the new entry, and
/// [`RelinkOutcome::Relinked`] reports whatever was evicted (`None` if the slot was empty).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /// The slot was empty, or its occupant sat on the wrong side (farther from the claimant | ||
| /// than this node is): the claimant is installed as the new entry, evicting whatever | ||
| /// occupied the slot before (`evicted` is `None` if it was empty). | ||
| Relinked { evicted: Option<Identity> }, |
There was a problem hiding this comment.
Good catch, fixed in 84c3158 — reworded both spots (this one and line 132's trait doc bullet) to describe the actual ordinal condition ("neither the claimant nor strictly between this node and the claimant, per the same comparison try_link uses") instead of the inaccurate distance claim.
|
Claude (@claude) review |
|
Claude finished TheP2P (@thep2p)'s task —— View job Code Review — PR #102
|
|
Re the identifier-collision edge case (note 1): identifiers are guaranteed unique in this system, so that path is unreachable — no doc or test change needed. Note 2 (extracting the shared comparison) — agreed, not worth it for two call sites. |
Adds
try_relink/RelinkOutcometoLookupTable, the repair counterpart totry_link(#93). Single write-lock critical section; closes #93.