简体   繁体   中英

Locking index with lucene.net

I've got a Lucene index on a SAN (shared area network) which is used by several instances of lucene, distributed on several machines. When updating the index, an instance of lucene, will say add or update document, it will make i nativeFSLock, which makes it impossible for others to write at the same moment, this works fine!

The thing is, that I want to be able to send a batch with updates to any instance of lucene and I want it to do all the updates then release the lock. In Lucene.net there is no addDocuments method, only AddDocument. So i have to loop through all my documents and add them one at a time. as soon as one document is added lucene releases the lock, then makes a new lock for the next file. So if someone elses tries to update or add document at the same time it successfully obtains the lock sometimes in that little time-span, and when that happens only some of my batch will go through (race condition).

I want to obtain a lock, and not release it until my whole batch is done, any suggestions?

Best Regards

Don't use the NativeFSLockFactory on an index stored on a SAN, or use a dedicated node to write to the index.

Try using the SimpleFSLockFactory and see if it solves your locking issues. But with SimpleFSLockFactory another problem may arise, it leaves it's lock behind if your process crashes while it holds the lock.

More details here: http://lucene.apache.org/core/old_versioned_docs/versions/2_9_4/api/all/org/apache/lucene/store/NativeFSLockFactory.html

I'd suggest you test your environment with the locking test tools specified in the link above. (VerifyingLockFactory, LockVerifyServer and LockStressTest)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM