Skip to content

Commit 80c67af

Browse files
Remove deployment-history configuration enforcement
Addresses denik review comment 4387609280. Existing file state can enable or disable shadow history without being rejected.
1 parent 640f7be commit 80c67af

4 files changed

Lines changed: 38 additions & 56 deletions

File tree

‎acceptance/bundle/dms/existing-state/output.txt‎

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,43 @@ Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged
2525
"features": null
2626
}
2727

28-
=== Enabling recording is refused because the existing deployment is not recorded
28+
=== Enabling history on existing file state succeeds
2929
>>> DATABRICKS_BUNDLE_DEPLOYMENT_HISTORY=true [CLI] bundle deploy
30-
Error: deployment history setting (true) does not match the existing state (false)
31-
32-
Update experimental.deployment_history to match the existing deployment, or run "databricks bundle destroy" to start over
33-
30+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/dms-existing-state-[UNIQUE_NAME]/default/files...
31+
Files: 0 uploaded, 0 deleted
32+
Resources: 0 created, 0 changed, 0 deleted, 1 unchanged
3433

3534
>>> print_requests.py --dms //api/2.0/bundle --oneline
35+
{"method": "POST", "path": "/api/2.0/bundle/deployments", "body": {"display_name": "dms-existing-state-[UNIQUE_NAME]", "initial_parent_path": "/Workspace/Users/[USERNAME]/.bundle/dms-existing-state-[UNIQUE_NAME]/default/state", "target_name": "default", "workspace_info": {"file_path": "/Workspace/Users/[USERNAME]/.bundle/dms-existing-state-[UNIQUE_NAME]/default/files", "root_path": "/Workspace/Users/[USERNAME]/.bundle/dms-existing-state-[UNIQUE_NAME]/default"}}}
3636

37-
=== Wiping the local cache still refuses after pulling the non-DMS state from the workspace
37+
=== Wiping the local cache still reads the existing file state
3838
>>> DATABRICKS_BUNDLE_DEPLOYMENT_HISTORY=true [CLI] bundle deploy
39-
Error: deployment history setting (true) does not match the existing state (false)
39+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/dms-existing-state-[UNIQUE_NAME]/default/files...
40+
Updated jobs.one
41+
Files: 2 uploaded, 0 deleted
42+
Resources: 0 created, 1 changed, 0 deleted, 0 unchanged
43+
44+
=== Disable history before testing ordinary file-state recovery
45+
>>> DATABRICKS_BUNDLE_DEPLOYMENT_HISTORY=false [CLI] bundle deploy
46+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/dms-existing-state-[UNIQUE_NAME]/default/files...
47+
Updated jobs.one
48+
Files: 0 uploaded, 0 deleted
49+
Resources: 0 created, 1 changed, 0 deleted, 0 unchanged
4050

41-
Update experimental.deployment_history to match the existing deployment, or run "databricks bundle destroy" to start over
51+
>>> jq .features // {} .databricks/bundle/default/resources.json
52+
{}
4253

54+
>>> print_requests.py --dms //api/2.0/bundle --oneline
55+
{"method": "POST", "path": "/api/2.0/bundle/deployments/[ORIGINAL_DEPLOYMENT_ID]/versions", "q": {"version_id": "3"}, "body": {"cli_version": "[CLI_VERSION]", "operations": [{"action_type": "OPERATION_ACTION_TYPE_UPDATE", "resource_key": "jobs.one"}], "version_type": "VERSION_TYPE_DEPLOY"}}
56+
{"method": "PATCH", "path": "/api/2.0/bundle/deployments/[ORIGINAL_DEPLOYMENT_ID]/versions/3/operations/jobs.one", "q": {"update_mask": "state,error_message,resource_id,status"}, "body": {"error_message": "", "resource_id": "[ORIGINAL_JOB_ID]", "sequence_id": 0, "state": "{\"state\":{\"deployment\":{\"deployment_id\":\"[ORIGINAL_DEPLOYMENT_ID]\",\"kind\":\"BUNDLE\",\"metadata_file_path\":\"/Workspace/Users/[USERNAME]/.bundle/dms-existing-state-[UNIQUE_NAME]/default/state/metadata.json\",\"version_id\":\"3\"},\"edit_mode\":\"UI_LOCKED\",\"format\":\"MULTI_TASK\",\"max_concurrent_runs\":1,\"name\":\"one\",\"queue\":{\"enabled\":true}}}", "status": "OPERATION_STATUS_SUCCEEDED"}}
57+
{"method": "POST", "path": "/api/2.0/bundle/deployments/[ORIGINAL_DEPLOYMENT_ID]/versions/3/complete", "body": {"completion_reason": "VERSION_COMPLETE_SUCCESS"}}
4358

4459
=== A leftover local WAL with the wrong lineage is still refused
4560
>>> DATABRICKS_BUNDLE_DEPLOYMENT_HISTORY=true [CLI] bundle deploy
4661
Error: reading state from [TEST_TMP_DIR]/.databricks/bundle/default/resources.json: WAL recovery failed: WAL lineage ("stale") does not match state lineage ("[UUID]")
4762

4863

49-
=== Destroy clears the deployment. With nothing recorded remotely the bundle is treated as new, so recording can be enabled once the stale WAL is gone
64+
=== Destroy follows the disabled history marker; the next deployment can enable history again
5065
>>> DATABRICKS_BUNDLE_DEPLOYMENT_HISTORY=true [CLI] bundle destroy --auto-approve
5166
The following resources will be deleted:
5267
delete resources.jobs.one

‎acceptance/bundle/dms/existing-state/script‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,30 @@ trace $CLI bundle deploy
55
dms_plan
66
trace print_requests.py --dms //api/2.0/bundle --oneline
77
trace jq '{state_version, features}' .databricks/bundle/default/resources.json
8+
job_id=$(jq -r '.state["resources.jobs.one"].__id__' .databricks/bundle/default/resources.json)
9+
add_repl "$job_id" ORIGINAL_JOB_ID
810

9-
title "Enabling recording is refused because the existing deployment is not recorded"
10-
musterr trace DATABRICKS_BUNDLE_DEPLOYMENT_HISTORY=true $CLI bundle deploy
11+
title "Enabling history on existing file state succeeds"
12+
trace DATABRICKS_BUNDLE_DEPLOYMENT_HISTORY=true $CLI bundle deploy
13+
deployment_id=$(MSYS_NO_PATHCONV=1 $CLI workspace get-status "/Workspace/Users/${CURRENT_USER_NAME}/.bundle/dms-existing-state-${UNIQUE_NAME}/default/state/resources.deployment.json" | python3 -c 'import sys, json; print(json.load(sys.stdin)["object_id"])')
14+
add_repl "$deployment_id" ORIGINAL_DEPLOYMENT_ID
1115
trace print_requests.py --dms //api/2.0/bundle --oneline
1216

13-
title "Wiping the local cache still refuses after pulling the non-DMS state from the workspace"
17+
title "Wiping the local cache still reads the existing file state"
1418
rm -rf .databricks
15-
musterr trace DATABRICKS_BUNDLE_DEPLOYMENT_HISTORY=true $CLI bundle deploy
19+
trace DATABRICKS_BUNDLE_DEPLOYMENT_HISTORY=true $CLI bundle deploy
20+
21+
title "Disable history before testing ordinary file-state recovery"
22+
trace DATABRICKS_BUNDLE_DEPLOYMENT_HISTORY=false $CLI bundle deploy
23+
trace jq '.features // {}' .databricks/bundle/default/resources.json
24+
trace print_requests.py --dms //api/2.0/bundle --oneline
1625

1726
title "A leftover local WAL with the wrong lineage is still refused"
1827
mkdir -p .databricks/bundle/default
1928
printf '{"lineage":"stale","serial":99,"state_version":2,"features":{"deployment_history_shadow":{}}}\n' > .databricks/bundle/default/resources.json.wal
2029
musterr trace DATABRICKS_BUNDLE_DEPLOYMENT_HISTORY=true $CLI bundle deploy
2130

22-
title "Destroy clears the deployment. With nothing recorded remotely the bundle is treated as new, so recording can be enabled once the stale WAL is gone"
31+
title "Destroy follows the disabled history marker; the next deployment can enable history again"
2332
# Clear the stale WAL first: it was refused, not deleted, and destroy runs without recording, so it
2433
# would otherwise try to replay it and fail on the lineage mismatch.
2534
rm -f .databricks/bundle/default/resources.json.wal

‎bundle/statemgmt/state_pull.go‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,6 @@ func (s *StateDesc) IsDMS() bool {
7777
return ok
7878
}
7979

80-
// RecordsHistory includes both DMS-authoritative state and deployment history shadow.
81-
func (s *StateDesc) RecordsHistory() bool {
82-
_, bestEffort := s.Features["deployment_history_shadow"]
83-
return bestEffort || s.IsDMS()
84-
}
85-
8680
func localRead(ctx context.Context, fullPath string, engine engine.EngineType) *StateDesc {
8781
content, err := os.ReadFile(fullPath)
8882
if err != nil {

‎cmd/bundle/utils/process.go‎

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,6 @@ func ProcessBundleRet(cmd *cobra.Command, opts ProcessOptions) (b *bundle.Bundle
359359
}
360360
}
361361

362-
if stateDesc.Engine.IsDirect() && (opts.Deploy || opts.PreDeployChecks) {
363-
if err := enforceDeploymentHistorySetting(ctx, b, stateDesc, true); err != nil {
364-
logdiag.LogError(ctx, err)
365-
return b, stateDesc, root.ErrAlreadyPrinted
366-
}
367-
}
368-
369362
stateMode := dstate.WritingFile
370363
switch {
371364
case stateDesc.IsDMS():
@@ -668,9 +661,6 @@ func OpenDirectStateForRead(ctx context.Context, b *bundle.Bundle, stateDesc *st
668661
if err := b.DeploymentBundle.StateDB.Open(ctx, localPath, dstate.ReadingFile, dstate.WithRecovery(true), dstate.OpenDmsArgs{}); err != nil {
669662
return err
670663
}
671-
if err := enforceDeploymentHistorySetting(ctx, b, stateDesc, false); err != nil {
672-
return err
673-
}
674664
if configuresDeploymentHistory(ctx, b) {
675665
if _, err := prepareDeploymentHistoryShadow(ctx, b); err != nil {
676666
log.Warnf(ctx, "Could not read deployment history: %s", err)
@@ -694,32 +684,6 @@ func OpenDirectStateForRead(ctx context.Context, b *bundle.Bundle, stateDesc *st
694684
if err := b.DeploymentBundle.StateDB.Open(ctx, localPath, dstate.WritingDeploymentHistoryOnly, dstate.WithRecovery(false), dstate.OpenDmsArgs{DeploymentID: dmsDeploymentID, LastVersionID: lastVersionID}); err != nil {
695685
return err
696686
}
697-
return enforceDeploymentHistorySetting(ctx, b, stateDesc, false)
698-
}
699-
700-
func enforceDeploymentHistorySetting(ctx context.Context, b *bundle.Bundle, stateDesc *statemgmt.StateDesc, requireMatch bool) error {
701-
if stateDesc.SourcePath == "" {
702-
return nil
703-
}
704-
configured := configuresDeploymentHistory(ctx, b)
705-
recorded := stateDesc.RecordsHistory()
706-
if b.DeploymentBundle.StateDB.IsOpen() {
707-
recorded = b.DeploymentBundle.StateDB.RecordsHistory()
708-
}
709-
if configured == recorded || (!configured && !stateDesc.IsDMS()) {
710-
return nil
711-
}
712-
if requireMatch {
713-
return fmt.Errorf(`deployment history setting (%t) does not match the existing state (%t)
714-
715-
Update experimental.deployment_history to match the existing deployment, or run "databricks bundle destroy" to start over`, configured, recorded)
716-
}
717-
if configured {
718-
return errors.New(`enabling experimental.deployment_history for an existing deployment is not supported
719-
720-
Run "databricks bundle destroy" first, then deploy again with deployment history enabled`)
721-
}
722-
log.Warnf(ctx, "Deployment history setting (%t) does not match the existing state (%t). Using the existing state.", configured, recorded)
723687
return nil
724688
}
725689

0 commit comments

Comments
 (0)