Check reservation scope on takeover and tighten scope deferral spec

What does this MR do and why?

Addresses three non-blocking review notes from !264227 (merged):

  • Reservation takeover checks the scope (!264227 (comment 4140110227)). A job deferred while the scope was off waits in the main queue, and resuming it reserves a slot with no scope. Once the scope is on, the job resolves a scope key at perform and took that reservation over without a share check, so the backlog that was queued when the scope was turned on skipped the share. A resumed job now takes over a reservation only when the reservation is of its own scope. Otherwise the reservation is released and the job is checked like a new one, so a job that must wait goes to its own scope queue. The worker limit was never at risk, because the reservation already counted against it.
  • Scheduled-job spec covers the job['at'] guard (!264227 (comment 4140110526)). The spec passed without the guard, because its job had no scope key and the worker was below its limit. It now enqueues under the queued scope, so only the guard keeps the job scheduled.
  • Help text of sidekiq_concurrency_limit_scope_deferred_jobs_total (!264227 (comment 4140110480)). The counter also counts jobs deferred on enqueue behind their scope's queue, so the help text says both.

Part 1 of #637499 (per-scope counters) has to keep this in mind: releasing a reservation of another scope decrements that reservation's scope, not the job's.

References

How to set up and validate locally

bin/rspec spec/lib/gitlab/sidekiq_middleware/concurrency_limit/client_spec.rb \
  spec/lib/gitlab/sidekiq_middleware/concurrency_limit/server_spec.rb \
  spec/lib/gitlab/sidekiq_middleware/concurrency_limit/worker_execution_tracker_spec.rb

The new server and tracker examples for a reservation of another scope fail without the Lua change, and the scheduled-job example fails without the job['at'] guard.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Alan (Maciej) Paruszewski

Merge request reports

Loading
Loading