|
@@ -22,6 +22,7 @@ package org.elasticsearch.cluster.metadata;
|
|
import org.elasticsearch.Version;
|
|
import org.elasticsearch.Version;
|
|
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
|
|
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
|
|
import org.elasticsearch.cluster.ClusterModule;
|
|
import org.elasticsearch.cluster.ClusterModule;
|
|
|
|
+import org.elasticsearch.cluster.DataStreamTestHelper;
|
|
import org.elasticsearch.cluster.coordination.CoordinationMetadata;
|
|
import org.elasticsearch.cluster.coordination.CoordinationMetadata;
|
|
import org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion;
|
|
import org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion;
|
|
import org.elasticsearch.common.Strings;
|
|
import org.elasticsearch.common.Strings;
|
|
@@ -50,6 +51,7 @@ import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
|
|
+import java.util.SortedMap;
|
|
|
|
|
|
import static org.elasticsearch.cluster.DataStreamTestHelper.createBackingIndex;
|
|
import static org.elasticsearch.cluster.DataStreamTestHelper.createBackingIndex;
|
|
import static org.elasticsearch.cluster.DataStreamTestHelper.createFirstBackingIndex;
|
|
import static org.elasticsearch.cluster.DataStreamTestHelper.createFirstBackingIndex;
|
|
@@ -163,7 +165,8 @@ public class MetadataTests extends ESTestCase {
|
|
fail("exception should have been thrown");
|
|
fail("exception should have been thrown");
|
|
} catch (IllegalStateException e) {
|
|
} catch (IllegalStateException e) {
|
|
assertThat(e.getMessage(),
|
|
assertThat(e.getMessage(),
|
|
- equalTo("index and alias names need to be unique, but the following duplicates were found [index (alias of [index])]"));
|
|
|
|
|
|
+ equalTo("index, alias, and data stream names need to be unique, but the following duplicates were found [index (alias " +
|
|
|
|
+ "of [index]) conflicts with index]"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -198,7 +201,7 @@ public class MetadataTests extends ESTestCase {
|
|
metadataBuilder.build();
|
|
metadataBuilder.build();
|
|
fail("exception should have been thrown");
|
|
fail("exception should have been thrown");
|
|
} catch (IllegalStateException e) {
|
|
} catch (IllegalStateException e) {
|
|
- assertThat(e.getMessage(), startsWith("index and alias names need to be unique"));
|
|
|
|
|
|
+ assertThat(e.getMessage(), startsWith("index, alias, and data stream names need to be unique"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -925,7 +928,8 @@ public class MetadataTests extends ESTestCase {
|
|
|
|
|
|
IllegalStateException e = expectThrows(IllegalStateException.class, b::build);
|
|
IllegalStateException e = expectThrows(IllegalStateException.class, b::build);
|
|
assertThat(e.getMessage(),
|
|
assertThat(e.getMessage(),
|
|
- containsString("data stream [" + dataStreamName + "] conflicts with existing concrete index [" + dataStreamName + "]"));
|
|
|
|
|
|
+ containsString("index, alias, and data stream names need to be unique, but the following duplicates were found [data " +
|
|
|
|
+ "stream [" + dataStreamName + "] conflicts with index]"));
|
|
}
|
|
}
|
|
|
|
|
|
public void testBuilderRejectsDataStreamThatConflictsWithAlias() {
|
|
public void testBuilderRejectsDataStreamThatConflictsWithAlias() {
|
|
@@ -939,7 +943,8 @@ public class MetadataTests extends ESTestCase {
|
|
|
|
|
|
IllegalStateException e = expectThrows(IllegalStateException.class, b::build);
|
|
IllegalStateException e = expectThrows(IllegalStateException.class, b::build);
|
|
assertThat(e.getMessage(),
|
|
assertThat(e.getMessage(),
|
|
- containsString("data stream [" + dataStreamName + "] conflicts with existing alias [" + dataStreamName + "]"));
|
|
|
|
|
|
+ containsString("index, alias, and data stream names need to be unique, but the following duplicates were found [" +
|
|
|
|
+ dataStreamName + " (alias of [" + DataStream.getBackingIndexName(dataStreamName, 1) + "]) conflicts with data stream]"));
|
|
}
|
|
}
|
|
|
|
|
|
public void testBuilderRejectsDataStreamWithConflictingBackingIndices() {
|
|
public void testBuilderRejectsDataStreamWithConflictingBackingIndices() {
|
|
@@ -1026,6 +1031,54 @@ public class MetadataTests extends ESTestCase {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void testIndicesLookupRecordsDataStreamForBackingIndices() {
|
|
|
|
+ // create some indices that do not back a data stream
|
|
|
|
+ final List<Index> indices = new ArrayList<>();
|
|
|
|
+ final int numIndices = randomIntBetween(2, 5);
|
|
|
|
+ int lastIndexNum = randomIntBetween(9, 50);
|
|
|
|
+ Metadata.Builder b = Metadata.builder();
|
|
|
|
+ for (int k = 1; k <= numIndices; k++) {
|
|
|
|
+ IndexMetadata im = IndexMetadata.builder(DataStream.getBackingIndexName("index", lastIndexNum))
|
|
|
|
+ .settings(settings(Version.CURRENT))
|
|
|
|
+ .numberOfShards(1)
|
|
|
|
+ .numberOfReplicas(1)
|
|
|
|
+ .build();
|
|
|
|
+ b.put(im, false);
|
|
|
|
+ indices.add(im.getIndex());
|
|
|
|
+ lastIndexNum = randomIntBetween(lastIndexNum + 1, lastIndexNum + 50);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // create some backing indices for a data stream
|
|
|
|
+ final String dataStreamName = "my-data-stream";
|
|
|
|
+ final List<Index> backingIndices = new ArrayList<>();
|
|
|
|
+ final int numBackingIndices = randomIntBetween(2, 5);
|
|
|
|
+ int lastBackingIndexNum = 0;
|
|
|
|
+ for (int k = 1; k <= numBackingIndices; k++) {
|
|
|
|
+ lastBackingIndexNum = randomIntBetween(lastBackingIndexNum + 1, lastBackingIndexNum + 50);
|
|
|
|
+ IndexMetadata im = IndexMetadata.builder(DataStream.getBackingIndexName(dataStreamName, lastBackingIndexNum))
|
|
|
|
+ .settings(settings(Version.CURRENT))
|
|
|
|
+ .numberOfShards(1)
|
|
|
|
+ .numberOfReplicas(1)
|
|
|
|
+ .build();
|
|
|
|
+ b.put(im, false);
|
|
|
|
+ backingIndices.add(im.getIndex());
|
|
|
|
+ }
|
|
|
|
+ b.put(new DataStream(dataStreamName, "ts", backingIndices, lastBackingIndexNum));
|
|
|
|
+ Metadata metadata = b.build();
|
|
|
|
+
|
|
|
|
+ SortedMap<String, IndexAbstraction> indicesLookup = metadata.getIndicesLookup();
|
|
|
|
+ assertThat(indicesLookup.size(), equalTo(indices.size() + backingIndices.size() + 1));
|
|
|
|
+ for (Index index : indices) {
|
|
|
|
+ assertTrue(indicesLookup.containsKey(index.getName()));
|
|
|
|
+ assertNull(indicesLookup.get(index.getName()).getParentDataStream());
|
|
|
|
+ }
|
|
|
|
+ for (Index index : backingIndices) {
|
|
|
|
+ assertTrue(indicesLookup.containsKey(index.getName()));
|
|
|
|
+ assertNotNull(indicesLookup.get(index.getName()).getParentDataStream());
|
|
|
|
+ assertThat(indicesLookup.get(index.getName()).getParentDataStream().getName(), equalTo(dataStreamName));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
public void testSerialization() throws IOException {
|
|
public void testSerialization() throws IOException {
|
|
final Metadata orig = randomMetadata();
|
|
final Metadata orig = randomMetadata();
|
|
final BytesStreamOutput out = new BytesStreamOutput();
|
|
final BytesStreamOutput out = new BytesStreamOutput();
|
|
@@ -1037,8 +1090,6 @@ public class MetadataTests extends ESTestCase {
|
|
}
|
|
}
|
|
|
|
|
|
public static Metadata randomMetadata() {
|
|
public static Metadata randomMetadata() {
|
|
- DataStream randomDataStream = DataStreamTests.randomInstance();
|
|
|
|
-
|
|
|
|
Metadata.Builder md = Metadata.builder()
|
|
Metadata.Builder md = Metadata.builder()
|
|
.put(buildIndexMetadata("index", "alias", randomBoolean() ? null : randomBoolean()).build(), randomBoolean())
|
|
.put(buildIndexMetadata("index", "alias", randomBoolean() ? null : randomBoolean()).build(), randomBoolean())
|
|
.put(IndexTemplateMetadata.builder("template" + randomAlphaOfLength(3))
|
|
.put(IndexTemplateMetadata.builder("template" + randomAlphaOfLength(3))
|
|
@@ -1058,15 +1109,13 @@ public class MetadataTests extends ESTestCase {
|
|
.indexGraveyard(IndexGraveyardTests.createRandom())
|
|
.indexGraveyard(IndexGraveyardTests.createRandom())
|
|
.version(randomNonNegativeLong())
|
|
.version(randomNonNegativeLong())
|
|
.put("component_template_" + randomAlphaOfLength(3), ComponentTemplateTests.randomInstance())
|
|
.put("component_template_" + randomAlphaOfLength(3), ComponentTemplateTests.randomInstance())
|
|
- .put("index_template_v2_" + randomAlphaOfLength(3), IndexTemplateV2Tests.randomInstance())
|
|
|
|
- .put(randomDataStream);
|
|
|
|
|
|
+ .put("index_template_v2_" + randomAlphaOfLength(3), IndexTemplateV2Tests.randomInstance());
|
|
|
|
|
|
|
|
+ DataStream randomDataStream = DataStreamTests.randomInstance();
|
|
for (Index index : randomDataStream.getIndices()) {
|
|
for (Index index : randomDataStream.getIndices()) {
|
|
- md.put(IndexMetadata.builder(index.getName())
|
|
|
|
- .settings(ESTestCase.settings(Version.CURRENT).put("index.hidden", true))
|
|
|
|
- .numberOfShards(1)
|
|
|
|
- .numberOfReplicas(1));
|
|
|
|
|
|
+ md.put(DataStreamTestHelper.getIndexMetadataBuilderForIndex(index));
|
|
}
|
|
}
|
|
|
|
+ md.put(randomDataStream);
|
|
|
|
|
|
return md.build();
|
|
return md.build();
|
|
}
|
|
}
|