solr transaction management using solrj

2019-05-22 10:11发布

问题:

How to handle transaction management in Solr using Solrj? There is not much documentation related to this on the net. But I would appreciate if someone can provide any links or information related to transaction management using SolrJ.

回答1:

You would have to programatically deal with the transactions in SolrJ. When dealing with multiple writes.

  1. Use the SolrServer api add method to add the SolrInputDoucments to the server.
  2. When all the SolrInputDocuments are added, call the commit method from the SolrServer api to commit all the changes.
  3. In case of an exception from Solr, if you want to rollback the writes to the Solr, Call the SolServer api rollback method.
  4. If you want to rollback the writes to the database as well, just throw back a runtime-exception from the catch block.

This is how I dealt with the transaction management. If anyone has better answers, please feel free to improve the answer.