BigW Consortium Gitlab
Use optimistic locking ## What does this MR do? Removes the usage of pessimistic locking in favor of optimistic which is way cheaper and doesn't block database operation. Since this is very simple change it should be safe. If we receive `StaleObjectError` message we will reload object a retry operations in lock. However, I still believe that we need this one: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7005 as this will reduce a load on Database and FS. This changes a behavior from: ### Pesimistic locking (previous behavior) #### For updating 1. SELECT * FOR UPDATE (other updates wait on this) 2. we update ci_pipeline 3. latest_build_status 4. enqueue: (use: transition :created -> :pending) 5. [state_machine] we are in state created, we can go to pending 6. [state_machine] ci_pipeline.status = created 7. [state_machine] ci_pipeline.save 8. [state_machine] after_transition: (if for success): PipelineSuccessWorker on Sidekiq 9. release DB lock #### If no update is required 1. SELECT * FOR UPDATE (other updates wait on this) 2. we update ci_pipeline 3. latest_build_status 4. we are in pending, we can't transition to pending, because it's forbidden 5. release DB lock ### Optimistic locking (implemented by this MR) #### For updating 1. latest_build_status 2. enqueue: (use `transition :created -> :pending`) 3. [state_machine] we are in state created, we can go to pending 4. [state_machine] ci_pipeline.status = created 5. [state_machine] ci_pipeline.save 6. [state_machine] [save] where(lock_version: ci_pipeline.lock_version).update_all(status: :created, updated_at: Time.now) 7. [state_machine] [save] unless we_updated_row then raise ObjectInconsistentError #### If no update is required 1. we update ci_pipeline 2. latest_build_status 3. we are in pending, we can't transition to pending, because it's forbidden ## Why was this MR needed? We have been seeing a number of problems when we migrated Pipeline/Build processing to Sidekiq. Especially we started seeing a lot of blocking queries. We used a pessimistic locking which doesn't seem to be required. This effectively allows us to fix our issues with blocked queries by using more efficient method of operation. ## What are the relevant issue numbers? Issues: https://gitlab.com/gitlab-com/infrastructure/issues/623 and https://gitlab.com/gitlab-com/infrastructure/issues/584, but also there's a bunch of Merge Requests that try to improve behavior of scheduled jobs. cc @pcarranza @yorickpeterse @stanhu See merge request !7040
Name |
Last commit
|
Last update |
---|---|---|
.. | ||
access_requests_spec.rb | Loading commit data... | |
api_helpers_spec.rb | Loading commit data... | |
award_emoji_spec.rb | Loading commit data... | |
boards_spec.rb | Loading commit data... | |
branches_spec.rb | Loading commit data... | |
broadcast_messages_spec.rb | Loading commit data... | |
builds_spec.rb | Loading commit data... | |
commit_statuses_spec.rb | Loading commit data... | |
commits_spec.rb | Loading commit data... | |
deploy_keys_spec.rb | Loading commit data... | |
deployments_spec.rb | Loading commit data... | |
doorkeeper_access_spec.rb | Loading commit data... | |
environments_spec.rb | Loading commit data... | |
files_spec.rb | Loading commit data... | |
fork_spec.rb | Loading commit data... | |
groups_spec.rb | Loading commit data... | |
internal_spec.rb | Loading commit data... | |
issues_spec.rb | Loading commit data... | |
keys_spec.rb | Loading commit data... | |
labels_spec.rb | Loading commit data... | |
lint_spec.rb | Loading commit data... | |
members_spec.rb | Loading commit data... | |
merge_request_diffs_spec.rb | Loading commit data... | |
merge_requests_spec.rb | Loading commit data... | |
milestones_spec.rb | Loading commit data... | |
namespaces_spec.rb | Loading commit data... | |
notes_spec.rb | Loading commit data... | |
notification_settings_spec.rb | Loading commit data... | |
oauth_tokens_spec.rb | Loading commit data... | |
pipelines_spec.rb | Loading commit data... | |
project_hooks_spec.rb | Loading commit data... | |
project_snippets_spec.rb | Loading commit data... | |
projects_spec.rb | Loading commit data... | |
repositories_spec.rb | Loading commit data... | |
runners_spec.rb | Loading commit data... | |
services_spec.rb | Loading commit data... | |
session_spec.rb | Loading commit data... | |
settings_spec.rb | Loading commit data... | |
sidekiq_metrics_spec.rb | Loading commit data... | |
system_hooks_spec.rb | Loading commit data... | |
tags_spec.rb | Loading commit data... | |
templates_spec.rb | Loading commit data... | |
todos_spec.rb | Loading commit data... | |
triggers_spec.rb | Loading commit data... | |
users_spec.rb | Loading commit data... | |
variables_spec.rb | Loading commit data... | |
version_spec.rb | Loading commit data... |