From fa99721295d76e5b297c99e9032b3dfb0aaa5649 Mon Sep 17 00:00:00 2001 From: Jack Conradson Date: Wed, 16 Oct 2019 16:09:22 -0700 Subject: [PATCH] Drop stored scripts with the old style-id (#48078) This PR fixes (#47593). Stored scripts with the old-style id of lang#id are saved through the upgrade process but are no longer accessible in recent versions. This fix will drop those scripts altogether since there is no way for a user to access them. --- .../elasticsearch/script/ScriptMetaData.java | 7 +++- .../script/ScriptMetaDataTests.java | 37 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/script/ScriptMetaData.java b/server/src/main/java/org/elasticsearch/script/ScriptMetaData.java index 52a06db5829..b55f87efd68 100644 --- a/server/src/main/java/org/elasticsearch/script/ScriptMetaData.java +++ b/server/src/main/java/org/elasticsearch/script/ScriptMetaData.java @@ -249,7 +249,12 @@ public final class ScriptMetaData implements MetaData.Custom, Writeable, ToXCont source = StoredScriptSource.fromXContent(parser, true); if (exists == null) { - scripts.put(id, source); + // due to a bug (https://github.com/elastic/elasticsearch/issues/47593) + // scripts may have been retained during upgrade that include the old-style + // id of lang#id; these scripts are unreachable after 7.0, so they are dropped + if (id.contains("#") == false) { + scripts.put(id, source); + } } else if (exists.getLang().equals(source.getLang()) == false) { throw new IllegalArgumentException("illegal stored script, id [" + id + "] used for multiple scripts with " + "different languages [" + exists.getLang() + "] and [" + source.getLang() + "]; scripts using the old " + diff --git a/server/src/test/java/org/elasticsearch/script/ScriptMetaDataTests.java b/server/src/test/java/org/elasticsearch/script/ScriptMetaDataTests.java index 7a856ee13b9..fc0ebe3f23f 100644 --- a/server/src/test/java/org/elasticsearch/script/ScriptMetaDataTests.java +++ b/server/src/test/java/org/elasticsearch/script/ScriptMetaDataTests.java @@ -32,6 +32,7 @@ import org.elasticsearch.test.AbstractSerializingTestCase; import java.io.IOException; import java.io.UncheckedIOException; +import java.util.Collections; public class ScriptMetaDataTests extends AbstractSerializingTestCase { @@ -168,6 +169,42 @@ public class ScriptMetaDataTests extends AbstractSerializingTestCase