Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion runtime/drivers/clickhouse/model_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package clickhouse

import (
"context"
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -282,7 +283,13 @@ func (c *Connection) Exists(ctx context.Context, res *drivers.ModelResult) (bool
}

_, err := olap.InformationSchema().Lookup(ctx, c.config.Database, "", res.Table)
return err == nil, nil
if err != nil {
if errors.Is(err, drivers.ErrNotFound) {
return false, nil
}
return false, err
}
return true, nil
}

func (c *Connection) Delete(ctx context.Context, res *drivers.ModelResult) error {
Expand Down
9 changes: 8 additions & 1 deletion runtime/drivers/duckdb/model_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package duckdb

import (
"context"
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -137,7 +138,13 @@ func (c *connection) Exists(ctx context.Context, res *drivers.ModelResult) (bool
}

_, err := olap.InformationSchema().Lookup(ctx, "", "", res.Table)
return err == nil, nil
if err != nil {
if errors.Is(err, drivers.ErrNotFound) {
return false, nil
}
return false, err
}
return true, nil
}

func (c *connection) Delete(ctx context.Context, res *drivers.ModelResult) error {
Expand Down
2 changes: 1 addition & 1 deletion runtime/metricsview/executor/executor_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (e *Executor) ValidateAndNormalizeMetricsView(ctx context.Context) (*Valida
res.OtherErrs = append(res.OtherErrs, fmt.Errorf("table %q does not exist", mv.Table))
return res, nil
}
return nil, fmt.Errorf("could not find table %q: %w", mv.Table, err)
return nil, fmt.Errorf("failed to look up table %q: %w", mv.Table, err)
}

// Populate empty database/databaseSchema from table metadata for StarRocks only.
Expand Down
13 changes: 12 additions & 1 deletion runtime/reconcilers/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,19 @@ func (r *ModelReconciler) Reconcile(ctx context.Context, n *runtimev1.ResourceNa
var exists bool
if prevManager != nil {
exists, err = prevManager.Exists(ctx, prevResult)
// If the check errored, we can't know if the output is still there.
// Treating it as missing could trigger a destructive full reset on a transient failure,
// so we return the error instead and let the next reconcile retry.
// Exception: a manually triggered full refresh is an explicit instruction to rebuild,
// so we let it proceed as the escape hatch for a persistently failing check.
if err != nil {
r.C.Logger.Warn("failed to check if model output exists", zap.String("model", n.Name), zap.Error(err), observability.ZapCtx(ctx))
if !model.Spec.TriggerFull {
return runtime.ReconcileResult{
Err: fmt.Errorf("failed to check if model output exists (trigger a full refresh to rebuild anyway): %w", err),
Retrigger: refreshOn,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Recompute a future retry time after lookup failures

When a scheduled model reaches its refresh time and Exists returns a transient error, refreshOn was computed from the last successful RefreshedOn, so it is already in the past. Returning that same value makes processCompletedInvocation treat the retrigger as immediate (inv.reschedule = true when the time is not after time.Now()), causing a tight reconcile loop that repeatedly hits the failing connector until it recovers. For this error path, use a future retry time such as nextRefreshTime(time.Now(), ...) instead of the stale scheduled time.

Useful? React with 👍 / 👎.

}
}
r.C.Logger.Warn("failed to check if model output exists, proceeding because a full refresh was manually triggered", zap.String("model", n.Name), zap.Error(err), observability.ZapCtx(ctx))
}
}

Expand Down
Loading