diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 6e96cbbc65d..5d6d9d7096c 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -169,6 +169,10 @@ New Features * SOLR-10039: New LatLonPointSpatialField replacement for LatLonType (and some uses of RPT). Multi-value capable indexed geo lat-lon points, query by rect or circle. Efficient distance sorting/boosting too. (David Smiley) +* SOLR-10250: CloudSolrClient can now return versions for documents added or deleted when "versions=true" is passed. + However, if there is a leader election while this request is in transit, the versions may not be returned from that + shard. (Boris Naguet, Ishan Chattopadhyaya) + Bug Fixes ---------------------- diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java index d3938c8fda2..6941a77663d 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java @@ -903,7 +903,10 @@ public class CloudSolrClient extends SolrClient { // TolerantUpdateProcessor List> toleratedErrors = null; int maxToleratedErrors = Integer.MAX_VALUE; - + + // For "adds", "deletes", "deleteByQuery" etc. + Map versions = new HashMap<>(); + for(int i=0; i response = updateRequest.commit(cluster.getSolrClient(), COLLECTION).getResponse(); + Object addsObject = response.get("adds"); + + assertNotNull("There must be a adds parameter", addsObject); + assertTrue(addsObject instanceof NamedList); + NamedList adds = (NamedList) addsObject; + assertEquals("There must be 2 versions (one per doc)", 2, adds.size()); + + Map versions = new HashMap<>(); + Object object = adds.get("1"); + assertNotNull("There must be a version for id 1", object); + assertTrue("Version for id 1 must be a long", object instanceof Long); + versions.put("1", (Long) object); + + object = adds.get("2"); + assertNotNull("There must be a version for id 2", object); + assertTrue("Version for id 2 must be a long", object instanceof Long); + versions.put("2", (Long) object); + + QueryResponse resp = cluster.getSolrClient().query(COLLECTION, new SolrQuery("*:*")); + assertEquals("There should be one document because overwrite=true", 2, resp.getResults().getNumFound()); + + for (SolrDocument doc : resp.getResults()) { + Long version = versions.get(doc.getFieldValue("id")); + assertEquals("Version on add must match _version_ field", version, doc.getFieldValue("_version_")); + } + + // assert that "deletes" are returned + UpdateRequest deleteRequest = new UpdateRequest().deleteById("1"); + deleteRequest.setParam(UpdateParams.VERSIONS, Boolean.TRUE.toString()); + response = deleteRequest.commit(cluster.getSolrClient(), COLLECTION).getResponse(); + Object deletesObject = response.get("deletes"); + assertNotNull("There must be a deletes parameter", deletesObject); + NamedList deletes = (NamedList) deletesObject; + assertEquals("There must be 1 version", 1, deletes.size()); + } + private static void checkSingleServer(NamedList response) { final CloudSolrClient.RouteResponse rr = (CloudSolrClient.RouteResponse) response; final Map routes = rr.getRoutes();