YUKI Hiroshi
null+****@clear*****
Thu Jun 26 14:27:13 JST 2014
YUKI Hiroshi 2014-06-26 14:27:13 +0900 (Thu, 26 Jun 2014) New Revision: 08d7f45e666da2cdd97d6d867f2fb6570b83aab1 https://github.com/droonga/droonga-engine/commit/08d7f45e666da2cdd97d6d867f2fb6570b83aab1 Message: Handle nodes status correctly Modified files: lib/droonga/command/serf_event_handler.rb lib/droonga/engine.rb lib/droonga/engine_state.rb lib/droonga/path.rb Renamed files: lib/droonga/nodes_status_loader.rb (from lib/droonga/live_nodes_list_loader.rb) Modified: lib/droonga/command/serf_event_handler.rb (+9 -9) =================================================================== --- lib/droonga/command/serf_event_handler.rb 2014-06-26 14:03:02 +0900 (2ed8034) +++ lib/droonga/command/serf_event_handler.rb 2014-06-26 14:27:13 +0900 (7c4a5f8) @@ -39,7 +39,7 @@ module Droonga def run parse_event - output_live_nodes + output_nodes_status true end @@ -65,24 +65,24 @@ module Droonga parsed end - def live_nodes - nodes = {} + def nodes_status + nodes_status = {} members = `#{@serf} members -rpc-addr #{@serf_rpc_address}` members.each_line do |member| name, address, status, tags, = member.strip.split(/\s+/) - nodes[name] = { + nodes_status[name] = { "serfAddress" => address, "live" => status == "alive", "tags" => parse_tags(tags), } end - nodes + nodes_status end - def output_live_nodes - path = Path.live_nodes - nodes = live_nodes - file_contents = JSON.pretty_generate(nodes) + def output_nodes_status + path = Path.nodes_status + status = nodes_status + file_contents = JSON.pretty_generate(status) FileUtils.mkdir_p(path.parent.to_s) # Don't output the file directly to prevent loading of incomplete file! Tempfile.open(path.basename.to_s, path.parent.to_s, "w") do |output| Modified: lib/droonga/engine.rb (+13 -13) =================================================================== --- lib/droonga/engine.rb 2014-06-26 14:03:02 +0900 (41f837f) +++ lib/droonga/engine.rb 2014-06-26 14:27:13 +0900 (ea4b875) @@ -23,7 +23,7 @@ require "droonga/engine_state" require "droonga/catalog_loader" require "droonga/dispatcher" require "droonga/file_observer" -require "droonga/live_nodes_list_loader" +require "droonga/nodes_status_loader" module Droonga class Engine @@ -34,23 +34,23 @@ module Droonga @catalog = load_catalog @state.catalog = @catalog @dispatcher = create_dispatcher - @live_nodes_list_observer = FileObserver.new(loop, Path.live_nodes) - @live_nodes_list_observer.on_change = lambda do - @state.live_nodes = load_live_nodes + @nodes_status_observer = FileObserver.new(loop, Path.nodes_status) + @nodes_status_observer.on_change = lambda do + @state.nodes_status = load_nodes_status end end def start logger.trace("start: start") @state.start - @live_nodes_list_observer.start + @nodes_status_observer.start @dispatcher.start logger.trace("start: done") end def stop_gracefully logger.trace("stop_gracefully: start") - @live_nodes_list_observer.stop + @nodes_status_observer.stop on_finish = lambda do output_last_processed_timestamp @dispatcher.shutdown @@ -69,7 +69,7 @@ module Droonga def stop_immediately logger.trace("stop_immediately: start") output_last_processed_timestamp - @live_nodes_list_observer.stop + @nodes_status_observer.stop @dispatcher.shutdown @state.shutdown logger.trace("stop_immediately: done") @@ -92,14 +92,14 @@ module Droonga catalog end - def load_live_nodes - path = Path.live_nodes - loader = LiveNodesListLoader.new(path) - live_nodes = loader.load - logger.info("live-nodes loaded", + def load_nodes_status + path = Path.nodes_status + loader = NodesStatusLoader.new(path) + nodes_status = loader.load + logger.info("nodes-status loaded", :path => path, :mtime => path.mtime) - live_nodes + nodes_status end def create_dispatcher Modified: lib/droonga/engine_state.rb (+15 -3) =================================================================== --- lib/droonga/engine_state.rb 2014-06-26 14:03:02 +0900 (ec12a44) +++ lib/droonga/engine_state.rb 2014-06-26 14:27:13 +0900 (39d92ce) @@ -33,7 +33,7 @@ module Droonga attr_reader :replier attr_accessor :on_finish attr_accessor :catalog - attr_accessor :live_nodes + attr_reader :nodes_status def initialize(loop, name, internal_name) @loop = loop @name = name @@ -45,7 +45,7 @@ module Droonga @replier = Replier.new(@forwarder) @on_finish = nil @catalog = nil - @live_nodes = nil + @nodes_status = nil end def start @@ -107,10 +107,22 @@ module Droonga end def live_nodes - @live_nodes || @catalog.all_nodes + retur****@catal*****_nodes unless @nodes_status + @live_nodes ||= prepare_live_nodes + end + + def nodes_status=(new_status) + @live_nodes = nil + @nodes_status = new_status end private + def prepare_live_nodes + @nodes_status.keys.select do |key| + @nodes_status[key]["live"] + end + end + def log_tag "engine_state" end Renamed: lib/droonga/nodes_status_loader.rb (+6 -11) 81% =================================================================== --- lib/droonga/live_nodes_list_loader.rb 2014-06-26 14:03:02 +0900 (6d5fee2) +++ lib/droonga/nodes_status_loader.rb 2014-06-26 14:27:13 +0900 (82fe247) @@ -17,31 +17,26 @@ require "pathname" require "json" module Droonga - class LiveNodesListLoader + class NodesStatusLoader def initialize(path) @path = path end def load - list = parse - list.keys - end - - private - def parse - return default_list unles****@path*****? + return default_status unles****@path*****? contents =****@path***** - return default_list if contents.empty? + return default_status if contents.empty? begin JSON.parse(contents) rescue JSON::ParserError - default_list + default_status end end - def default_list + private + def default_status {} end end Modified: lib/droonga/path.rb (+2 -2) =================================================================== --- lib/droonga/path.rb 2014-06-26 14:03:02 +0900 (d18768d) +++ lib/droonga/path.rb 2014-06-26 14:27:13 +0900 (fd46812) @@ -38,8 +38,8 @@ module Droonga base + "state" end - def live_nodes - state + "live-nodes.json" + def nodes_status + state + "nodes-status.json" end def last_processed_timestamp -------------- next part -------------- HTML����������������������������... ダウンロード