[feat][core] Add try_relink repair primitive - #102
Open
TheP2P (thep2p) wants to merge 1 commit into
Open
Conversation
Contributor
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.
Comment on lines
+38
to
+41
| /// 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> }, |
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.
Adds
try_relink/RelinkOutcometoLookupTable, the repair counterpart totry_link(#93). Single write-lock critical section; closes #93.