@@ -1353,7 +1353,7 @@ public Builder generateClusterUuidIfNeeded() {
1353
1353
1354
1354
public MetaData build () {
1355
1355
// TODO: We should move these datastructures to IndexNameExpressionResolver, this will give the following benefits:
1356
- // 1) The datastructures will only be rebuilded when needed. Now during serializing we rebuild these datastructures
1356
+ // 1) The datastructures will be rebuilt only when needed. Now during serializing we rebuild these datastructures
1357
1357
// while these datastructures aren't even used.
1358
1358
// 2) The aliasAndIndexLookup can be updated instead of rebuilding it all the time.
1359
1359
@@ -1391,20 +1391,21 @@ public MetaData build() {
1391
1391
// iterate again and constructs a helpful message
1392
1392
ArrayList <String > duplicates = new ArrayList <>();
1393
1393
for (ObjectCursor <IndexMetaData > cursor : indices .values ()) {
1394
- for (String alias : duplicateAliasesIndices ) {
1394
+ for (String alias : duplicateAliasesIndices ) {
1395
1395
if (cursor .value .getAliases ().containsKey (alias )) {
1396
1396
duplicates .add (alias + " (alias of " + cursor .value .getIndex () + ")" );
1397
1397
}
1398
1398
}
1399
1399
}
1400
1400
assert duplicates .size () > 0 ;
1401
1401
throw new IllegalStateException ("index and alias names need to be unique, but the following duplicates were found ["
1402
- + Strings .collectionToCommaDelimitedString (duplicates )+ "]" );
1402
+ + Strings .collectionToCommaDelimitedString (duplicates ) + "]" );
1403
1403
1404
1404
}
1405
1405
1406
1406
SortedMap <String , AliasOrIndex > aliasAndIndexLookup = Collections .unmodifiableSortedMap (buildAliasAndIndexLookup ());
1407
1407
1408
+ validateDataStreams (aliasAndIndexLookup );
1408
1409
1409
1410
// build all concrete indices arrays:
1410
1411
// TODO: I think we can remove these arrays. it isn't worth the effort, for operations on all indices.
@@ -1447,6 +1448,24 @@ private SortedMap<String, AliasOrIndex> buildAliasAndIndexLookup() {
1447
1448
return aliasAndIndexLookup ;
1448
1449
}
1449
1450
1451
+ private void validateDataStreams (SortedMap <String , AliasOrIndex > aliasAndIndexLookup ) {
1452
+ DataStreamMetadata dsMetadata = (DataStreamMetadata ) customs .get (DataStreamMetadata .TYPE );
1453
+ if (dsMetadata != null ) {
1454
+ for (DataStream ds : dsMetadata .dataStreams ().values ()) {
1455
+ if (aliasAndIndexLookup .containsKey (ds .getName ())) {
1456
+ throw new IllegalStateException ("data stream [" + ds .getName () + "] conflicts with existing index or alias" );
1457
+ }
1458
+
1459
+ SortedMap <?, ?> map = aliasAndIndexLookup .subMap (ds .getName () + "-" , ds .getName () + "." ); // '.' is the char after '-'
1460
+ if (map .size () != 0 ) {
1461
+ throw new IllegalStateException ("data stream [" + ds .getName () +
1462
+ "] could create backing indices that conflict with " + map .size () + " existing index(s) or alias(s)" +
1463
+ " including '" + map .firstKey () + "'" );
1464
+ }
1465
+ }
1466
+ }
1467
+ }
1468
+
1450
1469
public static void toXContent (MetaData metaData , XContentBuilder builder , ToXContent .Params params ) throws IOException {
1451
1470
XContentContext context = XContentContext .valueOf (params .param (CONTEXT_MODE_PARAM , CONTEXT_MODE_API ));
1452
1471
0 commit comments