[Groonga-commit] droonga/droonga-engine at 9f3dfc1 [master] Modify catalog with generator's instance methods

Back to archive index

YUKI Hiroshi null+****@clear*****
Sun Jun 29 00:53:07 JST 2014


YUKI Hiroshi	2014-06-29 00:53:07 +0900 (Sun, 29 Jun 2014)

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

  Message:
    Modify catalog with generator's instance methods

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

  Modified: lib/droonga/command/serf_event_handler.rb (+12 -18)
===================================================================
--- lib/droonga/command/serf_event_handler.rb    2014-06-29 00:33:14 +0900 (97a35f0)
+++ lib/droonga/command/serf_event_handler.rb    2014-06-29 00:53:07 +0900 (eaf3a01)
@@ -85,12 +85,10 @@ module Droonga
 
         return unless @payload["type"] == "replica"
 
-        modifications = {
-          dataset => {
-            :add_replica_hosts => [host],
-          },
-        }
-        modify_catalog(modifications)
+        modify_catalog do |generator|
+          generator.datasets[dataset].replicas.hosts << host
+          generator.datasets[dataset].replicas.hosts.uniq!
+        end
       end
 
       def process_node_unjoin
@@ -102,21 +100,17 @@ module Droonga
 
         return unless @payload["type"] == "replica"
 
-        modifications = {
-          dataset => {
-            :remove_replica_hosts => [host],
-          },
-        }
-        modify_catalog(modifications)
+        modify_catalog do |generator|
+          generator.datasets[dataset].replicas.hosts -= [host]
+        end
       end
 
-      def modify_catalog(modifications)
+      def modify_catalog
         current_catalog = JSON.parse(Path.catalog.read)
-        current_params = CatalogGenerator.catalog_to_params(current_catalog)
-        updated_params = CatalogGenerator.update_params(current_params,
-                                                        modifications)
-        updated_catalog = CatalogGenerator.generate(updated_params)
-        SafeFileWriter.write(Path.catalog, JSON.pretty_generate(updated_catalog))
+        generator = CatalogGenerator.new
+        generator.load(current_catalog)
+        yield(generator)
+        SafeFileWriter.write(Path.catalog, JSON.pretty_generate(generator.catalog))
       end
 
       def live_nodes
-------------- next part --------------
HTML����������������������������...
Télécharger 



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