Apache Lucene open-source search software
SOLR-11459: Fix in-place nonexistent doc update following existing doc update
Mikhail Khludnevc50806824005
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 444b8aeb8a4..aaad547f0f5 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -186,6 +186,9 @@ Bug Fixes* SOLR-11661: New HDFS collection reuses unremoved data from a deleted HDFS collection with same name causesinconsistent view of documents (Cao Manh Dat, shalin)+* SOLR-11459: In-place update of nonexistent doc following existing doc update fails to create the doc.+ (Andrey Kudryavtsev via Mikhail Khludnev)+Optimizations----------------------diff --git a/solr/core/src/java/org/apache/solr/update/AddUpdateCommand.java b/solr/core/src/java/org/apache/solr/update/AddUpdateCommand.javaindex cb1af9a29f2..3bfe9345f56 100644--- a/solr/core/src/java/org/apache/solr/update/AddUpdateCommand.java+++ b/solr/core/src/java/org/apache/solr/update/AddUpdateCommand.java@@ -78,6 +78,7 @@ public class AddUpdateCommand extends UpdateCommand implements Iterable<DocumentupdateTerm = null;isLastDocInBatch = false;version = 0;+ prevVersion = -1;}public SolrInputDocument getSolrInputDocument() {diff --git a/solr/core/src/test/org/apache/solr/update/TestInPlaceUpdatesDistrib.java b/solr/core/src/test/org/apache/solr/update/TestInPlaceUpdatesDistrib.javaindex 14f0a7cb014..d01d68f4269 100644--- a/solr/core/src/test/org/apache/solr/update/TestInPlaceUpdatesDistrib.java+++ b/solr/core/src/test/org/apache/solr/update/TestInPlaceUpdatesDistrib.java@@ -144,6 +144,7 @@ public class TestInPlaceUpdatesDistrib extends AbstractFullDistribZkTestBase {outOfOrderUpdatesIndividualReplicaTest();delayedReorderingFetchesMissingUpdateFromLeaderTest();updatingDVsInAVeryOldSegment();+ updateExistingThenNonExistentDoc();// TODO Should we combine all/some of these into a single test, so as to cut down on execution time?reorderedDBQIndividualReplicaTest();@@ -411,6 +412,45 @@ public class TestInPlaceUpdatesDistrib extends AbstractFullDistribZkTestBase {log.info("updatingDVsInAVeryOldSegment: This test passed fine...");}++ /**+ * Test scenario:+ * <ul>+ * <li>Send a batch of documents to one node</li>+ * <li>Batch consist of an update for document which is existed and an update for documents which is not existed </li>+ * <li>Assumption which is made is that both updates will be applied: field for existed document will be updated,+ * new document will be created for a non existed one</li>+ * </ul>+ *+ */+ private void updateExistingThenNonExistentDoc() throws Exception {+ clearIndex();+ index("id", 1, "inplace_updatable_float", "1", "title_s", "newtitle");+ commit();+ SolrInputDocument existingDocUpdate = new SolrInputDocument();+ existingDocUpdate.setField("id", 1);+ existingDocUpdate.setField("inplace_updatable_float", map("set", "50"));++ SolrInputDocument nonexistentDocUpdate = new SolrInputDocument();+ nonexistentDocUpdate.setField("id", 2);+ nonexistentDocUpdate.setField("inplace_updatable_float", map("set", "50"));++ SolrInputDocument docs[] = new SolrInputDocument[] {existingDocUpdate, nonexistentDocUpdate};++ SolrClient solrClient = clients.get(random().nextInt(clients.size()));+ add(solrClient, null, docs);+ commit();+ for (SolrClient client: new SolrClient[] {LEADER, NONLEADERS.get(0), NONLEADERS.get(1)}) {+ for (SolrInputDocument expectDoc : docs) {+ String docId = expectDoc.getFieldValue("id").toString();+ SolrDocument actualDoc = client.getById(docId);+ assertNotNull("expected to get doc by id:" + docId, actualDoc);+ assertEquals("expected to update "+actualDoc,+ 50.0f, actualDoc.get("inplace_updatable_float"));+ }+ }+ }+/*** Retries the specified 'req' against each SolrClient in "clients" untill the expected number of* results are returned, at which point the results are verified using assertDocIdsAndValuesInResults