YUKI Hiroshi
null+****@clear*****
Tue Apr 14 21:38:54 JST 2015
YUKI Hiroshi 2015-04-14 21:38:54 +0900 (Tue, 14 Apr 2015) New Revision: 12a6a159c81166320dfda24638dd1e278bf037de https://github.com/droonga/droonga-engine/commit/12a6a159c81166320dfda24638dd1e278bf037de Message: Implement system.absorb-data without Fiber and timer. They are not required because Drndump::Dumper is already asynchronous. Modified files: lib/droonga/plugin/async_command.rb lib/droonga/plugins/dump.rb lib/droonga/plugins/system/absorb_data.rb Modified: lib/droonga/plugin/async_command.rb (+10 -38) =================================================================== --- lib/droonga/plugin/async_command.rb 2015-04-14 21:07:26 +0900 (3860bde) +++ lib/droonga/plugin/async_command.rb 2015-04-14 21:38:54 +0900 (5d22511) @@ -93,36 +93,9 @@ module Droonga end def start - setup_forward_data - - forward("#{prefix}.start") - - runner = Fiber.new do - handle - end - - timer = Coolio::TimerWatcher.new(0.1, true) - timer.on_timer do - if runner.alive? - begin - runner.resume - rescue - timer.detach - logger.trace("start: watcher detached on unexpected exception", - :watcher => timer) - logger.exception(error_message, $!) - error(error_name, error_message) - end - else - timer.detach - logger.trace("start: watcher detached on unexpected exception", - :watcher => timer) - end - end - - @loop.attach(timer) - logger.trace("start: new watcher attached", - :watcher => timer) + #XXX override me!! + on_start + on_finish end private @@ -130,9 +103,14 @@ module Droonga "" #XXX override me!! end - def handle + def on_start + setup_forward_data + forward("#{prefix}.start") + end + + def on_finish #XXX override me!! - forward("#{prefix}.end") #XXX you must forward "end" message by self! + forward("#{prefix}.end") end def setup_forward_data @@ -141,8 +119,6 @@ module Droonga "dataset" => @request.dataset, } @forward_to =****@reque*****_to - @n_forwarded_messages = 0 - @messages_per_100msec =****@reque*****_per_seconds / 10 end def error_name @@ -175,10 +151,6 @@ module Droonga @messenger.forward(forward_message, "to" => @forward_to, "type" => type) - - @n_forwarded_messages += 1 - @n_forwarded_messages %= @messages_per_100msec - Fiber.yield if @n_forwarded_messages.zero? end def log_tag Modified: lib/droonga/plugins/dump.rb (+47 -7) =================================================================== --- lib/droonga/plugins/dump.rb 2015-04-14 21:07:26 +0900 (98706d3) +++ lib/droonga/plugins/dump.rb 2015-04-14 21:38:54 +0900 (614a4cf) @@ -50,6 +50,40 @@ module Droonga super(loop, messenger, request) end + def start + on_start + + runner = Fiber.new do + dump_schema + dump_records + dump_indexes + on_finish + end + + timer = Coolio::TimerWatcher.new(0.1, true) + timer.on_timer do + if runner.alive? + begin + runner.resume + rescue + timer.detach + logger.trace("start: watcher detached on unexpected exception", + :watcher => timer) + logger.exception(error_message, $!) + error(error_name, error_message) + end + else + timer.detach + logger.trace("start: watcher detached on unexpected exception", + :watcher => timer) + end + end + + @loop.attach(timer) + logger.trace("start: new watcher attached", + :watcher => timer) + end + private def prefix "dump" @@ -63,13 +97,6 @@ module Droonga "failed to dump" end - def handle - dump_schema - dump_records - dump_indexes - forward("#{prefix}.end") - end - def dump_schema reference_tables = [] each_table do |table| @@ -246,6 +273,19 @@ module Droonga end end + def setup_forward_data + super + @n_forwarded_messages = 0 + @messages_per_100msec =****@reque*****_per_seconds / 10 + end + + def forward(type, body=nil) + super + @n_forwarded_messages += 1 + @n_forwarded_messages %= @messages_per_100msec + Fiber.yield if @n_forwarded_messages.zero? + end + def log_tag "[#{Process.ppid}] dumper" end Modified: lib/droonga/plugins/system/absorb_data.rb (+16 -14) =================================================================== --- lib/droonga/plugins/system/absorb_data.rb 2015-04-14 21:07:26 +0900 (293c30e) +++ lib/droonga/plugins/system/absorb_data.rb 2015-04-14 21:38:54 +0900 (44fc8fd) @@ -42,20 +42,9 @@ module Droonga class EmptyBody < StandardError end - private - def prefix - "system.absorb-data" - end + def start + on_start - def error_name - "AbsorbFailure" - end - - def error_message - "failed to absorb data" - end - - def handle @dumper_error_message = nil dumper = Drndump::Dumper.new(dumper_params) @@ -96,6 +85,19 @@ module Droonga on_finish if @dumper_error_message end + private + def prefix + "system.absorb-data" + end + + def error_name + "AbsorbFailure" + end + + def error_message + "failed to absorb data" + end + def on_finish begin if @dumper_error_message @@ -108,7 +110,7 @@ module Droonga @dumper_error_message = exception.to_s error(error_name, @dumper_error_message) end - forward("#{prefix}.end") + super end def dumper_params -------------- next part -------------- HTML����������������������������... 다운로드