Navigation Menu

Skip to content

Commit

Permalink
Forward "read" messages always even if roles of nodes are different
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 2, 2015
1 parent 166cdb9 commit 9931a2d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/droonga/dispatcher.rb
Expand Up @@ -212,6 +212,7 @@ def dispatch_steps(steps)
dataset = @catalog.dataset(step["dataset"])
if dataset
if write_step?(step)
step["write"] = true
target_nodes = @cluster.writable_nodes
if target_nodes.empty?
logger.error("there is no node to dispath a write step!",
Expand Down
24 changes: 22 additions & 2 deletions lib/droonga/engine_node.rb
Expand Up @@ -55,9 +55,21 @@ def shutdown
end

def forward(message, destination)
if not really_writable?
if read_message?(message)
# A node can receive read messages for other nodes,
# while changing its role. They must not be buffered.
output(message, destination)
return
end

unless really_writable?
# The target node is not ready. We should send the message later.
@buffer.add(message, destination)
elsif @buffer.empty?
return
end

# The target node is ready.
if @buffer.empty?
output(message, destination)
else
@buffer.add(message, destination)
Expand Down Expand Up @@ -170,6 +182,14 @@ def sender_role
@sender_node_metadata.role
end

def read_message?(message)
steps = message["body"]["steps"]
return false unless steps
steps.all? do |step|
not step["write"]
end
end

def output(message, destination)
command = destination["type"]
receiver = destination["to"]
Expand Down

0 comments on commit 9931a2d

Please sign in to comment.