Skip to content

Commit

Permalink
Update live-nodes-list on the startup.
Browse files Browse the repository at this point in the history
The serf agent updates the list at first.
After that, the engine loads the list.
  • Loading branch information
piroor committed Dec 24, 2014
1 parent 1f197bf commit e44d911
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
13 changes: 1 addition & 12 deletions lib/droonga/command/remote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -397,18 +397,7 @@ def unjoining_node?

class UpdateLiveNodesList < Base
def process
path = Path.live_nodes_list
new_list = live_nodes_list
file_contents = JSON.pretty_generate(new_list)
SafeFileWriter.write(path) do |output, file|
output.puts(file_contents)
@service_installation.ensure_correct_file_permission(file)
end
end

private
def live_nodes_list
@serf.live_nodes_list
@serf.update_live_nodes_list
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/droonga/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Engine
attr_writer :on_ready
def initialize(loop, name, internal_name)
@state = EngineState.new(loop, name, internal_name)
@state.live_nodes_list = load_live_nodes_list
@catalog = load_catalog
@state.catalog = @catalog
@dispatcher = create_dispatcher
Expand Down
14 changes: 14 additions & 0 deletions lib/droonga/serf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
require "droonga/node_status"
require "droonga/serf_downloader"
require "droonga/line_buffer"
require "droonga/safe_file_writer"
require "droonga/service_installation"

module Droonga
class Serf
Expand All @@ -45,6 +47,7 @@ def initialize(loop, name)
@loop = loop
@name = name
@agent = nil
@service_installation = ServiceInstallation.new
end

def start
Expand All @@ -64,6 +67,7 @@ def start
"-tag", "role=#{role}",
"-tag", "cluster_id=#{cluster_id}",
*retry_joins)
update_live_nodes_list
logger.trace("start: done")
end

Expand Down Expand Up @@ -116,6 +120,16 @@ def send_query(query, payload)
result
end

def update_live_nodes_list
path = Path.live_nodes_list
new_list = live_nodes_list
file_contents = JSON.pretty_generate(new_list)
SafeFileWriter.write(path) do |output, file|
output.puts(file_contents)
@service_installation.ensure_correct_file_permission(file)
end
end

def live_nodes_list
ensure_serf
nodes_list = {}
Expand Down

0 comments on commit e44d911

Please sign in to comment.