[Groonga-commit] long-long-float/droonga-engine at 2713b40 [master] fetch catalog.json while joining to cluster

Back to archive index

long-long-float null+****@clear*****
Fri Aug 22 18:43:21 JST 2014


long-long-float	2014-08-22 18:43:21 +0900 (Fri, 22 Aug 2014)

  New Revision: 2713b4083c9296c6633b7f48a1209b952a1ced32
  https://github.com/long-long-float/droonga-engine/commit/2713b4083c9296c6633b7f48a1209b952a1ced32

  Merged 7fb2af2: Merge pull request #12 from long-long-float/share-catalog-automatically

  Message:
    fetch catalog.json while joining to cluster

  Modified files:
    bin/droonga-engine-join
    lib/droonga/command/serf_event_handler.rb

  Modified: bin/droonga-engine-join (+10 -3)
===================================================================
--- bin/droonga-engine-join    2014-08-22 14:44:12 +0900 (72091a1)
+++ bin/droonga-engine-join    2014-08-22 18:43:21 +0900 (5fbf772)
@@ -32,17 +32,20 @@ options.base_dir = ENV[Droonga::Path::BASE_DIR_ENV_NAME] || Dir.pwd
 options.drndump  = "drndump"
 options.client   = "droonga-request"
 options.copy     = true
+options.dataset  = Droonga::CatalogGenerator::DEFAULT_DATASET
 options.port     = Droonga::CatalogGenerator::DEFAULT_PORT
 options.tag      = Droonga::CatalogGenerator::DEFAULT_TAG
 
 parser = OptionParser.new
 parser.version = Droonga::Engine::VERSION
 
+=begin
 parser.on("--base-dir=PATH",
-          "Path to the base directory the catalog.json is located in.",
+         "Path to the base directory the catalog.json is located in.",
           "(#{options.base_dir})") do |path|
   options.base_dir = path
 end
+=end
 
 parser.on("--[no-]copy",
           "Do or don't copy data from the source cluster.",
@@ -82,13 +85,14 @@ parser.parse!(ARGV)
 base_dir = Pathname(options.base_dir).expand_path
 ENV[Droonga::Path::BASE_DIR_ENV_NAME] = base_dir.to_s
 
+=begin
 catalog_path = Droonga::Path.catalog
 unless catalog_path.exist?
   raise "Cannot load 'catalog.json'. You must specify correct path " +
           "to the base directory via --base-dir option."
 end
 source_catalog = JSON.parse(catalog_path.read)
-
+=end
 
 unless options.joining_host
   raise "You must specify the host name or the IP address of the node " +
@@ -99,7 +103,7 @@ unless options.replica_source_host
            "of an existing cluster via --replica-source-host option."
 end
 
-
+=begin
 generator = Droonga::CatalogGenerator.new
 generator.load(source_catalog)
 
@@ -114,6 +118,7 @@ if dataset
   options.tag     = dataset.replicas.tag
   options.port    = dataset.replicas.port
 end
+=end
 
 options.joining_node = "#{options.joining_host}:#{options.port}/#{options.tag}"
 options.source_node  = "#{options.replica_source_host}:#{options.port}/#{options.tag}"
@@ -130,6 +135,8 @@ run_remote_command(options.joining_node, "join",
                    "node"   => options.joining_node,
                    "type"   => "replica",
                    "source" => options.source_node,
+                   "port" => options.port,
+                   "dataset" => options.dataset,
                    "copy"   => options.copy)
 sleep(5) #TODO: wait for restarting of the joining node. this should be done more safely.
 

  Modified: lib/droonga/command/serf_event_handler.rb (+8 -5)
===================================================================
--- lib/droonga/command/serf_event_handler.rb    2014-08-22 14:44:12 +0900 (907382b)
+++ lib/droonga/command/serf_event_handler.rb    2014-08-22 18:43:21 +0900 (e166cb1)
@@ -130,16 +130,19 @@ module Droonga
       end
 
       def join_as_replica
-        source_node = @payload["source"]
-        return unless source_node
+        source_node, source_node_port, source_node_dataset = @payload["source"], @payload["port"], @payload["dataset"]
+        return unless [source_node, source_node_port, source_node_dataset].all?
 
         log("source_node  = #{source_node}")
 
         source_host = source_node.split(":").first
 
-        # fetch_port = @payload["fetch_port"]
-        # catalog = fetch_catalog(source_node, fetch_port)
-        catalog = JSON.parse(Path.catalog.read) #XXX workaround until "fetch" become available
+        Droonga::Client.new(:host => source_node, :port => source_node_port, :tag => "droonga", :protocol => :droonga, :timeout => 1, :exit_on_responce => true, :receiver_host => "localhost", :receiver_port => 0, :report_request => false, :report_elapsed_time => true) do |client|
+          client.request({"dataset": source_node_dataset , type: "catalog.fetch"}) do |responce|
+            File.write(Path.catalog, responce)
+            catalog = JSON.parse(responce)
+          end
+        end
 
         generator = create_current_catalog_generator(catalog)
         dataset = generator.dataset_for_host(source_host) ||
-------------- next part --------------
HTML����������������������������...
Télécharger 



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