[Groonga-commit] droonga/droonga-engine at b732e23 [master] Sepcify target cluster id for "add_replicas" (in "join") and "unjoin" remote commands

Back to archive index

YUKI Hiroshi null+****@clear*****
Fri Dec 5 18:04:06 JST 2014


YUKI Hiroshi	2014-12-05 18:04:06 +0900 (Fri, 05 Dec 2014)

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

  Merged 97ba0d9: Merge ../droonga-engine into replicas-in-a-branch

  Message:
    Sepcify target cluster id for "add_replicas" (in "join") and "unjoin" remote commands

  Modified files:
    bin/droonga-engine-join
    bin/droonga-engine-unjoin
    lib/droonga/catalog_loader.rb

  Modified: bin/droonga-engine-join (+28 -0)
===================================================================
--- bin/droonga-engine-join    2014-12-02 12:44:16 +0900 (9bb510e)
+++ bin/droonga-engine-join    2014-12-05 18:04:06 +0900 (86ad5b9)
@@ -22,7 +22,9 @@ require "socket"
 
 require "droonga/engine/version"
 require "droonga/path"
+require "droonga/catalog_fetcher"
 require "droonga/catalog_generator"
+require "droonga/catalog_loader"
 require "droonga/safe_file_writer"
 require "droonga/data_absorber"
 require "droonga/serf"
@@ -94,6 +96,31 @@ class JoinCommand
     "#{@options["replica-source-host"]}:#{@options[:port]}/#{@options[:tag]}"
   end
 
+  def source_cluster_id
+    source_catalog.cluster_id
+  end
+
+  def source_catalog
+    @source_catalog ||= parse_source_catalog
+  end
+
+  def parse_source_catalog
+    loader = Droonga::CatalogLoader.new
+    loader.parse(raw_source_catalog)
+  end
+
+  def raw_source_catalog
+    @raw_source_catalog ||= fetch_source_catalog
+  end
+
+  def fetch_source_catalog
+    fetcher = Droonga::CatalogFetcher.new(:host          => @options["replica-source-host"],
+                                          :port          => @options[:port],
+                                          :tag           => @options[:tag],
+                                          :receiver_host => @options["receiver-host"])
+    fetcher.fetch(:dataset => @options[:dataset])
+  end
+
   def run_remote_command(target, command, options)
     serf = Droonga::Serf.new(nil, target)
     result = serf.send_query(command, options)
@@ -195,6 +222,7 @@ class JoinCommand
   def update_other_nodes
     puts("Update existing hosts in the cluster...")
     run_remote_command(source_node, "add_replicas",
+                       "cluster_id" => source_cluster_id,
                        "dataset" => @options[:dataset],
                        "hosts"   => [@options[:host]])
   end

  Modified: bin/droonga-engine-unjoin (+20 -2)
===================================================================
--- bin/droonga-engine-unjoin    2014-12-02 12:44:16 +0900 (7535ad3)
+++ bin/droonga-engine-unjoin    2014-12-05 18:04:06 +0900 (634f609)
@@ -23,6 +23,7 @@ require "droonga/engine/version"
 require "droonga/path"
 require "droonga/catalog_fetcher"
 require "droonga/catalog_generator"
+require "droonga/catalog_loader"
 require "droonga/serf"
 
 class UnjoinCommand
@@ -85,6 +86,23 @@ class UnjoinCommand
     "#{replica_remove_host}:#{port}/#{tag}"
   end
 
+  def cluster_id
+    catalog.cluster_id
+  end
+
+  def catalog
+    @catalog ||= parse_catalog
+  end
+
+  def parse_catalog
+    loader = Droonga::CatalogLoader.new
+    loader.parse(raw_catalog)
+  end
+
+  def raw_catalog
+    @raw_catalog ||= fetch_catalog
+  end
+
   def fetch_catalog
     fetcher = Droonga::CatalogFetcher.new(:host          => replica_remove_host,
                                           :port          => port,
@@ -98,9 +116,8 @@ class UnjoinCommand
   end
 
   def detect_remaining_node
-    catalog = fetch_catalog
     generator = Droonga::CatalogGenerator.new
-    generator.load(catalog)
+    generator.load(raw_catalog)
 
     dataset = generator.dataset_for_host(replica_remove_host)
     unless dataset
@@ -127,6 +144,7 @@ class UnjoinCommand
     puts "Unjoining replica from the cluster..."
 
     run_remote_command(remaining_node, "unjoin",
+                       "cluster_id" => cluster_id,
                        "dataset" => dataset_name,
                        "hosts"   => [replica_remove_host])
   end

  Modified: lib/droonga/catalog_loader.rb (+8 -1)
===================================================================
--- lib/droonga/catalog_loader.rb    2014-12-02 12:44:16 +0900 (8dc6f56)
+++ lib/droonga/catalog_loader.rb    2014-12-05 18:04:06 +0900 (b7b755b)
@@ -20,11 +20,15 @@ require "droonga/catalog/version2"
 
 module Droonga
   class CatalogLoader
-    def initialize(path)
+    def initialize(path=nil)
       @path = path
     end
 
     def load
+      unless @path
+        raise Error.new("nothing specified")
+      end
+
       data = nil
       begin
         data = File.open(@path) do |file|
@@ -35,7 +39,10 @@ module Droonga
       rescue JSON::ParserError => error
         raise Error.new("Syntax error in #{@path}:\n#{error.to_s}")
       end
+      parse(data)
+    end
 
+    def parse(data)
       unless data.is_a?(Hash)
         raise Error.new("Root element of catalog must be an object in #{@path}")
       end
-------------- next part --------------
HTML����������������������������...
Download 



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