Skip to content

[feat][core] Add try_relink repair primitive - #102

Open
TheP2P (thep2p) wants to merge 1 commit into
mainfrom
thep2p/93-try-relink
Open

[feat][core] Add try_relink repair primitive#102
TheP2P (thep2p) wants to merge 1 commit into
mainfrom
thep2p/93-try-relink

Conversation

@thep2p

Copy link
Copy Markdown
Collaborator

Adds try_relink/RelinkOutcome to LookupTable, the repair counterpart to try_link (#93). Single write-lock critical section; closes #93.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 RelinkOutcome and LookupTable::try_relink (repair counterpart to try_link) to the core lookup API.
  • Implement try_relink in ArrayLookupTable using a single inner.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_relink docs describe the "otherwise" case as an occupant being "farther from claimant than this node is", but the implementation (and try_link docs) 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 thread src/core/lookup/mod.rs
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> },
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.

[Core] Add try_relink: single-lock repair primitive for LookupTable

2 participants