|
@@ -8,6 +8,8 @@
|
|
|
|
|
|
package org.elasticsearch.cluster.metadata;
|
|
package org.elasticsearch.cluster.metadata;
|
|
|
|
|
|
|
|
+import org.apache.logging.log4j.LogManager;
|
|
|
|
+import org.apache.logging.log4j.Logger;
|
|
import org.elasticsearch.Version;
|
|
import org.elasticsearch.Version;
|
|
import org.elasticsearch.action.admin.indices.rollover.RolloverInfo;
|
|
import org.elasticsearch.action.admin.indices.rollover.RolloverInfo;
|
|
import org.elasticsearch.action.support.ActiveShardCount;
|
|
import org.elasticsearch.action.support.ActiveShardCount;
|
|
@@ -83,6 +85,8 @@ import static org.elasticsearch.snapshots.SearchableSnapshotsSettings.SEARCHABLE
|
|
|
|
|
|
public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragment {
|
|
public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragment {
|
|
|
|
|
|
|
|
+ private static final Logger logger = LogManager.getLogger(IndexMetadata.class);
|
|
|
|
+
|
|
public static final ClusterBlock INDEX_READ_ONLY_BLOCK = new ClusterBlock(
|
|
public static final ClusterBlock INDEX_READ_ONLY_BLOCK = new ClusterBlock(
|
|
5,
|
|
5,
|
|
"index read-only (api)",
|
|
"index read-only (api)",
|
|
@@ -1589,7 +1593,7 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
builder.stats(stats);
|
|
builder.stats(stats);
|
|
builder.indexWriteLoadForecast(indexWriteLoadForecast);
|
|
builder.indexWriteLoadForecast(indexWriteLoadForecast);
|
|
builder.shardSizeInBytesForecast(shardSizeInBytesForecast);
|
|
builder.shardSizeInBytesForecast(shardSizeInBytesForecast);
|
|
- return builder.build();
|
|
|
|
|
|
+ return builder.build(true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1656,7 +1660,7 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
builder.indexWriteLoadForecast(in.readOptionalDouble());
|
|
builder.indexWriteLoadForecast(in.readOptionalDouble());
|
|
builder.shardSizeInBytesForecast(in.readOptionalLong());
|
|
builder.shardSizeInBytesForecast(in.readOptionalLong());
|
|
}
|
|
}
|
|
- return builder.build();
|
|
|
|
|
|
+ return builder.build(true);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -2012,6 +2016,11 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
}
|
|
}
|
|
|
|
|
|
public IndexMetadata build() {
|
|
public IndexMetadata build() {
|
|
|
|
+ return build(false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // package private for testing
|
|
|
|
+ IndexMetadata build(boolean repair) {
|
|
/*
|
|
/*
|
|
* We expect that the metadata has been properly built to set the number of shards and the number of replicas, and do not rely
|
|
* We expect that the metadata has been properly built to set the number of shards and the number of replicas, and do not rely
|
|
* on the default values here. Those must have been set upstream.
|
|
* on the default values here. Those must have been set upstream.
|
|
@@ -2140,7 +2149,16 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
var aliasesMap = aliases.build();
|
|
var aliasesMap = aliases.build();
|
|
for (AliasMetadata alias : aliasesMap.values()) {
|
|
for (AliasMetadata alias : aliasesMap.values()) {
|
|
if (alias.alias().equals(index)) {
|
|
if (alias.alias().equals(index)) {
|
|
- throw new IllegalArgumentException("alias name [" + index + "] self-conflicts with index name");
|
|
|
|
|
|
+ if (repair && indexCreatedVersion.equals(Version.V_8_5_0)) {
|
|
|
|
+ var updatedBuilder = ImmutableOpenMap.builder(aliasesMap);
|
|
|
|
+ final var brokenAlias = updatedBuilder.remove(index);
|
|
|
|
+ final var fixedAlias = AliasMetadata.newAliasMetadata(brokenAlias, index + "-alias-corrupted-by-8-5");
|
|
|
|
+ aliasesMap = updatedBuilder.fPut(fixedAlias.getAlias(), fixedAlias).build();
|
|
|
|
+ logger.warn("Repaired corrupted alias with the same name as its index for [{}]", index);
|
|
|
|
+ break;
|
|
|
|
+ } else {
|
|
|
|
+ throw new IllegalArgumentException("alias name [" + index + "] self-conflicts with index name");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2463,7 +2481,7 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
assert settingsVersion : "settings version should be present for indices created on or after 6.5.0";
|
|
assert settingsVersion : "settings version should be present for indices created on or after 6.5.0";
|
|
assert indexCreatedVersion(builder.settings).before(Version.V_7_2_0) || aliasesVersion
|
|
assert indexCreatedVersion(builder.settings).before(Version.V_7_2_0) || aliasesVersion
|
|
: "aliases version should be present for indices created on or after 7.2.0";
|
|
: "aliases version should be present for indices created on or after 7.2.0";
|
|
- return builder.build();
|
|
|
|
|
|
+ return builder.build(true);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -2574,7 +2592,7 @@ public class IndexMetadata implements Diffable<IndexMetadata>, ToXContentFragmen
|
|
builder.putMapping(MappingMetadata.EMPTY_MAPPINGS); // just make sure it's not empty so that _source can be read
|
|
builder.putMapping(MappingMetadata.EMPTY_MAPPINGS); // just make sure it's not empty so that _source can be read
|
|
}
|
|
}
|
|
|
|
|
|
- IndexMetadata indexMetadata = builder.build();
|
|
|
|
|
|
+ IndexMetadata indexMetadata = builder.build(true);
|
|
assert indexMetadata.getCreationVersion().isLegacyIndexVersion();
|
|
assert indexMetadata.getCreationVersion().isLegacyIndexVersion();
|
|
assert indexMetadata.getCompatibilityVersion().isLegacyIndexVersion();
|
|
assert indexMetadata.getCompatibilityVersion().isLegacyIndexVersion();
|
|
return indexMetadata;
|
|
return indexMetadata;
|