[chef] Re: Concurrency node creation issue


Chronological Thread 
  • From: Andrew Shafer < >
  • To:
  • Subject: [chef] Re: Concurrency node creation issue
  • Date: Mon, 5 Sep 2011 07:43:34 +0900


You have yourself a bona fide race condition.

You might consider a simpler formulation that assigns the master explicitly.

If you insist on the discovery over specificity route, then you need some way to deal with distributed coordination, which range from hacked up happy path implementations to paxos.

Noah or Zookeeper might be useful do you.

Someone might have examples of solutions to problems like this laying around.

Please share whatever you decide to do.


On Mon, Sep 5, 2011 at 6:57 AM, Daniel Cukier < "> > wrote:
Hi, 

I have in my infrastructure a topology where there's one master node and many slave nodes.
What I want to do is to automatically detect if a node is a master or a slave. The rule is:
 1) If there is no master node yet, the next node will be the master
 2) If there is a master, the next node will be slave and its master will be the already existing master.

The problem occurs when I have an empty infrastructure (zero nodes) and I try to create the first 2 nodes simultaneously.
When both nodes get provisioned, both check that there is no master and both are set to be master, which is a wrong configuration.
This is a very common synchronization problem, but I don't know how to deal with it in the Chef environment. 

Here's the recipe to configure a node:

@@master = node

search(:node, 'role:myrole') do |n|
  if n['myrole']['container_type'] == "master"
    @@master = n
    if n.name != node.name
      node.set['myrole']['container_type'] = "slave"
    end
  end
end

if @@master == node
  node.set['myrole']['container_type'] = "master"
end

template "#{node['myrole']['install_dir']}/#{ZIP_FILE.gsub('.zip', '')}/conf/topology.xml" do
  source "topology.xml.erb"
  owner "root"
  group "root"
  mode "0644"
  variables({:master => @@master})
end

How can I avoid this problem? 

Thanks a lot

Daniel Cukier




Archive powered by MHonArc 2.6.16.

§