File tree 2 files changed +25
-1
lines changed
main/java/org/elasticsearch/cluster/metadata
test/java/org/elasticsearch/cluster/metadata 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change 8
8
9
9
package org .elasticsearch .cluster .metadata ;
10
10
11
+ import org .apache .logging .log4j .LogManager ;
12
+ import org .apache .logging .log4j .Logger ;
11
13
import org .elasticsearch .Version ;
12
14
import org .elasticsearch .action .admin .indices .rollover .RolloverInfo ;
13
15
import org .elasticsearch .action .support .ActiveShardCount ;
83
85
84
86
public class IndexMetadata implements Diffable <IndexMetadata >, ToXContentFragment {
85
87
88
+ private static final Logger logger = LogManager .getLogger (IndexMetadata .class );
89
+
86
90
public static final ClusterBlock INDEX_READ_ONLY_BLOCK = new ClusterBlock (
87
91
5 ,
88
92
"index read-only (api)" ,
@@ -2140,7 +2144,16 @@ public IndexMetadata build() {
2140
2144
var aliasesMap = aliases .build ();
2141
2145
for (AliasMetadata alias : aliasesMap .values ()) {
2142
2146
if (alias .alias ().equals (index )) {
2143
- throw new IllegalArgumentException ("alias name [" + index + "] self-conflicts with index name" );
2147
+ if (indexCreatedVersion .equals (Version .V_8_5_0 )) {
2148
+ var updatedBuilder = ImmutableOpenMap .builder (aliasesMap );
2149
+ final var brokenAlias = updatedBuilder .remove (index );
2150
+ final var fixedAlias = AliasMetadata .newAliasMetadata (brokenAlias , index + "-alias-corrupted-by-8-5" );
2151
+ aliasesMap = updatedBuilder .fPut (fixedAlias .getAlias (), fixedAlias ).build ();
2152
+ logger .warn ("Repaired corrupted alias with the same name as its index for [{}]" , index );
2153
+ break ;
2154
+ } else {
2155
+ throw new IllegalArgumentException ("alias name [" + index + "] self-conflicts with index name" );
2156
+ }
2144
2157
}
2145
2158
}
2146
2159
Original file line number Diff line number Diff line change 47
47
import static org .elasticsearch .cluster .metadata .IndexMetadata .parseIndexNameCounter ;
48
48
import static org .hamcrest .Matchers .containsString ;
49
49
import static org .hamcrest .Matchers .equalTo ;
50
+ import static org .hamcrest .Matchers .hasKey ;
50
51
import static org .hamcrest .Matchers .is ;
51
52
52
53
public class IndexMetadataTests extends ESTestCase {
@@ -509,6 +510,16 @@ public void testIndexAndAliasWithSameName() {
509
510
assertEquals ("alias name [index] self-conflicts with index name" , iae .getMessage ());
510
511
}
511
512
513
+ public void testRepairIndexAndAliasWithSameName () {
514
+ final IndexMetadata indexMetadata = IndexMetadata .builder ("index" )
515
+ .settings (Settings .builder ().put (IndexMetadata .SETTING_VERSION_CREATED , Version .V_8_5_0 ))
516
+ .numberOfShards (1 )
517
+ .numberOfReplicas (0 )
518
+ .putAlias (AliasMetadata .builder ("index" ).build ())
519
+ .build ();
520
+ assertThat (indexMetadata .getAliases (), hasKey ("index-alias-corrupted-by-8-5" ));
521
+ }
522
+
512
523
private static Settings indexSettingsWithDataTier (String dataTier ) {
513
524
return Settings .builder ()
514
525
.put (IndexMetadata .SETTING_VERSION_CREATED , Version .CURRENT )
You can’t perform that action at this time.
0 commit comments