oxidecomputer / oxidecomputer/omicron

The query used to filter out overlapping IP Pool ranges could be simpler

Open
#9,283 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

database Good for new hires
Dominant language
Rust
Stars
572
Forks
97
Avg merge
2d 12h
Merged PRs (30d)
96

Description

I ran into this while testing IPv6 address allocations. We use the following type:

https://github.com/oxidecomputer/omicron/blob/a65cda6f7d1e969caa7fd72423e2ed8aa91cb386/nexus/db-queries/src/db/queries/ip_pool.rs#L113

to filter out overlapping IP Ranges when we add them to a pool. This generates four subqueries, and uses them inside WHERE NOT EXISTS(subq) in the main INSERT query. If any one of those returns TRUE, we try to insert NULL and fail the whole query.

Those four conditions check:

  • The candidate first address is between any existing first / last address
  • The candidate last address is between any existing first / last address
  • Any existing first address is between the candidate first / last address
  • Any existing last address is between the candidate first / last address

That's all fine, but it's overly complicated. We could simplify this whole thing to:

INSERT INTO
    ip_pool_range
SELECT
    <candidate_data>
WHERE NOT EXISTS (
    SELECT 1
    FROM ip_pool_range
    WHERE time_deleted IS NULL
      AND first_address <= $candidate_last_address
      AND last_address >= $candidate_first_address
)

That's logically equivalent, but probably faster and certainly simpler.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in nexus/db-queries/src/db/queries/ip_pool.rs around line 113 and inspect how the current overlap checks are used in the insert query. Replace the four-condition overlap check with the simpler equivalent predicate described in the issue, then verify IPv6 range allocation and overlap rejection using the relevant existing tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, sql
Domain
backend, databases
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.