diff options
Diffstat (limited to 'lib/gitlab/database/reindexing/coordinator.rb')
-rw-r--r-- | lib/gitlab/database/reindexing/coordinator.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/gitlab/database/reindexing/coordinator.rb b/lib/gitlab/database/reindexing/coordinator.rb new file mode 100644 index 00000000000..0957f43e166 --- /dev/null +++ b/lib/gitlab/database/reindexing/coordinator.rb @@ -0,0 +1,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 |