技术库 > Java

Distributed Search with Index Sharding

技术库:tec.5lulu.com

from:tec.5lulu.com

It is highly recommended that you use SolrCloud when needing to scale up or scale out. The setup described below is legacy and was used prior to the existence of SolrCloudSolrCloud provides for a truly distributed set of features with support for things like automatic routing, leader election, optimistic concurrency and other sanity checks that are expected out of a distributed system.

Everything on this page is specific to legacy setup of distributed search. Users trying out SolrCloud should not follow any of the steps or information below.

Update reorders (i.e., replica A may see update X then Y, and replica B may see update Y then X). deleteByQuery also handles reorders the same way, to ensure replicas are consistent.  All replicas of a shard are consistent, even if the updates arrive in a different order on different replicas.

1 Distributing Documents across Shards

When not using SolrCloud, it is up to you to get all your documents indexed on each shard of your server farm. Solr supports distributed indexing (routing) in its true form only in the SolrCloud mode.

In the legacy distributed mode, Solr does not calculate universal term/doc frequencies. For most large-scale implementations, it is not likely to matter that Solr calculates TF/IDF at the shard level. However, if your collection is heavily skewed in its distribution across servers, you may find misleading relevancy results in your searches. In general, it is probably best to randomly distribute documents to your shards.

2 Executing Distributed Searches with theshardsParameter

If a query request includes theshardsparameter, the Solr server distributes the request across all the shards listed as arguments to the parameter. Theshardsparameter uses this syntax:

host :port /base_url [,host :port /base_url ]*

For example, theshardsparameter below causes the search to be distributed across two Solr servers: solr1 and solr2, both of which are running on port 8983:

http://localhost:8983/solr/core1/select?shards=solr1:8983/solr/core1,solr2:8983/solr/core1&indent=true&q=ipod+solr

Rather than require users to include the shards parameter explicitly, it is usually preferred to configure this parameter as a default in the RequestHandler section ofsolrconfig.xml.

Do not add theshardsparameter to the standard requestHandler; otherwise, search queries may enter an infinite loop. Instead, define a new requestHandler that uses theshardsparameter, and pass distributed search requests to that handler.

With Legacy mode, only query requests are distributed. This includes requests to the SearchHandler (or any handler extending fromorg.apache.solr.handler.component.SearchHandler) using standard components that support distributed search.

As in SolrCloud mode, when shards.info=true, distributed responses will include information about the shard (where each shard represents a logically different index or physical location)

The following components support distributed search:

  • The Query component, which returns documents matching a query
  • The Facet component, which processes facet.query and facet.field requests where facets are sorted by count (the default).
  • The Highlighting component, which enables Solr to include "highlighted" matches in field values.
  • The Stats component, which returns simple statistics for numeric fields within the DocSet.
  • The Debug component, which helps with debugging.

3 Limitations to Distributed Search

Distributed searching in Solr has the following limitations:

  • Each document indexed must have a unique key.
  • If Solr discovers duplicate document IDs, Solr selects the first document and discards subsequent ones.
  • The index for distributed searching may become momentarily out of sync if a commit happens between the first and second phase of the distributed search. This might cause a situation where a document that once matched a query and was subsequently changed may no longer match the query but will still be retrieved. This situation is expected to be quite rare, however, and is only possible for a single query request.
  • The number of shards is limited by number of characters allowed for GET method's URI; most Web servers generally support at least 4000 characters, but many servers limit URI length to reduce their vulnerability to Denial of Service (DoS) attacks.
  • Shard information can be returned with each document in a distributed search by includingfl=id, [shard]in the search request. This returns the shard URL.
  • In a distributed search, the data directory from the core descriptor overrides any data directory insolrconfig.xml.
  • Update commands may be sent to any server with distributed indexing configured correctly. Document adds and deletes are forwarded to the appropriate server/shard based on a hash of the unique document id. commit commands and deleteByQuery commands are sent to every server inshards.

Formerly a limitation was that TF/IDF relevancy computations only used shard-local statistics.  This is still the case by default.  If your data isn't randomly distributed, or if you want more exact statistics, then remember to configure the ExactStatsCache.

4 Avoiding Distributed Deadlock

Like in SolrCloud mode, inter-shard requests could lead to a distributed deadlock. It can be avoided by following the instructions here.

5 Testing Index Sharding on Two Local Servers

For simple functionality testing, it's easiest to just set up two local Solr servers on different ports. (In a production environment, of course, these servers would be deployed on separate machines.)

  1. Make two Solr home directories:

    #666666solid
  2. Start the two Solr instances

    #666666solid
  3. Create a core on both the nodes with the sample_techproducts_configs.

    #666666solid
  4. In the third window, index an example document to each of the server:

    #666666solid
  5. Search on the node on port 8983:

    #666666solid

    This should bring back one document.

    Search on the node on port 8984:

    #666666solid

    This should also bring back a single document.

    Now do a distributed search across both servers with your browser orcurl. In the example below, an extra parameter 'fl' is passed to restrict the returned fields to id and name.

    #666666solid

    This should contain both the documents as shown below:

    #666666solid 0 8 *:* localhost:8983/solr/core1,localhost:8984/solr/core1 true id,name xml 3007WFP Dell Widescreen UltraSharp 3007WFP VA902B ViewSonic VA902B - flat panel display - TFT - 19" ]]>

Distributed Search with Index Sharding


标签: solr solrcloud本文链接 http://tec.5lulu.com/detail/110drn2eh2gcm853a.html

我来评分 :6.1
0

转载注明:转自5lulu技术库

本站遵循:署名-非商业性使用-禁止演绎 3.0 共享协议

www.5lulu.com