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:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-07-20 18:40:28 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-07-20 18:40:28 +0300
commitb595cb0c1dec83de5bdee18284abe86614bed33b (patch)
tree8c3d4540f193c5ff98019352f554e921b3a41a72 /lib/bulk_imports
parent2f9104a328fc8a4bddeaa4627b595166d24671d0 (diff)
Add latest changes from gitlab-org/gitlab@15-2-stable-eev15.2.0-rc42
Diffstat (limited to 'lib/bulk_imports')
-rw-r--r--lib/bulk_imports/groups/transformers/group_attributes_transformer.rb28
-rw-r--r--lib/bulk_imports/network_error.rb4
-rw-r--r--lib/bulk_imports/pipeline/runner.rb26
-rw-r--r--lib/bulk_imports/retry_pipeline_error.rb13
4 files changed, 55 insertions, 16 deletions
diff --git a/lib/bulk_imports/groups/transformers/group_attributes_transformer.rb b/lib/bulk_imports/groups/transformers/group_attributes_transformer.rb
index df27275b664..3067e0997c2 100644
--- a/lib/bulk_imports/groups/transformers/group_attributes_transformer.rb
+++ b/lib/bulk_imports/groups/transformers/group_attributes_transformer.rb
@@ -7,10 +7,15 @@ module BulkImports
def transform(context, data)
import_entity = context.entity
+ if import_entity.destination_namespace.present?
+ namespace = Namespace.find_by_full_path(import_entity.destination_namespace)
+ end
+
data
+ .then { |data| transform_name(import_entity, namespace, data) }
.then { |data| transform_path(import_entity, data) }
.then { |data| transform_full_path(data) }
- .then { |data| transform_parent(context, import_entity, data) }
+ .then { |data| transform_parent(context, import_entity, namespace, data) }
.then { |data| transform_visibility_level(data) }
.then { |data| transform_project_creation_level(data) }
.then { |data| transform_subgroup_creation_level(data) }
@@ -18,6 +23,20 @@ module BulkImports
private
+ def transform_name(import_entity, namespace, data)
+ if namespace.present?
+ namespace_children_names = namespace.children.pluck(:name) # rubocop: disable CodeReuse/ActiveRecord
+
+ if namespace_children_names.include?(data['name'])
+ data['name'] = Uniquify.new(1).string(-> (counter) { "#{data['name']}(#{counter})" }) do |base|
+ namespace_children_names.include?(base)
+ end
+ end
+ end
+
+ data
+ end
+
def transform_path(import_entity, data)
data['path'] = import_entity.destination_name.parameterize
data
@@ -28,11 +47,8 @@ module BulkImports
data
end
- def transform_parent(context, import_entity, data)
- unless import_entity.destination_namespace.blank?
- namespace = Namespace.find_by_full_path(import_entity.destination_namespace)
- data['parent_id'] = namespace.id
- end
+ def transform_parent(context, import_entity, namespace, data)
+ data['parent_id'] = namespace.id if namespace.present?
data
end
diff --git a/lib/bulk_imports/network_error.rb b/lib/bulk_imports/network_error.rb
index d69b0172f6c..3514291a75d 100644
--- a/lib/bulk_imports/network_error.rb
+++ b/lib/bulk_imports/network_error.rb
@@ -7,9 +7,9 @@ module BulkImports
RETRIABLE_EXCEPTIONS = Gitlab::HTTP::HTTP_TIMEOUT_ERRORS
RETRIABLE_HTTP_CODES = [429].freeze
- DEFAULT_RETRY_DELAY_SECONDS = 60
+ DEFAULT_RETRY_DELAY_SECONDS = 30
- MAX_RETRIABLE_COUNT = 3
+ MAX_RETRIABLE_COUNT = 10
def initialize(message = nil, response: nil)
raise ArgumentError, 'message or response required' if message.blank? && response.blank?
diff --git a/lib/bulk_imports/pipeline/runner.rb b/lib/bulk_imports/pipeline/runner.rb
index 8f515b571a6..c03da7d8d01 100644
--- a/lib/bulk_imports/pipeline/runner.rb
+++ b/lib/bulk_imports/pipeline/runner.rb
@@ -56,12 +56,16 @@ module BulkImports
pipeline_step: step,
step_class: class_name
)
+ rescue BulkImports::NetworkError => e
+ if e.retriable?(context.tracker)
+ raise BulkImports::RetryPipelineError.new(e.message, e.retry_delay)
+ else
+ log_and_fail(e, step)
+ end
+ rescue BulkImports::RetryPipelineError
+ raise
rescue StandardError => e
- log_import_failure(e, step)
-
- mark_as_failed if abort_on_failure?
-
- nil
+ log_and_fail(e, step)
end
def extracted_data_from
@@ -74,11 +78,17 @@ module BulkImports
run if extracted_data.has_next_page?
end
- def mark_as_failed
- warn(message: 'Pipeline failed')
+ def log_and_fail(exception, step)
+ log_import_failure(exception, step)
- context.entity.fail_op!
tracker.fail_op!
+
+ if abort_on_failure?
+ warn(message: 'Aborting entity migration due to pipeline failure')
+ context.entity.fail_op!
+ end
+
+ nil
end
def skip!(message, extra = {})
diff --git a/lib/bulk_imports/retry_pipeline_error.rb b/lib/bulk_imports/retry_pipeline_error.rb
new file mode 100644
index 00000000000..a1b02addf45
--- /dev/null
+++ b/lib/bulk_imports/retry_pipeline_error.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+module BulkImports
+ class RetryPipelineError < Error
+ attr_reader :retry_delay
+
+ def initialize(message, retry_delay)
+ super(message)
+
+ @retry_delay = retry_delay
+ end
+ end
+end