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-16 18:06:17 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-16 18:06:17 +0300
commit00c78fb814d7ce00989ac04edd6cdaa3239da284 (patch)
treef04920f08eb4e481ce27bd1d96862676dff735dc /lib/gitlab/cluster
parentd2ffc30fd583e86d4122bb5061098f4f3ca7b3f1 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/cluster')
-rw-r--r--lib/gitlab/cluster/lifecycle_events.rb68
-rw-r--r--lib/gitlab/cluster/mixins/puma_cluster.rb19
-rw-r--r--lib/gitlab/cluster/mixins/unicorn_http_server.rb19
3 files changed, 94 insertions, 12 deletions
diff --git a/lib/gitlab/cluster/lifecycle_events.rb b/lib/gitlab/cluster/lifecycle_events.rb
index 3fbbccbf56e..294ffad02ce 100644
--- a/lib/gitlab/cluster/lifecycle_events.rb
+++ b/lib/gitlab/cluster/lifecycle_events.rb
@@ -8,14 +8,50 @@ module Gitlab
# watchdog threads. This lets us abstract away the Unix process
# lifecycles of Unicorn, Sidekiq, Puma, Puma Cluster, etc.
#
- # We have three lifecycle events.
+ # We have the following lifecycle events.
#
- # - before_fork (only in forking processes)
- # In forking processes (Unicorn and Puma in multiprocess mode) this
- # will be called exactly once, on startup, before the workers are
- # forked. This will be called in the parent process.
- # - worker_start
- # - before_master_restart (only in forking processes)
+ # - on_master_start:
+ #
+ # Unicorn/Puma Cluster: This will be called exactly once,
+ # on startup, before the workers are forked. This is
+ # called in the PARENT/MASTER process.
+ #
+ # Sidekiq/Puma Single: This is called immediately.
+ #
+ # - on_before_fork:
+ #
+ # Unicorn/Puma Cluster: This will be called exactly once,
+ # on startup, before the workers are forked. This is
+ # called in the PARENT/MASTER process.
+ #
+ # Sidekiq/Puma Single: This is not called.
+ #
+ # - on_worker_start:
+ #
+ # Unicorn/Puma Cluster: This is called in the worker process
+ # exactly once before processing requests.
+ #
+ # Sidekiq/Puma Single: This is called immediately.
+ #
+ # - on_before_phased_restart:
+ #
+ # Unicorn/Puma Cluster: This will be called before a graceful
+ # shutdown of workers starts happening.
+ # This is called on `master` process.
+ #
+ # Sidekiq/Puma Single: This is not called.
+ #
+ # - on_before_master_restart:
+ #
+ # Unicorn: This will be called before a new master is spun up.
+ # This is called on forked master before `execve` to become
+ # a new masterfor Unicorn. This means that this does not really
+ # affect old master process.
+ #
+ # Puma Cluster: This will be called before a new master is spun up.
+ # This is called on `master` process.
+ #
+ # Sidekiq/Puma Single: This is not called.
#
# Blocks will be executed in the order in which they are registered.
#
@@ -34,15 +70,17 @@ module Gitlab
end
def on_before_fork(&block)
- return unless in_clustered_environment?
-
# Defer block execution
(@before_fork_hooks ||= []) << block
end
- def on_before_master_restart(&block)
- return unless in_clustered_environment?
+ # Read the config/initializers/cluster_events_before_phased_restart.rb
+ def on_before_phased_restart(&block)
+ # Defer block execution
+ (@master_phased_restart ||= []) << block
+ end
+ def on_before_master_restart(&block)
# Defer block execution
(@master_restart_hooks ||= []) << block
end
@@ -70,8 +108,14 @@ module Gitlab
end
end
+ def do_before_phased_restart
+ @master_phased_restart&.each do |block|
+ block.call
+ end
+ end
+
def do_before_master_restart
- @master_restart_hooks && @master_restart_hooks.each do |block|
+ @master_restart_hooks&.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
new file mode 100644
index 00000000000..e9157d9f1e4
--- /dev/null
+++ b/lib/gitlab/cluster/mixins/puma_cluster.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Cluster
+ module Mixins
+ module PumaCluster
+ def self.prepended(base)
+ raise 'missing method Puma::Cluster#stop_workers' unless base.method_defined?(:stop_workers)
+ end
+
+ def stop_workers
+ Gitlab::Cluster::LifecycleEvents.do_before_phased_restart
+
+ super
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/cluster/mixins/unicorn_http_server.rb b/lib/gitlab/cluster/mixins/unicorn_http_server.rb
new file mode 100644
index 00000000000..765fd0c2baa
--- /dev/null
+++ b/lib/gitlab/cluster/mixins/unicorn_http_server.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Cluster
+ module Mixins
+ module UnicornHttpServer
+ def self.prepended(base)
+ raise 'missing method Unicorn::HttpServer#reexec' unless base.method_defined?(:reexec)
+ end
+
+ def reexec
+ Gitlab::Cluster::LifecycleEvents.do_before_phased_restart
+
+ super
+ end
+ end
+ end
+ end
+end