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
After (when the usage has not been updated today - once per day for a project - 3 primary queries, no sticky)
After (when the usage is already updated today - 0 primary queries)
Does this MR meet the acceptance criteria?
Conformity
-
📋 Does this MR need a changelog?-
I have included a changelog entry. -
I have not included a changelog entry because _____.
-
-
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
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)