When should we apply Hard commit and Soft commit i

2019-02-26 01:03发布

问题:

I want to know when we should do hard commit and when we should do soft commit in SOLR.

Thanks

回答1:

In the same vein as the question you just asked but deleted, this is explained thoroughly on the internet:

Soft commit when you want something to be made available as soon as possible without waiting for it to be written to disk. Hard commit when you want make sure its being persisted to disk.

From the link above:

Soft commits

Soft commits are about visibility, hard commits are about durability. The thing to understand most about soft commits are that they will make documents visible, but at some cost. In particular the “top level” caches, which include what you configure in solrconfig.xml (filterCache, queryResultCache, etc) will be invalidated! Autowarming will be performed on your top level caches (e.g. filterCache, queryResultCache), and any newSearcher queries will be executed. Also, the FieldValueCache is invalidated, so facet queries will have to wait until the cache is refreshed. With very frequent soft commits it’s often the case that your top-level caches are little used and may, in some cases, be eliminated. However, “segment level caches”, used for function queries, sorting, etc., are “per segment”, so will not be invalidated on soft commit; they can continue to be used.

Hard commits

Hard commits are about durability, soft commits are about visibility. There are really two flavors here, openSearcher=true and openSearcher=false. First we’ll talk about what happens in both cases. If openSearcher=true or openSearcher=false, the following consequences are most important:

  • The tlog is truncated: A new tlog is started.
  • Old tlogs will be deleted if there are more than 100 documents in newer, closed tlogs.
  • The current index segment is closed and flushed.
  • Background segment merges may be initiated.
  • The above happens on all hard commits.

That leaves the openSearcher setting

  • openSearcher=true: The Solr/Lucene searchers are re-opened and all caches are invalidated. Autowarming is done etc. This used to be the only way you could see newly-added documents.
  • openSearcher=false: Nothing further happens other than the four points above. To search the docs, a soft commit is necessary.


标签: solr