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:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-30 12:27:58 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-30 12:27:58 +0300
commitb539ac1d619c0aafe5988ab8b125a8b43b14d87f (patch)
treebe1924f2d30fb714e4efd7ffb486f25fa271cb55 /lib/gitlab/cluster
parent4c016ad02422709d3a341215952a9b1cdb4a8451 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/cluster')
-rw-r--r--lib/gitlab/cluster/lifecycle_events.rb10
-rw-r--r--lib/gitlab/cluster/mixins/puma_cluster.rb6
-rw-r--r--lib/gitlab/cluster/mixins/unicorn_http_server.rb19
3 files changed, 27 insertions, 8 deletions
diff --git a/lib/gitlab/cluster/lifecycle_events.rb b/lib/gitlab/cluster/lifecycle_events.rb
index 294ffad02ce..f931a94938f 100644
--- a/lib/gitlab/cluster/lifecycle_events.rb
+++ b/lib/gitlab/cluster/lifecycle_events.rb
@@ -33,7 +33,7 @@ module Gitlab
#
# Sidekiq/Puma Single: This is called immediately.
#
- # - on_before_phased_restart:
+ # - on_before_graceful_shutdown:
#
# Unicorn/Puma Cluster: This will be called before a graceful
# shutdown of workers starts happening.
@@ -75,9 +75,9 @@ module Gitlab
end
# Read the config/initializers/cluster_events_before_phased_restart.rb
- def on_before_phased_restart(&block)
+ def on_before_graceful_shutdown(&block)
# Defer block execution
- (@master_phased_restart ||= []) << block
+ (@master_graceful_shutdown ||= []) << block
end
def on_before_master_restart(&block)
@@ -108,8 +108,8 @@ module Gitlab
end
end
- def do_before_phased_restart
- @master_phased_restart&.each do |block|
+ def do_before_graceful_shutdown
+ @master_graceful_shutdown&.each do |block|
block.call
end
end
diff --git a/lib/gitlab/cluster/mixins/puma_cluster.rb b/lib/gitlab/cluster/mixins/puma_cluster.rb
index e9157d9f1e4..106c2731c07 100644
--- a/lib/gitlab/cluster/mixins/puma_cluster.rb
+++ b/lib/gitlab/cluster/mixins/puma_cluster.rb
@@ -8,8 +8,12 @@ module Gitlab
raise 'missing method Puma::Cluster#stop_workers' unless base.method_defined?(:stop_workers)
end
+ # This looks at internal status of `Puma::Cluster`
+ # https://github.com/puma/puma/blob/v3.12.1/lib/puma/cluster.rb#L333
def stop_workers
- Gitlab::Cluster::LifecycleEvents.do_before_phased_restart
+ if @status == :stop # rubocop:disable Gitlab/ModuleWithInstanceVariables
+ Gitlab::Cluster::LifecycleEvents.do_before_graceful_shutdown
+ end
super
end
diff --git a/lib/gitlab/cluster/mixins/unicorn_http_server.rb b/lib/gitlab/cluster/mixins/unicorn_http_server.rb
index 765fd0c2baa..440ed02a355 100644
--- a/lib/gitlab/cluster/mixins/unicorn_http_server.rb
+++ b/lib/gitlab/cluster/mixins/unicorn_http_server.rb
@@ -5,11 +5,26 @@ module Gitlab
module Mixins
module UnicornHttpServer
def self.prepended(base)
- raise 'missing method Unicorn::HttpServer#reexec' unless base.method_defined?(:reexec)
+ unless base.method_defined?(:reexec) && base.method_defined?(:stop)
+ raise 'missing method Unicorn::HttpServer#reexec or Unicorn::HttpServer#stop'
+ end
end
def reexec
- Gitlab::Cluster::LifecycleEvents.do_before_phased_restart
+ Gitlab::Cluster::LifecycleEvents.do_before_graceful_shutdown
+
+ super
+ end
+
+ # The stop on non-graceful shutdown is executed twice:
+ # `#stop(false)` and `#stop`.
+ #
+ # The first stop will wipe-out all workers, so we need to check
+ # the flag and a list of workers
+ def stop(graceful = true)
+ if graceful && @workers.any? # rubocop:disable Gitlab/ModuleWithInstanceVariables
+ Gitlab::Cluster::LifecycleEvents.do_before_graceful_shutdown
+ end
super
end