Repository navigation
importguard: enforce one-way dependencies between components - #1433
Merged
Merged
Conversation
adapter imported internal/raftengine/etcd only for DeriveNodeID, which made the protocol layer depend on the concrete Raft backend. The derivation (FNV-64a of the raft ID) is engine-neutral cluster identity, so it now lives in internal/raftengine; etcd.DeriveNodeID delegates to it so the backend and the wiring code keep their call sites. Golden values pin the derivation, and an etcd test checks both names agree. Signed-off-by: bootjp <contact@bootjp.me>
Extend the production import guard (scripts/check-production-imports.sh, run in go-test.yml) with layer rules in layers.go: - leaf packages (proto, keyviz, proxy, key codecs, utility and wire packages, raftbootstrap, kek) import no module package; - store, distribution, internal/raftengine, internal/encryption, kv and internal/filesystem never import the layers above them (adapter, monitoring, proxy, autosplit, admin, adminbridge, serverwiring, snapshotoffload), and each also stays below its own consumers; - monitoring and internal/admin stay off the data plane and adapters; - internal/raftengine/etcd, internal/serverwiring and internal/adminbridge may only be imported at the binary wiring edge. Every rule holds on main after the previous commit. Rules use module-relative paths, so they do not depend on where the repository is checked out, and they cover files excluded by build tags. The guard now reports every violation in one run instead of stopping at the first. CLAUDE.md records the convention. Signed-off-by: bootjp <contact@bootjp.me>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 50 minutes. View limit details
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. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
bootjp
added a commit
that referenced
this pull request
Nov 12, 2026
…M4 part 1) (#1436) Design: docs/design/2026_11_12_partial_root_package_decomposition.md ## Summary This is milestone M4, part 1, of the root package decomposition. Two areas leave `package main`: | From (root) | To | API | |---|---|---| | `main_leader_balance.go` (652 lines) + tests | `internal/leaderbalance` | `Start(ctx, eg, []Group, Options, newConnCache, done)`, `Group` interface (`GroupID`, `Engine`), `Options`, `Metrics`/`NewMetrics`, `ParsePinnedGroups`, `Default*` | | `main_filesystem.go` (494 lines) + tests | `internal/fsmount` | `Start(ctx, eg, cleanup, shardStore, coordinate, observer, Config)`, `Config`, `MountService`, `InstallLifecycle`, `MountServer`, `OverrideServeStopTimeout` | Neither package reads flags or knows about `*raftGroupRuntime`: - **leaderbalance** sees groups through a two-method `Group` interface. `main` adapts its runtimes and drops nil entries, so no typed-nil interface reaches the scheduler. The gRPC connection cache comes from a factory, and as before it is created only when the scheduler runs. - **fsmount** takes a resolved `Config`. Capacity, max files and the collector intervals were previously read from flags inside the start function. They are now `Config` fields that `main` fills in. `filesystemStartConfigFromFlags` stays in `main` and returns the same values as before. The design doc gains a Progress section and one decision: extracted areas declare narrow inputs instead of waiting for `raftGroupRuntime` to move. `raftGroupRuntime` embeds bootstrap types, so moving it first would drag the bootstrap area along with it. Snapshot-offload wiring is deferred until after M2, because it reads about 20 flags directly. ## Behavior change None. Function bodies are unchanged apart from two things: flag dereferences became config fields, and some identifiers were renamed so they could be exported. ## Risk Low to medium. The leader-balance and FUSE start-up paths are rewired, but their logic is identical. The two signal-shutdown kernel-mount tests stay in `main` and now drive the exported `fsmount` API. The serve-stop timeout knob is now `OverrideServeStopTimeout`, which returns a restore func; before, another package wrote the package variable directly. ## Test evidence - `go build ./...`, `go vet . ./internal/leaderbalance ./internal/fsmount` - `golangci-lint run . ./internal/leaderbalance/ ./internal/fsmount/` → 0 issues - `go test -race -count=1 ./internal/leaderbalance/ ./internal/fsmount/ ./internal/testutil/...` → ok - `go test -race -count=1 .` → ok, after rebasing onto `main` - `importguard` (the layer rules from #1433) → passes - The set of `func Test*` names is unchanged: tests moved, none were lost. - Jepsen was not run: no Raft, MVCC, OCC or HLC path changed. Leader balancing uses the same gated transfer RPCs. ## Self-review 1. Data loss: no storage or apply path was touched. The filesystem unmount/cleanup ordering is unchanged, and its lifecycle tests moved intact. 2. Concurrency / distributed failures: leaderbalance reads engines through `Engine()`, which takes the same `snapshotEngine()` lock as before. Nil runtimes are filtered out before the interface conversion. The shutdown join and cancellation tests moved and pass. 3. Performance: no hot path changed. The only addition is one interface call per group per balance tick. 4. Data consistency: no change. 5. Test coverage: every test of the moved code moved with it. The root keeps the flag-parsing tests and the signal-shutdown integration tests. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **改善** * ファイルシステムの起動時に設定を検証し、不正な設定をエラーとして通知するようになりました。 * 起動時にリーダーを検出できない場合や期限切れの場合、一定時間再試行するようになりました。 * **ドキュメント** * ファイルシステム関連機能の移行状況と設計方針を更新しました。 <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR makes the dependency direction between components a CI-enforced rule.
raftengine: own DeriveNodeID: the protocol layeradapterimported the concrete Raft backendinternal/raftengine/etcdonly forDeriveNodeID.DeriveNodeID(FNV-64a of the raft ID) is engine-neutral cluster identity, so it now lives ininternal/raftengine.etcd.DeriveNodeIDdelegates to it, so existing callers are unchanged.adapternow depends only oninternal/raftengine.importguardlayer rules (internal/testutil/cmd/importguard/layers.go), run by the existingscripts/check-production-imports.shingo-test.yml:proto,keyviz,proxy, key codecs, utility and wire packages,raftbootstrap,kek) import no module package.store→distribution/internal/raftengine/internal/encryption→kv→internal/filesystem: none of these imports the layers above it (adapter,monitoring,proxy,distribution/autosplit,internal/admin,internal/adminbridge,internal/serverwiring,internal/snapshotoffload), and each lower layer stays below its consumers.monitoringandinternal/admindo not reach into the data plane or adapters. This matches the existing comments sayinginternal/adminstays free ofadapter.internal/raftengine/etcd,internal/serverwiringandinternal/adminbridgemay only be imported from the root binary andcmd/. The etcd backend is additionally importable from insideinternal/raftengineand frominternal/snapshotoffload.The rules use module-relative paths, so they do not depend on where the repo is checked out, and they also cover files excluded by build tags. depguard was not used because its globs match absolute paths, so a rule like
**/kv/**would misfire whenever a parent directory is namedkv. CLAUDE.md now documents the convention.Behavior change
None.
DeriveNodeIDkeeps the same implementation and results; only where it is defined changed. The second commit is a CI/tooling change.Risk
Low. If someone later needs an upward dependency, CI fails. The intended fix is to invert the dependency, not to relax the rule (documented in CLAUDE.md and
layers.go).Note for #1432: its branch predates this fix, so after a rebase it will pass.
internal/adminbridgeitself already satisfies the rules.Test evidence
bash scripts/check-production-imports.sh→ passes. Before the first commit it fails with:adapter/migration_namespace_activation.go:8:2: layer violation: internal/raftengine/etcd may only be imported from ., cmd, internal/raftengine, internal/snapshotoffload, not from adaptergo test -race ./internal/testutil/...(newTestCheckLayeringtable,TestModuleDir,TestCheckTreeReportsEveryLayerViolation)go test ./internal/raftengine/ ./internal/raftengine/etcd/ -run DeriveNodeID(golden values pinning the derivation, plus a check that both names agree)go test -race -run 'Namespace|Migration' ./adapter/→ okgolangci-lint runon the touched packages → 0 issuesSelf-review