YUKI Hiroshi
null+****@clear*****
Fri Nov 21 18:01:49 JST 2014
YUKI Hiroshi 2014-11-21 18:01:49 +0900 (Fri, 21 Nov 2014) New Revision: c9465ca539bc53c724c2430125cfb406eb67b65e https://github.com/droonga/droonga-engine/commit/c9465ca539bc53c724c2430125cfb406eb67b65e Message: Report progress of the absorbing process Modified files: bin/droonga-engine-absorb-data lib/droonga/data_absorber.rb Modified: bin/droonga-engine-absorb-data (+30 -7) =================================================================== --- bin/droonga-engine-absorb-data 2014-11-21 17:46:10 +0900 (59b7941) +++ bin/droonga-engine-absorb-data 2014-11-21 18:01:49 +0900 (5a92329) @@ -83,7 +83,7 @@ destination_node = "#{options.destination_host}:#{options.port}/#{options.tag}" def run_remote_command(target, command, options) serf = Droonga::Serf.new(nil, target) result = serf.send_query(command, options) - puts result[:result] + # puts result[:result] puts result[:error] unless result[:error].empty? result[:response] end @@ -96,7 +96,17 @@ puts " tag = #{options.tag}" puts "" puts "Absorbing..." +absorber_options = { + :dataset => options.dataset, + :source_host => options.source_host, + :destination_host => options.destination_host, + :port => options.port, + :tag => options.tag, +} +absorber = Droonga::DataAbsorber.new(absorber_options) + if options.remote + start = Time.new.to_i run_remote_command(destination_node, "absorb_data", "node" => destination_node, "source" => options.source_host, @@ -110,6 +120,16 @@ if options.remote "key" => "absorbing") absorbing = response["value"] break unless absorbing + + if calculated_required_time != Droonga::DataAbsorber::TIME_UNKNOWN and + calculated_required_time > 0 + elapsed_time = Time.new.to_i - start + progress = elapsed_time / calculated_required_time + progress = (progress * 100).to_i + remaining_time_in_seconds = calculated_required_time - elapsed_time + remaining_time_in_minutes = remaining_time_in_seconds / 60 + puts "#{progress}% done (maybe #{remaining_time_in_minutes}minutes remaining)" + end end response = run_remote_command(source_node, "report_status", "node" => source_node, @@ -124,12 +144,15 @@ if options.remote "value" => timestamp) end else - Droonga::DataAbsorber.absorb(:dataset => options.dataset, - :source_host => options.source_host, - :destination_host => options.destination_host, - :port => options.port, - :tag => options.tag) do |output| - puts output + absorber.absorb do |live_status| + if live_status[:progress] != Droonga::DataAbsorber::PROGRESS_UNKNOWN + progress = (live_status[:progress] * 100).to_i + remaining_time_in_seconds = calculated_required_time * (1 - live_status[:progress]) + remaining_time_in_minutes = remaining_time_in_seconds / 60 + puts "#{progress}% done (maybe #{remaining_time_in_minutes}minutes remaining)" + else + puts live_status[:output] + end end response = run_remote_command(source_node, "report_status", "node" => source_node, Modified: lib/droonga/data_absorber.rb (+9 -15) =================================================================== --- lib/droonga/data_absorber.rb 2014-11-21 17:46:10 +0900 (2052b80) +++ lib/droonga/data_absorber.rb 2014-11-21 18:01:49 +0900 (c4f6a4c) @@ -51,13 +51,6 @@ module Droonga client_command_line = [client] + client_options(client) calculated_required_time = required_time_in_seconds - unless calculated_required_time == TIME_UNKNOWN - logger.info("calculated required time: #{calculated_required_time}sec") - if block_given? - yield(:required_time_in_seconds => calculated_required_time) - end - end - start = Time.new.to_i env = {} Open3.pipeline_r([env, *drndump_command_line], @@ -76,6 +69,15 @@ module Droonga end end + def required_time_in_seconds + @params[:client].include?("droonga-send") + total_n_source_records / @params[:messages_per_second] + else + TIME_UNKNOWN + end + end + + private def drndump_options options = [] options += ["--host", @params[:source_host]] if @params[:source_host] @@ -128,14 +130,6 @@ module Droonga end end - def required_time_in_seconds - @params[:client].include?("droonga-send") - total_n_source_records / @params[:messages_per_second] - else - TIME_UNKNOWN - end - end - def source_client options = { :host => @params[:source_host], -------------- next part -------------- HTML����������������������������... ダウンロード