[Groonga-commit] droonga/droonga-engine at b36c20d [master] Implement "join" event via serf

Back to archive index

YUKI Hiroshi null+****@clear*****
Sat Jun 28 00:29:33 JST 2014


YUKI Hiroshi	2014-06-28 00:29:33 +0900 (Sat, 28 Jun 2014)

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

  Message:
    Implement "join" event via serf
    
    serf event join {"type":"replica","host":"192.168.x.x","dataset":"Default"}

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

  Modified: lib/droonga/command/serf_event_handler.rb (+28 -0)
===================================================================
--- lib/droonga/command/serf_event_handler.rb    2014-06-28 00:29:18 +0900 (ad2c41f)
+++ lib/droonga/command/serf_event_handler.rb    2014-06-28 00:29:33 +0900 (6bcabf1)
@@ -21,6 +21,7 @@ require "tempfile"
 
 require "droonga/path"
 require "droonga/serf"
+require "droonga/catalog_generator"
 require "droonga/safe_file_writer"
 
 module Droonga
@@ -73,6 +74,33 @@ module Droonga
            @event_name == "query:change_role"
           save_status(:role, @payload["role"])
         end
+
+        if @event_name == "user:join" or
+           @event_name == "query:join"
+          process_node_join
+        end
+      end
+
+      def process_node_join
+        dataset = @payload["dataset"]
+        return unless dataset
+
+        host = @payload["host"]
+        return unless host
+
+        return unless @payload["type"] == "replica"
+
+        current_catalog = JSON.parse(Path.catalog.read)
+        current_params = generator.catalog_to_params(current_catalog)
+        modifications = {
+          dataset => {
+            :add_replica_hosts => [host],
+          },
+        }
+        updated_params = CatalogGenerator.update_params(current_params,
+                                                        modifications)
+        updated_catalog = CatalogGenerator.generate(updated_params)
+        SafeFileWriter.write(Catalog.path, JSON.pretty_generate(updated_catalog))
       end
 
       def live_nodes
-------------- next part --------------
HTML����������������������������...
Download 



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