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

migrate_to_hashed_storage.rb « background_migration « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4054db4fb873e2eb24a11cb5743c3fdd14910172 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# frozen_string_literal: true

module Gitlab
  module BackgroundMigration
    # Background migration to move any legacy project to Hashed Storage
    class MigrateToHashedStorage
      def perform
        batch_size = helper.batch_size
        legacy_projects_count = Project.with_unmigrated_storage.count

        if storage_migrator.rollback_pending?
          logger.warn(
            migrator: 'MigrateToHashedStorage',
            message: 'Aborting an storage rollback operation currently in progress'
          )

          storage_migrator.abort_rollback!
        end

        if legacy_projects_count == 0
          logger.info(
            migrator: 'MigrateToHashedStorage',
            message: 'There are no projects requiring migration to Hashed Storage'
          )

          return
        end

        logger.info(
          migrator: 'MigrateToHashedStorage',
          message: "Enqueuing migration of #{legacy_projects_count} projects in batches of #{batch_size}"
        )

        helper.project_id_batches_migration do |start, finish|
          storage_migrator.bulk_schedule_migration(start: start, finish: finish)

          logger.info(
            migrator: 'MigrateToHashedStorage',
            message: "Enqueuing migration of projects in batches of #{batch_size} from ID=#{start} to ID=#{finish}",
            batch_from: start,
            batch_to: finish
          )
        end
      end

      private

      def helper
        Gitlab::HashedStorage::RakeHelper
      end

      def storage_migrator
        @storage_migrator ||= Gitlab::HashedStorage::Migrator.new
      end

      def logger
        @logger ||= ::Gitlab::BackgroundMigration::Logger.build
      end
    end
  end
end