From 4ae4bd2077ffa42abe52bc93673b3e2c60acae00 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 27 Aug 2018 08:48:33 -0400 Subject: [PATCH] Disable assertions sometimes --- qa/mixed-cluster/build.gradle | 1 + qa/rolling-upgrade/build.gradle | 2 + .../index/mapper/MapperService.java | 39 +-------- .../index/mapper/MapperServiceAssertions.java | 86 +++++++++++++++++++ x-pack/qa/rolling-upgrade-basic/build.gradle | 2 + x-pack/qa/rolling-upgrade/build.gradle | 2 + 6 files changed, 94 insertions(+), 38 deletions(-) create mode 100644 server/src/main/java/org/elasticsearch/index/mapper/MapperServiceAssertions.java diff --git a/qa/mixed-cluster/build.gradle b/qa/mixed-cluster/build.gradle index ac57d51def7c6..4c1e66cbec531 100644 --- a/qa/mixed-cluster/build.gradle +++ b/qa/mixed-cluster/build.gradle @@ -44,6 +44,7 @@ for (Version version : bwcVersions.wireCompatible) { numNodes = 4 numBwcNodes = 2 bwcVersion = version + jvmArgs += ' -da:org.elasticsearch.index.mapper.MapperAssertions' } Task versionBwcTest = tasks.create(name: "${baseName}#bwcTest") { diff --git a/qa/rolling-upgrade/build.gradle b/qa/rolling-upgrade/build.gradle index bfd37863cc246..b29b5d00f77d4 100644 --- a/qa/rolling-upgrade/build.gradle +++ b/qa/rolling-upgrade/build.gradle @@ -61,6 +61,7 @@ for (Version version : bwcVersions.wireCompatible) { bwcVersion = version numBwcNodes = 3 numNodes = 3 + jvmArgs += ' -da:org.elasticsearch.index.mapper.MapperAssertions' clusterName = 'rolling-upgrade' setting 'repositories.url.allowed_urls', 'http://snapshot.test*' if (version.onOrAfter('5.3.0')) { @@ -76,6 +77,7 @@ for (Version version : bwcVersions.wireCompatible) { Closure configureUpgradeCluster = {String name, Task lastRunner, int stopNode, Closure unicastSeed -> configure(extensions.findByName("${baseName}#${name}")) { dependsOn lastRunner, "${baseName}#oldClusterTestCluster#node${stopNode}.stop" + jvmArgs += ' -da:org.elasticsearch.index.mapper.MapperAssertions' clusterName = 'rolling-upgrade' unicastTransportUri = { seedNode, node, ant -> unicastSeed() } minimumMasterNodes = { 3 } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/MapperService.java b/server/src/main/java/org/elasticsearch/index/mapper/MapperService.java index 43d3352b39431..9fdcb4ce23c1f 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/MapperService.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/MapperService.java @@ -25,7 +25,6 @@ import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.DelegatingAnalyzerWrapper; import org.apache.lucene.index.Term; -import org.elasticsearch.Assertions; import org.elasticsearch.ElasticsearchGenerationException; import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetaData; @@ -73,6 +72,7 @@ import static java.util.Collections.emptyMap; import static java.util.Collections.unmodifiableMap; +import static org.elasticsearch.index.mapper.MapperServiceAssertions.assertMappingVersion; public class MapperService extends AbstractIndexComponent implements Closeable { @@ -243,43 +243,6 @@ public boolean updateMapping(final IndexMetaData currentIndexMetaData, final Ind return requireRefresh; } - private void assertMappingVersion( - final IndexMetaData currentIndexMetaData, - final IndexMetaData newIndexMetaData, - final Map updatedEntries) { - if (Assertions.ENABLED && currentIndexMetaData != null) { - if (currentIndexMetaData.getMappingVersion() == newIndexMetaData.getMappingVersion()) { - // if the mapping version is unchanged, then there should not be any updates and all mappings should be the same - assert updatedEntries.isEmpty() : updatedEntries; - for (final ObjectCursor mapping : newIndexMetaData.getMappings().values()) { - final CompressedXContent currentSource = currentIndexMetaData.mapping(mapping.value.type()).source(); - final CompressedXContent newSource = mapping.value.source(); - assert currentSource.equals(newSource) : - "expected current mapping [" + currentSource + "] for type [" + mapping.value.type() + "] " - + "to be the same as new mapping [" + newSource + "]"; - } - } else { - // if the mapping version is changed, it should increase, there should be updates, and the mapping should be different - final long currentMappingVersion = currentIndexMetaData.getMappingVersion(); - final long newMappingVersion = newIndexMetaData.getMappingVersion(); - assert currentMappingVersion < newMappingVersion : - "expected current mapping version [" + currentMappingVersion + "] " - + "to be less than new mapping version [" + newMappingVersion + "]"; - assert updatedEntries.isEmpty() == false; - for (final DocumentMapper documentMapper : updatedEntries.values()) { - final MappingMetaData currentMapping = currentIndexMetaData.mapping(documentMapper.type()); - if (currentMapping != null) { - final CompressedXContent currentSource = currentMapping.source(); - final CompressedXContent newSource = documentMapper.mappingSource(); - assert currentSource.equals(newSource) == false : - "expected current mapping [" + currentSource + "] for type [" + documentMapper.type() + "] " + - "to be different than new mapping"; - } - } - } - } - } - public void merge(Map> mappings, MergeReason reason) { Map mappingSourcesCompressed = new LinkedHashMap<>(mappings.size()); for (Map.Entry> entry : mappings.entrySet()) { diff --git a/server/src/main/java/org/elasticsearch/index/mapper/MapperServiceAssertions.java b/server/src/main/java/org/elasticsearch/index/mapper/MapperServiceAssertions.java new file mode 100644 index 0000000000000..020fae0d990ba --- /dev/null +++ b/server/src/main/java/org/elasticsearch/index/mapper/MapperServiceAssertions.java @@ -0,0 +1,86 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.mapper; + +import com.carrotsearch.hppc.cursors.ObjectCursor; +import org.elasticsearch.Assertions; +import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.cluster.metadata.MappingMetaData; +import org.elasticsearch.common.compress.CompressedXContent; + +import java.util.Map; + +/** + * This class exists so that we can disable these assertions in a mixed-version cluster without disabling all assertions in + * {@link MapperService}. These assertions can not necessarily hold in a mixed-version cluster because older nodes will not be serializing + * mapping version. + */ +// TODO: this indirection can be removed when all nodes in a mixed-version cluster test understand mapping version +final class MapperServiceAssertions { + + private MapperServiceAssertions() { + + } + + /** + * Assertions regarding changes in the mapping version. + * + * @param currentIndexMetaData the current index metadata + * @param newIndexMetaData the new index metadata + * @param updatedEntries the updated document mappers + */ + static void assertMappingVersion( + final IndexMetaData currentIndexMetaData, + final IndexMetaData newIndexMetaData, + final Map updatedEntries) { + if (Assertions.ENABLED && currentIndexMetaData != null) { + if (currentIndexMetaData.getMappingVersion() == newIndexMetaData.getMappingVersion()) { + // if the mapping version is unchanged, then there should not be any updates and all mappings should be the same + assert updatedEntries.isEmpty() : updatedEntries; + for (final ObjectCursor mapping : newIndexMetaData.getMappings().values()) { + final CompressedXContent currentSource = currentIndexMetaData.mapping(mapping.value.type()).source(); + final CompressedXContent newSource = mapping.value.source(); + assert currentSource.equals(newSource) : + "expected current mapping [" + currentSource + "] for type [" + mapping.value.type() + "] " + + "to be the same as new mapping [" + newSource + "]"; + } + } else { + // if the mapping version is changed, it should increase, there should be updates, and the mapping should be different + final long currentMappingVersion = currentIndexMetaData.getMappingVersion(); + final long newMappingVersion = newIndexMetaData.getMappingVersion(); + assert currentMappingVersion < newMappingVersion : + "expected current mapping version [" + currentMappingVersion + "] " + + "to be less than new mapping version [" + newMappingVersion + "]"; + assert updatedEntries.isEmpty() == false; + for (final DocumentMapper documentMapper : updatedEntries.values()) { + final MappingMetaData currentMapping = currentIndexMetaData.mapping(documentMapper.type()); + if (currentMapping != null) { + final CompressedXContent currentSource = currentMapping.source(); + final CompressedXContent newSource = documentMapper.mappingSource(); + assert currentSource.equals(newSource) == false : + "expected current mapping [" + currentSource + "] for type [" + documentMapper.type() + "] " + + "to be different than new mapping"; + } + } + } + } + } + +} diff --git a/x-pack/qa/rolling-upgrade-basic/build.gradle b/x-pack/qa/rolling-upgrade-basic/build.gradle index 5774e5d78561d..c4730c6c70570 100644 --- a/x-pack/qa/rolling-upgrade-basic/build.gradle +++ b/x-pack/qa/rolling-upgrade-basic/build.gradle @@ -36,6 +36,7 @@ for (Version version : bwcVersions.wireCompatible) { numBwcNodes = 3 numNodes = 3 minimumMasterNodes = { 3 } + jvmArgs += ' -da:org.elasticsearch.index.mapper.MapperAssertions' clusterName = 'rolling-upgrade-basic' setting 'xpack.security.enabled', 'false' setting 'xpack.monitoring.enabled', 'false' @@ -52,6 +53,7 @@ for (Version version : bwcVersions.wireCompatible) { Closure configureUpgradeCluster = {String name, Task lastRunner, int stopNode, Closure unicastSeed -> configure(extensions.findByName("${baseName}#${name}")) { dependsOn lastRunner, "${baseName}#oldClusterTestCluster#node${stopNode}.stop" + jvmArgs += ' -da:org.elasticsearch.index.mapper.MapperAssertions' clusterName = 'rolling-upgrade-basic' unicastTransportUri = { seedNode, node, ant -> unicastSeed() } minimumMasterNodes = { 3 } diff --git a/x-pack/qa/rolling-upgrade/build.gradle b/x-pack/qa/rolling-upgrade/build.gradle index 548081a893881..2158db95ec573 100644 --- a/x-pack/qa/rolling-upgrade/build.gradle +++ b/x-pack/qa/rolling-upgrade/build.gradle @@ -132,6 +132,7 @@ subprojects { numBwcNodes = 3 numNodes = 3 minimumMasterNodes = { 3 } + jvmArgs += ' -da:org.elasticsearch.index.mapper.MapperAssertions' clusterName = 'rolling-upgrade' waitCondition = waitWithAuth setting 'xpack.monitoring.exporters._http.type', 'http' @@ -172,6 +173,7 @@ subprojects { configure(extensions.findByName("${baseName}#${name}")) { dependsOn lastRunner, "${baseName}#oldClusterTestCluster#node${stopNode}.stop" setupCommand 'setupTestUser', 'bin/elasticsearch-users', 'useradd', 'test_user', '-p', 'x-pack-test-password', '-r', 'superuser' + jvmArgs += ' -da:org.elasticsearch.index.mapper.MapperAssertions' clusterName = 'rolling-upgrade' unicastTransportUri = { seedNode, node, ant -> unicastSeed() } minimumMasterNodes = { 3 }