Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve backing index ordering for data streams #63749

Merged
merged 2 commits into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -577,7 +577,6 @@ private static void enrichIndexAbstraction(String indexAbstraction, SortedMap<St
case DATA_STREAM:
IndexAbstraction.DataStream dataStream = (IndexAbstraction.DataStream) ia;
String[] backingIndices = dataStream.getIndices().stream().map(i -> i.getIndex().getName()).toArray(String[]::new);
Arrays.sort(backingIndices);
dataStreams.add(new ResolvedDataStream(
dataStream.getName(),
backingIndices,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,34 @@ public void testResolveWithMultipleNames() {
validateDataStreams(dataStreams, "logs-mysql-test");
}

public void testResolvePreservesBackingIndexOrdering() {
Metadata.Builder builder = Metadata.builder();
String dataStreamName = "my-data-stream";
List<IndexMetadata> backingIndices = new ArrayList<>();
backingIndices.add(createIndexMetadata("not-in-order-2", true));
backingIndices.add(createIndexMetadata("not-in-order-1", true));
backingIndices.add(createIndexMetadata(DataStream.getDefaultBackingIndexName(dataStreamName, 3), true));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
backingIndices.add(createIndexMetadata("not-in-order-2", true));
backingIndices.add(createIndexMetadata("not-in-order-1", true));
backingIndices.add(createIndexMetadata(DataStream.getDefaultBackingIndexName(dataStreamName, 3), true));
String[] names = new String[]{"not-in-order-2", "not-in-order-1", DataStream.getDefaultBackingIndexName(dataStreamName, 3)};
List<IndexMetadata> backingIndices = Arrays.stream(names).map(n -> createIndexMetadata(n, true)).collect(Collectors.toList());

for (IndexMetadata index : backingIndices) {
builder.put(index, false);
}

DataStream ds = new DataStream(dataStreamName, createTimestampField("@timestamp"),
backingIndices.stream().map(IndexMetadata::getIndex).collect(Collectors.toList()));
builder.put(ds);

IndicesOptions indicesOptions = IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED_HIDDEN;
List<ResolvedIndex> indices = new ArrayList<>();
List<ResolvedAlias> aliases = new ArrayList<>();
List<ResolvedDataStream> dataStreams = new ArrayList<>();
TransportAction.resolveIndices(new String[]{"*"}, indicesOptions, builder.build(), resolver, indices, aliases, dataStreams, true);

assertThat(dataStreams.size(), equalTo(1));
assertThat(dataStreams.get(0).getBackingIndices().length, equalTo(3));
assertThat(dataStreams.get(0).getBackingIndices()[0], equalTo(backingIndices.get(0).getIndex().getName()));
assertThat(dataStreams.get(0).getBackingIndices()[1], equalTo(backingIndices.get(1).getIndex().getName()));
assertThat(dataStreams.get(0).getBackingIndices()[2], equalTo(backingIndices.get(2).getIndex().getName()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assertThat(dataStreams.get(0).getBackingIndices().length, equalTo(3));
assertThat(dataStreams.get(0).getBackingIndices()[0], equalTo(backingIndices.get(0).getIndex().getName()));
assertThat(dataStreams.get(0).getBackingIndices()[1], equalTo(backingIndices.get(1).getIndex().getName()));
assertThat(dataStreams.get(0).getBackingIndices()[2], equalTo(backingIndices.get(2).getIndex().getName()));
assertThat(dataStreams.get(0).getBackingIndices(), arrayContaining(names));

}

private void validateIndices(List<ResolvedIndex> resolvedIndices, String... expectedIndices) {
assertThat(resolvedIndices.size(), equalTo(expectedIndices.length));
for (int k = 0; k < resolvedIndices.size(); k++) {
Expand Down