Navigation Menu

Skip to content

Commit

Permalink
Set cluster id as a serf tag
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Jun 26, 2014
1 parent 654ddf2 commit 464c89d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/droonga/engine.rb
Expand Up @@ -33,6 +33,10 @@ def initialize(loop, name, internal_name)
@state = EngineState.new(loop, name, internal_name)
@catalog = load_catalog
@state.catalog = @catalog

serf = Serf.new(loop, name)
serf.set_tag("cluster_id", @state.cluster_id)

@dispatcher = create_dispatcher
@nodes_status_observer = FileObserver.new(loop, Path.nodes_status)
@nodes_status_observer.on_change = lambda do
Expand Down
9 changes: 9 additions & 0 deletions lib/droonga/engine_state.rb
Expand Up @@ -16,6 +16,7 @@
require "English"

require "coolio"
require "digest/sha1"

require "droonga/loggable"
require "droonga/event_loop"
Expand Down Expand Up @@ -116,13 +117,21 @@ def nodes_status=(new_status)
@nodes_status = new_status
end

def cluster_id
@cluster_id ||= prepare_cluster_id
end

private
def prepare_live_nodes
@nodes_status.keys.select do |key|
@nodes_status[key]["live"]
end
end

def prepare_cluster_id
Digest::SHA1.hexdigest(all_nodes.join("\n"))
end

def log_tag
"engine_state"
end
Expand Down

0 comments on commit 464c89d

Please sign in to comment.