Skip to content

Commit

Permalink
Preserve backing index ordering for data streams (elastic#63749) (ela…
Browse files Browse the repository at this point in the history
  • Loading branch information
danhermann authored Oct 20, 2020
1 parent 2ac3568 commit b06c617
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,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 @@ -47,6 +47,7 @@
import java.util.stream.Collectors;

import static org.elasticsearch.cluster.DataStreamTestHelper.createTimestampField;
import static org.hamcrest.Matchers.arrayContaining;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.core.IsNull.notNullValue;
Expand Down Expand Up @@ -169,6 +170,29 @@ public void testResolveWithMultipleNames() {
validateDataStreams(dataStreams, "logs-mysql-test");
}

public void testResolvePreservesBackingIndexOrdering() {
Metadata.Builder builder = Metadata.builder();
String dataStreamName = "my-data-stream";
String[] names = {"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(), 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

0 comments on commit b06c617

Please sign in to comment.