Skip to content

bundle/statemgmt: add StateReader abstraction for file and DMS state#5355

Draft
shreyas-goenka wants to merge 1 commit into
mainfrom
shreyas-goenka/cli-state-read-from-dms
Draft

bundle/statemgmt: add StateReader abstraction for file and DMS state#5355
shreyas-goenka wants to merge 1 commit into
mainfrom
shreyas-goenka/cli-state-read-from-dms

Conversation

@shreyas-goenka
Copy link
Copy Markdown
Contributor

@shreyas-goenka shreyas-goenka commented May 28, 2026

Summary

Adds a self-contained StateReader abstraction for reading the direct engine's
resource state, with two implementations:

type StateReader interface {
    Load(ctx context.Context, db *dstate.DeploymentState) error
}
  • NewFileStateReader(path) — reads local resources.json (delegates to
    DeploymentState.Open, so WAL recovery + migration are preserved).
  • NewDMSStateReader(client, deploymentID, path) — reads from the deployment
    metadata service via Bundle.ListResourcesAll, mapping each DMS resource into
    a state entry (prefixing keys with resources., copying resource_id +
    serialized state).

This is deliberately not wired into the deploy path. It is a drop-in seam to
replace the current StateDB.Open call in process.go once the DMS lock and
op-reporting PRs land; selecting the reader by managed-state and sourcing the
deployment ID are integration-time concerns that depend on those PRs.

Rework notes (vs the previous version of this PR)

The earlier version inlined LoadStateFromDMS and scattered managed-state
branches across state_pull.go / state_push.go / process.go, stacked on the
now-superseded old DMS-lock branch. This version instead:

  • Models the two backends as one interface with two implementations, matching
    the house style of lock.DeploymentManager and direct.opRecorder.
  • Keeps the file path delegating to DeploymentState.Open so WAL recovery and
    state migration are not lost.
  • Is based on main and carries no integration changes, so it can land
    independently and be integrated later.

Test plan

  • go test ./bundle/statemgmt/... (new TestDMSStateReader* / TestFileStateReader*)
  • go build ./...
  • go tool golangci-lint run ./bundle/statemgmt/ — 0 issues

shreyas-goenka added a commit that referenced this pull request May 28, 2026
The deadcode lint check flagged this as unreachable on PR #5355's CI.
ManagedState returned (string, bool) but no caller existed — every consumer
uses IsManagedState (the bool wrapper). Drop it; reintroduce only if a
caller needs the raw value.

Co-authored-by: Isaac
@eng-dev-ecosystem-bot
Copy link
Copy Markdown
Collaborator

eng-dev-ecosystem-bot commented May 28, 2026

Commit: 71a41d9

Run: 26727951172

Introduce a StateReader interface with two implementations that populate the
direct engine's resource-state DB:

- file-based, reading the local resources.json (delegates to
  DeploymentState.Open, preserving WAL recovery + migration)
- DMS-based, reading from the deployment metadata service via the SDK
  Bundle.ListResourcesAll

This is a self-contained, drop-in abstraction with unit tests; it is not yet
wired into the deploy path. Integration (selecting the reader by managed-state
and sourcing the deployment ID) follows once the DMS lock and op-reporting PRs
land.

Co-authored-by: Isaac
@shreyas-goenka shreyas-goenka force-pushed the shreyas-goenka/cli-state-read-from-dms branch from 0e706b8 to 71a41d9 Compare May 31, 2026 23:44
@shreyas-goenka shreyas-goenka changed the title [bundle] Read deployment state from Deployment Metadata Service (step 4) bundle/statemgmt: add StateReader abstraction for file and DMS state May 31, 2026
@shreyas-goenka shreyas-goenka changed the base branch from shreyas-goenka/bundle-dms-lock-impl to main May 31, 2026 23:45
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.

2 participants