Skip to content

Commit 35705a1

Browse files
committed
direct: Engine.SaveState takes ctx, returns void; logs I/O failures internally
Resource implementations cannot recover from a state-persistence failure — the resource already exists on the server and aborting would not undo its creation. Log the error via logdiag instead of propagating it, and drop the error return so call sites are a single statement. Co-authored-by: Denis Bilenko
1 parent 4876b0e commit 35705a1

8 files changed

Lines changed: 17 additions & 22 deletions

File tree

bundle/direct/dresources/adapter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type IResource interface {
5353

5454
// DoCreate creates a new resource from the newState. Returns id of the resource and optionally remote state.
5555
// If remote state is available as part of the operation, return it; otherwise return nil.
56-
// Call engine.SaveState(id, state) to persist intermediate state before long-running waits.
56+
// Call engine.SaveState(ctx, id, state) to persist intermediate state before long-running waits.
5757
// Example: func (r *ResourceVolume) DoCreate(ctx context.Context, _ *Engine, newState *catalog.CreateVolumeRequestContent) (string, *catalog.VolumeInfo, error)
5858
DoCreate(ctx context.Context, engine *Engine, newState any) (id string, remoteState any, e error)
5959

bundle/direct/dresources/app.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,7 @@ func (r *ResourceApp) DoCreate(ctx context.Context, engine *Engine, config *AppS
157157
// Save state as soon as the app exists so it is not orphaned if the wait or
158158
// lifecycle management is interrupted.
159159

160-
if err := engine.SaveState(app.Name, config); err != nil {
161-
return "", nil, err
162-
}
160+
engine.SaveState(ctx, app.Name, config)
163161

164162
remote, err := r.waitForApp(ctx, r.client, config.Name)
165163
if err != nil {

bundle/direct/dresources/cluster.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,7 @@ func (r *ResourceCluster) DoCreate(ctx context.Context, engine *Engine, config *
156156

157157
// Save state immediately after the cluster is created so it is not orphaned
158158
// if the subsequent wait or terminate is interrupted.
159-
if err := engine.SaveState(id, config); err != nil {
160-
return "", nil, err
161-
}
159+
engine.SaveState(ctx, id, config)
162160

163161
// Always wait for RUNNING first: clusters start in PENDING state and must be polled.
164162
_, err = r.client.Clusters.WaitGetClusterRunning(ctx, id, 15*time.Minute, nil)

bundle/direct/dresources/database_instance.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ func (d *ResourceDatabaseInstance) DoCreate(ctx context.Context, engine *Engine,
3636

3737
// Save state immediately after the instance is created so it is not orphaned
3838
// if the subsequent wait is interrupted.
39-
if err := engine.SaveState(id, config); err != nil {
40-
return "", nil, err
41-
}
39+
engine.SaveState(ctx, id, config)
4240

4341
waiterObj := &database.WaitGetDatabaseInstanceDatabaseAvailable[database.DatabaseInstance]{
4442
Response: config,

bundle/direct/dresources/engine.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package dresources
22

33
import (
4+
"context"
45
"fmt"
56
"reflect"
7+
8+
"github.com/databricks/cli/libs/logdiag"
69
)
710

811
// Engine provides state persistence to resource implementations.
@@ -28,15 +31,19 @@ func NewNopEngine(stateType reflect.Type) *Engine {
2831
// SaveState saves the resource state. id must be the resource's identifier; on
2932
// the first call it is recorded, and subsequent calls panic if a different id is
3033
// passed. x must be a pointer to the same struct type as the resource's state.
31-
func (e *Engine) SaveState(id string, x any) error {
34+
// Failures to persist state are logged but do not abort the deployment — the
35+
// resource already exists and aborting would not undo its creation.
36+
func (e *Engine) SaveState(ctx context.Context, id string, x any) {
3237
if e.id == "" {
3338
e.id = id
3439
} else if e.id != id {
3540
panic(fmt.Sprintf("SaveState: id mismatch: expected %q, got %q", e.id, id))
3641
}
3742
xt := reflect.TypeOf(x)
3843
if xt != e.stateType {
39-
return fmt.Errorf("SaveState: type mismatch: expected %v, got %v", e.stateType, xt)
44+
panic(fmt.Sprintf("SaveState: type mismatch: expected %v, got %v", e.stateType, xt))
45+
}
46+
if err := e.saveFunc(e.id, x); err != nil {
47+
logdiag.LogError(ctx, err)
4048
}
41-
return e.saveFunc(e.id, x)
4249
}

bundle/direct/dresources/model_serving_endpoint.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,7 @@ func (r *ResourceModelServingEndpoint) DoCreate(ctx context.Context, engine *Eng
137137

138138
// Save state immediately after the endpoint is created so it is not orphaned
139139
// if the subsequent wait is interrupted.
140-
if err := engine.SaveState(id, config); err != nil {
141-
return "", nil, err
142-
}
140+
engine.SaveState(ctx, id, config)
143141

144142
remote, err := r.waitForEndpointReady(ctx, config.Name)
145143
return id, remote, err

bundle/direct/dresources/vector_search_endpoint.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ func (r *ResourceVectorSearchEndpoint) DoCreate(ctx context.Context, engine *Eng
7474

7575
// Save state immediately after the endpoint is created so it is not orphaned
7676
// if the subsequent wait is interrupted.
77-
if err := engine.SaveState(id, config); err != nil {
78-
return "", nil, err
79-
}
77+
engine.SaveState(ctx, id, config)
8078

8179
info, err := r.client.VectorSearchEndpoints.WaitGetEndpointVectorSearchEndpointOnline(ctx, config.Name, 60*time.Minute, nil)
8280
if err != nil {

bundle/direct/dresources/vector_search_index.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,7 @@ func (r *ResourceVectorSearchIndex) DoCreate(ctx context.Context, engine *Engine
138138

139139
// Save state immediately after the index is created (endpoint UUID now set) so it
140140
// is not orphaned if the subsequent provisioning wait is interrupted.
141-
if err := engine.SaveState(config.Name, config); err != nil {
142-
return "", nil, err
143-
}
141+
engine.SaveState(ctx, config.Name, config)
144142

145143
remote, err := r.waitForIndexReady(ctx, config.Name, endpointUuid)
146144
if err != nil {

0 commit comments

Comments
 (0)