Class: Gitlab::Database::Reindexing::Coordinator

Inherits:
Object
  • Object
show all
Includes:
AsyncDdlExclusiveLeaseGuard
Defined in:
lib/gitlab/database/reindexing/coordinator.rb

Constant Summary collapse

TIMEOUT_PER_ACTION =

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).

1.day

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AsyncDdlExclusiveLeaseGuard

#database_config_name, #lease_key

Methods included from ExclusiveLeaseGuard

#exclusive_lease, #lease_key, #lease_release?, #lease_taken_log_level, #lease_taken_message, #log_lease_taken, #release_lease, #renew_lease!, #try_obtain_lease

Constructor Details

#initialize(index, notifier = GrafanaNotifier.new) ⇒ Coordinator

Returns a new instance of Coordinator.



17
18
19
20
# File 'lib/gitlab/database/reindexing/coordinator.rb', line 17

def initialize(index, notifier = GrafanaNotifier.new)
  @index = index
  @notifier = notifier
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



15
16
17
# File 'lib/gitlab/database/reindexing/coordinator.rb', line 15

def index
  @index
end

#notifierObject (readonly)

Returns the value of attribute notifier.



15
16
17
# File 'lib/gitlab/database/reindexing/coordinator.rb', line 15

def notifier
  @notifier
end

Instance Method Details

#dropObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/gitlab/database/reindexing/coordinator.rb', line 36

def drop
  return if too_late_for_reindexing?

  try_obtain_lease do
    Gitlab::AppLogger.info("Removing index #{index.identifier} which is a leftover, temporary index from previous reindexing activity")

    retries = Gitlab::Database::WithLockRetriesOutsideTransaction.new(
      connection: connection,
      timing_configuration: REMOVE_INDEX_RETRY_CONFIG,
      klass: self.class,
      logger: Gitlab::AppLogger
    )

    retries.run(raise_on_exhaustion: false) do
      connection.execute("DROP INDEX CONCURRENTLY IF EXISTS #{full_index_name}")
    end
  end
end

#performObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/gitlab/database/reindexing/coordinator.rb', line 22

def perform
  return if too_late_for_reindexing?

  # This obtains a global lease such that there's
  # only one live reindexing process at a time.
  try_obtain_lease do
    action = ReindexAction.create_for(index)

    with_notifications(action) do
      perform_for(index, action)
    end
  end
end