diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-05 15:07:52 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-05 15:07:52 +0000 |
commit | afe2b984524ae4b0c8a0636db7ec5b2c452f0734 (patch) | |
tree | 3de39f954c7239e09a9afe84263a64e7042b2b60 /lib | |
parent | 5a6b36b60502c50ab59c0bc3c345793b70a3d548 (diff) | |
download | gitlab-ce-afe2b984524ae4b0c8a0636db7ec5b2c452f0734.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/database/connection_timer.rb | 50 | ||||
-rw-r--r-- | lib/gitlab/database/postgresql_adapter/force_disconnectable_mixin.rb | 30 | ||||
-rw-r--r-- | lib/gitlab/import_export/project/tree_restorer.rb | 5 | ||||
-rw-r--r-- | lib/gitlab_danger.rb | 1 |
4 files changed, 82 insertions, 4 deletions
diff --git a/lib/gitlab/database/connection_timer.rb b/lib/gitlab/database/connection_timer.rb new file mode 100644 index 00000000000..ef8d52ba71c --- /dev/null +++ b/lib/gitlab/database/connection_timer.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +module Gitlab + module Database + class ConnectionTimer + DEFAULT_INTERVAL = 3600 + RANDOMIZATION_INTERVAL = 600 + + class << self + def configure + yield self + end + + def starting_now + # add a small amount of randomization to the interval, so reconnects don't all occur at once + new(interval_with_randomization, current_clock_value) + end + + attr_writer :interval + + def interval + @interval ||= DEFAULT_INTERVAL + end + + def interval_with_randomization + interval + rand(RANDOMIZATION_INTERVAL) if interval.positive? + end + + def current_clock_value + Concurrent.monotonic_time + end + end + + attr_reader :interval, :starting_clock_value + + def initialize(interval, starting_clock_value) + @interval = interval + @starting_clock_value = starting_clock_value + end + + def expired? + interval&.positive? && self.class.current_clock_value > (starting_clock_value + interval) + end + + def reset! + @starting_clock_value = self.class.current_clock_value + end + end + end +end diff --git a/lib/gitlab/database/postgresql_adapter/force_disconnectable_mixin.rb b/lib/gitlab/database/postgresql_adapter/force_disconnectable_mixin.rb new file mode 100644 index 00000000000..9f664fa2137 --- /dev/null +++ b/lib/gitlab/database/postgresql_adapter/force_disconnectable_mixin.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +module Gitlab + module Database + module PostgresqlAdapter + module ForceDisconnectableMixin + extend ActiveSupport::Concern + + prepended do + set_callback :checkin, :after, :force_disconnect_if_old! + end + + def force_disconnect_if_old! + if force_disconnect_timer.expired? + disconnect! + reset_force_disconnect_timer! + end + end + + def reset_force_disconnect_timer! + force_disconnect_timer.reset! + end + + def force_disconnect_timer + @force_disconnect_timer ||= ConnectionTimer.starting_now + end + end + end + end +end diff --git a/lib/gitlab/import_export/project/tree_restorer.rb b/lib/gitlab/import_export/project/tree_restorer.rb index 904cb461ac3..295e0d5f348 100644 --- a/lib/gitlab/import_export/project/tree_restorer.rb +++ b/lib/gitlab/import_export/project/tree_restorer.rb @@ -43,10 +43,7 @@ module Gitlab def read_tree_hash path = File.join(@shared.export_path, 'project.json') - dedup_entries = large_project?(path) && - Feature.enabled?(:dedup_project_import_metadata, project.group) - - @tree_loader.load(path, dedup_entries: dedup_entries) + @tree_loader.load(path, dedup_entries: large_project?(path)) rescue => e Rails.logger.error("Import/Export error: #{e.message}") # rubocop:disable Gitlab/RailsLogger raise Gitlab::ImportExport::Error.new('Incorrect JSON format') diff --git a/lib/gitlab_danger.rb b/lib/gitlab_danger.rb index 29300d02985..ee0951f18ca 100644 --- a/lib/gitlab_danger.rb +++ b/lib/gitlab_danger.rb @@ -11,6 +11,7 @@ class GitlabDanger karma database commit_messages + telemetry ].freeze CI_ONLY_RULES ||= %w[ |