[Groonga-commit] droonga/droonga-engine at 6c88ec2 [master] Use internal database.reopen command to reopen database

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Jun 25 11:09:54 JST 2014


Kouhei Sutou	2014-06-25 11:09:54 +0900 (Wed, 25 Jun 2014)

  New Revision: 6c88ec244c1e3044952a2096ec99d2b45a13e7e0
  https://github.com/droonga/droonga-engine/commit/6c88ec244c1e3044952a2096ec99d2b45a13e7e0

  Message:
    Use internal database.reopen command to reopen database
    
    "touch catalog.json" workaround is removed.

  Modified files:
    lib/droonga/handler_runner.rb
    lib/droonga/job_pusher.rb
    lib/droonga/processor.rb

  Modified: lib/droonga/handler_runner.rb (+28 -12)
===================================================================
--- lib/droonga/handler_runner.rb    2014-06-24 18:16:22 +0900 (ac2439b)
+++ lib/droonga/handler_runner.rb    2014-06-25 11:09:54 +0900 (c50fdbe)
@@ -43,11 +43,7 @@ module Droonga
     def shutdown
       logger.trace("shutdown: start")
       @forwarder.shutdown
-      if @database
-        @database.close
-        @context.close
-        @database = @context = nil
-      end
+      close_database if @database
       logger.trace("shutdown: done")
     end
 
@@ -62,12 +58,17 @@ module Droonga
     def process(message)
       logger.trace("process: start")
       type = message["type"]
-      handler_class = find_handler_class(type)
-      if handler_class.nil?
-        logger.trace("process: done: no handler: <#{type}>")
-        return
+      if type == "database.reopen"
+        handler_class = nil
+        reopen
+      else
+        handler_class = find_handler_class(type)
+        if handler_class.nil?
+          logger.trace("process: done: no handler: <#{type}>")
+          return
+        end
+        process_type(handler_class, type, message)
       end
-      process_type(handler_class, type, message)
       logger.trace("process: done: <#{type}>",
                    :handler => handler_class)
     end
@@ -75,8 +76,7 @@ module Droonga
     private
     def prepare
       if @database_name and !@database_name.empty?
-        @context = Groonga::Context.new
-        @database =****@conte*****_database(@database_name)
+        open_database
       end
       logger.debug("#{self.class.name}: activating plugins for the dataset \"#{@dataset_name}\": " +
                      "#{@options[:plugins].join(", ")}")
@@ -84,6 +84,22 @@ module Droonga
       @forwarder = Forwarder.new(@loop)
     end
 
+    def close_database
+      @database.close
+      @context.close
+      @database = @context = nil
+    end
+
+    def open_database
+      @context = Groonga::Context.new
+      @database =****@conte*****_database(@database_name)
+    end
+
+    def reopen
+      close_database
+      open_database
+    end
+
     def find_handler_class(type)
       step_definition = @step_runner.find(type)
       return nil if step_definition.nil?

  Modified: lib/droonga/job_pusher.rb (+12 -0)
===================================================================
--- lib/droonga/job_pusher.rb    2014-06-24 18:16:22 +0900 (cfcfd83)
+++ lib/droonga/job_pusher.rb    2014-06-25 11:09:54 +0900 (16c5954)
@@ -57,6 +57,12 @@ module Droonga
       logger.trace("push: done")
     end
 
+    def broadcast(message)
+      logger.trace("broadcast start")
+      @job_queue.broadcast(message)
+      logger.trace("broadcast done")
+    end
+
     private
     def log_tag
       "job_pusher"
@@ -104,6 +110,12 @@ module Droonga
         end
       end
 
+      def broadcast(message)
+        @workers.each do |worker|
+          worker.write(message.to_msgpack)
+        end
+      end
+
       private
       def supply_job(worker)
         if****@buffe*****?

  Modified: lib/droonga/processor.rb (+9 -4)
===================================================================
--- lib/droonga/processor.rb    2014-06-24 18:16:22 +0900 (8622a72)
+++ lib/droonga/processor.rb    2014-06-25 11:09:54 +0900 (0ced2b1)
@@ -15,7 +15,6 @@
 
 require "droonga/loggable"
 require "droonga/handler_runner"
-require "fileutils"
 
 module Droonga
   class Processor
@@ -47,9 +46,9 @@ module Droonga
         synchronous = @handler_runner.prefer_synchronous?(type)
         if @n_workers.zero? or synchronous
           @handler_runner.process(message)
-          #XXX Workaround to restart system by any schema change.
-          #    This should be done more smartly...
-          FileUtils.touch(Path.catalog.to_s) if synchronous
+          if synchronous
+            @job_pusher.broadcast(database_reopen_message)
+          end
         else
           @job_pusher.push(message)
         end
@@ -60,6 +59,12 @@ module Droonga
     end
 
     private
+    def database_reopen_message
+      {
+        "type" => "database.reopen",
+      }
+    end
+
     def log_tag
       "processor"
     end
-------------- next part --------------
HTML����������������������������...
下载 



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