summaryrefslogtreecommitdiff
path: root/lib/gitlab/database/tables_truncate.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-01-18 19:00:14 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-01-18 19:00:14 +0000
commit05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2 (patch)
tree11d0f2a6ec31c7793c184106cedc2ded3d9a2cc5 /lib/gitlab/database/tables_truncate.rb
parentec73467c23693d0db63a797d10194da9e72a74af (diff)
downloadgitlab-ce-05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2.tar.gz
Add latest changes from gitlab-org/gitlab@15-8-stable-eev15.8.0-rc42
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