[Groonga-commit] droonga/droonga-engine at 878dccc [master] Implement serf events to modify replicas

Back to archive index

YUKI Hiroshi null+****@clear*****
Sun Jun 29 01:01:48 JST 2014


YUKI Hiroshi	2014-06-29 01:01:48 +0900 (Sun, 29 Jun 2014)

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

  Message:
    Implement serf events to modify replicas

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

  Modified: lib/droonga/command/serf_event_handler.rb (+32 -15)
===================================================================
--- lib/droonga/command/serf_event_handler.rb    2014-06-29 00:53:07 +0900 (eaf3a01)
+++ lib/droonga/command/serf_event_handler.rb    2014-06-29 01:01:48 +0900 (5135e86)
@@ -69,39 +69,56 @@ module Droonga
         case @event_sub_name
         when "change_role"
           save_status(:role, @payload["role"])
-        when "join"
-          process_node_join
-        when "unjoin" # TODO: Is "unjoin" clear word? How about "leave"?
-          process_node_unjoin
+        when "set_replicas"
+          set_replicas
+        when "add_replicas"
+          add_replicas
+        when "remove_replicas"
+          remove_replicas
         end
       end
 
-      def process_node_join
+      def given_hosts
+        hosts = @payload["hosts"]
+        return nil unless hosts
+        hosts = [hosts] if hosts.is_a?(String)
+        hosts
+      end
+
+      def set_replicas
         dataset = @payload["dataset"]
         return unless dataset
 
-        host = @payload["host"]
-        return unless host
+        hosts = given_hosts
+        return unless hosts
+
+        modify_catalog do |generator|
+          generator.datasets[dataset].replicas.hosts = hosts
+        end
+      end
+
+      def add_replicas
+        dataset = @payload["dataset"]
+        return unless dataset
 
-        return unless @payload["type"] == "replica"
+        hosts = given_hosts
+        return unless hosts
 
         modify_catalog do |generator|
-          generator.datasets[dataset].replicas.hosts << host
+          generator.datasets[dataset].replicas.hosts += hosts
           generator.datasets[dataset].replicas.hosts.uniq!
         end
       end
 
-      def process_node_unjoin
+      def remove_replica
         dataset = @payload["dataset"]
         return unless dataset
 
-        host = @payload["host"]
-        return unless host
-
-        return unless @payload["type"] == "replica"
+        hosts = given_hosts
+        return unless hosts
 
         modify_catalog do |generator|
-          generator.datasets[dataset].replicas.hosts -= [host]
+          generator.datasets[dataset].replicas.hosts -= hosts
         end
       end
 
-------------- next part --------------
HTML����������������������������...
다운로드 



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