Skip to content

Commit

Permalink
lock for delete (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessepeterson authored Nov 27, 2024
1 parent 0ee5b5c commit 7d76fa7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
10 changes: 10 additions & 0 deletions engine/storage/mysql/query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ WHERE
step_id = ? AND
completed != 0;

-- name: LockIDCommandsByStepID :exec
SELECT
command_uuid
FROM
id_commands
WHERE
enrollment_id = ? AND
step_id = ?
FOR UPDATE;

-- name: RemoveIDCommandsByStepID :exec
DELETE FROM
id_commands
Expand Down
21 changes: 21 additions & 0 deletions engine/storage/mysql/sqlc/query.sql.go

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

8 changes: 7 additions & 1 deletion engine/storage/mysql/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,13 @@ func (s *MySQLStorage) StoreCommandResponseAndRetrieveCompletedStep(ctx context.
Commands: []storage.StepCommandResult{*sc},
}

// TODO: select ... for update on id commands?
err = qtx.LockIDCommandsByStepID(ctx, sqlc.LockIDCommandsByStepIDParams{
EnrollmentID: id,
StepID: cmdCt.StepID,
})
if err != nil {
return fmt.Errorf("lock commands by step by id (%d): %w", cmdCt.StepID, err)
}

cmdR, err := qtx.GetIDCommandsByStepID(ctx, sqlc.GetIDCommandsByStepIDParams{
EnrollmentID: id,
Expand Down

0 comments on commit 7d76fa7

Please sign in to comment.