Navigation Menu

Skip to content

Commit

Permalink
Stop joining if the new node is not empty
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 17, 2015
1 parent 455ec5a commit 489f060
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bin/droonga-engine-join
Expand Up @@ -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
Expand Down
50 changes: 50 additions & 0 deletions lib/droonga/data_absorber_client.rb
Expand Up @@ -30,6 +30,12 @@ def initialize(params)
end
end

class EmptyResponse < StandardError
end

class EmptyBody < StandardError
end

DEFAULT_MESSAGES_PER_SECOND = 100
DEFAULT_PROGRESS_INTERVAL_SECONDS = 3

Expand Down Expand Up @@ -120,6 +126,10 @@ def source_node_suspendable?
(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,
Expand Down Expand Up @@ -152,6 +162,46 @@ def create_destination_client
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
Expand Down

0 comments on commit 489f060

Please sign in to comment.