Skip to content

fix: claim machine interface addresses before publishing hostnames - #4659

Closed
chet wants to merge 1 commit into
NVIDIA:mainfrom
chet:gh-issue-4654
Closed

fix: claim machine interface addresses before publishing hostnames#4659
chet wants to merge 1 commit into
NVIDIA:mainfrom
chet:gh-issue-4654

Conversation

@chet

@chet chet commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

New-interface creation and existing-interface replacement used opposite write orders. create_inner published a new interface's (domain_id, hostname) before inserting its address rows. The replacement path claimed the address first, then updated (domain_id, hostname).

That was fine with the existing database constraints, but #4150 will add site-wide uniqueness to machine_interface_addresses.address alongside fqdn_must_be_unique. With both constraints in place, a create could hold the FQDN while waiting for the address, while a replacement could hold the address and wait for the FQDN.

So, this makes new-interface creation follow the same address-before-FQDN order. create_inner now inserts the interface with its final hostname and domain_id = NULL, sorts and inserts its addresses, and then calls update_hostname_and_domain to publish the FQDN. domain_id used to receive its configured value in the initial INSERT; the helper now applies that value after the address rows exist.

For callers, this is a noop. There are no API, config, or database schema changes, successful creates store the same interface data as before, and the surrounding transaction still rolls everything back on failure. This just gives #4150 one lock order to build on.

And, there's a PostgreSQL regression test that uses a test-only trigger to make the intermediate writes visible. It verifies that the interface stays outside its DNS domain until its addresses are claimed, and that dual-stack addresses are inserted in a deterministic order.

Related issues

Type of Change

  • Add - New feature or capability
  • Change - Changes in existing functionality
  • Fix - Bug fixes
  • Remove - Removed features or deprecated functionality
  • Internal - Internal changes (refactoring, tests, docs, etc.)

Breaking Changes

  • This PR contains breaking changes

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • No testing required (docs, internal refactor, etc.)

Additional Notes

@chet
chet requested a review from a team as a code owner August 6, 2026 07:41
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Summary by CodeRabbit

  • Bug Fixes

    • Improved machine-interface creation to prevent address and DNS association conflicts.
    • Ensured interface addresses are stored in a consistent order, including dual-stack configurations.
    • Improved reliability when assigning hostnames and domains during interface setup.
  • Tests

    • Added coverage verifying deterministic address ordering and correct DNS association.

Walkthrough

Machine-interface creation now inserts addresses in deterministic order before assigning hostname and domain metadata. A SQLx integration test enforces this ordering and verifies dual-stack creation results.

Changes

Machine-interface creation

Layer / File(s) Summary
Ordered interface creation
crates/api-db/src/machine_interface.rs
create_inner accepts the target domain separately, inserts the interface without DNS metadata, sorts allocated addresses before insertion, and assigns hostname and domain data afterward. Helper calls now borrow the hostname.
Creation order validation
crates/api-db/src/machine_interface/tests.rs
An integration test configures dual-stack prefixes and a DNS domain, uses a database trigger to enforce address-first publication and ascending address insertion, and verifies the resulting address order and DNS metadata.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant create_inner
  participant Database
  participant DNS_metadata
  create_inner->>Database: Insert interface without DNS metadata
  create_inner->>Database: Insert allocated addresses in sorted order
  create_inner->>DNS_metadata: Assign hostname and domain metadata
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: claiming interface addresses before publishing hostnames.
Description check ✅ Passed The description directly explains the write-order change, its concurrency rationale, testing, and scope.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@chet

chet commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full_review, thanks!

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

@chet I will perform a complete review of pull request #4659.

🐇

✅ Action performed

Full review finished.

Comment thread crates/api-db/src/machine_interface.rs Outdated
for address in &sorted_addresses {
insert_machine_interface_address(txn, &interface_id, address, allocation_type).await?;
}
update_hostname_and_domain(txn, interface_id, &hostname, domain_id).await?;

@wminckler wminckler Aug 6, 2026

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.

the description implies this was moved, but it looks like a new call. is it now a duplicate call?

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@chet

chet commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full_review, thanks!

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

@chet I will perform a complete review of pull request #4659.

🐇

✅ Action performed

Full review finished.

`create_inner` currently inserts the final `(domain_id, hostname)` before its address rows. Existing-interface replacements claim the address first, so the site-wide address constraint in NVIDIA#4150 would make the two paths take their address and FQDN locks in opposite orders.

Create the interface outside its DNS domain, sort and insert its addresses, and then apply the final hostname and domain. This keeps successful creates unchanged while every writer uses the same address-before-FQDN order.

A PostgreSQL regression installs a test-only trigger to verify the intermediate row stays DNS-silent and dual-stack address inserts stay ordered.

This supports NVIDIA#4654

Signed-off-by: Chet Nichols III <chetn@nvidia.com>
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@chet

chet commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full_review, thanks!

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

@chet I will perform a complete review of pull request #4659.

🐇

✅ Action performed

Full review finished.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
crates/api-db/src/machine_interface.rs (1)

2125-2135: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Replace the lint suppression with a private parameter struct.

create_inner now accepts eight positional parameters. target_domain_id makes incorrect argument ordering easier. Replace #[allow(clippy::too_many_arguments)] with a private request struct for the creation inputs.

As per coding guidelines, “Avoid #[allow(...)]” and “Design APIs to be hard to misuse.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/api-db/src/machine_interface.rs` around lines 2125 - 2135, Replace the
#[allow(clippy::too_many_arguments)] suppression on create_inner with a private
request struct containing the creation inputs currently passed positionally.
Update create_inner and all call sites to accept and use that struct, preserving
the existing transaction, segment, and creation behavior while making argument
ordering explicit and harder to misuse.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/api-db/src/machine_interface.rs`:
- Around line 2181-2186: Update create_inner to sort allocated_addresses before
constructing NamingContext, then reuse that canonical sorted slice for both
hostname derivation and insert_machine_interface_address calls. Remove the later
duplicate sorting so address ordering is consistent across naming and
synchronization.

---

Nitpick comments:
In `@crates/api-db/src/machine_interface.rs`:
- Around line 2125-2135: Replace the #[allow(clippy::too_many_arguments)]
suppression on create_inner with a private request struct containing the
creation inputs currently passed positionally. Update create_inner and all call
sites to accept and use that struct, preserving the existing transaction,
segment, and creation behavior while making argument ordering explicit and
harder to misuse.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: b55df442-95e4-4b00-8d51-3baab1fc93cc

📥 Commits

Reviewing files that changed from the base of the PR and between 9d296f6 and bc01bba.

📒 Files selected for processing (2)
  • crates/api-db/src/machine_interface.rs
  • crates/api-db/src/machine_interface/tests.rs

Comment thread crates/api-db/src/machine_interface.rs
@chet chet closed this Aug 10, 2026
@chet
chet deleted the gh-issue-4654 branch August 10, 2026 18:09
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.

3 participants