YUKI Hiroshi
null+****@clear*****
Fri Apr 17 17:31:37 JST 2015
YUKI Hiroshi 2015-04-17 17:31:37 +0900 (Fri, 17 Apr 2015) New Revision: 489f060316e77943051c97386e760cb6ef93603d https://github.com/droonga/droonga-engine/commit/489f060316e77943051c97386e760cb6ef93603d Message: Stop joining if the new node is not empty Modified files: bin/droonga-engine-join lib/droonga/data_absorber_client.rb Modified: bin/droonga-engine-join (+6 -0) =================================================================== --- bin/droonga-engine-join 2015-04-17 17:31:10 +0900 (c3af996) +++ bin/droonga-engine-join 2015-04-17 17:31:37 +0900 (c773da8) @@ -53,6 +53,12 @@ module Droonga puts "Source Cluster ID: #{source_cluster_id}" puts "" + if should_copy? and not absorber.empty_destination? + $stderr.puts("Error: The joining node's dataset #{dataset} is not empty.") + $stderr.puts(" You must clear all data of the node before joining.") + return false + end + begin set_joining_node_role do_join Modified: lib/droonga/data_absorber_client.rb (+50 -0) =================================================================== --- lib/droonga/data_absorber_client.rb 2015-04-17 17:31:10 +0900 (c634ae3) +++ lib/droonga/data_absorber_client.rb 2015-04-17 17:31:37 +0900 (02ee256) @@ -30,6 +30,12 @@ module Droonga end end + class EmptyResponse < StandardError + end + + class EmptyBody < StandardError + end + DEFAULT_MESSAGES_PER_SECOND = 100 DEFAULT_PROGRESS_INTERVAL_SECONDS = 3 @@ -120,6 +126,10 @@ module Droonga (source_replica_hosts - [@source_host]).size >= 1 end + def empty_destination? + source_table_names.empty? + end + private def validate_params source_node_name = NodeName.new(:host => @source_host, @@ -152,6 +162,46 @@ module Droonga Droonga::Client.new(destination_client_options) end + def source_client_options + { + :host => @source_host, + :port => @source_port, + :tag => @source_tag, + :dataset => @source_dataset, + :protocol => :droonga, + :receiver_host => @receiver_host, + :receiver_port => @receiver_port, + } + end + + def create_source_client + Droonga::Client.new(source_client_options) + end + + def source_table_names + @source_table_names ||= get_source_table_names + end + + def get_source_table_names + client = create_source_client + response = client.request("dataset" => @source_dataset, + "type" => "table_list") + + unless response + raise EmptyResponse.new("table_list returns nil response") + end + unless response["body"] + raise EmptyBody.new("table_list returns nil result") + end + + message_body = response["body"] + body = message_body[1] + tables = body[1..-1] + tables.collect do |table| + table[1] + end + end + def source_replica_hosts @source_replica_hosts ||= get_source_replica_hosts end -------------- next part -------------- HTML����������������������������...Download