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/migrations')
-rw-r--r--lib/gitlab/database/migrations/redis_helpers.rb17
-rw-r--r--lib/gitlab/database/migrations/runner.rb4
-rw-r--r--lib/gitlab/database/migrations/test_batched_background_runner.rb16
3 files changed, 34 insertions, 3 deletions
diff --git a/lib/gitlab/database/migrations/redis_helpers.rb b/lib/gitlab/database/migrations/redis_helpers.rb
new file mode 100644
index 00000000000..41a2841da7c
--- /dev/null
+++ b/lib/gitlab/database/migrations/redis_helpers.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Database
+ module Migrations
+ module RedisHelpers
+ SCAN_START_CURSOR = '0'
+
+ # Check if the migration exists before enqueueing the worker
+ def queue_redis_migration_job(job_name)
+ RedisMigrationWorker.fetch_migrator!(job_name)
+ RedisMigrationWorker.perform_async(job_name, SCAN_START_CURSOR)
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/database/migrations/runner.rb b/lib/gitlab/database/migrations/runner.rb
index ed55081c9ab..dc9ea304aac 100644
--- a/lib/gitlab/database/migrations/runner.rb
+++ b/lib/gitlab/database/migrations/runner.rb
@@ -32,7 +32,7 @@ module Gitlab
result_dir = background_migrations_dir(for_database, legacy_mode)
# Only one loop iteration since we pass `only:` here
- Gitlab::Database::EachDatabase.each_database_connection(only: for_database) do |connection|
+ Gitlab::Database::EachDatabase.each_connection(only: for_database) do |connection|
from_id = batched_migrations_last_id(for_database).read
runner = Gitlab::Database::Migrations::TestBatchedBackgroundRunner
@@ -68,7 +68,7 @@ module Gitlab
runner = nil
base_dir = background_migrations_dir(for_database, false)
- Gitlab::Database::EachDatabase.each_database_connection(only: for_database) do |connection|
+ Gitlab::Database::EachDatabase.each_connection(only: for_database) do |connection|
runner = Gitlab::Database::Migrations::BatchedMigrationLastId
.new(connection, base_dir)
end
diff --git a/lib/gitlab/database/migrations/test_batched_background_runner.rb b/lib/gitlab/database/migrations/test_batched_background_runner.rb
index af853c933ba..c5e0b361df5 100644
--- a/lib/gitlab/database/migrations/test_batched_background_runner.rb
+++ b/lib/gitlab/database/migrations/test_batched_background_runner.rb
@@ -57,6 +57,20 @@ module Gitlab
job_arguments: migration.job_arguments
)
+ # If no rows match, the next_bounds are nil.
+ # This will only happen if there are zero rows to match from the current sampling point to the end
+ # of the table
+ # Simulate the approach in the actual background migration worker by not sampling a batch
+ # from this range.
+ # (The actual worker would finish the migration, but we may find batches that can be sampled elsewhere
+ # in the table)
+ if next_bounds.nil?
+ # If the migration has no work to do across the entire table, sampling can get stuck
+ # in a loop if we don't mark the attempted batches as completed
+ completed_batches << (batch_start..(batch_start + migration.batch_size))
+ next
+ end
+
batch_min, batch_max = next_bounds
job = migration.create_batched_job!(batch_min, batch_max)
@@ -65,7 +79,7 @@ module Gitlab
job
end
- end
+ end.reject(&:nil?) # Remove skipped batches from the lazy list of batches to test
job_class_name = migration.job_class_name