Class: Database::MonitorLockedTablesWorker

Inherits:
Object
  • Object
show all
Includes:
ApplicationWorker, CronjobQueue
Defined in:
app/workers/database/monitor_locked_tables_worker.rb

Constant Summary collapse

INITIAL_DATABASE_RESULT =
{
  tables_need_lock: [],
  tables_need_lock_count: 0,
  tables_need_unlock: [],
  tables_need_unlock_count: 0
}.freeze

Constants included from ApplicationWorker

ApplicationWorker::LOGGING_EXTRA_KEY, ApplicationWorker::SAFE_PUSH_BULK_LIMIT

Constants included from Gitlab::Loggable

Gitlab::Loggable::ANONYMOUS

Constants included from WorkerAttributes

WorkerAttributes::DEFAULT_DATA_CONSISTENCY, WorkerAttributes::DEFAULT_DEFER_DELAY, WorkerAttributes::NAMESPACE_WEIGHTS, WorkerAttributes::VALID_DATA_CONSISTENCIES, WorkerAttributes::VALID_RESOURCE_BOUNDARIES, WorkerAttributes::VALID_URGENCIES

Instance Method Summary collapse

Methods included from Gitlab::Loggable

#build_structured_payload

Methods included from Gitlab::SidekiqVersioning::Worker

#job_version

Methods included from WorkerContext

#with_context

Instance Method Details

#performObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/workers/database/monitor_locked_tables_worker.rb', line 22

def perform
  return unless Gitlab::Database.database_mode == Gitlab::Database::MODE_MULTIPLE_DATABASES
  return if Feature.disabled?(:monitor_database_locked_tables, type: :ops)

  lock_writes_results = ::Gitlab::Database::TablesLocker.new(dry_run: true, include_partitions: false).lock_writes

  tables_lock_info_per_db = ::Gitlab::Database.database_base_models_with_gitlab_shared.keys.to_h do |db_name, _|
    [db_name, INITIAL_DATABASE_RESULT.deep_dup]
  end

  lock_writes_results.each do |result|
    handle_lock_writes_result(tables_lock_info_per_db, result)
  end

  tables_lock_info_per_db.each do |database_name, database_results|
    next if database_results[:tables_need_lock].empty?
    break if Feature.disabled?(:lock_tables_in_monitoring, type: :ops)

    LockTablesWorker.perform_async(database_name, database_results[:tables_need_lock])
  end

  (:results, tables_lock_info_per_db)
end