[Groonga-commit] droonga/droonga-engine at 2cd5b5b [master] Add droonga-engine-unjoin command

Back to archive index

YUKI Hiroshi null+****@clear*****
Sat Jun 28 02:54:04 JST 2014


YUKI Hiroshi	2014-06-28 02:54:04 +0900 (Sat, 28 Jun 2014)

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

  Message:
    Add droonga-engine-unjoin command

  Added files:
    bin/droonga-engine-unjoin

  Added: bin/droonga-engine-unjoin (+96 -0) 100755
===================================================================
--- /dev/null
+++ bin/droonga-engine-unjoin    2014-06-28 02:54:04 +0900 (60f8e5a)
@@ -0,0 +1,96 @@
+#!/usr/bin/env ruby
+#
+# Copyright (C) 2014 Droonga Project
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1 as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+require "ostruct"
+require "optparse"
+require "json"
+require "pathname"
+
+require "droonga/engine/version"
+require "droonga/path"
+require "droonga/catalog_generator"
+require "droonga/safe_file_writer"
+require "droonga/data_absorber"
+require "droonga/serf"
+
+options = OpenStruct.new
+options.dataset     = "Default"
+options.port        = 10031
+options.tag         = "droonga"
+options.other_hosts = []
+
+parser = OptionParser.new
+parser.version = Droonga::Engine::VERSION
+
+parser.on("--base-dir=PATH",
+          "Path to the base directory the catalog.json is located in.") do |path|
+  options.base_dir = path
+end
+
+parser.separator("")
+parser.separator("Connections:")
+parser.on("--replica-remove-host=HOST",
+          "Host name of the replica removed from cluster.") do |host|
+  options.replica_remove_host = host
+end
+parser.on("--my-host=HOST",
+          "Host name of this node.") do |host|
+  options.my_host = host
+end
+
+parser.parse!(ARGV)
+
+
+base_dir = options.base_dir || ENV[Droonga::Path::BASE_DIR_ENV_NAME] || Dir.pwd
+base_dir = Pathname(base_dir).expand_path
+ENV[Droonga::Path::BASE_DIR_ENV_NAME] = base_dir.to_s
+
+catalog_path = Droonga::Path.base + "catalog.json"
+source_catalog = JSON.parse(catalog_path.read)
+
+
+generator = Droonga::CatalogGenerator.new
+dataset_params = generator.catalog_to_params(source_catalog)
+dataset_params.each do |name, dataset|
+  next unless dataset[:hosts].include?(options.replica_remove_host)
+
+  options.dataset     = name
+  options.tag         = dataset[:tag]
+  options.port        = dataset[:port]
+  options.other_hosts = dataset[:hosts]
+end
+
+sleep(1) # wait for restart
+
+puts "Unjoining from the cluster..."
+
+rpc_host = options.other_hosts.first || options.replica_remove_host
+name = "#{rpc_host}:#{options.port}/#{options.tag}"
+Droonga::Serf.send_event(name, "unjoin", "dataset" => options.dataset,
+                                         "type"    => "replica",
+                                         "host"    => options.replica_remove_host)
+
+puts "Restarting replica..."
+
+final_params = Marshal.load(Marshal.dump(dataset_params))
+final_params[options.dataset][:hosts] -= [options.replica_remove_host]
+final_catalog = Droonga::CatalogGenerator.generate(final_params)
+Droonga::SafeFileWriter.write(catalog_path, JSON.pretty_generate(final_catalog))
+
+puts "Done."
+
+exit 0
-------------- next part --------------
HTML����������������������������...
下载 



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