You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mk...@apache.org on 2020/02/27 18:56:40 UTC

[lucene-solr] branch branch_8x updated: SOLR-13411: reject incremental update for route.field, uniqueKey and _version_.

This is an automated email from the ASF dual-hosted git repository.

mkhl pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/branch_8x by this push:
     new 64193f0  SOLR-13411: reject incremental update for route.field, uniqueKey and _version_.
64193f0 is described below

commit 64193f052acbb216d393c719400637648664a1c1
Author: Mikhail Khludnev <mk...@apache.org>
AuthorDate: Thu Feb 27 14:40:04 2020 +0300

    SOLR-13411: reject incremental update for route.field, uniqueKey and
    _version_.
---
 solr/CHANGES.txt                                     |  2 ++
 .../update/processor/AtomicUpdateDocumentMerger.java |  9 +++++++--
 .../solr/update/TestInPlaceUpdateWithRouteField.java | 20 +++++++++++++-------
 .../src/test/org/apache/solr/update/TestUpdate.java  |  2 +-
 4 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 1375733..c460860 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -157,6 +157,8 @@ Bug Fixes
 
 * SOLR-14252: Avoid NullPointerException in AggregateMetric. (Andy Webb via ab)
 
+* SOLR-13411: Deny atomic update for route.field, uniqueKey, version and throw exception. (Dr Oleg Savrasov via Mikhail Khludnev) 
+
 Other Changes
 ---------------------
 
diff --git a/solr/core/src/java/org/apache/solr/update/processor/AtomicUpdateDocumentMerger.java b/solr/core/src/java/org/apache/solr/update/processor/AtomicUpdateDocumentMerger.java
index 8bd51c2..9ebcde5 100644
--- a/solr/core/src/java/org/apache/solr/update/processor/AtomicUpdateDocumentMerger.java
+++ b/solr/core/src/java/org/apache/solr/update/processor/AtomicUpdateDocumentMerger.java
@@ -183,12 +183,17 @@ public class AtomicUpdateDocumentMerger {
     // first pass, check the things that are virtually free,
     // and bail out early if anything is obviously not a valid in-place update
     for (String fieldName : sdoc.getFieldNames()) {
+      Object fieldValue = sdoc.getField(fieldName).getValue();
       if (fieldName.equals(uniqueKeyFieldName)
           || fieldName.equals(CommonParams.VERSION_FIELD)
           || fieldName.equals(routeFieldOrNull)) {
-        continue;
+        if (fieldValue instanceof Map ) {
+          throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
+              "Updating unique key, version or route field is not allowed: " + sdoc.getField(fieldName));
+        } else {
+          continue;
+        }
       }
-      Object fieldValue = sdoc.getField(fieldName).getValue();
       if (! (fieldValue instanceof Map) ) {
         // not an in-place update if there are fields that are not maps
         return Collections.emptySet();
diff --git a/solr/core/src/test/org/apache/solr/update/TestInPlaceUpdateWithRouteField.java b/solr/core/src/test/org/apache/solr/update/TestInPlaceUpdateWithRouteField.java
index 14a4808..fc85fad 100644
--- a/solr/core/src/test/org/apache/solr/update/TestInPlaceUpdateWithRouteField.java
+++ b/solr/core/src/test/org/apache/solr/update/TestInPlaceUpdateWithRouteField.java
@@ -113,14 +113,20 @@ public class TestInPlaceUpdateWithRouteField extends SolrCloudTestCase {
         newVersion > initialVersion);
     Assert.assertThat( "Doc value must be updated", solrDocument.get("inplace_updatable_int"), is(newDocValue));
     Assert.assertThat("Lucene doc id should not be changed for In-Place Updates.", solrDocument.get("[docid]"), is(luceneDocId));
-    
+
+    sdoc.remove("shardName");
+    checkWrongCommandFailure(sdoc);
+
+    sdoc.addField("shardName",  map("set", "newShardName"));
+    checkWrongCommandFailure(sdoc);
+  }
+
+  private void checkWrongCommandFailure(SolrInputDocument sdoc) throws SolrServerException, IOException {
     try {
-      sdoc.remove("shardName");
-      new UpdateRequest()
-         .add(sdoc).process(cluster.getSolrClient(), COLLECTION);
-      fail("expect  an exception w/o route field");
-    }catch(SolrException ex) {
-      assertThat("expecting 400 in "+ex.getMessage(), ex.code(), is(400));
+      new UpdateRequest().add(sdoc).process(cluster.getSolrClient(), COLLECTION);
+      fail("expect an exception for wrong update command");
+    } catch (SolrException ex) {
+      assertThat("expecting 400 in " + ex.getMessage(), ex.code(), is(400));
     }
   }
 
diff --git a/solr/core/src/test/org/apache/solr/update/TestUpdate.java b/solr/core/src/test/org/apache/solr/update/TestUpdate.java
index f276dc7..2418169 100644
--- a/solr/core/src/test/org/apache/solr/update/TestUpdate.java
+++ b/solr/core/src/test/org/apache/solr/update/TestUpdate.java
@@ -203,7 +203,7 @@ public class TestUpdate extends SolrTestCaseJ4 {
     );
     resetExceptionIgnores();
     assertEquals(400, se.code());
-    assertTrue(se.getMessage().contains("Invalid update of id field"));
+    assertTrue(se.getMessage().contains("Updating unique key, version or route field is not allowed"));
 
     afterUpdate.call();