Class PatchedLBHttpSolrClient
- java.lang.Object
-
- org.apache.solr.client.solrj.SolrClient
-
- de.hybris.platform.solrfacetsearch.solr.impl.PatchedLBSolrClient
-
- de.hybris.platform.solrfacetsearch.solr.impl.PatchedLBHttpSolrClient
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Serializable,java.lang.AutoCloseable
public class PatchedLBHttpSolrClient extends PatchedLBSolrClient
Hybris note: This is a patched version of
LBHttpSolrClientwhich we had to create due to https://issues.apache.org/jira/browse/SOLR-12415.LBHttpSolrClient or "LoadBalanced HttpSolrClient" is a load balancing wrapper around
HttpSolrClient. This is useful when you have multiple Solr servers 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, it is usually better to useCloudSolrClient, but this class may be used for updates because the server will forward them to the appropriate leader.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 usingSolrClient lbHttpSolrClient = new LBHttpSolrClient("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(); SolrClient lbHttpSolrClient = new LBHttpSolrClient(httpClient, "http://host1:8080/solr/", "http://host2:8080/solr", "http://host2:8080/solr");PatchedLBSolrClient.setAliveCheckInterval(int), the default is set to one minute.When to use this?
This can be used as a software load balancer when you do not wish to setup an external load balancer. Alternatives to this code are to use a dedicated hardware load balancer or using Apache httpd with mod_proxy_balancer as a load balancer. See Load balancing on Wikipedia- Since:
- solr 1.4
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPatchedLBHttpSolrClient.BuilderConstructsPatchedLBHttpSolrClientinstances from provided configuration.static classPatchedLBHttpSolrClient.ReqDeprecated.usePatchedLBSolrClient.Reqinsteadstatic classPatchedLBHttpSolrClient.RspDeprecated.usePatchedLBSolrClient.Rspinstead-
Nested classes/interfaces inherited from class de.hybris.platform.solrfacetsearch.solr.impl.PatchedLBSolrClient
PatchedLBSolrClient.ServerWrapper
-
-
Field Summary
-
Fields inherited from class de.hybris.platform.solrfacetsearch.solr.impl.PatchedLBSolrClient
parser, queryParams, requestWriter
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedPatchedLBHttpSolrClient(PatchedLBHttpSolrClient.Builder builder)protectedPatchedLBHttpSolrClient(org.apache.http.client.HttpClient httpClient, org.apache.solr.client.solrj.ResponseParser parser, java.lang.String... solrServerUrl)Deprecated.usePatchedLBHttpSolrClient(Builder)instead, as it is a more extension/subclassing-friendly alternativeprotectedPatchedLBHttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient.Builder httpSolrClientBuilder, org.apache.http.client.HttpClient httpClient, java.lang.String... solrServerUrl)Deprecated.usePatchedLBHttpSolrClient(Builder)instead, as it is a more extension/subclassing-friendly alternative
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclose()protected org.apache.solr.client.solrj.SolrClientgetClient(java.lang.String baseUrl)org.apache.http.client.HttpClientgetHttpClient()Return the HttpClient this instance uses.protected org.apache.solr.client.solrj.impl.HttpSolrClientmakeSolrClient(java.lang.String server)java.lang.StringremoveSolrServer(java.lang.String server)PatchedLBHttpSolrClient.Rsprequest(PatchedLBHttpSolrClient.Req req)Deprecated.voidsetConnectionTimeout(int timeout)Deprecated.since 7.0 UsePatchedLBHttpSolrClient.Buildermethods instead.voidsetSoTimeout(int timeout)Deprecated.since 7.0 UsePatchedLBHttpSolrClient.Buildermethods instead.-
Methods inherited from class de.hybris.platform.solrfacetsearch.solr.impl.PatchedLBSolrClient
addQueryParams, addSolrServer, createServerWrapper, doRequest, getParser, getQueryParams, getRequestWriter, normalize, pickServer, request, request, request, setAliveCheckInterval, setParser, setQueryParams, setRequestWriter, updateAliveList
-
Methods inherited from class org.apache.solr.client.solrj.SolrClient
add, add, add, add, add, add, add, add, add, add, addBean, addBean, addBean, addBean, addBeans, addBeans, addBeans, addBeans, addBeans, addBeans, commit, commit, commit, commit, commit, commit, deleteById, deleteById, deleteById, deleteById, deleteById, deleteById, deleteById, deleteById, deleteByQuery, deleteByQuery, deleteByQuery, deleteByQuery, getBinder, getById, getById, getById, getById, getById, getById, getById, getById, optimize, optimize, optimize, optimize, optimize, optimize, ping, ping, query, query, query, query, queryAndStreamResponse, queryAndStreamResponse, queryAndStreamResponse, request, rollback, rollback
-
-
-
-
Constructor Detail
-
PatchedLBHttpSolrClient
@Deprecated protected PatchedLBHttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient.Builder httpSolrClientBuilder, org.apache.http.client.HttpClient httpClient, java.lang.String... solrServerUrl)Deprecated.usePatchedLBHttpSolrClient(Builder)instead, as it is a more extension/subclassing-friendly alternativeThe provided httpClient should use a multi-threaded connection manager
-
PatchedLBHttpSolrClient
@Deprecated protected PatchedLBHttpSolrClient(org.apache.http.client.HttpClient httpClient, org.apache.solr.client.solrj.ResponseParser parser, java.lang.String... solrServerUrl)Deprecated.usePatchedLBHttpSolrClient(Builder)instead, as it is a more extension/subclassing-friendly alternativeThe provided httpClient should use a multi-threaded connection manager
-
PatchedLBHttpSolrClient
protected PatchedLBHttpSolrClient(PatchedLBHttpSolrClient.Builder builder)
-
-
Method Detail
-
makeSolrClient
protected org.apache.solr.client.solrj.impl.HttpSolrClient makeSolrClient(java.lang.String server)
-
setConnectionTimeout
@Deprecated public void setConnectionTimeout(int timeout)
Deprecated.since 7.0 UsePatchedLBHttpSolrClient.Buildermethods instead.
-
setSoTimeout
@Deprecated public void setSoTimeout(int timeout)
Deprecated.since 7.0 UsePatchedLBHttpSolrClient.Buildermethods instead.set soTimeout (read timeout) on the underlying HttpConnectionManager. This is desirable for queries, but probably not for indexing.
-
request
@Deprecated public PatchedLBHttpSolrClient.Rsp request(PatchedLBHttpSolrClient.Req req) throws org.apache.solr.client.solrj.SolrServerException, java.io.IOException
Deprecated.- Throws:
org.apache.solr.client.solrj.SolrServerExceptionjava.io.IOException
-
getClient
protected org.apache.solr.client.solrj.SolrClient getClient(java.lang.String baseUrl)
- Specified by:
getClientin classPatchedLBSolrClient
-
removeSolrServer
public java.lang.String removeSolrServer(java.lang.String server)
- Overrides:
removeSolrServerin classPatchedLBSolrClient
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classPatchedLBSolrClient
-
getHttpClient
public org.apache.http.client.HttpClient getHttpClient()
Return the HttpClient this instance uses.
-
-