diff --git a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java index 22eb69d8305c2..0f8078b34432b 100644 --- a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java +++ b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java @@ -39,6 +39,7 @@ import org.elasticsearch.cluster.block.ClusterBlock; import org.elasticsearch.cluster.block.ClusterBlocks; import org.elasticsearch.cluster.metadata.IndexMetaData.*; +import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.allocation.AllocationService; @@ -558,9 +559,22 @@ public int compare(IndexTemplateMetaData o1, IndexTemplateMetaData o2) { private void validate(CreateIndexClusterStateUpdateRequest request, ClusterState state) throws ElasticsearchException { validateIndexName(request.index(), state); String customPath = request.settings().get(IndexMetaData.SETTING_DATA_PATH, null); - if (customPath != null && nodeEnv.isCustomPathsEnabled() == false) { - throw new IndexCreationException(new Index(request.index()), - new ElasticsearchIllegalArgumentException("custom data_paths for indices is disabled")); + if (customPath != null) { + if (nodeEnv.isCustomPathsEnabled() == false) { + throw new IndexCreationException(new Index(request.index()), + new ElasticsearchIllegalArgumentException("custom data_path for indices is disabled")); + } + // This checks for all nodes to be at least 1.5.0+ when creating an + // index with a custom data_path. It will only work if the 1.5.0 + // node is the master in the cluster, but it is better protection + // than nothing. + for (ObjectObjectCursor entry : state.nodes().dataNodes()) { + if (entry.value.version().onOrAfter(Version.V_1_5_0) == false) { + throw new IndexCreationException(new Index(request.index()), + new ElasticsearchIllegalArgumentException("custom data_path is disabled unless all nodes are at least version " + + Version.V_1_5_0)); + } + } } } diff --git a/src/test/java/org/elasticsearch/bwcompat/BasicAnalysisBackwardCompatibilityTests.java b/src/test/java/org/elasticsearch/bwcompat/BasicAnalysisBackwardCompatibilityTests.java index 40216d5ccd34b..ed872f7c9e1aa 100644 --- a/src/test/java/org/elasticsearch/bwcompat/BasicAnalysisBackwardCompatibilityTests.java +++ b/src/test/java/org/elasticsearch/bwcompat/BasicAnalysisBackwardCompatibilityTests.java @@ -42,7 +42,40 @@ public class BasicAnalysisBackwardCompatibilityTests extends ElasticsearchBackwardsCompatIntegrationTest { // This pattern match characters with Line_Break = Complex_Content. - final static Pattern complexUnicodeChars = Pattern.compile("[\u17B4\u17B5\u17D3\u17CB-\u17D1\u17DD\u1036\u17C6\u1A74\u1038\u17C7\u0E4E\u0E47-\u0E4D\u0EC8-\u0ECD\uAABF\uAAC1\u1037\u17C8-\u17CA\u1A75-\u1A7C\u1AA8-\u1AAB\uAADE\uAADF\u1AA0-\u1AA6\u1AAC\u1AAD\u109E\u109F\uAA77-\uAA79\u0E46\u0EC6\u17D7\u1AA7\uA9E6\uAA70\uAADD\u19DA\u0E01-\u0E3A\u0E40-\u0E45\u0EDE\u0E81\u0E82\u0E84\u0E87\u0E88\u0EAA\u0E8A\u0EDF\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAB\u0EDC\u0EDD\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\uAA80-\uAABE\uAAC0\uAAC2\uAADB\uAADC\u1000\u1075\u1001\u1076\u1002\u1077\uAA60\uA9E9\u1003\uA9E0\uA9EA\u1004\u105A\u1005\u1078\uAA61\u1006\uA9E1\uAA62\uAA7E\u1007\uAA63\uA9EB\u1079\uAA72\u1008\u105B\uA9E2\uAA64\uA9EC\u1061\uAA7F\u1009\u107A\uAA65\uA9E7\u100A\u100B\uAA66\u100C\uAA67\u100D\uAA68\uA9ED\u100E\uAA69\uA9EE\u100F\u106E\uA9E3\uA9EF\u1010-\u1012\u107B\uA9FB\u1013\uAA6A\uA9FC\u1014\u107C\uAA6B\u105E\u1015\u1016\u107D\u107E\uAA6F\u108E\uA9E8\u1017\u107F\uA9FD\u1018\uA9E4\uA9FE\u1019\u105F\u101A\u103B\u101B\uAA73\uAA7A\u103C\u101C\u1060\u101D\u103D\u1082\u1080\u1050\u1051\u1065\u101E\u103F\uAA6C\u101F\u1081\uAA6D\u103E\uAA6E\uAA71\u1020\uA9FA\u105C\u105D\u106F\u1070\u1066\u1021-\u1026\u1052-\u1055\u1027-\u102A\u102C\u102B\u1083\u1072\u109C\u102D\u1071\u102E\u1033\u102F\u1073\u1074\u1030\u1056-\u1059\u1031\u1084\u1035\u1085\u1032\u109D\u1034\u1062\u1067\u1068\uA9E5\u1086\u1039\u103A\u1063\u1064\u1069-\u106D\u1087\u108B\u1088\u108C\u108D\u1089\u108A\u108F\u109A\u109B\uAA7B-\uAA7D\uAA74-\uAA76\u1780-\u17A2\u17DC\u17A3-\u17B3\u17B6-\u17C5\u17D2\u1950-\u196D\u1970-\u1974\u1980-\u199C\u19DE\u19DF\u199D-\u19AB\u19B0-\u19C9\u1A20-\u1A26\u1A58\u1A59\u1A27-\u1A3B\u1A5A\u1A5B\u1A3C-\u1A46\u1A54\u1A47-\u1A4C\u1A53\u1A6B\u1A55-\u1A57\u1A5C-\u1A5E\u1A4D-\u1A52\u1A61\u1A6C\u1A62-\u1A6A\u1A6E\u1A6F\u1A73\u1A70-\u1A72\u1A6D\u1A60]"); + final static Pattern complexUnicodeChars = + Pattern.compile("[\u17B4\u17B5\u17D3\u17CB-\u17D1\u17DD\u1036\u17C6" + + "\u1A74\u1038\u17C7\u0E4E\u0E47-\u0E4D\u0EC8-\u0ECD\uAABF" + + "\uAAC1\u1037\u17C8-\u17CA\u1A75-\u1A7C\u1AA8-\u1AAB\uAADE" + + "\uAADF\u1AA0-\u1AA6\u1AAC\u1AAD\u109E\u109F\uAA77-\uAA79" + + "\u0E46\u0EC6\u17D7\u1AA7\uA9E6\uAA70\uAADD\u19DA\u0E01-" + + "\u0E3A\u0E40-\u0E45\u0EDE\u0E81\u0E82\u0E84\u0E87\u0E88" + + "\u0EAA\u0E8A\u0EDF\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-" + + "\u0EA3\u0EA5\u0EA7\u0EAB\u0EDC\u0EDD\u0EAD-\u0EB9\u0EBB-" + + "\u0EBD\u0EC0-\u0EC4\uAA80-\uAABE\uAAC0\uAAC2\uAADB\uAADC" + + "\u1000\u1075\u1001\u1076\u1002\u1077\uAA60\uA9E9\u1003" + + "\uA9E0\uA9EA\u1004\u105A\u1005\u1078\uAA61\u1006\uA9E1" + + "\uAA62\uAA7E\u1007\uAA63\uA9EB\u1079\uAA72\u1008\u105B" + + "\uA9E2\uAA64\uA9EC\u1061\uAA7F\u1009\u107A\uAA65\uA9E7" + + "\u100A\u100B\uAA66\u100C\uAA67\u100D\uAA68\uA9ED\u100E" + + "\uAA69\uA9EE\u100F\u106E\uA9E3\uA9EF\u1010-\u1012\u107B" + + "\uA9FB\u1013\uAA6A\uA9FC\u1014\u107C\uAA6B\u105E\u1015" + + "\u1016\u107D\u107E\uAA6F\u108E\uA9E8\u1017\u107F\uA9FD" + + "\u1018\uA9E4\uA9FE\u1019\u105F\u101A\u103B\u101B\uAA73" + + "\uAA7A\u103C\u101C\u1060\u101D\u103D\u1082\u1080\u1050" + + "\u1051\u1065\u101E\u103F\uAA6C\u101F\u1081\uAA6D\u103E" + + "\uAA6E\uAA71\u1020\uA9FA\u105C\u105D\u106F\u1070\u1066" + + "\u1021-\u1026\u1052-\u1055\u1027-\u102A\u102C\u102B\u1083" + + "\u1072\u109C\u102D\u1071\u102E\u1033\u102F\u1073\u1074" + + "\u1030\u1056-\u1059\u1031\u1084\u1035\u1085\u1032\u109D" + + "\u1034\u1062\u1067\u1068\uA9E5\u1086\u1039\u103A\u1063" + + "\u1064\u1069-\u106D\u1087\u108B\u1088\u108C\u108D\u1089" + + "\u108A\u108F\u109A\u109B\uAA7B-\uAA7D\uAA74-\uAA76\u1780-" + + "\u17A2\u17DC\u17A3-\u17B3\u17B6-\u17C5\u17D2\u1950-\u196D" + + "\u1970-\u1974\u1980-\u199C\u19DE\u19DF\u199D-\u19AB\u19B0-" + + "\u19C9\u1A20-\u1A26\u1A58\u1A59\u1A27-\u1A3B\u1A5A\u1A5B" + + "\u1A3C-\u1A46\u1A54\u1A47-\u1A4C\u1A53\u1A6B\u1A55-\u1A57" + + "\u1A5C-\u1A5E\u1A4D-\u1A52\u1A61\u1A6C\u1A62-\u1A6A\u1A6E" + + "\u1A6F\u1A73\u1A70-\u1A72\u1A6D\u1A60]"); /** * Simple upgrade test for analyzers to make sure they analyze to the same tokens after upgrade diff --git a/src/test/java/org/elasticsearch/bwcompat/BasicBackwardsCompatibilityTest.java b/src/test/java/org/elasticsearch/bwcompat/BasicBackwardsCompatibilityTest.java index 02824e12953af..87d273602e622 100644 --- a/src/test/java/org/elasticsearch/bwcompat/BasicBackwardsCompatibilityTest.java +++ b/src/test/java/org/elasticsearch/bwcompat/BasicBackwardsCompatibilityTest.java @@ -49,7 +49,6 @@ import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider; -import org.elasticsearch.common.Strings; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.ImmutableSettings; diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchBackwardsCompatIntegrationTest.java b/src/test/java/org/elasticsearch/test/ElasticsearchBackwardsCompatIntegrationTest.java index 754aeeb2c7db1..eca750faaf9ef 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchBackwardsCompatIntegrationTest.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchBackwardsCompatIntegrationTest.java @@ -84,6 +84,14 @@ @Ignore public abstract class ElasticsearchBackwardsCompatIntegrationTest extends ElasticsearchIntegrationTest { + @Override + public boolean useCustomDataPath() { + // Backwards compatibility tests cannot use custom data paths, because + // some nodes in the cluster may not support the setting, so this is + // set to false for all backwards integration tests + return false; + } + private static File backwardsCompatibilityPath() { String path = System.getProperty(TESTS_BACKWARDS_COMPATIBILITY_PATH); if (path == null || path.isEmpty()) { diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java b/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java index f13e63350cfad..27af3e873f442 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java @@ -732,6 +732,11 @@ public void clearDisruptionScheme() { } } + /** overridable method to turn custom data paths on or off */ + public boolean useCustomDataPath() { + return true; + } + /** * Returns a settings object used in {@link #createIndex(String...)} and {@link #prepareCreate(String)} and friends. * This method can be overwritten by subclasses to set defaults for the indices that are created by the test. @@ -751,7 +756,7 @@ public Settings indexSettings() { } } // 30% of the time - if (randomInt(9) < 3) { + if (useCustomDataPath() && (randomInt(9) < 3)) { String dataPath = "data/custom-" + CHILD_JVM_ID + "/" + UUID.randomUUID().toString(); logger.info("using custom data_path for index: [{}]", dataPath); builder.put(IndexMetaData.SETTING_DATA_PATH, dataPath);