Commit 9428adf9 authored by Kamil Trzciński's avatar Kamil Trzciński

Fix atomic processing bumping a lock_version

parent eb014d6b
...@@ -189,8 +189,10 @@ class CommitStatus < ApplicationRecord ...@@ -189,8 +189,10 @@ class CommitStatus < ApplicationRecord
end end
def self.update_as_processed! def self.update_as_processed!
# Marks items as processed, and increases `lock_version` (Optimisitc Locking) # Marks items as processed
update_all('processed=TRUE, lock_version=COALESCE(lock_version,0)+1') # we do not increase `lock_version`, as we are the one
# holding given lock_version (Optimisitc Locking)
update_all(processed: true)
end end
def self.locking_enabled? def self.locking_enabled?
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
module Projects module Projects
class UpdatePagesService < BaseService class UpdatePagesService < BaseService
include Gitlab::OptimisticLocking
InvalidStateError = Class.new(StandardError) InvalidStateError = Class.new(StandardError)
FailedToExtractError = Class.new(StandardError) FailedToExtractError = Class.new(StandardError)
...@@ -25,8 +23,8 @@ module Projects ...@@ -25,8 +23,8 @@ module Projects
# Create status notifying the deployment of pages # Create status notifying the deployment of pages
@status = create_status @status = create_status
retry_optimistic_lock(@status, &:enqueue!) @status.enqueue!
retry_optimistic_lock(@status, &:run!) @status.run!
raise InvalidStateError, 'missing pages artifacts' unless build.artifacts? raise InvalidStateError, 'missing pages artifacts' unless build.artifacts?
raise InvalidStateError, 'build SHA is outdated for this ref' unless latest? raise InvalidStateError, 'build SHA is outdated for this ref' unless latest?
...@@ -53,7 +51,7 @@ module Projects ...@@ -53,7 +51,7 @@ module Projects
private private
def success def success
retry_optimistic_lock(@status, &:success) @status.success
@project.mark_pages_as_deployed @project.mark_pages_as_deployed
super super
end end
...@@ -63,7 +61,7 @@ module Projects ...@@ -63,7 +61,7 @@ module Projects
log_error("Projects::UpdatePagesService: #{message}") log_error("Projects::UpdatePagesService: #{message}")
@status.allow_failure = !latest? @status.allow_failure = !latest?
@status.description = message @status.description = message
retry_optimistic_lock(@status) { |status| status.drop(:script_failure) } @status.drop(:script_failure)
super super
end end
......
---
title: Fix atomic processing bumping a lock_version
merge_request: 32914
author:
type: fixed
...@@ -106,7 +106,7 @@ module API ...@@ -106,7 +106,7 @@ module API
status.enqueue! status.enqueue!
when 'running' when 'running'
status.enqueue status.enqueue
Gitlab::OptimisticLocking.retry_lock(status, &:run!) status.run!
when 'success' when 'success'
status.success! status.success!
when 'failed' when 'failed'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment