Skip to content

Add direct state v3 - opt in only for record_deployment_history preview#5403

Open
shreyas-goenka wants to merge 1 commit into
mainfrom
shreyas-goenka/dms-state-version
Open

Add direct state v3 - opt in only for record_deployment_history preview#5403
shreyas-goenka wants to merge 1 commit into
mainfrom
shreyas-goenka/dms-state-version

Conversation

@shreyas-goenka
Copy link
Copy Markdown
Contributor

@shreyas-goenka shreyas-goenka commented Jun 1, 2026

Why

experimental.record_deployment_history is the opt-in preview of the deployment metadata service (DMS). Previewing DMS changes the on-disk state format — but most bundles haven't opted in, and we must not force that format change on them. Two things have to hold:

  • A preview user's upgraded state must be safe to keep using.
  • A CLI that predates the format (an older release, or one that knows an older DMS protocol) must refuse to operate on it — but only for bundles that are actually using DMS.

What

  • Non-DMS deploys keep writing state_version: 2 — unchanged.
  • When a bundle previews DMS, the deploy upgrades its state to state_version: 3 and stamps dms_version: 1. UpgradeToDMS runs before the WAL is started so the bumped version is captured in the WAL header (it panics if called after).
  • On load, the CLI accepts both v2 and v3 and never downgrades a v3 state; a state newer than it understands is rejected (reporting the real supported version, 3).
  • The DMS protocol version (dms_version) is enforced by Open's WithDMS option, passed by process.go only when the bundle has opted into DMS — a bundle that hasn't opted in does not act on the recorded version, so it isn't blocked by it.
  • record_deployment_history is rejected under the terraform engine (it drives DMS, which only the direct engine supports) instead of being silently ignored.

dmsStateVersion/currentDmsVersion are deliberately separate from currentStateVersion; the constant comments record this and the bump-to-4 procedure (step-by-step in TestStateSchemaVersions).

Tests

  • Unit (dstate): state-version gating, WithDMS rejection (newer rejected / gated off when not opted in), UpgradeToDMS round-trip + panic-after-WAL, the bump-procedure tripwire, and a migrations-completeness invariant.
  • Acceptance (record-deployment-history/):
    • state-upgrade — baseline (v2) → opt-in upgrade (v3) → older CLI rejects v3 → newer dms_version rejected → without the flag the same state is accepted.
    • terraform-unsupported — the flag is rejected under the terraform engine.

This pull request and its description were written by Isaac.

@eng-dev-ecosystem-bot
Copy link
Copy Markdown
Collaborator

eng-dev-ecosystem-bot commented Jun 1, 2026

Commit: cf6ef38

Run: 26828525415

@shreyas-goenka shreyas-goenka force-pushed the shreyas-goenka/dms-state-version branch from ad20bc3 to ccbd8f1 Compare June 1, 2026 19:55
@shreyas-goenka shreyas-goenka changed the base branch from shreyas-goenka/dms-version to main June 1, 2026 19:55
@shreyas-goenka shreyas-goenka force-pushed the shreyas-goenka/dms-state-version branch from ccbd8f1 to cefabe0 Compare June 1, 2026 20:10
@shreyas-goenka shreyas-goenka force-pushed the shreyas-goenka/dms-state-version branch from cefabe0 to e70bc2c Compare June 1, 2026 20:11
@shreyas-goenka shreyas-goenka force-pushed the shreyas-goenka/dms-state-version branch from e70bc2c to e1babf2 Compare June 1, 2026 20:23
@shreyas-goenka shreyas-goenka force-pushed the shreyas-goenka/dms-state-version branch from e1babf2 to d15b537 Compare June 1, 2026 20:27
@shreyas-goenka shreyas-goenka force-pushed the shreyas-goenka/dms-state-version branch from d15b537 to fab41cc Compare June 1, 2026 20:42
@shreyas-goenka shreyas-goenka force-pushed the shreyas-goenka/dms-state-version branch from fab41cc to ea32c1d Compare June 1, 2026 20:57
@shreyas-goenka shreyas-goenka force-pushed the shreyas-goenka/dms-state-version branch from ea32c1d to cf5f00d Compare June 1, 2026 21:17
@shreyas-goenka shreyas-goenka force-pushed the shreyas-goenka/dms-state-version branch from cf5f00d to 69c7de4 Compare June 1, 2026 21:18
@shreyas-goenka shreyas-goenka force-pushed the shreyas-goenka/dms-state-version branch from 69c7de4 to 522d49e Compare June 1, 2026 21:25
@shreyas-goenka shreyas-goenka changed the title bundle/direct: conditionally upgrade state version when opted into DMS Add direct state v3 - opt in only for record_deployment_history preview Jun 1, 2026
@shreyas-goenka shreyas-goenka force-pushed the shreyas-goenka/dms-state-version branch from 522d49e to 47fbd29 Compare June 1, 2026 21:40
Comment thread cmd/bundle/utils/process.go Outdated

// Enforce the recorded DMS protocol version only when this bundle has
// opted into DMS; a bundle that has not opted in does not act on it.
if b.Config.Experimental != nil && b.Config.Experimental.RecordDeploymentHistory {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the config is not set - the deployment just falls back to direct deplioyment.

@shreyas-goenka shreyas-goenka marked this pull request as ready for review June 1, 2026 21:51
@shreyas-goenka shreyas-goenka requested a review from denik June 1, 2026 21:51
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 1, 2026

Approval status: pending

/acceptance/bundle/ - needs approval

12 files changed
Suggested: @denik
Also eligible: @pietern, @janniklasrose, @andrewnester, @lennartkats-db, @anton-107

/bundle/ - needs approval

8 files changed
Suggested: @denik
Also eligible: @pietern, @janniklasrose, @andrewnester, @lennartkats-db, @anton-107

/cmd/bundle/ - needs approval

Files: cmd/bundle/generate/dashboard.go, cmd/bundle/utils/process.go
Suggested: @denik
Also eligible: @pietern, @janniklasrose, @andrewnester, @lennartkats-db, @anton-107

General files (require maintainer)

Files: acceptance/acceptance_test.go
Based on git history:

  • @denik -- recent work in bundle/direct/dstate/, bundle/phases/, cmd/bundle/generate/

Any maintainer (@andrewnester, @anton-107, @denik, @pietern, @simonfaltum, @renaudhartert-db) can approve all areas.
See OWNERS for ownership rules.

Comment thread bundle/direct/dstate/state.go Outdated
Comment thread bundle/direct/dstate/migrate_test.go Outdated
func TestStateSchemaVersions(t *testing.T) {
assert.Equal(t, 2, currentStateVersion)
assert.Equal(t, 3, dmsStateVersion)
assert.Equal(t, 1, currentDmsVersion)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this test? We know constants in golang work.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a tripwire test that will trigger anytime someone does a version bump. This forces the author and reviewer to read the instructions above and not miss them.

Comment thread bundle/direct/dstate/state.go Outdated

title "without the flag, the same state is accepted (the check is gated on opt-in)"
trace update_file.py databricks.yml "record_deployment_history: true" "record_deployment_history: false"
trace errcode $CLI bundle plan 2>&1 | contains.py "!is newer than supported version"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if experimental flag is removed? Do we stop calling DMS but keep using normal direct engine? Do we keep version 3 or 2 in that case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we stop calling DMS but keep using normal direct engine?

Yes, we fall back to normal direct engine. It works fine because we'll continue to maintain direct state with WAL and resources.json as we preview.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we keep version 3 or 2 in that case?

We keep version 3. The configuration remains the source of truth for whether to use direct or DMS (provide easy fallback for customers).

Comment thread cmd/bundle/utils/process.go Outdated
@shreyas-goenka shreyas-goenka force-pushed the shreyas-goenka/dms-state-version branch from 47fbd29 to 94d066e Compare June 2, 2026 12:53
Normal deploys keep writing state_version 2. When the bundle opts into
experimental.record_deployment_history, the deploy upgrades the local
state to dmsStateVersion (3) and stamps a new CurrentDmsVersion header
field, so future DMS breaking changes or minimum-CLI requirements can be
gated on what the state was written with.

migrateState now reads up to dmsStateVersion but still auto-migrates only
up to the baseline currentStateVersion, so a v3 state is neither
auto-applied nor downgraded. The upgrade is applied explicitly in
deployCore, never as an automatic migration.

Co-authored-by: Isaac
@shreyas-goenka shreyas-goenka force-pushed the shreyas-goenka/dms-state-version branch from 94d066e to cf6ef38 Compare June 2, 2026 15:01
@shreyas-goenka shreyas-goenka requested a review from denik June 2, 2026 15:02
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.

3 participants