refactor: split daemon_ha_userspace.go by concern (#4659)#4685
Merged
Conversation
pkg/daemon/daemon_ha_userspace.go had grown to 1123 LOC interleaving four distinct concerns of the userspace-dataplane HA control path: wire delta<->session conversion, the delta stream/drain/queue loop, bulk session export, and takeover/demotion readiness plus failover barriers. codex-review-174 #17 flagged the mix as a real review hazard — the ACK/withhold and demotion-barrier logic sits next to endian/NAT conversion helpers, so a reviewer scanning the barrier path has to wade through unrelated byte-order code. This is a class-B HA control path, so the split is PURE code motion: every top-level declaration is moved verbatim, byte-for-byte, with no behavior change. Concerns are grouped into four sibling files in package daemon: - daemon_ha_userspace_convert.go (16 decls): buildZoneIDs, the endian/NAT-port/MAC helpers, userspaceSessionFromDeltaV4/V6, and the forward-wire alias/key builders. - daemon_ha_userspace_stream.go (11 decls): the drainer and event-stream provider interfaces, shouldSyncUserspaceDelta, syncUserspaceSessionDeltas, runUserspaceEventStream, wireUserspaceEventStreamCallbacks, handleEventStreamDelta, handleEventStreamFullResync, eventStreamFallbackLoop, queueUserspaceSessionDeltas, drainUserspaceSessionDeltasWithConfig. - daemon_ha_userspace_export.go (4 decls): the exporter interfaces, primaryOwnerRGIDs, exportUserspaceOwnerRGSessionsWithConfig. - daemon_ha_userspace_readiness.go (18 decls): the mode / takeover / transfer-readiness / HA-protocol-mismatch interfaces, the demotion-prep suppression-window methods, the prepareUserspaceRGDemotionWithTimeout peer barrier, the manual-failover wrappers, and userspaceDataplaneActive / userspaceRGConfigured / checkUserspaceTakeoverReadiness. daemon_ha_userspace.go stays as the shared shell (3 decls: userspaceXSKBindingController, buildZoneRGMap, rgHasRETH). Load-bearing semantics preserved byte-identical: the delta-slice behavior, the ACK/withhold return contract of handleEventStreamDelta (returns false only for transient readiness gaps so the helper replays), the userspaceDeltaSyncMu (delta drain) vs userspaceDemotionPrepMu (demotion suppression window) lock separation, and the failover peer-barrier logic. The split moves methods, not the lock discipline. Same package, so every unexported symbol stays reachable — buildZoneIDs (consumed by stream + export), the exporter interfaces (used by daemon_ha_sync.go), and buildZoneRGMap / rgHasRETH (used by daemon_apply.go, daemon_ha_vip.go, and package tests). Validation: verified byte-for-byte against origin/master with a go/parser decl-diff over the union of the new files — 52 top-level declarations, identical=52, 0 bodydiff / 0 missing / 0 extra (import lists differ per file as expected and are excluded from the diff). go build ./... clean, go vet ./pkg/daemon/... clean, and go test ./pkg/daemon/... green (the userspace-sync and HA-sync semantic tests are the gate — all pass). No design/doc change: pkg/daemon/ README.md carries no per-file layout entry for this file and the split is behavior-identical. Closes #4659 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015oARShYtiJJ2H4UB4nXGqi
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the userspace-dataplane HA control path by splitting the former monolithic pkg/daemon/daemon_ha_userspace.go into smaller, concern-focused files within the same daemon package to reduce review hazard while keeping symbol visibility unchanged.
Changes:
- Extracts wire/session conversion helpers into
daemon_ha_userspace_convert.go. - Extracts event-stream + polling/drain/queue logic into
daemon_ha_userspace_stream.go, and bulk export intodaemon_ha_userspace_export.go. - Extracts takeover/demotion readiness + demotion barrier logic into
daemon_ha_userspace_readiness.go, leavingdaemon_ha_userspace.goas a small shared shell.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/daemon/daemon_ha_userspace.go | Reduced to shared shell (XSK binding interface + zone/RG helpers). |
| pkg/daemon/daemon_ha_userspace_convert.go | Houses zone ID derivation and delta→session conversion / endian / NAT / MAC helpers. |
| pkg/daemon/daemon_ha_userspace_stream.go | Houses event stream wiring + fallback polling and delta drain/queue pipeline. |
| pkg/daemon/daemon_ha_userspace_export.go | Houses bulk export interfaces and owner-RG session export helpers. |
| pkg/daemon/daemon_ha_userspace_readiness.go | Houses takeover readiness + demotion suppression window + peer-barrier logic. |
| _Log.md | Logs the refactor per repository logging rules. |
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
Closes #4659. Splits
pkg/daemon/daemon_ha_userspace.go(1123 LOC) byconcern into four sibling files in package
daemon. codex-review-174 #17flagged the file as a review hazard: ACK/withhold and demotion-barrier
logic (a class-B HA control path) was interleaved with endian/NAT
wire-conversion helpers.
PURE code motion — behavior-identical. Every top-level declaration is
moved verbatim; no logic changed.
New file layout
daemon_ha_userspace_convert.gouserspaceSessionFromDeltaV4/V6, forward-wire alias/key builders)daemon_ha_userspace_stream.goshouldSyncUserspaceDelta, the sync/event-stream loops,queueUserspaceSessionDeltas,drainUserspaceSessionDeltasWithConfig)daemon_ha_userspace_export.goprimaryOwnerRGIDs,exportUserspaceOwnerRGSessionsWithConfig)daemon_ha_userspace_readiness.goprepareUserspaceRGDemotionWithTimeoutbarrier, manual-failover wrappers,checkUserspaceTakeoverReadiness)daemon_ha_userspace.go(shell)userspaceXSKBindingController,buildZoneRGMap,rgHasRETHLoad-bearing invariants preserved byte-identical
handleEventStreamDeltaACK/withhold contract (returnsfalseonly for transient readiness gaps so the helper replays)userspaceDeltaSyncMu(delta drain) vsuserspaceDemotionPrepMu(demotion suppression window) lock separation — the split moves methods, not the lock disciplineSame package, so all unexported symbols stay reachable (
buildZoneIDs,the exporter interfaces used by
daemon_ha_sync.go, andbuildZoneRGMap/rgHasRETHused bydaemon_apply.go/daemon_ha_vip.goand tests).
Validation
origin/master: 52 top-level declarations, identical=52, 0 bodydiff / 0 missing / 0 extra (import lists differ per file as expected, excluded from diff)go build ./...cleango vet ./pkg/daemon/...cleango test ./pkg/daemon/...green — the userspace-sync + HA-sync semantic tests are the gate; all passgofmt -lcleanNo design/doc change:
pkg/daemon/README.mdhas no per-file layout entryfor this file (it documents behavior, not a file index) and the split is
behavior-identical.
🤖 Generated with Claude Code
https://claude.ai/code/session_015oARShYtiJJ2H4UB4nXGqi