Skip to content

refactor: move snapshot-offload wiring to internal/snapshotoffloadwiring (M4) - #1447

Merged
bootjp merged 2 commits into
mainfrom
design/root-package-decomposition-m4-offload
Nov 12, 2026
Merged

bootjp merged 2 commits into
mainfrom
design/root-package-decomposition-m4-offload

Conversation

@bootjp

@bootjp bootjp commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Design: docs/design/2026_11_12_partial_root_package_decomposition.md

The first M4 area of the root package decomposition: snapshot offload. The first commit updates the design doc. It records the new package, which is a sibling of the snapshotoffload library rather than part of it, so flag and start-up code stays out of the library and away from its test fakes. The second commit moves the code.

Changes

New package internal/snapshotoffloadwiring:

  • offload.go (from main_snapshot_offload.go):
    • Flags with Register
    • plaintext-endpoint refusal, prefix and spool-dir validation
    • the TLS-enforcing HTTP client and redirect policy
    • store construction and stale-spool cleanup
    • Start
  • retention.go (was main_snapshot_offload_gc.go): RetentionFlags, the retention runner, and the worker loop.
  • Start takes []snapshotoffload.OffloadGroup and the build version instead of the node runtimes, so the package never sees raftGroupRuntime.
  • Tests moved with the code: offload_test.go, plus retention_test.go (was main_snapshot_offload_gc_test.go). Three start/cleanup tests now pass offload groups directly instead of runtimes, since the mapping from runtimes is now main's job.

main keeps:

  • snapshotOffloadGroups and the leadership callbacks: runtimes become offload groups, and each group reads the engine through snapshotEngine.
  • A thin startSnapshotOffload that calls snapshotoffloadwiring.Start.
  • The tests that cover the runtime mapping and the runbook data-dir table.
  • The three-node acceptance test. It now builds its flags from defaultServerFlags().snapshotOffload, with the same final values as before.

serverFlags.snapshotOffload is now snapshotoffloadwiring.Flags.

The import guard lists the package as a wiring layer and restricts it to binaries. Only its test imports the concrete etcd backend.

Behavior change

None:

  • Flag names, defaults and help text are unchanged: -help output is identical to the base.
  • The set of test names across root and internal/snapshotoffloadwiring is identical to the base.
  • The "snapshot offload enabled" log line now counts offload groups rather than runtime slots. These are equal, because runtimes are never nil in production.

Risk

Low. Offload is opt-in and off by default. Validation order, the fail-closed start-up and the store hand-off are unchanged.

Test evidence

  • go test -race -count=1 . ./internal/snapshotoffloadwiring/ ./internal/testutil/cmd/importguard/: ok (root 224s).
  • go build ./...: ok.
  • golangci-lint: 0 issues.
  • scripts/check-production-imports.sh: ok.
  • -help and test-name set: identical to the base.
  • Jepsen (./scripts/run-jepsen-local.sh, binary built from af0374f21, JDK 21): PASSED. The DynamoDB list-append workload and all ten type workloads report :valid? true. The filesystem workloads were skipped because FUSE is unavailable on the macOS runner.

Self-review

  1. Data loss: retention keeps the same claims-complete / min-generation / grace guards, and the GC code is unchanged. The store is still closed on any start-up failure before hand-off.
  2. Concurrency: the leadership callbacks still read the engine through the locked snapshotEngine. The worker goroutine and shutdown path are unchanged.
  3. Performance: start-up only.
  4. Consistency: manifests carry the same prefix, source cluster and build version. Only-the-leader publication with pre-commit re-verification is unchanged.
  5. Test coverage: all moved functions' tests moved with them. The acceptance test still exercises the full main → package path.

Summary by CodeRabbit

  • リファクタリング
    • スナップショットのオフロードと保持機能に関する起動設定を整理しました。設定項目や機能の動作に変更はありません。

First M4 area of the root package decomposition. Move the snapshot
offload start-up wiring out of package main into a new
internal/snapshotoffloadwiring package: the offload and retention flag
structs (now Flags / RetentionFlags with Register), endpoint, prefix and
spool validation, the TLS-enforcing HTTP client, store construction,
stale-spool cleanup, and the scheduler and retention workers.

Start takes []snapshotoffload.OffloadGroup and the build version instead
of the node runtimes, so the package never sees raftGroupRuntime. main
keeps snapshotOffloadGroups (runtimes -> offload groups with their
leadership callbacks) and a thin startSnapshotOffload that calls Start.
Tests moved with the code; the ones that exercise the runtime mapping
stay in main. The import guard restricts the package to binaries.

No behavior change: -help output and the set of test names are
identical to the base.

Signed-off-by: bootjp <contact@bootjp.me>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 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-11-12T16:47:44.837807Z af0374f PR opened
🔒 Security Review ✅ Completed 2026-11-12T16:49:53.261472Z af0374f PR opened
ℹ️ 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.

@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

スナップショットオフロードの設定、検証、ストア構築、スケジューラーと保持ワーカーの起動処理を、新設のinternal/snapshotoffloadwiringに移しました。mainは新しいパッケージの設定型とStartを使用します。

Changes: スナップショットオフロード配線

Layer / File(s) Summary
設定型とパッケージ境界
internal/snapshotoffloadwiring/offload.go, internal/snapshotoffloadwiring/retention.go, internal/snapshotoffloadwiring/doc.go, docs/design/2026_11_12_partial_root_package_decomposition.md
オフロード設定をFlags、保持設定をRetentionFlagsとして公開します。設計文書とパッケージコメントに、新しいパッケージの担当範囲とStartの入力を記載します。
オフロード構築と起動
internal/snapshotoffloadwiring/offload.go, internal/snapshotoffloadwiring/retention.go, internal/snapshotoffloadwiring/offload_test.go, internal/snapshotoffloadwiring/retention_test.go, main_snapshot_offload_test.go
HTTPSを既定とするエンドポイント検証、リダイレクト制御、プレフィックスとスプール先の検証、ストア構築、古いスプールファイルの削除を実装します。Startはスケジューラーと保持処理を構築してワーカーを登録します。テストは設定検証、起動条件、クリーンアップなどを確認します。
mainからの呼び出し
main_distribution.go, main_flags.go, main_flags_test.go, main_snapshot_offload.go, main_snapshot_offload_acceptance_test.go, internal/testutil/cmd/importguard/layers.go
mainの設定型とフラグ登録を新しい公開APIに切り替えます。startSnapshotOffloadはStartを呼び出すラッパーになります。インポートガードと受け入れテストも更新します。

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

Change: Refactor

Possibly related issues

  • Issue 1330 — スナップショットオフロード機能を扱う点で関連します。ただし、この変更は起動配線の移動であり、Issueに記載された未完了の受け入れ項目を完了するものではありません。

Possibly related PRs

  • bootjp/elastickv#1437 — 同じ設定型とフラグ登録を扱い、本PRはその構造を新しいパッケージに移しています。
Merge Risk: Minimal · up to af037

This refactor moves snapshot-offload startup and retention wiring into its own package, with flag names, defaults, validation order and failure handling reported unchanged. No actionable merge-blocking risk was found in the supplied evidence.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed タイトル「refactor: move snapshot-offload wiring to internal/snapshotoffloadwiring (M4)」は、PR の主要な変更を正確に示しています。スナップショットオフロードの起動配線とリテンション配線を main パッケージから新しい internal/snapshotoffloadwiring パッケージへ移す変更であり、変更内容(…
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.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

タイトル「refactor: move snapshot-offload wiring to internal/snapshotoffloadwiring (M4)」は、PR の主要な変更を正確に示しています。スナップショットオフロードの起動配線とリテンション配線を main パッケージから新しい internal/snapshotoffloadwiring パッケージへ移す変更であり、変更内容(新規パッケージ追加、main_snapshot_offload.go の縮小、フラグ型の移動、import guard の更新)と一致します。「(M4)」はマイルストーン番号であり、やや分かりにくい点はありますが、タイトルの主旨は明確です。

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 894e15be-2160-42b6-9d3c-53cfa7f1edf0
Commits

Reviewing files that changed from the base of the PR and between 6514ed4 and af0374f.

Files selected for processing: 13

  • docs/design/2026_11_12_partial_root_package_decomposition.md
  • internal/snapshotoffloadwiring/doc.go
  • internal/snapshotoffloadwiring/offload.go
  • internal/snapshotoffloadwiring/offload_test.go
  • internal/snapshotoffloadwiring/retention.go
  • internal/snapshotoffloadwiring/retention_test.go
  • internal/testutil/cmd/importguard/layers.go
  • main_distribution.go
  • main_flags.go
  • main_flags_test.go
  • main_snapshot_offload.go
  • main_snapshot_offload_acceptance_test.go
  • main_snapshot_offload_test.go
Files with no reviewable changes: 1

  • main_snapshot_offload_test.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@bootjp
bootjp merged commit 86b327a into main Nov 12, 2026
18 checks passed
@bootjp
bootjp deleted the design/root-package-decomposition-m4-offload branch November 12, 2026 17:21
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.

1 participant