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

coordinator.rb « reindexing « database « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0957f43e166a6104f751559b84f2cf769afdd2e0 (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
# frozen_string_literal: true

module Gitlab
  module Database
    module Reindexing
      class Coordinator
        include ExclusiveLeaseGuard

        # Maximum lease time for the global Redis lease
        # This should be higher than the maximum time for any
        # long running step in the reindexing process (compare with
        # statement timeouts).
        TIMEOUT_PER_ACTION = 1.day

        attr_reader :indexes

        def initialize(indexes)
          @indexes = indexes
        end

        def perform
          indexes.each do |index|
            # This obtains a global lease such that there's
            # only one live reindexing process at a time.
            try_obtain_lease do
              ReindexAction.keep_track_of(index) do
                ConcurrentReindex.new(index).perform
              end
            end
          end
        end

        private

        def lease_timeout
          TIMEOUT_PER_ACTION
        end
      end
    end
  end
end