Commit c0945d1b authored by Gabriel Mazetto's avatar Gabriel Mazetto
Browse files

disable_statement_timeout doesn't require any argument anymore

it will decide the method for disable statement_timeout upon
per transaction or per session, based on how it's called.

When calling with a block, block will be executed and it will use
session based statement_timeout, otherwise will default to existing
behavior.
parent a841bdd5a5a9
......@@ -106,7 +106,7 @@ def remove_orphaned_rows
# Disables statement timeouts for the current connection. This is
# necessary as removing of orphaned data might otherwise exceed the
# statement timeout.
disable_statement_timeout(transaction: false) do
disable_statement_timeout do
remove_orphans(*queue.pop) until queue.empty?
steal_from_queues(queues - [queue])
......
......@@ -25,7 +25,7 @@ def down
# trivial to write a query that checks for an index. BUT there is a
# convenient `IF EXISTS` parameter for `DROP INDEX`.
if supports_drop_index_concurrently?
disable_statement_timeout(transaction: false) do
disable_statement_timeout do
execute "DROP INDEX CONCURRENTLY IF EXISTS #{INDEX_NAME};"
end
else
......
......@@ -8,7 +8,7 @@ class AddIndexOnNamespacesLowerName < ActiveRecord::Migration
def up
return unless Gitlab::Database.postgresql?
disable_statement_timeout(transaction: false) do
disable_statement_timeout do
if Gitlab::Database.version.to_f >= 9.5
# Allow us to hot-patch the index manually ahead of the migration
execute "CREATE INDEX CONCURRENTLY IF NOT EXISTS #{INDEX_NAME} ON namespaces (lower(name));"
......@@ -21,7 +21,7 @@ def up
def down
return unless Gitlab::Database.postgresql?
disable_statement_timeout(transaction: false) do
disable_statement_timeout do
if Gitlab::Database.version.to_f >= 9.2
execute "DROP INDEX CONCURRENTLY IF EXISTS #{INDEX_NAME};"
else
......
......@@ -18,7 +18,7 @@ class ReworkRedirectRoutesIndexes < ActiveRecord::Migration
OLD_INDEX_NAME_PATH_LOWER = "index_on_redirect_routes_lower_path"
def up
disable_statement_timeout(transaction: false) do
disable_statement_timeout do
# this is a plain btree on a single boolean column. It'll never be
# selective enough to be valuable. This class is called by
# setup_postgresql.rake so it needs to be able to handle this
......@@ -29,7 +29,7 @@ def up
# If we're on MySQL then the existing index on path is ok. But on
# Postgres we need to clean things up:
return unless Gitlab::Database.postgresql?
break unless Gitlab::Database.postgresql?
if_not_exists = Gitlab::Database.version.to_f >= 9.5 ? "IF NOT EXISTS" : ""
......@@ -52,10 +52,10 @@ def up
end
def down
disable_statement_timeout(transaction: false) do
disable_statement_timeout do
add_concurrent_index(:redirect_routes, :permanent)
return unless Gitlab::Database.postgresql?
break unless Gitlab::Database.postgresql?
execute("CREATE INDEX CONCURRENTLY #{OLD_INDEX_NAME_PATH_TPOPS} ON redirect_routes (path varchar_pattern_ops);")
execute("CREATE INDEX CONCURRENTLY #{OLD_INDEX_NAME_PATH_LOWER} ON redirect_routes (LOWER(path));")
......
......@@ -13,7 +13,7 @@ def up
end
end
disable_statement_timeout(transaction: false) do
disable_statement_timeout do
# This particular INSERT will take between 10 and 20 seconds.
execute 'INSERT INTO project_ci_cd_settings (project_id) SELECT id FROM projects'
......
......@@ -14,7 +14,7 @@ class Build < ActiveRecord::Base
end
def up
disable_statement_timeout(transaction: false) do
disable_statement_timeout do
##
# We steal from the background migrations queue to catch up with the
# scheduled migrations set.
......@@ -55,7 +55,7 @@ def up
def down
if index_exists_by_name?(:ci_builds, TMP_INDEX)
disable_statement_timeout(transaction: false) do
disable_statement_timeout do
remove_concurrent_index_by_name(:ci_builds, TMP_INDEX)
end
end
......
......@@ -13,7 +13,7 @@ class ProjectNameLowerIndex < ActiveRecord::Migration
def up
return unless Gitlab::Database.postgresql?
disable_statement_timeout(transaction: false) do
disable_statement_timeout do
execute "CREATE INDEX CONCURRENTLY #{INDEX_NAME} ON projects (LOWER(name))"
end
end
......@@ -21,7 +21,7 @@ def up
def down
return unless Gitlab::Database.postgresql?
disable_statement_timeout(transaction: false) do
disable_statement_timeout do
if supports_drop_index_concurrently?
execute "DROP INDEX CONCURRENTLY IF EXISTS #{INDEX_NAME}"
else
......
......@@ -28,16 +28,16 @@ def up
# which is pretty close to our 15 second statement timeout. To ensure a
# smooth deployment procedure we disable the statement timeouts for this
# migration, just in case.
disable_statement_timeout
# On GitLab.com there are around 4000 orphaned project routes, and around
# 150 orphaned namespace routes.
[
Route.orphaned_project_routes,
Route.orphaned_namespace_routes
].each do |relation|
relation.each_batch(of: 1_000) do |batch|
batch.delete_all
disable_statement_timeout do
# On GitLab.com there are around 4000 orphaned project routes, and around
# 150 orphaned namespace routes.
[
Route.orphaned_project_routes,
Route.orphaned_namespace_routes
].each do |relation|
relation.each_batch(of: 1_000) do |batch|
batch.delete_all
end
end
end
end
......
......@@ -29,7 +29,7 @@ class CompositePrimaryKeysMigration < ActiveRecord::Migration
def up
return unless Gitlab::Database.postgresql?
disable_statement_timeout(transaction: false) do
disable_statement_timeout do
TABLES.each do |index|
add_primary_key(index)
end
......@@ -39,7 +39,7 @@ def up
def down
return unless Gitlab::Database.postgresql?
disable_statement_timeout(transaction: false) do
disable_statement_timeout do
TABLES.each do |index|
remove_primary_key(index)
end
......
......@@ -8,7 +8,7 @@ class EnableAutoCancelPendingPipelinesForAll < ActiveRecord::Migration
DOWNTIME = false
def up
disable_statement_timeout(transaction: false) do
disable_statement_timeout do
update_column_in_batches(:projects, :auto_cancel_pending_pipelines, 1)
end
end
......
......@@ -10,7 +10,7 @@ def up
if Gitlab::Database.mysql?
up_mysql
else
disable_statement_timeout(transaction: false) do
disable_statement_timeout do
up_postgres
end
end
......
......@@ -10,7 +10,7 @@ def up
pipelines = Arel::Table.new(:ci_pipelines)
merge_requests = Arel::Table.new(:merge_requests)
disable_statement_timeout(transaction: false) do
disable_statement_timeout do
head_id = pipelines
.project(Arel::Nodes::NamedFunction.new('max', [pipelines[:id]]))
.from(pipelines)
......
......@@ -87,7 +87,7 @@ class RenameAllReservedPathsAgain < ActiveRecord::Migration
].freeze
def up
disable_statement_timeout(transaction: false) do
disable_statement_timeout do
TOP_LEVEL_ROUTES.each { |route| rename_root_paths(route) }
PROJECT_WILDCARD_ROUTES.each { |route| rename_wildcard_paths(route) }
GROUP_ROUTES.each { |route| rename_child_paths(route) }
......@@ -95,7 +95,7 @@ def up
end
def down
disable_statement_timeout(transaction: false) do
disable_statement_timeout do
revert_renames
end
end
......
......@@ -6,7 +6,7 @@ class MigratePipelineStages < ActiveRecord::Migration
disable_ddl_transaction!
def up
disable_statement_timeout(transaction: false) do
disable_statement_timeout do
execute <<-SQL.strip_heredoc
INSERT INTO ci_stages (project_id, pipeline_id, name)
SELECT project_id, commit_id, stage FROM ci_builds
......
......@@ -13,7 +13,7 @@ def up
AND ci_stages.name = ci_builds.stage)
SQL
disable_statement_timeout(transaction: false) do
disable_statement_timeout do
update_column_in_batches(:ci_builds, :stage_id, stage_id) do |table, query|
query.where(table[:stage_id].eq(nil))
end
......@@ -21,7 +21,7 @@ def up
end
def down
disable_statement_timeout(transaction: false) do
disable_statement_timeout do
update_column_in_batches(:ci_builds, :stage_id, nil)
end
end
......
......@@ -26,8 +26,7 @@ def up
end
def down
disable_statement_timeout(transaction: false) do
disable_statement_timeout do
# rubocop:disable Migration/UpdateLargeTable
update_column_in_batches(:ci_stages, :status, nil)
end
......
......@@ -78,7 +78,7 @@ class CiTrigger < ActiveRecord::Base
MODELS = [Issue, MergeRequest, CiPipelineSchedule, CiTrigger].freeze
def up
disable_statement_timeout(transaction: false) do
disable_statement_timeout do
remove_personal_routes
remove_personal_namespaces
remove_group_namespaces
......
......@@ -38,7 +38,7 @@ def add_unique_index!
end
def remove_redundant_pipeline_stages!
disable_statement_timeout(transaction: false) do
disable_statement_timeout do
redundant_stages_ids = <<~SQL
SELECT id FROM ci_stages WHERE (pipeline_id, name) IN (
SELECT pipeline_id, name FROM ci_stages
......
......@@ -15,7 +15,7 @@ def up
# ReworkRedirectRoutesIndexes:
# https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/16211
if Gitlab::Database.postgresql?
disable_statement_timeout(transaction: false) do
disable_statement_timeout do
execute "DROP INDEX CONCURRENTLY IF EXISTS #{INDEX_NAME_PERM};"
execute "DROP INDEX CONCURRENTLY IF EXISTS #{INDEX_NAME_TEMP};"
end
......@@ -28,7 +28,7 @@ def down
add_column(:redirect_routes, :permanent, :boolean)
if Gitlab::Database.postgresql?
disable_statement_timeout(transaction: false) do
disable_statement_timeout do
execute("CREATE INDEX CONCURRENTLY #{INDEX_NAME_PERM} ON redirect_routes (lower(path) varchar_pattern_ops) where (permanent);")
execute("CREATE INDEX CONCURRENTLY #{INDEX_NAME_TEMP} ON redirect_routes (lower(path) varchar_pattern_ops) where (not permanent or permanent is null) ;")
end
......
......@@ -20,7 +20,7 @@ class AddPathIndexToRedirectRoutes < ActiveRecord::Migration
def up
return unless Gitlab::Database.postgresql?
disable_statement_timeout(transaction: false) do
disable_statement_timeout do
unless index_exists_by_name?(:redirect_routes, INDEX_NAME)
execute("CREATE UNIQUE INDEX CONCURRENTLY #{INDEX_NAME} ON redirect_routes (lower(path) varchar_pattern_ops);")
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment