[Groonga-commit] droonga/droonga-engine at cc04568 [master] Use status file instead of serf tags.

Back to archive index

YUKI Hiroshi null+****@clear*****
Wed Jul 23 16:33:38 JST 2014


YUKI Hiroshi	2014-07-23 16:33:38 +0900 (Wed, 23 Jul 2014)

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

  Message:
    Use status file instead of serf tags.
    
    Because modifying of serf tags by serf event handlers doesn't affect.

  Modified files:
    lib/droonga/command/serf_event_handler.rb
    lib/droonga/serf.rb

  Modified: lib/droonga/command/serf_event_handler.rb (+20 -4)
===================================================================
--- lib/droonga/command/serf_event_handler.rb    2014-07-23 16:14:48 +0900 (e9c741d)
+++ lib/droonga/command/serf_event_handler.rb    2014-07-23 16:33:38 +0900 (747f76f)
@@ -82,6 +82,8 @@ module Droonga
         case @event_sub_name
         when "change_role"
           save_status(:role, @payload["role"])
+        when "report_status"
+          report_status
         when "join"
           join
         when "set_replicas"
@@ -114,6 +116,10 @@ module Droonga
         hosts
       end
 
+      def report_status
+        puts status(@payload["key"])
+      end
+
       def join
         type = @payload["type"]
         log("type = #{type}")
@@ -160,13 +166,13 @@ module Droonga
           end
           sleep(1) # wait for restart
 
-          Serf.set_tag(@serf_name, "absorbing", "true")
+          save_status("absorbing", true)
           DataAbsorber.absorb(:dataset          => dataset_name,
                               :source_host      => source_host,
                               :destination_host => host,
                               :port             => port,
                               :tag              => tag)
-          Serf.delete_tag(@serf_name, "absorbing")
+          delete_status("absorbing")
           sleep(1)
         end
 
@@ -311,13 +317,13 @@ module Droonga
         log("port    = #{port}")
         log("tag     = #{tag}")
 
-        Serf.set_tag(@serf_name, "absorbing", "true")
+        save_status("absorbing", true)
         DataAbsorber.absorb(:dataset          => dataset_name,
                             :source_host      => source,
                             :destination_host => host,
                             :port             => port,
                             :tag              => tag)
-        Serf.delete_tag(@serf_name, "absorbing")
+        save_delete("absorbing")
       end
 
       def live_nodes
@@ -331,12 +337,22 @@ module Droonga
         SafeFileWriter.write(path, file_contents)
       end
 
+      def status(key)
+        Serf.status(key)
+      end
+
       def save_status(key, value)
         status = Serf.load_status
         status[key] = value
         SafeFileWriter.write(Serf.status_file, JSON.pretty_generate(status))
       end
 
+      def delete_status(key)
+        status = Serf.load_status
+        status.delete(key)
+        SafeFileWriter.write(Serf.status_file, JSON.pretty_generate(status))
+      end
+
       def log(message)
         @response["log"] << message
       end

  Modified: lib/droonga/serf.rb (+4 -23)
===================================================================
--- lib/droonga/serf.rb    2014-07-23 16:14:48 +0900 (e8e0e99)
+++ lib/droonga/serf.rb    2014-07-23 16:33:38 +0900 (6be17eb)
@@ -58,6 +58,10 @@ module Droonga
         {}
       end
 
+      def status(key)
+        load_status[key]
+      end
+
       def send_event(name, event, payload)
         new(nil, name).send_event(event, payload)
       end
@@ -69,19 +73,6 @@ module Droonga
       def live_nodes(name)
         new(nil, name).live_nodes
       end
-
-      def set_tag(node_name, tag_name, value)
-        new(nil, name).set_tag(tag_name, value)
-      end
-
-      def delete_tag(node_name, tag_name)
-        new(nil, name).delete_tag(tag_name)
-      end
-
-      def tag(node_name, tag_name)
-        node_info = live_nodes(node_name)[node_name]
-        node_info["tags"][tag_name]
-      end
     end
 
     include Loggable
@@ -138,16 +129,6 @@ module Droonga
       run_once("query", *options)
     end
 
-    def set_tag(name, value="")
-      ensure_serf
-      run_once("tags", "-set", "#{name}=#{value}")
-    end
-
-    def delete_tag(name)
-      ensure_serf
-      run_once("tags", "-delete", name)
-    end
-
     def live_nodes
       ensure_serf
       nodes = {}
-------------- next part --------------
HTML����������������������������...
Download 



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