Pre-compute pending build args outside state machine transaction
What does this MR do and why?
Re-roll of !223438 (closed) that will generalize for all enqueue actions.
Overrides Ci::Build's #save and #save! to pre-compute
Ci::PendingBuild.args_from_build before the state machine opens a
database transaction. The args are stored in transition.attributes and
read by UpdateBuildQueueService#push inside the transaction, replacing
the inline computation that previously held the transaction open during
tag lookups, CI minutes checks, and plan lookups.
In AssignResourceFromResourceGroupService, switch from
retry_lock_with_transaction to retry_lock so the
before_transition callback runs outside the transaction boundary.
Both changes are gated behind the :precompute_pending_build_args
feature flag.
References
Part of https://gitlab.com/gitlab-org/gitlab/-/work_items/589484
Screenshots or screen recordings
| Before | After |
|---|---|
How to set up and validate locally
- With the flag disabled, run a pipeline with the following
.gitlab-ci.yml# .gitlab-ci.yml simple_job: script: exit 0 # tests standard enqueue for regressions with_resource_group: resource_group: example-resource-group # tests the enqueue_waiting_for_resource changes script: exit 0- This establishes a baseline
- In rails console enable the feature flag
For good measure, you should also restart rails,
Feature.enable(:precompute_pending_build_args)gdk restart rails. This ensures the feature flag is definitely active in sidekiq later. - Run another pipeline
- This tests the new behaviors
Expected results: In both cases, jobs should complete successfully. This would mean each job successfully transitioned in and out of the pending state.
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.