SOLR-13411: reject incremental update for route.field, uniqueKey and

_version_.
This commit is contained in:
Mikhail Khludnev 2020-02-27 14:40:04 +03:00
parent d9c43d9fa3
commit 3befb8be94
4 changed files with 23 additions and 10 deletions

View File

@ -185,6 +185,8 @@ Bug Fixes
* SOLR-14250: Do not log error when trying to consume non-existing input stream due to Expect: 100-continue (janhoy) * SOLR-14250: Do not log error when trying to consume non-existing input stream due to Expect: 100-continue (janhoy)
* SOLR-13411: Deny atomic update for route.field, uniqueKey, version and throw exception. (Dr Oleg Savrasov via Mikhail Khludnev)
Other Changes Other Changes
--------------------- ---------------------

View File

@ -183,12 +183,17 @@ public class AtomicUpdateDocumentMerger {
// first pass, check the things that are virtually free, // first pass, check the things that are virtually free,
// and bail out early if anything is obviously not a valid in-place update // and bail out early if anything is obviously not a valid in-place update
for (String fieldName : sdoc.getFieldNames()) { for (String fieldName : sdoc.getFieldNames()) {
Object fieldValue = sdoc.getField(fieldName).getValue();
if (fieldName.equals(uniqueKeyFieldName) if (fieldName.equals(uniqueKeyFieldName)
|| fieldName.equals(CommonParams.VERSION_FIELD) || fieldName.equals(CommonParams.VERSION_FIELD)
|| fieldName.equals(routeFieldOrNull)) { || 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) ) { if (! (fieldValue instanceof Map) ) {
// not an in-place update if there are fields that are not maps // not an in-place update if there are fields that are not maps
return Collections.emptySet(); return Collections.emptySet();

View File

@ -114,13 +114,19 @@ public class TestInPlaceUpdateWithRouteField extends SolrCloudTestCase {
Assert.assertThat( "Doc value must be updated", solrDocument.get("inplace_updatable_int"), is(newDocValue)); 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)); 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 { try {
sdoc.remove("shardName"); new UpdateRequest().add(sdoc).process(cluster.getSolrClient(), COLLECTION);
new UpdateRequest() fail("expect an exception for wrong update command");
.add(sdoc).process(cluster.getSolrClient(), COLLECTION); } catch (SolrException ex) {
fail("expect an exception w/o route field"); assertThat("expecting 400 in " + ex.getMessage(), ex.code(), is(400));
}catch(SolrException ex) {
assertThat("expecting 400 in "+ex.getMessage(), ex.code(), is(400));
} }
} }

View File

@ -203,7 +203,7 @@ public class TestUpdate extends SolrTestCaseJ4 {
); );
resetExceptionIgnores(); resetExceptionIgnores();
assertEquals(400, se.code()); 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(); afterUpdate.call();