Skip to content

refactor(storage): move temporary spill files to Rust - #2790

Merged
footka merged 7 commits into
masterfrom
refactor/rust-tmp-file
Dec 1, 2026
Merged

footka merged 7 commits into
masterfrom
refactor/rust-tmp-file

Conversation

@footka

@footka footka commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

任务描述

把 SQL 外排和索引构建使用的临时文件迁到 Rust。临时段存入实例独立的 data_dir/spill,删除后空间可直接回到文件系统。

磁盘占用问题见 #2192。

  • 建索引磁盘占用。Linux ext4 上以相同的 768 维合成数据分别运行 C++ 基线 5e475af43 和 Rust 75d1cdea4 源码构建,每种规模各一对。56 万条建索引期间的库目录实际峰值从 4.82 GiB 降至 3.31 GiB,计入建完后 60 秒的全程峰值为 4.82 → 3.79 GiB。停机后库目录从 4.81 GiB 降至 3.79 GiB(−21%),其中 block_file 从 4.00 GiB 降至 3.00 GiB。Rust 独立临时段峰值为 1.22 GiB,建索引 SQL 返回时已归零。5.6 万条的停机后占用从 658 MiB 降至 399 MiB。客户原始数据待复测。
  • 磁盘布局。此前在预先碎片化的 ext4 上做了三轮混合外排对照。Rust 版让至少 128 MiB 的连续区间占空闲空间的比例从 51% 提高到 67%,平均空闲区间从 93 MiB 增至 126 MiB。SSTable 块文件的 extent 密度从 3.5 增至 20 个/GiB。实测改善的是文件系统的空闲空间布局。
  • 代码量。临时文件两个实现目录的生产源码从 20,145 行降到 2,149 行,约减少 89%。旧的 C++ 页池、宏块映射和刷盘调度由 Rust 的分段文件和有界写缓冲接管。

解决方案

Rust 统一管理临时段的读写、配额和回收,SQL 调用方沿用 data-plane 接口。

宽行按有界写缓冲分段写入。当异步预取拿不到读缓冲时,直接把数据读进调用方已有的缓冲。封存使用查询当时剩余的时间。

验证

  • Linux 75d1cdea4。17 项 Rust 测试、3 项仓内 mysqltest 通过。三个 45 MiB 排序键的用例在修复前报 4013,修复后和 C++ 基线返回一致。
  • seekdb_test 的临时文件配额建索引通过。现有用例已断言超配额返回 9135、放宽后可建索引,无需改动。
  • Windows 32 并发全量及基线差分覆盖此前的 dd6ab4fd1,未发现可复现的新增 SQL 回归。本次修复在 Linux 验证。

影响范围

SQL 外排、索引构建及临时文件的空间配额和监控。

合入理由

临时数据有独立的回收路径,并缩小了维护范围。已有微基准的模块耗时仍高于 C++,模块性能差距尚未达到 10% 目标。

@footka
footka marked this pull request as ready for review December 1, 2026 09:59
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-01T10:15:24.431863Z 75d1cde New commits
🔒 Security Review ✅ Completed 2026-12-01T10:20:08.689410Z 75d1cde New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5530ecc8e7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@footka
footka merged commit e82516f into master Dec 1, 2026
9 checks passed
@footka
footka deleted the refactor/rust-tmp-file branch December 1, 2026 11:44
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.

2 participants