Commit 953b47d6 authored by Russell Mull's avatar Russell Mull

(PDB-2071) Use shared atom for terminus failover

When running under PuppetServer, there can be many terminii running at
once in many JRuby instances. For sticky read failover to work properly,
the index of the last working server must be shared among these. This
uses the new PuppetDBTerminusState java class in PuppetServer to store
the shared data. 

When the java class is not available, or when running under MRI, a local
instances of a Ruby atom class is used. It obeys the same semantics but 
is not shared across Ruby instances. 
parent 411a039c
......@@ -13,7 +13,7 @@ module Puppet::Util::Puppetdb
}
end
def reset!(value)
def reset(value)
@mutex.synchronize {
@value = value
}
......
......@@ -10,7 +10,18 @@ module Puppet::Util::Puppetdb
class Http
SERVER_URL_FAIL_MSG = "Failing over to the next PuppetDB server_url in the 'server_urls' list"
@@last_good_query_server_url_index = Atom.new(0)
if RUBY_PLATFORM == 'java'
begin
@@last_good_query_server_url_index = com::puppetlabs::puppetserver::PuppetDBTerminusState.getSharedStateAtom()
@@last_good_query_server_url_index.compareAndSet(nil, 0)
rescue NameError
@@last_good_query_server_url_index = Atom.new(0)
Puppet.warning "Couldn't load the PuppetDB shared state component; please upgrade to a newer PuppetServer. " \
"Falling back to per-JRuby storage."
end
else
@@last_good_query_server_url_index = Atom.new(0)
end
# Concat two server_url snippets, taking into account a trailing/leading slash to
# ensure a correct server_url is constructed
......@@ -145,7 +156,7 @@ module Puppet::Util::Puppetdb
response_error = check_http_response(response, server_url, route)
if response_error.nil?
if server_url_index != server_try_order.first()
@@last_good_query_server_url_index.reset!(server_url_index)
@@last_good_query_server_url_index.reset(server_url_index)
end
break
end
......@@ -219,7 +230,7 @@ module Puppet::Util::Puppetdb
end
def self.reset_query_failover()
@@last_good_query_server_url_index.reset!(0)
@@last_good_query_server_url_index.reset(0)
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment