Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
public static final String EVENT_INGESTED_FIELD_NAME = "event.ingested";

private static final TransportVersion INDEX_RESHARDING_METADATA = TransportVersion.fromName("index_resharding_metadata");
private static final TransportVersion INDEX_CREATED_TRANSPORT_VERSION = TransportVersion.fromName("index_created_transport_version");

@Nullable
public String getDownsamplingInterval() {
Expand Down Expand Up @@ -586,6 +587,7 @@ public Iterator<Setting<?>> settings() {
public static final List<String> PARTIALLY_MOUNTED_INDEX_TIER_PREFERENCE = List.of(DataTier.DATA_FROZEN);

static final String KEY_VERSION = "version";
static final String KEY_TRANSPORT_VERSION = "transport_version";
static final String KEY_MAPPING_VERSION = "mapping_version";
static final String KEY_SETTINGS_VERSION = "settings_version";
static final String KEY_ALIASES_VERSION = "aliases_version";
Expand Down Expand Up @@ -626,6 +628,7 @@ public Iterator<Setting<?>> settings() {

private final Index index;
private final long version;
private final TransportVersion transportVersion;

private final long mappingVersion;

Expand Down Expand Up @@ -713,6 +716,7 @@ public Iterator<Setting<?>> settings() {
private IndexMetadata(
final Index index,
final long version,
final TransportVersion transportVersion,
final long mappingVersion,
final long settingsVersion,
final long aliasesVersion,
Expand Down Expand Up @@ -764,6 +768,7 @@ private IndexMetadata(
) {
this.index = index;
this.version = version;
this.transportVersion = transportVersion;
assert mappingVersion >= 0 : mappingVersion;
this.mappingVersion = mappingVersion;
this.mappingsUpdatedVersion = mappingsUpdatedVersion;
Expand Down Expand Up @@ -831,6 +836,7 @@ IndexMetadata withMappingMetadata(MappingMetadata mapping) {
return new IndexMetadata(
this.index,
this.version,
this.transportVersion,
this.mappingVersion,
this.settingsVersion,
this.aliasesVersion,
Expand Down Expand Up @@ -895,6 +901,7 @@ public IndexMetadata withInSyncAllocationIds(int shardId, Set<String> inSyncSet)
return new IndexMetadata(
this.index,
this.version,
this.transportVersion,
this.mappingVersion,
this.settingsVersion,
this.aliasesVersion,
Expand Down Expand Up @@ -967,6 +974,7 @@ public IndexMetadata withSetPrimaryTerm(int shardId, long primaryTerm) {
return new IndexMetadata(
this.index,
this.version,
this.transportVersion,
this.mappingVersion,
this.settingsVersion,
this.aliasesVersion,
Expand Down Expand Up @@ -1030,6 +1038,7 @@ public IndexMetadata withTimestampRanges(IndexLongFieldRange timestampRange, Ind
return new IndexMetadata(
this.index,
this.version,
this.transportVersion,
this.mappingVersion,
this.settingsVersion,
this.aliasesVersion,
Expand Down Expand Up @@ -1088,6 +1097,7 @@ public IndexMetadata withIncrementedVersion() {
return new IndexMetadata(
this.index,
this.version + 1,
this.transportVersion,
this.mappingVersion,
this.settingsVersion,
this.aliasesVersion,
Expand Down Expand Up @@ -1151,6 +1161,10 @@ public long getVersion() {
return this.version;
}

public TransportVersion getTransportVersion() {
return transportVersion;
}

public long getMappingVersion() {
return mappingVersion;
}
Expand Down Expand Up @@ -1658,6 +1672,7 @@ private static class IndexMetadataDiff implements Diff<IndexMetadata> {
private final String index;
private final int routingNumShards;
private final long version;
private final TransportVersion transportVersion;
private final long mappingVersion;
private final long settingsVersion;
private final long aliasesVersion;
Expand Down Expand Up @@ -1691,6 +1706,7 @@ private static class IndexMetadataDiff implements Diff<IndexMetadata> {
IndexMetadataDiff(IndexMetadata before, IndexMetadata after) {
index = after.index.getName();
version = after.version;
transportVersion = after.transportVersion;
mappingVersion = after.mappingVersion;
settingsVersion = after.settingsVersion;
aliasesVersion = after.aliasesVersion;
Expand Down Expand Up @@ -1744,6 +1760,9 @@ private static class IndexMetadataDiff implements Diff<IndexMetadata> {
index = in.readString();
routingNumShards = in.readInt();
version = in.readLong();
transportVersion = in.getTransportVersion().supports(INDEX_CREATED_TRANSPORT_VERSION)
? TransportVersion.readVersion(in)
: TransportVersion.fromId(0);
mappingVersion = in.readVLong();
settingsVersion = in.readVLong();
aliasesVersion = in.readVLong();
Expand Down Expand Up @@ -1811,6 +1830,9 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeString(index);
out.writeInt(routingNumShards);
out.writeLong(version);
if (out.getTransportVersion().supports(INDEX_CREATED_TRANSPORT_VERSION)) {
TransportVersion.writeVersion(transportVersion, out);
}
out.writeVLong(mappingVersion);
out.writeVLong(settingsVersion);
out.writeVLong(aliasesVersion);
Expand Down Expand Up @@ -1851,6 +1873,7 @@ public void writeTo(StreamOutput out) throws IOException {
public IndexMetadata apply(IndexMetadata part) {
Builder builder = builder(index);
builder.version(version);
builder.transportVersion(transportVersion);
builder.mappingVersion(mappingVersion);
builder.settingsVersion(settingsVersion);
builder.aliasesVersion(aliasesVersion);
Expand Down Expand Up @@ -1894,6 +1917,11 @@ public static IndexMetadata readFrom(StreamInput in) throws IOException {
public static IndexMetadata readFrom(StreamInput in, @Nullable Function<String, MappingMetadata> mappingLookup) throws IOException {
Builder builder = new Builder(in.readString());
builder.version(in.readLong());
builder.transportVersion(
in.getTransportVersion().supports(INDEX_CREATED_TRANSPORT_VERSION)
? TransportVersion.readVersion(in)
: TransportVersion.fromId(0)
);
builder.mappingVersion(in.readVLong());
builder.settingsVersion(in.readVLong());
builder.aliasesVersion(in.readVLong());
Expand Down Expand Up @@ -1961,6 +1989,9 @@ public static IndexMetadata readFrom(StreamInput in, @Nullable Function<String,
public void writeTo(StreamOutput out, boolean mappingsAsHash) throws IOException {
out.writeString(index.getName()); // uuid will come as part of settings
out.writeLong(version);
if (out.getTransportVersion().supports(INDEX_CREATED_TRANSPORT_VERSION)) {
TransportVersion.writeVersion(transportVersion, out);
}
out.writeVLong(mappingVersion);
out.writeVLong(settingsVersion);
out.writeVLong(aliasesVersion);
Expand Down Expand Up @@ -2036,6 +2067,7 @@ public static class Builder {
private String index;
private State state = State.OPEN;
private long version = 1;
private TransportVersion transportVersion = TransportVersion.fromId(0);
private long mappingVersion = 1;
private long settingsVersion = 1;
private long aliasesVersion = 1;
Expand Down Expand Up @@ -2072,6 +2104,7 @@ public Builder(IndexMetadata indexMetadata) {
this.index = indexMetadata.getIndex().getName();
this.state = indexMetadata.state;
this.version = indexMetadata.version;
this.transportVersion = indexMetadata.transportVersion;
this.mappingVersion = indexMetadata.mappingVersion;
this.settingsVersion = indexMetadata.settingsVersion;
this.aliasesVersion = indexMetadata.aliasesVersion;
Expand Down Expand Up @@ -2280,6 +2313,15 @@ public Builder version(long version) {
return this;
}

public TransportVersion transportVersion() {
return this.transportVersion;
}

public Builder transportVersion(TransportVersion transportVersion) {
this.transportVersion = transportVersion;
return this;
}

public long mappingVersion() {
return mappingVersion;
}
Expand Down Expand Up @@ -2555,6 +2597,7 @@ IndexMetadata build(boolean repair) {
return new IndexMetadata(
new Index(index, uuid),
version,
transportVersion,
mappingVersion,
settingsVersion,
aliasesVersion,
Expand Down Expand Up @@ -2615,6 +2658,7 @@ public static void toXContent(IndexMetadata indexMetadata, XContentBuilder build
builder.startObject(indexMetadata.getIndex().getName());

builder.field(KEY_VERSION, indexMetadata.getVersion());
builder.field(KEY_TRANSPORT_VERSION, indexMetadata.getTransportVersion().toString());
builder.field(KEY_MAPPING_VERSION, indexMetadata.getMappingVersion());
builder.field(KEY_SETTINGS_VERSION, indexMetadata.getSettingsVersion());
builder.field(KEY_ALIASES_VERSION, indexMetadata.getAliasesVersion());
Expand Down Expand Up @@ -2872,6 +2916,7 @@ public static IndexMetadata fromXContent(XContentParser parser, Map<String, Mapp
switch (currentFieldName) {
case KEY_STATE -> builder.state(State.fromString(parser.text()));
case KEY_VERSION -> builder.version(parser.longValue());
case KEY_TRANSPORT_VERSION -> builder.transportVersion(TransportVersion.fromString(parser.text()));
case KEY_MAPPING_VERSION -> {
mappingVersion = true;
builder.mappingVersion(parser.longValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ private IndexMetadata buildAndValidateTemporaryIndexMetadata(
final IndexMetadata.Builder tmpImdBuilder = IndexMetadata.builder(request.index());
tmpImdBuilder.setRoutingNumShards(routingNumShards);
tmpImdBuilder.settings(indexSettings);
tmpImdBuilder.transportVersion(TransportVersion.current());
tmpImdBuilder.system(isSystem);

// Set up everything, now locally create the index to see that things are ok, and apply
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9221000,9185009,9112014,8841075
2 changes: 1 addition & 1 deletion server/src/main/resources/transport/upper_bounds/8.19.csv
Original file line number Diff line number Diff line change
@@ -1 +1 @@
batched_response_might_include_reduction_failure,8841074
index_created_transport_version,8841075
2 changes: 1 addition & 1 deletion server/src/main/resources/transport/upper_bounds/9.1.csv
Original file line number Diff line number Diff line change
@@ -1 +1 @@
initial_9.1.8,9112013
index_created_transport_version,9112014
2 changes: 1 addition & 1 deletion server/src/main/resources/transport/upper_bounds/9.2.csv
Original file line number Diff line number Diff line change
@@ -1 +1 @@
initial_9.2.2,9185008
index_created_transport_version,9185009
2 changes: 1 addition & 1 deletion server/src/main/resources/transport/upper_bounds/9.3.csv
Original file line number Diff line number Diff line change
@@ -1 +1 @@
get_inference_fields_action,9220000
index_created_transport_version,9221000
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public void testToXContentWithDeprecatedClusterState() {
"indices": {
"index": {
"version": 1,
"transport_version" : "0",
"mapping_version": 1,
"settings_version": 1,
"aliases_version": 1,
Expand Down Expand Up @@ -249,6 +250,7 @@ public void testToXContentWithDeprecatedClusterStateAndMetadata() {
"indices" : {
"index" : {
"version" : 1,
"transport_version" : "0",
"mapping_version" : 1,
"settings_version" : 1,
"aliases_version" : 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ public void testToXContentWithMultipleProjects() throws IOException {
"indices": {
"common-index": {
"version": 2,
"transport_version" : "0",
"mapping_version": 1,
"settings_version": 1,
"aliases_version": 1,
Expand Down Expand Up @@ -529,6 +530,7 @@ public void testToXContentWithMultipleProjects() throws IOException {
"indices": {
"another-index": {
"version": 2,
"transport_version" : "0",
"mapping_version": 1,
"settings_version": 1,
"aliases_version": 1,
Expand All @@ -554,6 +556,7 @@ public void testToXContentWithMultipleProjects() throws IOException {
},
"common-index": {
"version": 2,
"transport_version" : "0",
"mapping_version": 1,
"settings_version": 1,
"aliases_version": 1,
Expand Down Expand Up @@ -1105,6 +1108,7 @@ public void testToXContent() throws IOException {
"indices": {
"index": {
"version": 1,
"transport_version" : "0",
"mapping_version": 1,
"settings_version": 1,
"aliases_version": 1,
Expand Down Expand Up @@ -1381,6 +1385,7 @@ public void testToXContent_FlatSettingTrue_ReduceMappingFalse() throws IOExcepti
"indices" : {
"index" : {
"version" : 1,
"transport_version" : "0",
"mapping_version" : 1,
"settings_version" : 1,
"aliases_version" : 1,
Expand Down Expand Up @@ -1663,6 +1668,7 @@ public void testToXContent_FlatSettingFalse_ReduceMappingTrue() throws IOExcepti
"indices" : {
"index" : {
"version" : 1,
"transport_version" : "0",
"mapping_version" : 1,
"settings_version" : 1,
"aliases_version" : 1,
Expand Down Expand Up @@ -1854,6 +1860,7 @@ public void testToXContentSameTypeName() throws IOException {
"indices" : {
"index" : {
"version" : 2,
"transport_version" : "0",
"mapping_version" : 1,
"settings_version" : 1,
"aliases_version" : 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public void testIndexMetadataSerialization() throws IOException {

IndexMetadata metadata = IndexMetadata.builder("foo")
.settings(indexSettings(numShard, numberOfReplicas).put("index.version.created", 1))
.transportVersion(TransportVersion.current())
.creationDate(randomLong())
.primaryTerm(0, 2)
.setRoutingNumShards(32)
Expand Down Expand Up @@ -152,6 +153,7 @@ public void testIndexMetadataSerialization() throws IOException {
);
assertEquals(metadata.hashCode(), fromXContentMeta.hashCode());

assertEquals(metadata.getTransportVersion(), fromXContentMeta.getTransportVersion());
assertEquals(metadata.getNumberOfReplicas(), fromXContentMeta.getNumberOfReplicas());
assertEquals(metadata.getNumberOfShards(), fromXContentMeta.getNumberOfShards());
assertEquals(metadata.getCreationVersion(), fromXContentMeta.getCreationVersion());
Expand Down Expand Up @@ -179,6 +181,7 @@ public void testIndexMetadataSerialization() throws IOException {
assertEquals(metadata, deserialized);
assertEquals(metadata.hashCode(), deserialized.hashCode());

assertEquals(metadata.getTransportVersion(), deserialized.getTransportVersion());
assertEquals(metadata.getNumberOfReplicas(), deserialized.getNumberOfReplicas());
assertEquals(metadata.getNumberOfShards(), deserialized.getNumberOfShards());
assertEquals(metadata.getCreationVersion(), deserialized.getCreationVersion());
Expand Down Expand Up @@ -215,6 +218,7 @@ public void testIndexMetadataFromXContentParsingWithoutEventIngestedField() thro

IndexMetadata metadata = IndexMetadata.builder("foo")
.settings(indexSettings(numShard, numberOfReplicas).put("index.version.created", 1))
.transportVersion(TransportVersion.current())
.creationDate(randomLong())
.primaryTerm(0, 2)
.setRoutingNumShards(32)
Expand Down Expand Up @@ -283,6 +287,7 @@ public void testIndexMetadataFromXContentParsingWithoutEventIngestedField() thro
fromXContentMeta
);
assertEquals(metadata.hashCode(), fromXContentMeta.hashCode());
assertEquals(metadata.getTransportVersion(), fromXContentMeta.getTransportVersion());
assertEquals(metadata.getNumberOfReplicas(), fromXContentMeta.getNumberOfReplicas());
assertEquals(metadata.getNumberOfShards(), fromXContentMeta.getNumberOfShards());
assertEquals(metadata.getCreationVersion(), fromXContentMeta.getCreationVersion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@ public void testSingleNonDefaultProjectXContent() throws IOException {
"indices": {
"index-1": {
"version": 1,
"transport_version": "0",
"mapping_version": 1,
"settings_version": 1,
"aliases_version": 1,
Expand Down Expand Up @@ -862,6 +863,7 @@ public void testSingleNonDefaultProjectXContent() throws IOException {
},
"index-2": {
"version": 1,
"transport_version": "0",
"mapping_version": 1,
"settings_version": 1,
"aliases_version": 1,
Expand Down
Loading