class RSolr::Cloud::Connection
RSolr
connection adapter for SolrCloud
Constants
- ZNODE_CLUSTER_PROPS
- ZNODE_LIVE_NODES
Public Class Methods
new(zk)
click to toggle source
Calls superclass method
# File lib/rsolr/cloud/connection.rb, line 10 def initialize(zk) super() @zk = zk init_url_scheme init_live_node_watcher end
Public Instance Methods
execute(client, request_context)
click to toggle source
Calls superclass method
# File lib/rsolr/cloud/connection.rb, line 17 def execute(client, request_context) collection_name = request_context[:collection] raise 'The :collection option must be specified.' unless collection_name path = request_context[:path].to_s query = request_context[:query] query = query ? "?#{query}" : '' url = select_node(collection_name) raise RSolr::Cloud::Error::NotEnoughNodes unless url request_context[:uri] = RSolr::Uri.create(url).merge(path + query) super(client, request_context) end
Private Instance Methods
init_live_node_watcher()
click to toggle source
# File lib/rsolr/cloud/connection.rb, line 44 def init_live_node_watcher @zk.register(ZNODE_LIVE_NODES) do update_live_nodes end update_live_nodes end
init_url_scheme()
click to toggle source
# File lib/rsolr/cloud/connection.rb, line 31 def init_url_scheme @url_scheme = 'http' if @zk.exists?(ZNODE_CLUSTER_PROPS) json, _stat = @zk.get(ZNODE_CLUSTER_PROPS) props = JSON.parse(json) @url_scheme = props['urlScheme'] || 'http' end end
select_node(collection)
click to toggle source
# File lib/rsolr/cloud/connection.rb, line 40 def select_node(collection) synchronize { @live_nodes.sample + '/' + collection } end
update_live_nodes()
click to toggle source
# File lib/rsolr/cloud/connection.rb, line 51 def update_live_nodes synchronize do @live_nodes = [] @zk.children(ZNODE_LIVE_NODES, watch: true).each do |node| # "/" between host_and_port part of url and context is replaced with "_" in ZK @live_nodes << @url_scheme + '://' + node.tr('_', '/') end end end