diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-09 09:11:16 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-09 09:11:16 +0000 |
commit | 54573816ab79fac6716d1a1eae8c0da602765774 (patch) | |
tree | 2ebdf1558969cc88eacba7ce5618a299c88dcf3d /lib/gitlab/database/migration_helpers/v2.rb | |
parent | 8602c599660974a47ad705fd5cc3f97cd37b1a0f (diff) | |
download | gitlab-ce-54573816ab79fac6716d1a1eae8c0da602765774.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/database/migration_helpers/v2.rb')
-rw-r--r-- | lib/gitlab/database/migration_helpers/v2.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/gitlab/database/migration_helpers/v2.rb b/lib/gitlab/database/migration_helpers/v2.rb index f20a9b30fa7..79d69676c44 100644 --- a/lib/gitlab/database/migration_helpers/v2.rb +++ b/lib/gitlab/database/migration_helpers/v2.rb @@ -6,6 +6,44 @@ module Gitlab module V2 include Gitlab::Database::MigrationHelpers + # Executes the block with a retry mechanism that alters the +lock_timeout+ and +sleep_time+ between attempts. + # The timings can be controlled via the +timing_configuration+ parameter. + # If the lock was not acquired within the retry period, a last attempt is made without using +lock_timeout+. + # + # In order to retry the block, the method wraps the block into a transaction. + # Note it cannot be used inside an already open transaction and will raise an error in that case. + # + # ==== Examples + # # Invoking without parameters + # with_lock_retries do + # drop_table :my_table + # end + # + # # Invoking with custom +timing_configuration+ + # t = [ + # [1.second, 1.second], + # [2.seconds, 2.seconds] + # ] + # + # with_lock_retries(timing_configuration: t) do + # drop_table :my_table # this will be retried twice + # end + # + # # Disabling the retries using an environment variable + # > export DISABLE_LOCK_RETRIES=true + # + # with_lock_retries do + # drop_table :my_table # one invocation, it will not retry at all + # end + # + # ==== Parameters + # * +timing_configuration+ - [[ActiveSupport::Duration, ActiveSupport::Duration], ...] lock timeout for the block, sleep time before the next iteration, defaults to `Gitlab::Database::WithLockRetries::DEFAULT_TIMING_CONFIGURATION` + # * +logger+ - [Gitlab::JsonLogger] + # * +env+ - [Hash] custom environment hash, see the example with `DISABLE_LOCK_RETRIES` + def with_lock_retries(*args, **kwargs, &block) + super(*args, **kwargs.merge(allow_savepoints: false), &block) + end + # Renames a column without requiring downtime. # # Concurrent renames work by using database triggers to ensure both the |