feat: enforce shared application resource quotas across namespaces
This commit is contained in:
@@ -46,6 +46,9 @@ func readExecutionTask(ctx context.Context, tx *sql.Tx, ns, id core.ID) (executi
|
||||
return row, err
|
||||
}
|
||||
func lockQueue(ctx context.Context, tx *sql.Tx, ns, id core.ID) (paused bool, max uint32, err error) {
|
||||
if _, err = lockApplicationResources(ctx, tx, ns, false); err != nil {
|
||||
return
|
||||
}
|
||||
err = tx.QueryRowContext(ctx, "SELECT paused,max_concurrency FROM pulse_queues WHERE namespace_id=? AND id=? FOR UPDATE", ns, id).Scan(&paused, &max)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
err = fault.NotFound
|
||||
@@ -232,6 +235,9 @@ func (s *ExecutionStore) Claim(ctx context.Context, token auth.Token, b worker.B
|
||||
if err := exactlyOne(changed, err); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := reserveApplicationAttempt(ctx, tx, token.NamespaceID); err != nil {
|
||||
return err
|
||||
}
|
||||
view, err := readTask(ctx, tx, token.NamespaceID, locked, false)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -417,6 +423,9 @@ func releasePermits(ctx context.Context, tx *sql.Tx, ns, attempt core.ID, now ti
|
||||
if len(permits) == 0 {
|
||||
return errors.New("active attempt has no permit to release")
|
||||
}
|
||||
if err := releaseApplicationAttempt(ctx, tx, ns, attempt); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, p := range permits {
|
||||
result, err := tx.ExecContext(ctx, `UPDATE pulse_concurrency_limits SET used_permits=used_permits-1,revision=revision+1,updated_at=? WHERE namespace_id=? AND id=? AND used_permits>0`, now, ns, p.limit)
|
||||
if err := exactlyOne(result, err); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user