feat(statestore): enforce the execution transition table and map ErrIllegalTransition over the wire
Every caller-supplied status write (Transition, ParkTask, Requeue, RetryTask, BeginRemediation) now checks the shared taskstate transition table inside the write's transaction, after the from guard decides staleness. An off-table pair returns the new storecontract.ErrIllegalTransition, carried over gRPC through mapError/unmapError on (FailedPrecondition, "illegal transition"). Claim, BeginRemediation and RecoverStale pin their pairs in SQL; a test pins those pairs to the table so a query edit cannot move a write off it. Requeue/RetryTask share one guarded requeue body. (archie-core-qdbo.5)
This commit is contained in:
8 files changed
+274
-33
No files matched your search
@@ -484,6 +484,20 @@ func (q *Queries) ListTaskSummaries(ctx context.Context, limit int32) ([]ListTas
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const lockTaskStatus = `-- name: LockTaskStatus :one
|
||||
SELECT status FROM tasks WHERE id = $1 FOR UPDATE
|
||||
`
|
||||
|
||||
// Locks the task's row and returns its current status, so the staleness and
|
||||
// transition-table checks that decide a guarded write hold against a
|
||||
// concurrent claim or transition until the update in the same transaction.
|
||||
func (q *Queries) LockTaskStatus(ctx context.Context, id int64) (string, error) {
|
||||
row := q.db.QueryRow(ctx, lockTaskStatus, id)
|
||||
var status string
|
||||
err := row.Scan(&status)
|
||||
return status, err
|
||||
}
|
||||
|
||||
const parkTask = `-- name: ParkTask :execrows
|
||||
UPDATE tasks
|
||||
SET status = 'parked', park_reason = $2, park_class = $3, updated_at = now()
|
||||
|
||||
Reference in new issue
Block a user