Skip to content

Commit c33cefa

Browse files
denikIsaac
andcommitted
direct: a with_parent child keeps only its edge to its parent
It sends no request, so its other delete edges are not needed; one to a sibling in the same parent closed a cycle through the parent. aws: TestAccept/bundle/resources/schemas/foreign_at_recorded_name TestAccept/bundle/resources/schemas/destroy_after_rename_out_of_band TestAccept/bundle/resources/schemas/recreated_at_recorded_name TestAccept/bundle/resources/schemas/destroy_renamed_with_model_and_secret TestAccept/bundle/resources/volumes/foreign_at_recorded_name TestAccept/bundle/resources/volumes/prevent_destroy_in_renamed_schema TestAccept/bundle/resources/volumes/removed_from_renamed_schema TestAccept/bundle/resources/volumes/prevent_destroy_schema_without_dependency TestAccept/bundle/resources/volumes/prevent_destroy_mixed_case_schema TestAccept/bundle/resources/volumes/select_renamed_schema Co-authored-by: Isaac <no-reply@databricks.com>
1 parent c633f80 commit c33cefa

4 files changed

Lines changed: 42 additions & 8 deletions

File tree

‎acceptance/bundle/resources/volumes/select_renamed_schema/output.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ Resources: 0 created, 0 changed, 2 deleted, 0 unchanged
5454
}
5555
}
5656

57-
>>> musterr [CLI] volumes read main.test-schema-renamed-[UNIQUE_NAME].myvolume2
58-
Error: Volume 'main.test-schema-renamed-[UNIQUE_NAME].myvolume2' does not exist.
57+
>>> musterr [CLI] schemas get main.test-schema-renamed-[UNIQUE_NAME]
58+
Error: Schema 'main.test-schema-renamed-[UNIQUE_NAME]' does not exist.
5959

6060
>>> [CLI] bundle summary --output json
6161
{}

‎acceptance/bundle/resources/volumes/select_renamed_schema/script‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ print_requests.py //unity-catalog &> LOG.rename_requests
2525
title "Selecting only the schema still lists the volume, which its delete takes along"
2626
trace $CLI bundle deploy --select schemas.schema1 --auto-approve
2727
trace print_requests.py //unity-catalog
28-
trace musterr $CLI volumes read "$NEW_SCHEMA.myvolume2"
28+
trace musterr $CLI schemas get "$NEW_SCHEMA"
2929
trace $CLI bundle summary --output json | jq '.resources // {}'

‎bundle/direct/graph.go‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,19 @@ func makeGraph(plan *deployplan.Plan) (*dagrun.Graph, error) {
2626

2727
isDelete := entry.Action == deployplan.Delete
2828

29+
if isDelete && entry.WithParent != "" {
30+
// No delete is sent for it, so nothing has to wait for it: its state is dropped only
31+
// once its parent's delete, which removes it, has succeeded. Its other edges are left
32+
// out, as one to a sibling in the same parent would close a cycle through the parent.
33+
if parent := slices.IndexFunc(entry.DependsOn, func(d deployplan.DependsOnEntry) bool { return d.Node == entry.WithParent }); parent >= 0 && plan.Plan[entry.WithParent] != nil {
34+
g.AddDirectedEdge(entry.WithParent, resourceKey, entry.DependsOn[parent].Label)
35+
}
36+
continue
37+
}
38+
2939
for _, dep := range entry.DependsOn {
3040
if _, exists := plan.Plan[dep.Node]; exists {
31-
if isDelete && dep.Node == entry.WithParent {
32-
// No delete is sent for it: its state is dropped only once its parent's
33-
// delete, which removes it, has succeeded.
34-
g.AddDirectedEdge(dep.Node, resourceKey, dep.Label)
35-
} else if isDelete {
41+
if isDelete {
3642
g.AddDirectedEdge(resourceKey, dep.Node, dep.Label)
3743
} else {
3844
g.AddDirectedEdge(dep.Node, resourceKey, dep.Label)

‎bundle/direct/graph_test.go‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,31 @@ func TestMakeGraphDeletesWithParentAfterItsParent(t *testing.T) {
5050
}
5151
}
5252
}
53+
54+
func TestMakeGraphWithParentReferencingASibling(t *testing.T) {
55+
const (
56+
schemaKey = "resources.schemas.schema1"
57+
volume1Key = "resources.volumes.volume1"
58+
volume2Key = "resources.volumes.volume2"
59+
)
60+
plan := deployplan.NewPlanDirect()
61+
plan.Plan[schemaKey] = &deployplan.PlanEntry{Action: deployplan.Delete, ID: "main.moved"}
62+
plan.Plan[volume1Key] = &deployplan.PlanEntry{Action: deployplan.Delete, ID: "main.moved.v1", DependsOn: []deployplan.DependsOnEntry{{Node: schemaKey}}}
63+
// volume2 names its schema through volume1: deleted before volume1 as usual, it would close a
64+
// cycle through the schema it goes with.
65+
plan.Plan[volume2Key] = &deployplan.PlanEntry{
66+
Action: deployplan.Delete, Gone: true, WithParent: schemaKey,
67+
DependsOn: []deployplan.DependsOnEntry{{Node: volume1Key}, {Node: schemaKey}},
68+
}
69+
70+
g, err := makeGraph(plan)
71+
require.NoError(t, err)
72+
require.NoError(t, g.DetectCycle())
73+
74+
var order []string
75+
g.Run(1, func(key string, failedDependency *string) bool {
76+
order = append(order, key)
77+
return true
78+
})
79+
assert.Equal(t, []string{volume1Key, schemaKey, volume2Key}, order)
80+
}

0 commit comments

Comments
 (0)