Class: Gitlab::Database::TablesLocker

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/database/tables_locker.rb

Constant Summary collapse

GITLAB_SCHEMAS_TO_IGNORE =
%i[gitlab_embedding gitlab_geo].freeze

Instance Method Summary collapse

Constructor Details

#initialize(logger: nil, dry_run: false, include_partitions: true) ⇒ TablesLocker

Returns a new instance of TablesLocker.



8
9
10
11
12
13
# File 'lib/gitlab/database/tables_locker.rb', line 8

def initialize(logger: nil, dry_run: false, include_partitions: true)
  @logger = logger
  @dry_run = dry_run
  @result = []
  @include_partitions = include_partitions
end

Instance Method Details

#lock_writesObject

It locks the tables on the database where they don’t belong. Also it unlocks the tables on the database where they belong



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gitlab/database/tables_locker.rb', line 30

def lock_writes
  Gitlab::Database::EachDatabase.each_connection(include_shared: false) do |connection, database_name|
    schemas_for_connection = Gitlab::Database.gitlab_schemas_for_connection(connection)

    tables_to_lock(connection) do |table_name, schema_name|
      # TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/366834
      next if schema_name.in? GITLAB_SCHEMAS_TO_IGNORE

      if schemas_for_connection.include?(schema_name)
        unlock_writes_on_table(table_name, connection, database_name)
      else
        lock_writes_on_table(table_name, connection, database_name)
      end
    end
  end

  @result
end

#unlock_writesObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gitlab/database/tables_locker.rb', line 15

def unlock_writes
  Gitlab::Database::EachDatabase.each_connection do |connection, database_name|
    tables_to_lock(connection) do |table_name, schema_name|
      # TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/366834
      next if schema_name.in? GITLAB_SCHEMAS_TO_IGNORE

      unlock_writes_on_table(table_name, connection, database_name)
    end
  end

  @result
end