You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Stacked on #1431 (base is its branch; retarget to main after it merges).
Summary
#1431 split main.go into per-area files, but they all still share package main (~25k lines of non-test code, ~28k lines of tests). This PR addresses the structural causes.
Design doc (first commit, reviewable on its own). The dependency survey found three root causes: 92 flag globals dereferenced deep inside helpers; the shared runtime types (raftGroupRuntime, groupSpec, raftBootstrapConfig, runtimeConfig) live in main, so no area can leave it; and even leaf code has never been extracted. The doc proposes six behavior-neutral milestones: M1 admin bridges → M2 typed flag config → M3 internal/noderuntime → M4 mid-sized areas → M5 encryption wiring → M6 bootstrap CLI.
M1: move the SQS/S3/DynamoDB admin bridges, convertAdminPrincipal / isLeaderChurnError, and the keyviz source/fan-out builders into the new internal/adminbridge package. Only constructors are exported; the bridge types and error translators stay unexported. Their tests move with them. Comments that pointed at main_admin.go for these bridges now point at the new package.
Behavior change
None. Function bodies are unchanged; only identifiers were exported and call sites qualified.
Risk
Low. M1 is leaf code (it depends only on adapter, internal/admin, keyviz) and introduces no import cycle. The design doc stays proposed and will be renamed to partial in a follow-up once this merges.
Test evidence
go build ./..., go vet . ./internal/adminbridge
golangci-lint run . ./internal/adminbridge/... ./internal/admin/... ./adapter/... → 0 issues
go test -race -count=1 ./internal/adminbridge/ ./internal/admin/ → ok
go test -race -count=1 . → ok github.com/bootjp/elastickv 228.767s
The set of func Test* names across the repository is identical before and after (no test lost in the move).
Jepsen not run: no runtime path or start-up order changed (per the doc's verification section, Jepsen starts at M3).
Self-review
Data loss: no logic changed.
Concurrency / distributed failures: no change; the bridges are stateless wrappers.
Performance: no change (same calls, one extra package boundary at construction time only).
Data consistency: no change; error mapping to admin.Err*NotLeader is covered by the moved translate tests.
Test coverage: every test covering the moved code moved with it and passes in the new package.
Milestone 1 of the root package decomposition. The SQS, S3 and DynamoDB
bridges that convert adapter admin DTOs to internal/admin sources, the
shared principal / leader-churn helpers, and the keyviz source and
fan-out builders move out of package main into internal/adminbridge.
Constructors are exported (NewSQSQueuesSource, NewBucketsSource,
NewDynamoTablesSource, KeyVizSource, KeyVizHotKeysSource,
NewKeyVizFanout, NewKeyVizHotKeysFanout, KeyVizFanoutConfig); the
bridge types and error translators stay unexported. Function bodies are
unchanged. The tests that cover the bridges move with them, and
comments that pointed at main_admin.go for the bridges now point at the
new package. parseCSV stays in main_admin.go because the admin role
flags use it.
Signed-off-by: bootjp <contact@bootjp.me>
This is a behavior-neutral refactor that moves admin bridge code into its own package, with call sites and tests updated to match. No actionable merge-blocking issue remains.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
## Summary
This PR makes the dependency direction between components a CI-enforced
rule.
1. **`raftengine: own DeriveNodeID`**: the protocol layer `adapter`
imported the concrete Raft backend `internal/raftengine/etcd` only for
`DeriveNodeID`. `DeriveNodeID` (FNV-64a of the raft ID) is
engine-neutral cluster identity, so it now lives in
`internal/raftengine`. `etcd.DeriveNodeID` delegates to it, so existing
callers are unchanged. `adapter` now depends only on
`internal/raftengine`.
2. **`importguard` layer rules**
(`internal/testutil/cmd/importguard/layers.go`), run by the existing
`scripts/check-production-imports.sh` in `go-test.yml`:
- Leaf packages (`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.
- `monitoring` and `internal/admin` do not reach into the data plane or
adapters. This matches the existing comments saying `internal/admin`
stays free of `adapter`.
- `internal/raftengine/etcd`, `internal/serverwiring` and
`internal/adminbridge` may only be imported from the root binary and
`cmd/`. The etcd backend is additionally importable from inside
`internal/raftengine` and from `internal/snapshotoffload`.
- The guard now reports every violation in one run instead of stopping
at the first.
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 named `kv`.
CLAUDE.md now documents the convention.
## Behavior change
None. `DeriveNodeID` keeps 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/adminbridge` itself 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 adapter`
- `go test -race ./internal/testutil/...` (new `TestCheckLayering`
table, `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/` → ok
- `golangci-lint run` on the touched packages → 0 issues
- Jepsen not run: no runtime change.
## Self-review
1. Data loss: none. The node ID derivation is unchanged and pinned by
golden values (it is persisted identity).
2. Concurrency / distributed failures: no runtime change.
3. Performance: none (one extra function call, inlined).
4. Data consistency: node IDs in ConfState, peer files and nonce
prefixes are unchanged; the golden test guards against drift.
5. Test coverage: the new rules and the moved function both have tests,
and the guard's own tests cover allow and deny cases plus reporting of
multiple violations.
M1 (internal/adminbridge) shipped in #1432, so the design doc moves to the partial lifecycle state; CLAUDE.md follows the rename.
Signed-off-by: bootjp <contact@bootjp.me>
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
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.
Design: docs/design/2026_11_12_proposed_root_package_decomposition.md
Stacked on #1431 (base is its branch; retarget to
mainafter it merges).Summary
#1431 split
main.gointo per-area files, but they all still sharepackage main(~25k lines of non-test code, ~28k lines of tests). This PR addresses the structural causes.raftGroupRuntime,groupSpec,raftBootstrapConfig,runtimeConfig) live inmain, so no area can leave it; and even leaf code has never been extracted. The doc proposes six behavior-neutral milestones: M1 admin bridges → M2 typed flag config → M3internal/noderuntime→ M4 mid-sized areas → M5 encryption wiring → M6 bootstrap CLI.convertAdminPrincipal/isLeaderChurnError, and the keyviz source/fan-out builders into the newinternal/adminbridgepackage. Only constructors are exported; the bridge types and error translators stay unexported. Their tests move with them. Comments that pointed atmain_admin.gofor these bridges now point at the new package.Behavior change
None. Function bodies are unchanged; only identifiers were exported and call sites qualified.
Risk
Low. M1 is leaf code (it depends only on
adapter,internal/admin,keyviz) and introduces no import cycle. The design doc staysproposedand will be renamed topartialin a follow-up once this merges.Test evidence
go build ./...,go vet . ./internal/adminbridgegolangci-lint run . ./internal/adminbridge/... ./internal/admin/... ./adapter/...→ 0 issuesgo test -race -count=1 ./internal/adminbridge/ ./internal/admin/→ okgo test -race -count=1 .→ok github.com/bootjp/elastickv 228.767sfunc Test*names across the repository is identical before and after (no test lost in the move).Self-review
admin.Err*NotLeaderis covered by the moved translate tests.Summary by CodeRabbit