Navigation Menu

Skip to content

Commit

Permalink
Split methods for joining steps
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Jan 16, 2015
1 parent 36be4f6 commit 755b0a3
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions lib/droonga/command/remote.rb
Expand Up @@ -188,27 +188,13 @@ def join_as_replica

@catalog = fetch_catalog

other_hosts = replica_hosts
log("other_hosts = #{other_hosts}")
return if other_hosts.empty?
@other_hosts = replica_hosts
log("other_hosts = #{@other_hosts}")
return if @other_hosts.empty?

@serf.role = NodeMetadata::Role::ABSORB_DESTINATION

# restart self with the fetched catalog.
SafeFileWriter.write(Path.catalog) do |output, file|
output.puts(JSON.pretty_generate(@catalog))
@service_installation.ensure_correct_file_permission(file)
end

log("joining to the cluster: update myself")

CatalogModifier.modify do |modifier, file|
modifier.datasets[dataset_name].replicas.hosts += other_hosts
modifier.datasets[dataset_name].replicas.hosts.uniq!
@service_installation.ensure_correct_file_permission(file)
end

@serf.join(*other_hosts)
join_to_cluster

absorb_data if should_absorb_data?

Expand All @@ -232,14 +218,26 @@ def fetch_catalog
fetcher.fetch(:dataset => dataset_name)
end

def absorb_data
log("starting to copy data from #{source_host}")
def join_to_cluster
# restart self with the fetched catalog.
SafeFileWriter.write(Path.catalog) do |output, file|
output.puts(JSON.pretty_generate(@catalog))
@service_installation.ensure_correct_file_permission(file)
end

log("joining to the cluster: update myself")

CatalogModifier.modify do |modifier, file|
modifier.datasets[dataset_name].replicas.hosts = [host]
modifier.datasets[dataset_name].replicas.hosts += @other_hosts
modifier.datasets[dataset_name].replicas.hosts.uniq!
@service_installation.ensure_correct_file_permission(file)
end
sleep(5) #TODO: wait for restart. this should be done more safely, to avoid starting of absorbing with old catalog.json.

@serf.join(*@other_hosts)
end

def absorb_data
log("starting to copy data from #{source_host}")

metadata = NodeMetadata.new
metadata.set(:absorbing, true)
Expand Down

0 comments on commit 755b0a3

Please sign in to comment.