YUKI Hiroshi
null+****@clear*****
Thu Apr 23 14:37:15 JST 2015
YUKI Hiroshi 2015-04-23 14:37:15 +0900 (Thu, 23 Apr 2015) New Revision: 6d4053f2b11d9fc11dbbb77c96efeb36927888b4 https://github.com/droonga/droonga-engine/commit/6d4053f2b11d9fc11dbbb77c96efeb36927888b4 Message: Add remote command to export last processed message timestamp Modified files: lib/droonga/command/serf_event_handler.rb lib/droonga/engine.rb lib/droonga/path.rb lib/droonga/serf/remote_command.rb Modified: lib/droonga/command/serf_event_handler.rb (+2 -0) =================================================================== --- lib/droonga/command/serf_event_handler.rb 2015-04-23 14:25:32 +0900 (4017626) +++ lib/droonga/command/serf_event_handler.rb 2015-04-23 14:37:15 +0900 (731a0dc) @@ -82,6 +82,8 @@ module Droonga case event_name when "change_role" Serf::RemoteCommand::ChangeRole + when "export_last_processed_message_timestamp" + Serf::RemoteCommand::ExportLastProcessedMessageTimestamp when "accept_messages_newer_than" Serf::RemoteCommand::AcceptMessagesNewerThan when "join" Modified: lib/droonga/engine.rb (+24 -8) =================================================================== --- lib/droonga/engine.rb 2015-04-23 14:25:32 +0900 (5c9c9b1) +++ lib/droonga/engine.rb 2015-04-23 14:37:15 +0900 (03d94fe) @@ -27,6 +27,7 @@ require "droonga/catalog/loader" require "droonga/dispatcher" require "droonga/serf" require "droonga/serf/tag" +require "droonga/file_observer" module Droonga class Engine @@ -54,6 +55,8 @@ module Droonga @cluster.on_change = lambda do @dispatcher.refresh_node_reference end + + @export_last_processed_message_timestamp_observer = run_export_last_processed_message_timestamp_observer end def start @@ -69,6 +72,7 @@ module Droonga @state.start @cluster.start @dispatcher.start + @export_last_processed_message_timestamp_observer.start logger.trace("start: done") end @@ -79,7 +83,7 @@ module Droonga logger.trace("stop_gracefully/on_finish: start") @dispatcher.stop_gracefully do @state.shutdown - save_last_processed_message_timestamp + @export_last_processed_message_timestamp_observer.shutdown yield end logger.trace("stop_gracefully/on_finish: done") @@ -100,7 +104,7 @@ module Droonga @dispatcher.stop_immediately @cluster.shutdown @state.shutdown - save_last_processed_message_timestamp + @export_last_processed_message_timestamp_observer.shutdown logger.trace("stop_immediately: done") end @@ -137,17 +141,29 @@ module Droonga MICRO_SECONDS_DECIMAL_PLACE = 6 - def save_last_processed_message_timestamp - logger.trace("save_last_processed_message_timestamp: start") + def export_last_processed_message_timestamp + logger.trace("export_last_processed_message_timestamp: start") if @last_processed_message_timestamp timestamp = @last_processed_message_timestamp timestamp = timestamp.utc.iso8601(MICRO_SECONDS_DECIMAL_PLACE) serf = Serf.new(@name) - serf.last_processed_message_timestamp = timestamp - logger.info("saved last processed message timestamp", - :timestamp => timestamp) + old_timestamp = serf.last_processed_message_timestamp + if timestamp > old_timestamp + serf.last_processed_message_timestamp = timestamp + logger.info("exported last processed message timestamp", + :timestamp => timestamp) + end + end + logger.trace("export_last_processed_message_timestamp: done") + end + + def run_export_last_processed_message_timestamp_observer + observer = FileObserver.new(@loop, Path.export_last_processed_message_timestamp) + observer.on_change = lambda do + export_last_processed_message_timestamp end - logger.trace("save_last_processed_message_timestamp: done") + observer.start + observer end def log_tag Modified: lib/droonga/path.rb (+4 -0) =================================================================== --- lib/droonga/path.rb 2015-04-23 14:25:32 +0900 (b70be58) +++ lib/droonga/path.rb 2015-04-23 14:37:15 +0900 (05be6d8) @@ -61,6 +61,10 @@ module Droonga Pathname.new(base_file_name).expand_path(base) end + def export_last_processed_message_timestamp + base + "export-last-processed-message-timestamp.txt" + end + def accidental_buffer state + "buffer" + "accidental" end Modified: lib/droonga/serf/remote_command.rb (+6 -0) =================================================================== --- lib/droonga/serf/remote_command.rb 2015-04-23 14:25:32 +0900 (271d35b) +++ lib/droonga/serf/remote_command.rb 2015-04-23 14:37:15 +0900 (8451df0) @@ -121,6 +121,12 @@ module Droonga end end + class ExportLastProcessedMessageTimestamp < Base + def process + FileUtils.touch(Path.export_last_processed_message_timestamp.to_s) + end + end + class AcceptMessagesNewerThan < Base def process log("old timestamp: #{@serf.accept_messages_newer_than_timestamp}") -------------- next part -------------- HTML����������������������������...Download