Write user refreshes through the shared write path

What does this MR do and why?

Moves today's per-user project_authorizations refresh onto the shared write path that the refresh queue uses (https://gitlab.com/groups/gitlab-org/-/work_items/24326), behind the authz_refresh_write_path flag.

Once the queue starts writing, it and today's refresh will write the same rows. If today's refresh keeps writing on its own, it can overwrite a newer result from the queue with one it calculated earlier. With the flag on, today's refresh still works out which projects changed, but sends only those to RecalculateUserService. That service rechecks them under the user's lock and writes them there, so whichever writer goes last writes a fresh result.

The flag is checked per user, so it can roll out by percentage of users. The refresh log now records the counts the refresh asked for next to the rows written, with shared_write_path. A difference shows where the recheck found something else, which we can compare during the rollout.

WriteBatchService refuses to run inside a transaction, because its locks would be held until the caller commits. Specs run the refresh inside their setup transaction, which production never does. Those specs already skip Gitlab::ExclusiveLease's matching transaction check, because the refresh workers take an exclusive lease. WriteBatchService now respects the same skip.

References

Database

No new queries. The flag adds RecalculateUserService's recheck of the changed projects, in slices of 1,000. Its queries were reviewed and benchmarked in !268607 (merged). Most refreshes change a few projects. The worst case, a full recheck of a user with access to 203k projects, took 9.1 s of warm database time on a production clone, with no statement over 121 ms.

How to set up and validate locally

  1. Enable the flag: Feature.enable(:authz_refresh_write_path).
  2. Add a user to a group with projects, then check log/application_json.log for the refresh with "shared_write_path":true and matching requested and written counts.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist.

🤖 Generated with Claude Code

Edited by Ian Anderson

Merge request reports

Loading
Loading