external IP allocations read the whole ip_pool_range table
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 48/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- rust
- 領域
- databases, performance
調査の方向性
Start with the allocation queries in nexus/db-queries/src/db/queries/external_ip.rs and external_multicast_group.rs, then use EXPLAIN ANALYZE to confirm whether the updated_pool_range CTE scans the whole table. Try the proposed join form and verify that it constrains the update to the selected range; the issue describes three other scan patterns in ip_pool.rs and external_subnet.rs that may also need investigation. Done when the affected queries avoid unnecessary full scans and the plans confirm the expected lookups.
索引モデルが issue の本文から書いたものです。
説明
(filing this for now as a followup to https://github.com/oxidecomputer/omicron/pull/11851. Plan to write this up properly as part of investigating it in the future)
robot text
Every external IP allocation currently reads all of ip_pool_range, because CockroachDB plans one step of the allocation query as a full scan of the table. Three other queries on the same table also scan more than they need to. I found these while checking index usage with EXPLAIN ANALYZE.
The allocation query is the most significant of the four because it's on a hot path. The sections below are in rough priority order.
1. External IP allocation
The allocation queries all have an updated_pool_range CTE that bumps rcgen on the range the new address came from:
UPDATE ip_pool_range
SET rcgen = rcgen + 1
WHERE id = (SELECT ip_pool_range_id FROM next_external_ip) AND time_deleted IS NULL
RETURNING id
CockroachDB 22.1 doesn't use the scalar subquery to constrain the scan, so it plans this as a full scan of the primary key rather than a lookup of one row. A read-only copy of the same predicate read about 24k rows in a table of 25.8k.
This affects next_automatic_floating_ip, next_explicit_floating_ip, next_instance_snat_ip, next_omicron_zone_snat_ip, and both multicast group allocation queries (which have the same CTE, reading from next_external_multicast_group). The queries are built in nexus/db-queries/src/db/queries/external_ip.rs and external_multicast_group.rs.
A possible fix is to express the id as a join that the optimizer can use, for example:
UPDATE ip_pool_range
SET rcgen = rcgen + 1
FROM next_external_ip
WHERE ip_pool_range.id = next_external_ip.ip_pool_range_id
AND ip_pool_range.time_deleted IS NULL
RETURNING ip_pool_range.id
I haven't tried this, so it needs to be confirmed with EXPLAIN.
2. Looking up the pool that contains an address
lookup_ip_pool_containing_address_on_connection in nexus/db-queries/src/db/datastore/ip_pool.rs (called by ip_pool_fetch_containing_address_in_current_silo and ip_pool_fetch_containing_address_for_services) filters on first_address <= X AND last_address >= X. No index can serve that as a two-sided bound, so the query is a full scan. It read all 25.8k rows in the test, even when X was in no range.
Live ranges never overlap, so the range that contains X, if there is one, is the range with the largest first_address that is at most X. That means the lookup can be written as:
SELECT ... FROM ip_pool_range
WHERE first_address <= X AND time_deleted IS NULL
ORDER BY first_address DESC
LIMIT 1
followed by a check that last_address >= X. This is a single seek on the existing lookup_pool_range_by_first_address index, which already stores last_address.
Two things to be careful about in the rewrite:
- The pool, silo, pool type and IP version filters have to be applied after the
LIMIT 1, not before it. If they're applied before, and the range that contains X is filtered out, the query returns a different range that doesn't contain X. - The rewrite relies on ranges not overlapping. That is an application-level invariant, enforced across all pools at insert time by the
filter_overlapping_ip_rangesquery, and not a database constraint. The reliance should be documented at the query.
3. Overlap checks when adding a range or subnet pool member
filter_overlapping_ip_ranges (nexus/db-queries/src/db/queries/ip_pool.rs) and insert_subnet_pool_member (nexus/db-queries/src/db/queries/external_subnet.rs) each have subqueries that ask whether an existing range contains an endpoint of the candidate, of the form $1 >= first_address AND $2 <= last_address or $1 BETWEEN first_address AND last_address. These are full scans for the same reason as in section 2.
The same approach likely applies here: find the range with the largest first_address at or below the endpoint, and check its last_address. I haven't worked through this one, so it needs checking.
4. ip_pool_delete's check for remaining ranges (minor)
ip_pool_delete checks whether a pool still has ranges with WHERE ip_pool_id = X AND time_deleted IS NULL LIMIT 1. This is planned as a scan of the primary key that stops at the first match, and it read about 1k rows in the test. A seek on lookup_pool_range_by_pool_and_first_address would read one row. The optimizer only picks the index when table statistics say the pool is empty.
This is low priority, because pool deletion is rare and the scan stops early.
How this was measured
I ran EXPLAIN ANALYZE on a single-node CockroachDB v22.1 with about 25.8k ranges across 12 pools and 6.2k external IPs, after collecting table statistics.
This came up while adding the lookup_pool_range_by_pool_and_first_address index on (ip_pool_id, first_address) for pagination. That index doesn't help any of the queries above.
- 主要言語
- Rust
- スター
- 630
- フォーク
- 110
- 平均マージ
- 2日 2時間
- マージ済み PR(30日)
- 160
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
oxidecomputer/omicron のほかの issue
-
Debugging fault-management
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
oxidecomputer/omicron#11831 ·
メンテナーはふだん 2 日以内に返信
-
fault-management
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
oxidecomputer/omicron#11444 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
oxidecomputer/omicron#11397 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
oxidecomputer/omicron#11390 ·
メンテナーはふだん 2 日以内に返信
-
non-important non-blocker Testing & Analysis
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
oxidecomputer/omicron#11374 ·
メンテナーはふだん 2 日以内に返信
oxidecomputer/omicron の issue をすべて見る
似ている issue
-
[Bug]: Add Data's question says "Link to the file" for a GeoPackage where small tables are copiedオープンunconfirmed possible issue
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
メンテナーはふだん 1 日以内に返信
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
jerney-nexus/epikrise#364 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
Yeachan-Heo/gajae-code#8058 ·
メンテナーはふだん 1 日以内に返信
-
bug daemon
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信