Skip to content

refactor: group Raft identity, topology and consistency flags (M2 part 6) - #1442

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

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

Conversation

@bootjp

@bootjp bootjp commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Design: docs/design/2026_11_12_partial_root_package_decomposition.md

M2 part 6. It is stacked on #1441, so retarget it to main once #1441 merges. It moves the node identity, cluster topology and consistency rollout-gate flags out of package globals.

Changes

  • raftFlags (main_runtime_config.go): --address, --raftId, --raftEngine, --raftDataDir.
  • topologyFlags (main_runtime_config.go): --raftGroups, --shardRanges, --raftRedisMap, --raftS3Map, --raftDynamoMap, --raftSqsMap, --sqsFifoPartitionMap. The HT-FIFO comment moved onto the struct.
  • consistencyFlags (main_commit_ts_fence.go): --commitTSFence, --readWatermarkAdvance.
  • resolveNetworkRuntimeInputs and resolveValidatedRuntimeInputs now take *serverFlags, so the parameter lists stop growing with each part. resolveRuntimeInputs takes the raft, topology and listener values.
  • Each of these now gets the values it needs as parameters:
    • loadKEKAfterPreNonceStartupGuards: Raft ID and data dir.
    • prepareAdminFromFlags: Raft ID.
    • startRaftServers: Raft ID and readWatermarkAdvance.
    • The server runner and S3 blob cluster: Raft ID.
    • Snapshot offload, via distributionStartupInput: data dir.
    • serversInput: node address and consistency flags.
  • Not in this PR: the bootstrap and join flags (--raftBootstrap, --raftBootstrapMembers, --raftGroupPeers, --raftJoinMembers, --raftJoinAsLearner, --raftBootstrapPeerConfigDir). The protected-bootstrap e2e fixtures read or overwrite them deep inside group construction, so they get their own part.

Behavior change

None. Flag names, defaults and help text are unchanged: -help output is identical to the base.

Risk

Low. The values are read-only after parsing. Every former global read now gets the same value through a parameter or struct field.

Test evidence

  • go test -race -count=1 .: ok (229s).
  • golangci-lint: 0 issues.
  • scripts/check-production-imports.sh: ok.
  • -help output: identical to the base binary.
  • Test list: identical apart from the new TestRaftTopologyConsistencyFlagsDefaultsAndParsing and TestRuntimeInputsRequireRaftID.
  • TestRuntimeInputsRejectCommitTSFenceBeforeOpeningStores no longer overwrites a global and runs t.Parallel.
  • Jepsen: not run. Nothing in replication, MVCC or OCC changed.

Self-review

  1. Data loss: no write, apply or persistence path changes. The data dir reaches the KEK guard, shard groups and snapshot offload unchanged.
  2. Concurrency: the values are immutable after parsing.
  3. Performance: start-up only. readWatermarkAdvance is still decided once per server build.
  4. Consistency: the commit-ts fence and read-watermark gates read the same parsed booleans in the shard store, the coordinator, Internal RPC options and the public-service start.
  5. Test coverage: new tests pin the defaults, parsing and the required --raftId check. The commit-ts fence test now builds its flags explicitly.

Move --address, --raftId, --raftEngine and --raftDataDir into
raftFlags; the Raft group, shard range, Raft-to-protocol address maps
and the HT-FIFO partition map into topologyFlags; and --commitTSFence
and --readWatermarkAdvance into consistencyFlags. The runtime-input
resolvers take *serverFlags; the KEK pre-nonce guard, admin listener,
raft gRPC servers, server runner and snapshot offload receive the
values they need.

The bootstrap and join flags stay package globals for a later part.
No flag name, default or help text changes.

Signed-off-by: bootjp <contact@bootjp.me>
Signed-off-by: bootjp <contact@bootjp.me>
@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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 7 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

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: e9dc582e-cc49-4009-a527-43c98f199e04
Commits

Reviewing files that changed from the base of the PR and between d6e8fbb and d679b25.

Files selected for processing: 15

  • docs/design/2026_11_12_partial_root_package_decomposition.md
  • main.go
  • main_admin.go
  • main_admin_service.go
  • main_bootstrap_network_wiring.go
  • main_commit_ts_fence.go
  • main_commit_ts_fence_test.go
  • main_distribution.go
  • main_encryption_admin.go
  • main_encryption_kek.go
  • main_flags.go
  • main_raft_servers.go
  • main_raft_topology_flags_test.go
  • main_runtime_config.go
  • main_server_runner.go
  • 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

@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-12T15:19:47.415922Z d679b25 PR opened
🔒 Security Review ✅ Completed 2026-11-12T15:21:43.336136Z d679b25 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.

Base automatically changed from design/root-package-decomposition-m2e to main November 12, 2026 15:20
@bootjp
bootjp merged commit 4c2c46a into main Nov 12, 2026
13 checks passed
@bootjp
bootjp deleted the design/root-package-decomposition-m2f branch November 12, 2026 15:44
bootjp added a commit that referenced this pull request Nov 12, 2026
…2) (#1443)

Design: docs/design/2026_11_12_partial_root_package_decomposition.md

M2 part 7, stacked on #1442. Retarget it to `main` once #1442 merges.
This is the last M2 part: after it, the root package registers no flag
as a package global.

## Changes
- `raftBootstrapFlags` (`main_raft_peers.go`) holds:
  - `--raftBootstrap`
  - `--raftBootstrapMembers`
  - `--raftGroupPeers`
  - `--raftJoinMembers`
  - `--raftJoinAsLearner`
- `--raftBootstrapPeerConfigDir`, which moved here from
`main_bootstrap_launch.go`
- `raftBootstrapConfig` gains `peerConfigDir` and `joinAsLearner`, set
in `resolveRuntimeInputs`. They reach:
- `loadProtectedBootstrapDomain` / `validateProtectedBootstrapDomain` /
`loadGroupBootstrapSpec`: these take the dir explicitly.
  - The shard-group builder's protected-spec and protected-TSO checks.
  - `buildRuntimeForGroup`.
- `buildDedicatedTSOGroup` / `buildProtectedDedicatedTSOGroup`: these
gain a `joinAsLearner` parameter after `bootstrap`.
- `serversInput.raftJoining` replaces the `--raftJoinMembers` read in
the server runner. It is computed by `raftBootstrapFlags.joining()`,
with the same trim semantics.
- Tests:
- The protected-bootstrap e2e fixtures (single-group, multi-node, TSO,
rotation, offline encryption, recovery race, external rotation) pass the
peer-config dir through `raftBootstrapConfig` and their start helpers.
They no longer overwrite a process global.
- The `require.Empty(*raftBootstrapPeerConfigDir)` leak guards are gone;
there is no global left to leak.
  - The two launch tests now run `t.Parallel`.
- `main_flags.go` has no package flag globals left. The design doc marks
M2 implemented, and CLAUDE.md states the rule as settled.

## Behavior change
None:
- Flag names, defaults and help text are unchanged: `-help` output is
identical to the base.
- `bootstrap` is still `--raftBootstrap || anyBootstrapServers()`.
- The protected path still turns on exactly when the peer-config dir is
non-empty.

## Risk
Low to moderate. The values are read-only after parsing. The one thing
to check is that every production path into group construction carries
`bootstrapCfg`. It does: `run()` →
`buildShardGroupsWithEncryptionWiring` → `buildShardGroups` →
`loadProtectedBootstrapDomain` and `shardGroupBuilder{bootstrapCfg}`.
That is the only production path.

## Test evidence
- `go test -race -count=1 .`: ok (229s).
- `golangci-lint`: 0 issues.
- `scripts/check-production-imports.sh`: ok.
- `-help` output: identical to the base binary.
- Test list: identical apart from the new
`TestRuntimeInputsCarryBootstrapFlagsIntoBootstrapConfig` and
`TestRaftBootstrapFlagsJoining`.
- Jepsen: not run. Nothing in replication, MVCC or OCC changed. The
protected-bootstrap e2e suites above cover the touched start-up path.

## Self-review
1. **Data loss**: no write or apply path changes. Protected groups still
refuse to open without the domain when a peer-config dir is set.
2. **Concurrency**: the values are immutable after parsing. Removing the
global means bootstrap tests no longer race on shared state, and the
launch tests can run in parallel.
3. **Performance**: start-up only.
4. **Consistency**: the commit-ts fence start-up check, protected-domain
loading, the spec-presence checks and learner join all read the same
parsed values as before.
5. **Test coverage**: new tests cover the flags → `raftBootstrapConfig`
mapping and `joining()`. All protected-bootstrap e2e fixtures now build
their config explicitly.
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