Skip to content

Commit e1c6fe6

Browse files
committed
Assert mapping version present
1 parent 755d4a5 commit e1c6fe6

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.carrotsearch.hppc.cursors.ObjectCursor;
2525
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
2626

27+
import org.elasticsearch.Assertions;
2728
import org.elasticsearch.Version;
2829
import org.elasticsearch.action.admin.indices.rollover.RolloverInfo;
2930
import org.elasticsearch.action.support.ActiveShardCount;
@@ -1258,6 +1259,7 @@ public static IndexMetaData fromXContent(XContentParser parser) throws IOExcepti
12581259
if (token != XContentParser.Token.START_OBJECT) {
12591260
throw new IllegalArgumentException("expected object but got a " + token);
12601261
}
1262+
boolean mappingVersion = false;
12611263
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
12621264
if (token == XContentParser.Token.FIELD_NAME) {
12631265
currentFieldName = parser.currentName();
@@ -1357,6 +1359,7 @@ public static IndexMetaData fromXContent(XContentParser parser) throws IOExcepti
13571359
} else if (KEY_VERSION.equals(currentFieldName)) {
13581360
builder.version(parser.longValue());
13591361
} else if (KEY_MAPPING_VERSION.equals(currentFieldName)) {
1362+
mappingVersion = true;
13601363
builder.mappingVersion(parser.longValue());
13611364
} else if (KEY_ROUTING_NUM_SHARDS.equals(currentFieldName)) {
13621365
builder.setRoutingNumShards(parser.intValue());
@@ -1367,6 +1370,9 @@ public static IndexMetaData fromXContent(XContentParser parser) throws IOExcepti
13671370
throw new IllegalArgumentException("Unexpected token " + token);
13681371
}
13691372
}
1373+
if (Assertions.ENABLED && Version.indexCreated(builder.settings).onOrAfter(Version.V_7_0_0_alpha1)) {
1374+
assert mappingVersion : "mapping version should be present for indices created on or after 7.0.0";
1375+
}
13701376
return builder.build();
13711377
}
13721378
}

0 commit comments

Comments
 (0)