Skip to content

Do not stick to primary after log Jira DVCS usage

What does this MR do?

Closes #325638 (closed)

In the /api/:version/repos/:namespace/:project/branches endpoint, we always update the timestamp of a project's feature usage:

        get ':namespace/:project/branches' do
          user_project = find_project_with_access(params)

          update_project_feature_usage_for(user_project) # !!!

          branches = ::Kaminari.paginate_array(user_project.repository.branches.sort_by(&:name))

          present paginate(branches), with: ::API::Github::Entities::Branch, project: user_project
        end

That leads the following DB queries to be redirected to the primary DB, instead of the replicas. This MR is to prevent primary stickiness afterward. In !56849 (merged), we introduces ::Gitlab::Database::LoadBalancing::Session.without_sticky_writes to prevent session stickiness after a write. It actually solves this issue. We just need to use that interface to wrap around the timestamp update.

Plus, as discussed in #325638 (comment 536421831), and in the slack thread, the usage doesn't need to be updated whenever the API is call. The update frequency of once per day is good enough.

Around 500k (38%) requests to this endpoint get this problem over total 1.3M request. We expect that after this fix, we could cut down 10M queries to primary.

Screenshots (strongly suggested)

Before

Screen_Shot_2021-03-25_at_14.09.52

After (when the usage has not been updated today - once per day for a project - 3 primary queries, no sticky)

Screen_Shot_2021-03-25_at_14.05.27

After (when the usage is already updated today - 0 primary queries)

Screen_Shot_2021-03-25_at_14.03.45

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Related to #325638 (closed)

Edited by Quang-Minh Nguyen

Merge request reports