public class LBHttpSolrServer extends SolrServer
HttpSolrServer
. This is useful when you
have multiple SolrServers and the requests need to be Load Balanced among them.
Do NOT use this class for indexing in master/slave scenarios since documents must be sent to the
correct master; no inter-node routing is done.
In SolrCloud (leader/replica) scenarios, this class may be used for updates since updates will be forwarded
to the appropriate leader.
Also see the wiki page.
It offers automatic failover when a server goes down and it detects when the server comes back up.
Load balancing is done using a simple round-robin on the list of servers.
If a request to a server fails by an IOException due to a connection timeout or read timeout then the host is taken
off the list of live servers and moved to a 'dead server list' and the request is resent to the next live server.
This process is continued till it tries all the live servers. If at least one server is alive, the request succeeds,
and if not it fails.
This detects if a dead server comes alive automatically. The check is done in fixed intervals in a dedicated thread. This interval can be set usingSolrServer lbHttpSolrServer = new LBHttpSolrServer("http://host1:8080/solr/","http://host2:8080/solr","http://host2:8080/solr"); //or if you wish to pass the HttpClient do as follows httpClient httpClient = new HttpClient(); SolrServer lbHttpSolrServer = new LBHttpSolrServer(httpClient,"http://host1:8080/solr/","http://host2:8080/solr","http://host2:8080/solr");
setAliveCheckInterval(int)
, the default is set to one minute.
When to use this?Modifier and Type | Class and Description |
---|---|
static class |
LBHttpSolrServer.Req |
static class |
LBHttpSolrServer.Rsp |
protected static class |
LBHttpSolrServer.ServerWrapper |
Modifier and Type | Field and Description |
---|---|
protected Map<String,LBHttpSolrServer.ServerWrapper> |
zombieServers |
Constructor and Description |
---|
LBHttpSolrServer(org.apache.http.client.HttpClient httpClient,
ResponseParser parser,
String... solrServerUrl)
The provided httpClient should use a multi-threaded connection manager
|
LBHttpSolrServer(org.apache.http.client.HttpClient httpClient,
String... solrServerUrl)
The provided httpClient should use a multi-threaded connection manager
|
LBHttpSolrServer(String... solrServerUrls) |
Modifier and Type | Method and Description |
---|---|
void |
addSolrServer(String server) |
protected Exception |
addZombie(HttpSolrServer server,
Exception e) |
protected Exception |
doRequest(HttpSolrServer server,
LBHttpSolrServer.Req req,
LBHttpSolrServer.Rsp rsp,
boolean isUpdate,
boolean isZombie,
String zombieKey) |
protected void |
finalize() |
org.apache.http.client.HttpClient |
getHttpClient() |
ResponseParser |
getParser() |
Set<String> |
getQueryParams() |
RequestWriter |
getRequestWriter() |
protected HttpSolrServer |
makeServer(String server) |
static String |
normalize(String server) |
String |
removeSolrServer(String server) |
LBHttpSolrServer.Rsp |
request(LBHttpSolrServer.Req req)
Tries to query a live server from the list provided in Req.
|
NamedList<Object> |
request(SolrRequest request)
Tries to query a live server.
|
void |
setAliveCheckInterval(int interval)
LBHttpSolrServer keeps pinging the dead servers at fixed interval to find if it is alive.
|
void |
setConnectionTimeout(int timeout) |
void |
setParser(ResponseParser parser) |
void |
setQueryParams(Set<String> queryParams)
Expert Method.
|
void |
setRequestWriter(RequestWriter requestWriter) |
void |
setSoTimeout(int timeout)
set soTimeout (read timeout) on the underlying HttpConnectionManager.
|
void |
shutdown()
Release allocated resources.
|
add, add, add, add, addBean, addBean, addBeans, addBeans, commit, commit, commit, deleteById, deleteById, deleteById, deleteById, deleteByQuery, deleteByQuery, getBinder, optimize, optimize, optimize, ping, query, query, queryAndStreamResponse, rollback
protected final Map<String,LBHttpSolrServer.ServerWrapper> zombieServers
public LBHttpSolrServer(String... solrServerUrls) throws MalformedURLException
MalformedURLException
public LBHttpSolrServer(org.apache.http.client.HttpClient httpClient, String... solrServerUrl)
public LBHttpSolrServer(org.apache.http.client.HttpClient httpClient, ResponseParser parser, String... solrServerUrl)
public void setQueryParams(Set<String> queryParams)
queryParams
- set of param keys to only send via the query stringprotected HttpSolrServer makeServer(String server)
public LBHttpSolrServer.Rsp request(LBHttpSolrServer.Req req) throws SolrServerException, IOException
req
- contains both the request as well as the list of servers to queryIOException
- If there is a low-level I/O error.SolrServerException
protected Exception addZombie(HttpSolrServer server, Exception e)
protected Exception doRequest(HttpSolrServer server, LBHttpSolrServer.Req req, LBHttpSolrServer.Rsp rsp, boolean isUpdate, boolean isZombie, String zombieKey) throws SolrServerException, IOException
SolrServerException
IOException
public void addSolrServer(String server) throws MalformedURLException
MalformedURLException
public void setConnectionTimeout(int timeout)
public void setSoTimeout(int timeout)
public void shutdown()
SolrServer
shutdown
in class SolrServer
public NamedList<Object> request(SolrRequest request) throws SolrServerException, IOException
request
in class SolrServer
request
- the SolrRequest.IOException
- If there is a low-level I/O error.SolrServerException
public void setAliveCheckInterval(int interval)
interval
- time in millisecondspublic org.apache.http.client.HttpClient getHttpClient()
public ResponseParser getParser()
public void setParser(ResponseParser parser)
public void setRequestWriter(RequestWriter requestWriter)
public RequestWriter getRequestWriter()
Copyright © 2000-2014 Apache Software Foundation. All Rights Reserved.