Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace deployment query broken into 2 queries #2110

Merged
merged 3 commits into from
Jul 18, 2024
Merged
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
10 changes: 6 additions & 4 deletions backend/controller/dal/dal.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,19 +752,21 @@ func (d *DAL) ReplaceDeployment(ctx context.Context, newDeploymentKey model.Depl
var replacedDeploymentKey optional.Option[model.DeploymentKey]
oldDeployment, err := tx.GetExistingDeploymentForModule(ctx, newDeployment.ModuleName)
if err == nil {
count, err := tx.ReplaceDeployment(ctx, oldDeployment.Key, newDeploymentKey, int32(minReplicas))
err = tx.SetDeploymentDesiredReplicas(ctx, oldDeployment.Key, 0)
if err != nil {
return fmt.Errorf("replace deployment failed to replace min replicas from %v to %v: %w", oldDeployment.Key, newDeploymentKey, dalerrs.TranslatePGError(err))
return fmt.Errorf("replace deployment failed to set old deployment replicas from %v to %v: %w", oldDeployment.Key, newDeploymentKey, dalerrs.TranslatePGError(err))
}
if count == 1 {
return fmt.Errorf("replace deployment failed: deployment already exists from %v to %v: %w", oldDeployment.Key, newDeploymentKey, ErrReplaceDeploymentAlreadyActive)
err = tx.SetDeploymentDesiredReplicas(ctx, newDeploymentKey, int32(minReplicas))
if err != nil {
return fmt.Errorf("replace deployment failed to set new deployment replicas from %v to %v: %w", oldDeployment.Key, newDeploymentKey, dalerrs.TranslatePGError(err))
}
err = d.deploymentWillDeactivate(ctx, tx, oldDeployment.Key)
if err != nil {
return fmt.Errorf("replace deployment failed willDeactivate trigger from %v to %v: %w", oldDeployment.Key, newDeploymentKey, dalerrs.TranslatePGError(err))
}
replacedDeploymentKey = optional.Some(oldDeployment.Key)
} else if !dalerrs.IsNotFound(err) {
// any error other than not found
return fmt.Errorf("replace deployment failed to get existing deployment for %v: %w", newDeploymentKey, dalerrs.TranslatePGError(err))
} else {
// Set the desired replicas for the new deployment
Expand Down
1 change: 0 additions & 1 deletion backend/controller/sql/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions backend/controller/sql/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,6 @@ RETURNING id;
INSERT INTO deployment_artefacts (deployment_id, artefact_id, executable, path)
VALUES ((SELECT id FROM deployments WHERE key = @key::deployment_key), $2, $3, $4);

-- name: ReplaceDeployment :one
WITH update_container AS (
UPDATE deployments AS d
SET min_replicas = update_deployments.min_replicas
FROM (VALUES (sqlc.arg('old_deployment')::deployment_key, 0),
(sqlc.arg('new_deployment')::deployment_key, sqlc.arg('min_replicas')::INT))
AS update_deployments(key, min_replicas)
WHERE d.key = update_deployments.key
RETURNING 1)
SELECT COUNT(*)
FROM update_container;

-- name: GetDeployment :one
SELECT sqlc.embed(d), m.language, m.name AS module_name, d.min_replicas
FROM deployments d
Expand Down
20 changes: 0 additions & 20 deletions backend/controller/sql/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading