[Groonga-commit] groonga/fluent-plugin-droonga at 243437e [master] Support graceful shutdown

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Jun 14 16:31:16 JST 2013


Kouhei Sutou	2013-06-14 16:31:16 +0900 (Fri, 14 Jun 2013)

  New Revision: 243437e30eb12651133fae436ca211a42a9e1282
  https://github.com/groonga/fluent-plugin-droonga/commit/243437e30eb12651133fae436ca211a42a9e1282

  Message:
    Support graceful shutdown
    
    It requires groonga 3.0.5 and rroonga 3.0.3. They are not released
    yet.

  Modified files:
    fluent-plugin-droonga.gemspec
    lib/droonga/worker.rb

  Modified: fluent-plugin-droonga.gemspec (+1 -1)
===================================================================
--- fluent-plugin-droonga.gemspec    2013-06-12 18:58:34 +0900 (1d8d966)
+++ fluent-plugin-droonga.gemspec    2013-06-14 16:31:16 +0900 (5538192)
@@ -28,7 +28,7 @@ Gem::Specification.new do |gem|
   gem.test_files    = gem.files.grep(%r{^(test|spec|features)/})
   gem.require_paths = ["lib"]
   gem.add_dependency "fluentd"
-  gem.add_dependency "rroonga"
+  gem.add_dependency "rroonga", ">= 3.0.3"
   gem.add_dependency "fluent-logger"
   gem.add_development_dependency "rake"
   gem.add_development_dependency "bundler"

  Modified: lib/droonga/worker.rb (+19 -4)
===================================================================
--- lib/droonga/worker.rb    2013-06-12 18:58:34 +0900 (6af21eb)
+++ lib/droonga/worker.rb    2013-06-14 16:31:16 +0900 (e11f419)
@@ -42,10 +42,7 @@ module Droonga
     end
 
     def shutdown
-      @pool.each do |pid|
-        # TODO: do it gracefully
-        Process.kill(:KILL, pid)
-      end
+      shutdown_workers
       @handlers.each do |handler|
         handler.shutdown
       end
@@ -76,6 +73,24 @@ module Droonga
     end
 
     private
+    def shutdown_workers
+      @pool.each do |pid|
+        Process.kill(:TERM, pid)
+      end
+      queue = @context[@queue_name]
+      3.times do |i|
+        break if****@pool*****?
+        queue.unblock
+        @pool.reject! do |pid|
+          not Process.waitpid(pid, Process::WNOHANG).nil?
+        end
+        sleep(i ** 2 * 0.1)
+      end
+      @pool.each do |pid|
+        Process.kill(:KILL, pid)
+      end
+    end
+
     def post_or_push(message, body, destination)
       route = nil
       unless destination
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index