Skip to content

Commit

Permalink
deal with case where another server in the replcation set is already
Browse files Browse the repository at this point in the history
initiated, and connect to it for config because we don't have a local
config yet. however, still support if our current server is already initialized
  • Loading branch information
jro authored and jamesonjlee committed Sep 18, 2013
1 parent b1a4fb3 commit 1e46e8f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion libraries/mongodb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,17 @@ def self.configure_replicaset(node, name, members)
end
if result.fetch("ok", nil) == 1
# everything is fine, do nothing
elsif result.fetch("errmsg", nil) == "already initialized"
elsif result.fetch("errmsg", nil) =~ %r/(\S+) is already initiated/ || (result.fetch("errmsg", nil) == "already initialized")
server,port = $1.nil? ? ['localhost',node['mongodb']['port']] : $1.split(":")
begin
connection = Mongo::Connection.new(server, port, :op_timeout => 5, :slave_ok => true)
rescue
abort("Could not connect to database: '#{server}:#{port}'")
end

# check if both configs are the same
config = connection['local']['system']['replset'].find_one({"_id" => name})

if config['_id'] == name and config['members'] == rs_members
# config is up-to-date, do nothing
Chef::Log.info("Replicaset '#{name}' already configured")
Expand Down

0 comments on commit 1e46e8f

Please sign in to comment.