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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/database/tables_truncate.rb')
-rw-r--r--lib/gitlab/database/tables_truncate.rb19
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/gitlab/database/tables_truncate.rb b/lib/gitlab/database/tables_truncate.rb
index 807ecdb862a..daef0402742 100644
--- a/lib/gitlab/database/tables_truncate.rb
+++ b/lib/gitlab/database/tables_truncate.rb
@@ -40,11 +40,12 @@ module Gitlab
table_name: table_name,
connection: connection,
database_name: database_name,
+ with_retries: true,
logger: logger,
dry_run: dry_run
)
- unless lock_writes_manager.table_locked_for_writes?(table_name)
+ unless lock_writes_manager.table_locked_for_writes?
raise "Table '#{table_name}' is not locked for writes. Run the rake task gitlab:db:lock_writes first"
end
end
@@ -81,6 +82,22 @@ module Gitlab
sql_statement = "SELECT set_config('lock_writes.#{table_name_without_schema}', 'false', false)"
logger&.info(sql_statement)
connection.execute(sql_statement) unless dry_run
+
+ # Temporarily unlocking writes on the attached partitions of the table.
+ # Because in some cases they might have been locked for writes as well, when they used to be
+ # normal tables before being converted into attached partitions.
+ Gitlab::Database::SharedModel.using_connection(connection) do
+ table_partitions = Gitlab::Database::PostgresPartition.for_parent_table(table_name_without_schema)
+ table_partitions.each do |table_partition|
+ partition_name_without_schema = ActiveRecord::ConnectionAdapters::PostgreSQL::Utils
+ .extract_schema_qualified_name(table_partition.identifier)
+ .identifier
+
+ sql_statement = "SELECT set_config('lock_writes.#{partition_name_without_schema}', 'false', false)"
+ logger&.info(sql_statement)
+ connection.execute(sql_statement) unless dry_run
+ end
+ end
end
# We do the truncation in stages to avoid high IO