[Groonga-commit] droonga/fluent-plugin-droonga at 4f74e90 [master] Create queue for each worker (monitor) instead of server

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Oct 17 18:07:29 JST 2013


Kouhei Sutou	2013-10-17 18:07:29 +0900 (Thu, 17 Oct 2013)

  New Revision: 4f74e90fda24198fd0022a6bfe509d3200802b49
  https://github.com/droonga/fluent-plugin-droonga/commit/4f74e90fda24198fd0022a6bfe509d3200802b49

  Message:
    Create queue for each worker (monitor) instead of server
    
    It may be more costful rather than without this change but signal
    handling is a rare process. So we don't care about it.

  Modified files:
    lib/droonga/server.rb

  Modified: lib/droonga/server.rb (+21 -12)
===================================================================
--- lib/droonga/server.rb    2013-10-16 17:02:37 +0900 (2777f04)
+++ lib/droonga/server.rb    2013-10-17 18:07:29 +0900 (469255f)
@@ -21,18 +21,11 @@ module Droonga
   module Server
     def before_run
       $log.trace("#{log_tag}: before_run: start")
-      # TODO: Use JobQueue object
-      @context = Groonga::Context.new
-      @database =****@conte*****_database(config[:database])
-      @queue = @context[config[:queue_name]]
       $log.trace("#{log_tag}: before_run: done")
     end
 
     def after_run
       $log.trace("#{log_tag}: after_run: start")
-      @queue.close
-      @database.close
-      @context.close
       $log.trace("#{log_tag}: after_run: done")
     end
 
@@ -50,14 +43,12 @@ module Droonga
     def start_worker(wid)
       worker = super(wid)
       worker.extend(WorkerStopper)
-      worker.queue = @queue
       worker
     end
 
     module WorkerStopper
-      attr_writer :queue
-
       def send_stop(stop_graceful)
+        open_queue do |queue|
         $log.trace("#{log_tag}: stop: start")
 
         $log.trace("#{log_tag}: stop: queue: unblock: start")
@@ -65,7 +56,7 @@ module Droonga
         max_n_retries.times do |i|
           $log.trace("#{log_tag}: stop: queue: unblock: #{i}: start")
           super(stop_graceful)
-          @queue.unblock
+          queue.unblock
           alive_p = alive?
           $log.trace("#{log_tag}: stop: queue: unblock: #{i}: done: #{alive_p}")
           break unless alive_p
@@ -74,19 +65,37 @@ module Droonga
         $log.trace("#{log_tag}: stop: queue: unblock: done")
 
         $log.trace("#{log_tag}: stop: done")
+        end
       end
 
       def send_reload
+        open_queue do |queue|
         $log.trace("#{log_tag}: reload: start")
         super
-        @queue.unblock
+        queue.unblock
         $log.trace("#{log_tag}: reload: done")
+        end
       end
 
       private
       def log_tag
         "[#{Process.ppid}][#{Process.pid}][#{@wid}] server: worker-stopper"
       end
+
+      def open_queue
+        config =****@worke*****
+        # TODO: Use JobQueue object
+        context = Groonga::Context.new
+        database = context.open_database(config[:database])
+        queue = context[config[:queue_name]]
+        begin
+          yield(queue)
+        ensure
+          queue.close
+          database.close
+          context.close
+        end
+      end
     end
   end
 end
-------------- next part --------------
HTML����������������������������...
Download 



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