Skip to content

Commit 4ae4bd2

Browse files
committed
Disable assertions sometimes
1 parent 7aabd21 commit 4ae4bd2

File tree

6 files changed

+94
-38
lines changed

6 files changed

+94
-38
lines changed

qa/mixed-cluster/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ for (Version version : bwcVersions.wireCompatible) {
4444
numNodes = 4
4545
numBwcNodes = 2
4646
bwcVersion = version
47+
jvmArgs += ' -da:org.elasticsearch.index.mapper.MapperAssertions'
4748
}
4849

4950
Task versionBwcTest = tasks.create(name: "${baseName}#bwcTest") {

qa/rolling-upgrade/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ for (Version version : bwcVersions.wireCompatible) {
6161
bwcVersion = version
6262
numBwcNodes = 3
6363
numNodes = 3
64+
jvmArgs += ' -da:org.elasticsearch.index.mapper.MapperAssertions'
6465
clusterName = 'rolling-upgrade'
6566
setting 'repositories.url.allowed_urls', 'http://snapshot.test*'
6667
if (version.onOrAfter('5.3.0')) {
@@ -76,6 +77,7 @@ for (Version version : bwcVersions.wireCompatible) {
7677
Closure configureUpgradeCluster = {String name, Task lastRunner, int stopNode, Closure unicastSeed ->
7778
configure(extensions.findByName("${baseName}#${name}")) {
7879
dependsOn lastRunner, "${baseName}#oldClusterTestCluster#node${stopNode}.stop"
80+
jvmArgs += ' -da:org.elasticsearch.index.mapper.MapperAssertions'
7981
clusterName = 'rolling-upgrade'
8082
unicastTransportUri = { seedNode, node, ant -> unicastSeed() }
8183
minimumMasterNodes = { 3 }

server/src/main/java/org/elasticsearch/index/mapper/MapperService.java

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.apache.lucene.analysis.Analyzer;
2626
import org.apache.lucene.analysis.DelegatingAnalyzerWrapper;
2727
import org.apache.lucene.index.Term;
28-
import org.elasticsearch.Assertions;
2928
import org.elasticsearch.ElasticsearchGenerationException;
3029
import org.elasticsearch.Version;
3130
import org.elasticsearch.cluster.metadata.IndexMetaData;
@@ -73,6 +72,7 @@
7372

7473
import static java.util.Collections.emptyMap;
7574
import static java.util.Collections.unmodifiableMap;
75+
import static org.elasticsearch.index.mapper.MapperServiceAssertions.assertMappingVersion;
7676

7777
public class MapperService extends AbstractIndexComponent implements Closeable {
7878

@@ -243,43 +243,6 @@ public boolean updateMapping(final IndexMetaData currentIndexMetaData, final Ind
243243
return requireRefresh;
244244
}
245245

246-
private void assertMappingVersion(
247-
final IndexMetaData currentIndexMetaData,
248-
final IndexMetaData newIndexMetaData,
249-
final Map<String, DocumentMapper> updatedEntries) {
250-
if (Assertions.ENABLED && currentIndexMetaData != null) {
251-
if (currentIndexMetaData.getMappingVersion() == newIndexMetaData.getMappingVersion()) {
252-
// if the mapping version is unchanged, then there should not be any updates and all mappings should be the same
253-
assert updatedEntries.isEmpty() : updatedEntries;
254-
for (final ObjectCursor<MappingMetaData> mapping : newIndexMetaData.getMappings().values()) {
255-
final CompressedXContent currentSource = currentIndexMetaData.mapping(mapping.value.type()).source();
256-
final CompressedXContent newSource = mapping.value.source();
257-
assert currentSource.equals(newSource) :
258-
"expected current mapping [" + currentSource + "] for type [" + mapping.value.type() + "] "
259-
+ "to be the same as new mapping [" + newSource + "]";
260-
}
261-
} else {
262-
// if the mapping version is changed, it should increase, there should be updates, and the mapping should be different
263-
final long currentMappingVersion = currentIndexMetaData.getMappingVersion();
264-
final long newMappingVersion = newIndexMetaData.getMappingVersion();
265-
assert currentMappingVersion < newMappingVersion :
266-
"expected current mapping version [" + currentMappingVersion + "] "
267-
+ "to be less than new mapping version [" + newMappingVersion + "]";
268-
assert updatedEntries.isEmpty() == false;
269-
for (final DocumentMapper documentMapper : updatedEntries.values()) {
270-
final MappingMetaData currentMapping = currentIndexMetaData.mapping(documentMapper.type());
271-
if (currentMapping != null) {
272-
final CompressedXContent currentSource = currentMapping.source();
273-
final CompressedXContent newSource = documentMapper.mappingSource();
274-
assert currentSource.equals(newSource) == false :
275-
"expected current mapping [" + currentSource + "] for type [" + documentMapper.type() + "] " +
276-
"to be different than new mapping";
277-
}
278-
}
279-
}
280-
}
281-
}
282-
283246
public void merge(Map<String, Map<String, Object>> mappings, MergeReason reason) {
284247
Map<String, CompressedXContent> mappingSourcesCompressed = new LinkedHashMap<>(mappings.size());
285248
for (Map.Entry<String, Map<String, Object>> entry : mappings.entrySet()) {
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.index.mapper;
21+
22+
import com.carrotsearch.hppc.cursors.ObjectCursor;
23+
import org.elasticsearch.Assertions;
24+
import org.elasticsearch.cluster.metadata.IndexMetaData;
25+
import org.elasticsearch.cluster.metadata.MappingMetaData;
26+
import org.elasticsearch.common.compress.CompressedXContent;
27+
28+
import java.util.Map;
29+
30+
/**
31+
* This class exists so that we can disable these assertions in a mixed-version cluster without disabling all assertions in
32+
* {@link MapperService}. These assertions can not necessarily hold in a mixed-version cluster because older nodes will not be serializing
33+
* mapping version.
34+
*/
35+
// TODO: this indirection can be removed when all nodes in a mixed-version cluster test understand mapping version
36+
final class MapperServiceAssertions {
37+
38+
private MapperServiceAssertions() {
39+
40+
}
41+
42+
/**
43+
* Assertions regarding changes in the mapping version.
44+
*
45+
* @param currentIndexMetaData the current index metadata
46+
* @param newIndexMetaData the new index metadata
47+
* @param updatedEntries the updated document mappers
48+
*/
49+
static void assertMappingVersion(
50+
final IndexMetaData currentIndexMetaData,
51+
final IndexMetaData newIndexMetaData,
52+
final Map<String, DocumentMapper> updatedEntries) {
53+
if (Assertions.ENABLED && currentIndexMetaData != null) {
54+
if (currentIndexMetaData.getMappingVersion() == newIndexMetaData.getMappingVersion()) {
55+
// if the mapping version is unchanged, then there should not be any updates and all mappings should be the same
56+
assert updatedEntries.isEmpty() : updatedEntries;
57+
for (final ObjectCursor<MappingMetaData> mapping : newIndexMetaData.getMappings().values()) {
58+
final CompressedXContent currentSource = currentIndexMetaData.mapping(mapping.value.type()).source();
59+
final CompressedXContent newSource = mapping.value.source();
60+
assert currentSource.equals(newSource) :
61+
"expected current mapping [" + currentSource + "] for type [" + mapping.value.type() + "] "
62+
+ "to be the same as new mapping [" + newSource + "]";
63+
}
64+
} else {
65+
// if the mapping version is changed, it should increase, there should be updates, and the mapping should be different
66+
final long currentMappingVersion = currentIndexMetaData.getMappingVersion();
67+
final long newMappingVersion = newIndexMetaData.getMappingVersion();
68+
assert currentMappingVersion < newMappingVersion :
69+
"expected current mapping version [" + currentMappingVersion + "] "
70+
+ "to be less than new mapping version [" + newMappingVersion + "]";
71+
assert updatedEntries.isEmpty() == false;
72+
for (final DocumentMapper documentMapper : updatedEntries.values()) {
73+
final MappingMetaData currentMapping = currentIndexMetaData.mapping(documentMapper.type());
74+
if (currentMapping != null) {
75+
final CompressedXContent currentSource = currentMapping.source();
76+
final CompressedXContent newSource = documentMapper.mappingSource();
77+
assert currentSource.equals(newSource) == false :
78+
"expected current mapping [" + currentSource + "] for type [" + documentMapper.type() + "] " +
79+
"to be different than new mapping";
80+
}
81+
}
82+
}
83+
}
84+
}
85+
86+
}

x-pack/qa/rolling-upgrade-basic/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ for (Version version : bwcVersions.wireCompatible) {
3636
numBwcNodes = 3
3737
numNodes = 3
3838
minimumMasterNodes = { 3 }
39+
jvmArgs += ' -da:org.elasticsearch.index.mapper.MapperAssertions'
3940
clusterName = 'rolling-upgrade-basic'
4041
setting 'xpack.security.enabled', 'false'
4142
setting 'xpack.monitoring.enabled', 'false'
@@ -52,6 +53,7 @@ for (Version version : bwcVersions.wireCompatible) {
5253
Closure configureUpgradeCluster = {String name, Task lastRunner, int stopNode, Closure unicastSeed ->
5354
configure(extensions.findByName("${baseName}#${name}")) {
5455
dependsOn lastRunner, "${baseName}#oldClusterTestCluster#node${stopNode}.stop"
56+
jvmArgs += ' -da:org.elasticsearch.index.mapper.MapperAssertions'
5557
clusterName = 'rolling-upgrade-basic'
5658
unicastTransportUri = { seedNode, node, ant -> unicastSeed() }
5759
minimumMasterNodes = { 3 }

x-pack/qa/rolling-upgrade/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ subprojects {
132132
numBwcNodes = 3
133133
numNodes = 3
134134
minimumMasterNodes = { 3 }
135+
jvmArgs += ' -da:org.elasticsearch.index.mapper.MapperAssertions'
135136
clusterName = 'rolling-upgrade'
136137
waitCondition = waitWithAuth
137138
setting 'xpack.monitoring.exporters._http.type', 'http'
@@ -172,6 +173,7 @@ subprojects {
172173
configure(extensions.findByName("${baseName}#${name}")) {
173174
dependsOn lastRunner, "${baseName}#oldClusterTestCluster#node${stopNode}.stop"
174175
setupCommand 'setupTestUser', 'bin/elasticsearch-users', 'useradd', 'test_user', '-p', 'x-pack-test-password', '-r', 'superuser'
176+
jvmArgs += ' -da:org.elasticsearch.index.mapper.MapperAssertions'
175177
clusterName = 'rolling-upgrade'
176178
unicastTransportUri = { seedNode, node, ant -> unicastSeed() }
177179
minimumMasterNodes = { 3 }

0 commit comments

Comments
 (0)