YUKI Hiroshi
null+****@clear*****
Thu Jun 26 15:52:12 JST 2014
YUKI Hiroshi 2014-06-26 15:52:12 +0900 (Thu, 26 Jun 2014) New Revision: d88b3e5a02e3161475de3f12b20196cbcab4f9e6 https://github.com/droonga/droonga-engine/commit/d88b3e5a02e3161475de3f12b20196cbcab4f9e6 Message: Revert "Handle nodes status correctly" This reverts commit 08d7f45e666da2cdd97d6d867f2fb6570b83aab1. 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/live_nodes_list_loader.rb (from lib/droonga/nodes_status_loader.rb) Modified: lib/droonga/command/serf_event_handler.rb (+9 -9) =================================================================== --- lib/droonga/command/serf_event_handler.rb 2014-06-26 15:52:11 +0900 (7c4a5f8) +++ lib/droonga/command/serf_event_handler.rb 2014-06-26 15:52:12 +0900 (2ed8034) @@ -39,7 +39,7 @@ module Droonga def run parse_event - output_nodes_status + output_live_nodes true end @@ -65,24 +65,24 @@ module Droonga parsed end - def nodes_status - nodes_status = {} + def live_nodes + nodes = {} members = `#{@serf} members -rpc-addr #{@serf_rpc_address}` members.each_line do |member| name, address, status, tags, = member.strip.split(/\s+/) - nodes_status[name] = { + nodes[name] = { "serfAddress" => address, "live" => status == "alive", "tags" => parse_tags(tags), } end - nodes_status + nodes end - def output_nodes_status - path = Path.nodes_status - status = nodes_status - file_contents = JSON.pretty_generate(status) + def output_live_nodes + path = Path.live_nodes + nodes = live_nodes + file_contents = JSON.pretty_generate(nodes) 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 15:52:11 +0900 (ea4b875) +++ lib/droonga/engine.rb 2014-06-26 15:52:12 +0900 (41f837f) @@ -23,7 +23,7 @@ require "droonga/engine_state" require "droonga/catalog_loader" require "droonga/dispatcher" require "droonga/file_observer" -require "droonga/nodes_status_loader" +require "droonga/live_nodes_list_loader" module Droonga class Engine @@ -34,23 +34,23 @@ module Droonga @catalog = load_catalog @state.catalog = @catalog @dispatcher = create_dispatcher - @nodes_status_observer = FileObserver.new(loop, Path.nodes_status) - @nodes_status_observer.on_change = lambda do - @state.nodes_status = load_nodes_status + @live_nodes_list_observer = FileObserver.new(loop, Path.live_nodes) + @live_nodes_list_observer.on_change = lambda do + @state.live_nodes = load_live_nodes end end def start logger.trace("start: start") @state.start - @nodes_status_observer.start + @live_nodes_list_observer.start @dispatcher.start logger.trace("start: done") end def stop_gracefully logger.trace("stop_gracefully: start") - @nodes_status_observer.stop + @live_nodes_list_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 - @nodes_status_observer.stop + @live_nodes_list_observer.stop @dispatcher.shutdown @state.shutdown logger.trace("stop_immediately: done") @@ -92,14 +92,14 @@ module Droonga catalog end - def load_nodes_status - path = Path.nodes_status - loader = NodesStatusLoader.new(path) - nodes_status = loader.load - logger.info("nodes-status loaded", + def load_live_nodes + path = Path.live_nodes + loader = LiveNodesListLoader.new(path) + live_nodes = loader.load + logger.info("live-nodes loaded", :path => path, :mtime => path.mtime) - nodes_status + live_nodes end def create_dispatcher Modified: lib/droonga/engine_state.rb (+3 -15) =================================================================== --- lib/droonga/engine_state.rb 2014-06-26 15:52:11 +0900 (39d92ce) +++ lib/droonga/engine_state.rb 2014-06-26 15:52:12 +0900 (ec12a44) @@ -33,7 +33,7 @@ module Droonga attr_reader :replier attr_accessor :on_finish attr_accessor :catalog - attr_reader :nodes_status + attr_accessor :live_nodes 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 - @nodes_status = nil + @live_nodes = nil end def start @@ -107,22 +107,10 @@ module Droonga end def live_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 + @live_nodes || @catalog.all_nodes 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/live_nodes_list_loader.rb (+11 -6) 81% =================================================================== --- lib/droonga/nodes_status_loader.rb 2014-06-26 15:52:11 +0900 (82fe247) +++ lib/droonga/live_nodes_list_loader.rb 2014-06-26 15:52:12 +0900 (6d5fee2) @@ -17,26 +17,31 @@ require "pathname" require "json" module Droonga - class NodesStatusLoader + class LiveNodesListLoader def initialize(path) @path = path end def load - return default_status unles****@path*****? + list = parse + list.keys + end + + private + def parse + return default_list unles****@path*****? contents =****@path***** - return default_status if contents.empty? + return default_list if contents.empty? begin JSON.parse(contents) rescue JSON::ParserError - default_status + default_list end end - private - def default_status + def default_list {} end end Modified: lib/droonga/path.rb (+2 -2) =================================================================== --- lib/droonga/path.rb 2014-06-26 15:52:11 +0900 (fd46812) +++ lib/droonga/path.rb 2014-06-26 15:52:12 +0900 (d18768d) @@ -38,8 +38,8 @@ module Droonga base + "state" end - def nodes_status - state + "nodes-status.json" + def live_nodes + state + "live-nodes.json" end def last_processed_timestamp -------------- next part -------------- HTML����������������������������... Download