Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Artur <felipefac@gmail.com>2019-03-01 22:24:47 +0300
committerFelipe Artur <felipefac@gmail.com>2019-03-01 22:24:47 +0300
commit294c5c41beaac1fbc60c67df2c8745f7583544a1 (patch)
tree2559085daf704a40e749288fa9b4bfeed313f725 /lib/gitlab/background_migration
parent7bd066a1fa51018211e26ca0c5624aecbc364a66 (diff)
Remove auto vacuum logic, decrease batch size and interval
Diffstat (limited to 'lib/gitlab/background_migration')
-rw-r--r--lib/gitlab/background_migration/reschedulable.rb60
-rw-r--r--lib/gitlab/background_migration/sync_issues_state_id.rb30
-rw-r--r--lib/gitlab/background_migration/sync_merge_requests_state_id.rb34
3 files changed, 22 insertions, 102 deletions
diff --git a/lib/gitlab/background_migration/reschedulable.rb b/lib/gitlab/background_migration/reschedulable.rb
deleted file mode 100644
index 3d6781c07c0..00000000000
--- a/lib/gitlab/background_migration/reschedulable.rb
+++ /dev/null
@@ -1,60 +0,0 @@
-# frozen_string_literal: true
-
-module Gitlab
- module BackgroundMigration
- # == Reschedulable helper
- #
- # Allows background migrations to be rescheduled if a condition is met,
- # the condition should be overridden in classes in #should_reschedule? method.
- #
- # For example, check DeleteDiffFiles migration which is rescheduled if dead tuple count
- # on DB is not acceptable.
- #
- module Reschedulable
- extend ActiveSupport::Concern
-
- # Use this method to perform the background migration and it will be rescheduled
- # if #should_reschedule? returns true.
- def reschedule_if_needed(*args, &block)
- if should_reschedule?
- BackgroundMigrationWorker.perform_in(wait_time, self.class.name.demodulize, args)
- else
- yield
- end
- end
-
- # Override this on base class if you need a different reschedule condition
- def should_reschedule?
- raise NotImplementedError, "#{self.class} does not implement #{__method__}"
- end
-
- # Override in subclass if a different dead tuple threshold
- def dead_tuples_threshold
- @dead_tuples_threshold ||= 50_000
- end
-
- # Override in subclass if a different wait time
- def wait_time
- @wait_time ||= 5.minutes
- end
-
- def execute_statement(sql)
- ActiveRecord::Base.connection.execute(sql)
- end
-
- def wait_for_deadtuple_vacuum?(table_name)
- return false unless Gitlab::Database.postgresql?
-
- dead_tuples_count_for(table_name) >= dead_tuples_threshold
- end
-
- def dead_tuples_count_for(table_name)
- dead_tuple =
- execute_statement("SELECT n_dead_tup FROM pg_stat_all_tables "\
- "WHERE relname = '#{table_name}'")[0]
-
- dead_tuple&.fetch('n_dead_tup', 0).to_i
- end
- end
- end
-end
diff --git a/lib/gitlab/background_migration/sync_issues_state_id.rb b/lib/gitlab/background_migration/sync_issues_state_id.rb
index 053d154cef8..33b997c8533 100644
--- a/lib/gitlab/background_migration/sync_issues_state_id.rb
+++ b/lib/gitlab/background_migration/sync_issues_state_id.rb
@@ -4,29 +4,19 @@
module Gitlab
module BackgroundMigration
class SyncIssuesStateId
- include Reschedulable
-
def perform(start_id, end_id)
Rails.logger.info("Issues - Populating state_id: #{start_id} - #{end_id}")
- reschedule_if_needed(start_id, end_id) do
- execute_statement <<~SQL
- UPDATE issues
- SET state_id =
- CASE state
- WHEN 'opened' THEN 1
- WHEN 'closed' THEN 2
- END
- WHERE state_id IS NULL
- AND id BETWEEN #{start_id} AND #{end_id}
- SQL
- end
- end
-
- private
-
- def should_reschedule?
- wait_for_deadtuple_vacuum?('issues')
+ ActiveRecord::Base.connection.execute <<~SQL
+ UPDATE issues
+ SET state_id =
+ CASE state
+ WHEN 'opened' THEN 1
+ WHEN 'closed' THEN 2
+ END
+ WHERE state_id IS NULL
+ AND id BETWEEN #{start_id} AND #{end_id}
+ SQL
end
end
end
diff --git a/lib/gitlab/background_migration/sync_merge_requests_state_id.rb b/lib/gitlab/background_migration/sync_merge_requests_state_id.rb
index a94529aaf5c..923ceaeec54 100644
--- a/lib/gitlab/background_migration/sync_merge_requests_state_id.rb
+++ b/lib/gitlab/background_migration/sync_merge_requests_state_id.rb
@@ -4,31 +4,21 @@
module Gitlab
module BackgroundMigration
class SyncMergeRequestsStateId
- include Reschedulable
-
def perform(start_id, end_id)
Rails.logger.info("Merge Requests - Populating state_id: #{start_id} - #{end_id}")
- reschedule_if_needed(start_id, end_id) do
- execute_statement <<~SQL
- UPDATE merge_requests
- SET state_id =
- CASE state
- WHEN 'opened' THEN 1
- WHEN 'closed' THEN 2
- WHEN 'merged' THEN 3
- WHEN 'locked' THEN 4
- END
- WHERE state_id IS NULL
- AND id BETWEEN #{start_id} AND #{end_id}
- SQL
- end
- end
-
- private
-
- def should_reschedule?
- wait_for_deadtuple_vacuum?('issues')
+ ActiveRecord::Base.connection.execute <<~SQL
+ UPDATE merge_requests
+ SET state_id =
+ CASE state
+ WHEN 'opened' THEN 1
+ WHEN 'closed' THEN 2
+ WHEN 'merged' THEN 3
+ WHEN 'locked' THEN 4
+ END
+ WHERE state_id IS NULL
+ AND id BETWEEN #{start_id} AND #{end_id}
+ SQL
end
end
end