Multiple updates simultaneously on same document i

2019-09-11 07:03发布

问题:

I have a doubt regarding solr document update. For example, when two requests to update a document in solr comes at the same time, How does solr work?

  • Does it take one request randomly and locks write before next request comes in?

Thanks in Advance

回答1:

There are different Locking mechanisms as mentioned in Lucene locking factory docs. By default NativeFSLockFactory is used in which file lock is acquired for the document that is being indexed. The settings for using a different locking mechanism can be changed in solrconfig.xml

Here is a snippet from solconfig.xml

<!-- LockFactory 

     This option specifies which Lucene LockFactory implementation
     to use.

     single = SingleInstanceLockFactory - suggested for a
              read-only index or when there is no possibility of
              another process trying to modify the index.
     native = NativeFSLockFactory - uses OS native file locking.
              Do not use when multiple solr webapps in the same
              JVM are attempting to share a single index.
     simple = SimpleFSLockFactory  - uses a plain file for locking

     Defaults: 'native' is default for Solr3.6 and later, otherwise
               'simple' is the default

     More details on the nuances of each LockFactory...
     http://wiki.apache.org/lucene-java/AvailableLockFactories
-->
<lockType>${solr.lock.type:native}</lockType>


回答2:

Are you talking about physical locks or logical version control? For logical version control, Solr 4+ supports optimistic concurrency using version field.

You can read about it:

  1. Official documentation
  2. Detailed writeup