Skip to content

Commit 386fc44

Browse files
committed
Revert "Remove most remaining uses of V_8_0_0 transport version (#136054)"
This reverts commit 175fe4c.
1 parent 9b335c5 commit 386fc44

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+471
-42
lines changed

server/src/main/java/org/elasticsearch/action/RoutingMissingException.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
package org.elasticsearch.action;
1111

1212
import org.elasticsearch.ElasticsearchException;
13+
import org.elasticsearch.TransportVersions;
1314
import org.elasticsearch.common.io.stream.StreamInput;
1415
import org.elasticsearch.common.io.stream.StreamOutput;
16+
import org.elasticsearch.index.mapper.MapperService;
1517
import org.elasticsearch.rest.RestStatus;
1618

1719
import java.io.IOException;
@@ -40,12 +42,18 @@ public RestStatus status() {
4042

4143
public RoutingMissingException(StreamInput in) throws IOException {
4244
super(in);
45+
if (in.getTransportVersion().before(TransportVersions.V_8_0_0)) {
46+
in.readString();
47+
}
4348
id = in.readString();
4449
}
4550

4651
@Override
4752
protected void writeTo(StreamOutput out, Writer<Throwable> nestedExceptionsWriter) throws IOException {
4853
super.writeTo(out, nestedExceptionsWriter);
54+
if (out.getTransportVersion().before(TransportVersions.V_8_0_0)) {
55+
out.writeString(MapperService.SINGLE_MAPPING_NAME);
56+
}
4957
out.writeString(id);
5058
}
5159
}

server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexRequest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
package org.elasticsearch.action.admin.indices.get;
1111

12+
import org.elasticsearch.TransportVersions;
1213
import org.elasticsearch.action.ActionRequestValidationException;
1314
import org.elasticsearch.action.IndicesRequest;
1415
import org.elasticsearch.action.support.IndicesOptions;
@@ -112,6 +113,9 @@ public GetIndexRequest(TimeValue masterTimeout) {
112113
public GetIndexRequest(StreamInput in) throws IOException {
113114
super(in);
114115
indices = in.readStringArray();
116+
if (in.getTransportVersion().before(TransportVersions.V_8_0_0)) {
117+
in.readStringArray();
118+
}
115119
indicesOptions = IndicesOptions.readIndicesOptions(in);
116120
features = in.readArray(i -> Feature.fromId(i.readByte()), Feature[]::new);
117121
humanReadable = in.readBoolean();

server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
package org.elasticsearch.action.admin.indices.get;
1111

12+
import org.elasticsearch.TransportVersions;
1213
import org.elasticsearch.action.ActionResponse;
1314
import org.elasticsearch.cluster.metadata.AliasMetadata;
1415
import org.elasticsearch.cluster.metadata.MappingMetadata;
@@ -19,6 +20,7 @@
1920
import org.elasticsearch.common.settings.Settings;
2021
import org.elasticsearch.common.xcontent.ChunkedToXContentObject;
2122
import org.elasticsearch.core.UpdateForV10;
23+
import org.elasticsearch.index.mapper.MapperService;
2224
import org.elasticsearch.xcontent.ToXContent;
2325

2426
import java.io.IOException;
@@ -75,10 +77,18 @@ public GetIndexResponse(
7577
@UpdateForV10(owner = UpdateForV10.Owner.DATA_MANAGEMENT)
7678
GetIndexResponse(StreamInput in) throws IOException {
7779
this.indices = in.readStringArray();
78-
mappings = in.readImmutableOpenMap(
79-
StreamInput::readString,
80-
i -> i.readBoolean() ? new MappingMetadata(i) : MappingMetadata.EMPTY_MAPPINGS
81-
);
80+
mappings = in.readImmutableOpenMap(StreamInput::readString, in.getTransportVersion().before(TransportVersions.V_8_0_0) ? i -> {
81+
int numMappings = i.readVInt();
82+
assert numMappings == 0 || numMappings == 1 : "Expected 0 or 1 mappings but got " + numMappings;
83+
if (numMappings == 1) {
84+
String type = i.readString();
85+
assert MapperService.SINGLE_MAPPING_NAME.equals(type) : "Expected [_doc] but got [" + type + "]";
86+
return new MappingMetadata(i);
87+
} else {
88+
return MappingMetadata.EMPTY_MAPPINGS;
89+
}
90+
} : i -> i.readBoolean() ? new MappingMetadata(i) : MappingMetadata.EMPTY_MAPPINGS);
91+
8292
aliases = in.readImmutableOpenMap(StreamInput::readString, i -> i.readCollectionAsList(AliasMetadata::new));
8393
settings = in.readImmutableOpenMap(StreamInput::readString, Settings::readSettingsFromStream);
8494
defaultSettings = in.readImmutableOpenMap(StreamInput::readString, Settings::readSettingsFromStream);

server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsIndexRequest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010
package org.elasticsearch.action.admin.indices.mapping.get;
1111

12+
import org.elasticsearch.TransportVersions;
1213
import org.elasticsearch.action.ActionRequestValidationException;
1314
import org.elasticsearch.action.OriginalIndices;
1415
import org.elasticsearch.action.support.IndicesOptions;
1516
import org.elasticsearch.action.support.single.shard.SingleShardRequest;
17+
import org.elasticsearch.common.Strings;
1618
import org.elasticsearch.common.io.stream.StreamInput;
1719
import org.elasticsearch.common.io.stream.StreamOutput;
1820

@@ -27,8 +29,14 @@ public class GetFieldMappingsIndexRequest extends SingleShardRequest<GetFieldMap
2729

2830
GetFieldMappingsIndexRequest(StreamInput in) throws IOException {
2931
super(in);
32+
if (in.getTransportVersion().before(TransportVersions.V_8_0_0)) {
33+
in.readStringArray(); // former types array
34+
}
3035
fields = in.readStringArray();
3136
includeDefaults = in.readBoolean();
37+
if (in.getTransportVersion().before(TransportVersions.V_8_0_0)) {
38+
in.readBoolean(); // former probablySingleField boolean
39+
}
3240
originalIndices = OriginalIndices.readOriginalIndices(in);
3341
}
3442

@@ -66,8 +74,14 @@ public IndicesOptions indicesOptions() {
6674
@Override
6775
public void writeTo(StreamOutput out) throws IOException {
6876
super.writeTo(out);
77+
if (out.getTransportVersion().before(TransportVersions.V_8_0_0)) {
78+
out.writeStringArray(Strings.EMPTY_ARRAY);
79+
}
6980
out.writeStringArray(fields);
7081
out.writeBoolean(includeDefaults);
82+
if (out.getTransportVersion().before(TransportVersions.V_8_0_0)) {
83+
out.writeBoolean(false);
84+
}
7185
OriginalIndices.writeOriginalIndices(originalIndices, out);
7286
}
7387

server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsRequest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
package org.elasticsearch.action.admin.indices.mapping.get;
1111

12+
import org.elasticsearch.TransportVersions;
1213
import org.elasticsearch.action.ActionRequestValidationException;
1314
import org.elasticsearch.action.IndicesRequest;
1415
import org.elasticsearch.action.LegacyActionRequest;
@@ -18,6 +19,7 @@
1819
import org.elasticsearch.common.io.stream.StreamOutput;
1920

2021
import java.io.IOException;
22+
import java.util.Arrays;
2123

2224
/**
2325
* Request the mappings of specific fields
@@ -40,7 +42,18 @@ public GetFieldMappingsRequest() {}
4042
public GetFieldMappingsRequest(StreamInput in) throws IOException {
4143
super(in);
4244
indices = in.readStringArray();
45+
if (in.getTransportVersion().before(TransportVersions.V_8_0_0)) {
46+
String[] types = in.readStringArray();
47+
if (types != Strings.EMPTY_ARRAY) {
48+
throw new IllegalArgumentException("Expected empty type array but received [" + Arrays.toString(types) + "]");
49+
}
50+
51+
}
4352
indicesOptions = IndicesOptions.readIndicesOptions(in);
53+
// Consume the deprecated local parameter
54+
if (in.getTransportVersion().before(TransportVersions.V_8_0_0)) {
55+
in.readBoolean();
56+
}
4457
fields = in.readStringArray();
4558
includeDefaults = in.readBoolean();
4659
}
@@ -104,7 +117,13 @@ public ActionRequestValidationException validate() {
104117
public void writeTo(StreamOutput out) throws IOException {
105118
super.writeTo(out);
106119
out.writeStringArray(indices);
120+
if (out.getTransportVersion().before(TransportVersions.V_8_0_0)) {
121+
out.writeStringArray(Strings.EMPTY_ARRAY);
122+
}
107123
indicesOptions.writeIndicesOptions(out);
124+
if (out.getTransportVersion().before(TransportVersions.V_8_0_0)) {
125+
out.writeBoolean(true);
126+
}
108127
out.writeStringArray(fields);
109128
out.writeBoolean(includeDefaults);
110129
}

server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99

1010
package org.elasticsearch.action.admin.indices.mapping.get;
1111

12+
import org.elasticsearch.TransportVersions;
1213
import org.elasticsearch.action.ActionResponse;
1314
import org.elasticsearch.common.bytes.BytesReference;
1415
import org.elasticsearch.common.io.stream.StreamInput;
1516
import org.elasticsearch.common.io.stream.StreamOutput;
1617
import org.elasticsearch.common.xcontent.XContentHelper;
1718
import org.elasticsearch.index.mapper.Mapper;
19+
import org.elasticsearch.index.mapper.MapperService;
1820
import org.elasticsearch.xcontent.ParseField;
1921
import org.elasticsearch.xcontent.ToXContentFragment;
2022
import org.elasticsearch.xcontent.ToXContentObject;
@@ -23,6 +25,7 @@
2325

2426
import java.io.IOException;
2527
import java.io.InputStream;
28+
import java.util.Collections;
2629
import java.util.Map;
2730
import java.util.Objects;
2831

@@ -43,9 +46,17 @@ public class GetFieldMappingsResponse extends ActionResponse implements ToXConte
4346
}
4447

4548
GetFieldMappingsResponse(StreamInput in) throws IOException {
46-
mappings = in.readImmutableMap(
47-
mapIn -> mapIn.readImmutableMap(inpt -> new FieldMappingMetadata(inpt.readString(), inpt.readBytesReference()))
48-
);
49+
mappings = in.readImmutableMap(mapIn -> {
50+
if (mapIn.getTransportVersion().before(TransportVersions.V_8_0_0)) {
51+
int typesSize = mapIn.readVInt();
52+
assert typesSize == 1 || typesSize == 0 : "Expected 0 or 1 types but got " + typesSize;
53+
if (typesSize == 0) {
54+
return Collections.emptyMap();
55+
}
56+
mapIn.readString(); // type
57+
}
58+
return mapIn.readImmutableMap(inpt -> new FieldMappingMetadata(inpt.readString(), inpt.readBytesReference()));
59+
});
4960
}
5061

5162
/** returns the retrieved field mapping. The return map keys are index, field (as specified in the request). */
@@ -123,6 +134,10 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
123134
@Override
124135
public void writeTo(StreamOutput out) throws IOException {
125136
out.writeMap(mappings, (outpt, map) -> {
137+
if (outpt.getTransportVersion().before(TransportVersions.V_8_0_0)) {
138+
outpt.writeVInt(1);
139+
outpt.writeString(MapperService.SINGLE_MAPPING_NAME);
140+
}
126141
outpt.writeMap(map, (o, v) -> {
127142
o.writeString(v.fullName());
128143
o.writeBytesReference(v.source);

server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsRequest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
package org.elasticsearch.action.admin.indices.mapping.get;
1111

12+
import org.elasticsearch.TransportVersions;
1213
import org.elasticsearch.action.ActionRequestValidationException;
1314
import org.elasticsearch.action.IndicesRequest;
1415
import org.elasticsearch.action.support.IndicesOptions;
@@ -42,6 +43,9 @@ public GetMappingsRequest(TimeValue masterTimeout) {
4243
public GetMappingsRequest(StreamInput in) throws IOException {
4344
super(in);
4445
indices = in.readStringArray();
46+
if (in.getTransportVersion().before(TransportVersions.V_8_0_0)) {
47+
in.readStringArray();
48+
}
4549
indicesOptions = IndicesOptions.readIndicesOptions(in);
4650
}
4751

server/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.elasticsearch.action.admin.indices.mapping.put;
1111

1212
import org.elasticsearch.ElasticsearchGenerationException;
13+
import org.elasticsearch.TransportVersions;
1314
import org.elasticsearch.action.ActionRequestValidationException;
1415
import org.elasticsearch.action.IndicesRequest;
1516
import org.elasticsearch.action.support.IndicesOptions;
@@ -23,6 +24,7 @@
2324
import org.elasticsearch.common.util.CollectionUtils;
2425
import org.elasticsearch.common.xcontent.XContentHelper;
2526
import org.elasticsearch.index.Index;
27+
import org.elasticsearch.index.mapper.MapperService;
2628
import org.elasticsearch.xcontent.XContentBuilder;
2729
import org.elasticsearch.xcontent.XContentFactory;
2830
import org.elasticsearch.xcontent.XContentType;
@@ -95,6 +97,12 @@ public PutMappingRequest(StreamInput in) throws IOException {
9597
super(in);
9698
indices = in.readStringArray();
9799
indicesOptions = IndicesOptions.readIndicesOptions(in);
100+
if (in.getTransportVersion().before(TransportVersions.V_8_0_0)) {
101+
String type = in.readOptionalString();
102+
if (MapperService.SINGLE_MAPPING_NAME.equals(type) == false) {
103+
throw new IllegalArgumentException("Expected type [_doc] but received [" + type + "]");
104+
}
105+
}
98106
source = in.readString();
99107
concreteIndex = in.readOptionalWriteable(Index::new);
100108
origin = in.readOptionalString();
@@ -322,6 +330,9 @@ public void writeTo(StreamOutput out) throws IOException {
322330
super.writeTo(out);
323331
out.writeStringArrayNullable(indices);
324332
indicesOptions.writeIndicesOptions(out);
333+
if (out.getTransportVersion().before(TransportVersions.V_8_0_0)) {
334+
out.writeOptionalString(MapperService.SINGLE_MAPPING_NAME);
335+
}
325336
out.writeString(source);
326337
out.writeOptionalWriteable(concreteIndex);
327338
out.writeOptionalString(origin);

server/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentsRequest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public IndicesSegmentsRequest() {
3131

3232
public IndicesSegmentsRequest(StreamInput in) throws IOException {
3333
super(in);
34+
if (in.getTransportVersion().before(TransportVersions.V_8_0_0)) {
35+
in.readBoolean(); // old 'verbose' option, since removed
36+
}
3437
if (in.getTransportVersion().onOrAfter(TransportVersions.V_8_15_0)) {
3538
this.includeVectorFormatsInfo = in.readBoolean();
3639
}
@@ -53,6 +56,9 @@ public boolean isIncludeVectorFormatsInfo() {
5356
@Override
5457
public void writeTo(StreamOutput out) throws IOException {
5558
super.writeTo(out);
59+
if (out.getTransportVersion().before(TransportVersions.V_8_0_0)) {
60+
out.writeBoolean(false);
61+
}
5662
if (out.getTransportVersion().onOrAfter(TransportVersions.V_8_15_0)) {
5763
out.writeBoolean(includeVectorFormatsInfo);
5864
}

server/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import org.elasticsearch.ElasticsearchGenerationException;
1212
import org.elasticsearch.ElasticsearchParseException;
13+
import org.elasticsearch.TransportVersions;
1314
import org.elasticsearch.action.ActionRequestValidationException;
1415
import org.elasticsearch.action.IndicesRequest;
1516
import org.elasticsearch.action.admin.indices.alias.Alias;
@@ -76,7 +77,15 @@ public PutIndexTemplateRequest(StreamInput in) throws IOException {
7677
order = in.readInt();
7778
create = in.readBoolean();
7879
settings = readSettingsFromStream(in);
79-
mappings = in.readOptionalString();
80+
if (in.getTransportVersion().before(TransportVersions.V_8_0_0)) {
81+
int size = in.readVInt();
82+
for (int i = 0; i < size; i++) {
83+
in.readString(); // type - cannot assert on _doc because 7x allows arbitrary type names
84+
this.mappings = in.readString();
85+
}
86+
} else {
87+
this.mappings = in.readOptionalString();
88+
}
8089
int aliasesSize = in.readVInt();
8190
for (int i = 0; i < aliasesSize; i++) {
8291
aliases.add(new Alias(in));
@@ -441,7 +450,15 @@ public void writeTo(StreamOutput out) throws IOException {
441450
out.writeInt(order);
442451
out.writeBoolean(create);
443452
settings.writeTo(out);
444-
out.writeOptionalString(mappings);
453+
if (out.getTransportVersion().before(TransportVersions.V_8_0_0)) {
454+
out.writeVInt(mappings == null ? 0 : 1);
455+
if (mappings != null) {
456+
out.writeString(MapperService.SINGLE_MAPPING_NAME);
457+
out.writeString(mappings);
458+
}
459+
} else {
460+
out.writeOptionalString(mappings);
461+
}
445462
out.writeCollection(aliases);
446463
out.writeOptionalVInt(version);
447464
}

0 commit comments

Comments
 (0)