YUKI Hiroshi
null+****@clear*****
Tue Apr 28 22:04:00 JST 2015
YUKI Hiroshi 2015-04-28 22:04:00 +0900 (Tue, 28 Apr 2015) New Revision: a062a208570b86f80347727fe3b9f0045d9f2c60 https://github.com/droonga/droonga-engine/commit/a062a208570b86f80347727fe3b9f0045d9f2c60 Message: Reuse serf instance Modified files: lib/droonga/engine.rb Modified: lib/droonga/engine.rb (+15 -8) =================================================================== --- lib/droonga/engine.rb 2015-04-28 21:54:53 +0900 (1bd6034) +++ lib/droonga/engine.rb 2015-04-28 22:04:00 +0900 (1cbdc64) @@ -62,7 +62,6 @@ module Droonga logger.trace("start: start") @state.on_ready = lambda do on_ready - serf = Serf.new(@name.to_s) serf.set_tag(Serf::Tag.internal_node_name, @internal_name) end @state.on_failure = lambda do @@ -146,12 +145,10 @@ module Droonga def export_last_message_timestamp_to_cluster logger.trace("export_last_message_timestamp_to_cluster: start") - @last_message_timestamp ||= read_last_message_timestamp + @last_message_timestamp ||= read_last_message_timestamp_file if @last_message_timestamp timestamp = @last_message_timestamp - serf = Serf.new(@name) - old_timestamp = serf.last_message_timestamp - old_timestamp = Time.parse(old_timestamp) if old_timestamp + old_timestamp = read_last_message_timestamp_tag logger.trace("export_last_message_timestamp_to_cluster: check", :old => old_timestamp, :current => @last_message_timestamp) @@ -167,7 +164,7 @@ module Droonga def export_last_message_timestamp_to_file logger.trace("export_last_message_timestamp_to_file: start") - old_timestamp = read_last_message_timestamp + old_timestamp = read_last_message_timestamp_file logger.trace("export_last_message_timestamp_to_file: check", :loaded => old_timestamp, :current => @last_message_timestamp) @@ -189,7 +186,7 @@ module Droonga path = Path.last_message_timestamp observer = FileObserver.new(@loop, path) observer.on_change = lambda do - timestamp = read_last_message_timestamp + timestamp = read_last_message_timestamp_file logger.trace("last message stamp file is modified", :loaded => timestamp, :current => @last_message_timestamp) @@ -205,7 +202,7 @@ module Droonga observer end - def read_last_message_timestamp + def read_last_message_timestamp_file file = Path.last_message_timestamp return nil unless file.exist? timestamp = file.read @@ -213,6 +210,16 @@ module Droonga Time.parse(timestamp) end + def read_last_message_timestamp_tag + old_timestamp = serf.last_message_timestamp + old_timestamp = Time.parse(old_timestamp) if old_timestamp + old_timestamp + end + + def serf + @serf ||= Serf.new(@name.to_s) + end + def log_tag "engine" end -------------- next part -------------- HTML����������������������������...Download