tsasaki609 opened a new pull request #150: URL: https://github.com/apache/solr/pull/150
https://issues.apache.org/jira/browse/SOLR-15411 <!-- _(If you are a project committer then you may remove some/all of the following template.)_ Before creating a pull request, please file an issue in the ASF Jira system for Solr: * https://issues.apache.org/jira/projects/SOLR You will need to create an account in Jira in order to create an issue. The title of the PR should reference the Jira issue number in the form: * SOLR-####: <short description of problem or changes> SOLR must be fully capitalized. A short description helps people scanning pull requests for items they can work on. Properly referencing the issue in the title ensures that Jira is correctly updated with code review comments and commits. --> # Description Enable failOnVersionConflicts even for atomic updates. # Solution Added a check for failOnVersionConflicts to prevent unintended exceptions from occurring. # Tests I have run the following client code to the techproducts example、 ``` ./gradlew clean dev ./solr/packaging/build/dev/bin/solr start -e techproducts -c -a "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=18983" ``` and add the hasUserAssertions field.  After the fix, the error message is no longer returned. ## Client Code ``` import static java.lang.System.out; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import org.apache.solr.client.solrj.impl.CloudSolrClient; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.client.solrj.response.UpdateResponse; import org.apache.solr.common.SolrInputDocument; public class Reproduce { public static void main(String[] args) throws Exception { CloudSolrClient solrClient = new CloudSolrClient.Builder(List.of("http://localhost:8983/solr")).build(); solrClient.setDefaultCollection("techproducts"); List<String> idList = List.of("TWINX2048-3200PRO", "VS1GB400C3", "VDBDB1A16", "MA147LL/A", "F8V7067-APL-KIT"); List<SolrInputDocument> batch = new ArrayList<>(); for(int idx = 1; idx <= idList.size(); idx++) { SolrInputDocument doc = new SolrInputDocument(); if (idx == 3) { doc.addField("id", idList.get(idx - 1) + "_invalid"); } else { doc.addField("id", idList.get(idx - 1)); } doc.addField("hasUserAssertions", new HashMap<String, Object>() {{ put("set", true); }}); doc.addField("price_c____l_ns", null); // this makes sure update only succeeds when record with specified id exists doc.addField("_version_", 1); out.println("Added solr doc for record: " + doc.get("id")); batch.add(doc); } UpdateRequest updateRequest = new UpdateRequest(); updateRequest.setAction(UpdateRequest.ACTION.COMMIT, false, false); updateRequest.setParam("failOnVersionConflicts", "false"); updateRequest.add(batch); // List<SolrInputDocument> batch updateRequest.lastDocInBatch(); try { UpdateResponse process = updateRequest.process(solrClient); out.println("xhk205 process = " + process.toString()); } catch (Exception e) { out.println("Failed to update solr doc, error message: " + e.getMessage()); } } } ``` ## Before Output: ``` Added solr doc for record: id=TWINX2048-3200PRO Added solr doc for record: id=VS1GB400C3 Added solr doc for record: id=VDBDB1A16_invalid Added solr doc for record: id=MA147LL/A Added solr doc for record: id=F8V7067-APL-KIT Failed to update solr doc, error message: Error from server at http://localhost:8983/solr/techproducts_shard1_replica_n1: Document not found for update. id=VDBDB1A16_invalid ``` Query: http://localhost:8983/solr/techproducts/select?fq=hasUserAssertions:*&q=*:*&fl=id ``` { "responseHeader":{ "zkConnected":true, "status":0, "QTime":18, "params":{ "q":"*:*", "fl":"id", "fq":"hasUserAssertions:*"}}, "response":{"numFound":2,"start":0,"numFoundExact":true,"docs":[ { "id":"TWINX2048-3200PRO"}, { "id":"VS1GB400C3"}] }} ``` ## After Output: ``` Added solr doc for record: id=TWINX2048-3200PRO Added solr doc for record: id=VS1GB400C3 Added solr doc for record: id=VDBDB1A16_invalid Added solr doc for record: id=MA147LL/A Added solr doc for record: id=F8V7067-APL-KIT xhk205 process = {responseHeader={status=0,QTime=260,rf=1}} ``` Query: http://localhost:8983/solr/techproducts/select?fq=hasUserAssertions:*&q=*:*&fl=id ``` { "responseHeader":{ "zkConnected":true, "status":0, "QTime":2, "params":{ "q":"*:*", "fl":"id", "fq":"hasUserAssertions:*"}}, "response":{"numFound":4,"start":0,"numFoundExact":true,"docs":[ { "id":"TWINX2048-3200PRO"}, { "id":"VS1GB400C3"}, { "id":"MA147LL/A"}, { "id":"F8V7067-APL-KIT"}] }} ``` # Checklist Please review the following and check all that apply: - [x] I have reviewed the guidelines for [How to Contribute](https://wiki.apache.org/solr/HowToContribute) and my code conforms to the standards described there to the best of my ability. - [x] I have created a Jira issue and added the issue ID to my pull request title. - [x] I have given Solr maintainers [access](https://help.github.com/en/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork) to contribute to my PR branch. (optional but recommended) - [x] I have developed this patch against the `main` branch. - [x] I have run `./gradlew check`. - [ ] I have added tests for my changes. - [ ] I have added documentation for the [Reference Guide](https://github.com/apache/solr/tree/main/solr/solr-ref-guide) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
