Skip to content

Commit

Permalink
wip on review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
danhermann committed Mar 31, 2020
1 parent 078dae1 commit 1284b2b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
index: simple-data-stream1
body: { query: { match_all: {} } }
- length: { hits.hits: 1 }
- match: { hits.hits.0._index: simple-data-stream1-000000 }
- match: { hits.hits.0._index: simple-data-stream1-000001 }
- match: { hits.hits.0._source.foo: 'bar' }

- do:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,12 @@ static ClusterState createDataStream(MetadataCreateIndexService metadataCreateIn
MetadataCreateIndexService.validateIndexOrAliasName(request.name,
(s1, s2) -> new IllegalArgumentException("data_stream [" + s1 + "] " + s2));

String firstBackingIndexName = request.name + "-000000";
String firstBackingIndexName = request.name + "-000001";
CreateIndexClusterStateUpdateRequest createIndexRequest =
new CreateIndexClusterStateUpdateRequest("initialize_data_stream", firstBackingIndexName, firstBackingIndexName);
currentState = metadataCreateIndexService.applyCreateIndexRequest(currentState, createIndexRequest, false);
IndexMetadata firstBackingIndex = currentState.metadata().index(firstBackingIndexName);
assert firstBackingIndex != null;

Metadata.Builder builder = Metadata.builder(currentState.metadata()).put(
new DataStream(request.name, request.timestampFieldName, List.of(firstBackingIndex.getIndex())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,42 +252,4 @@ private boolean isNonEmpty(List<IndexMetadata> idxMetas) {
return (Objects.isNull(idxMetas) || idxMetas.isEmpty()) == false;
}
}

class DataStream implements IndexAbstraction {

private final org.elasticsearch.cluster.metadata.DataStream dataStream;
private final List<IndexMetaData> dataStreamIndices;
private final IndexMetaData writeIndex;

public DataStream(org.elasticsearch.cluster.metadata.DataStream dataStream, List<IndexMetaData> dataStreamIndices,
IndexMetaData writeIndex) {
this.dataStream = dataStream;
this.dataStreamIndices = dataStreamIndices;
this.writeIndex = writeIndex;
}

@Override
public String getName() {
return dataStream.getName();
}

@Override
public Type getType() {
return Type.DATA_STREAM;
}

@Override
public List<IndexMetaData> getIndices() {
return dataStreamIndices;
}

public IndexMetaData getWriteIndex() {
return writeIndex;
}

@Override
public boolean isHidden() {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ public void testBuilderRejectsDataStreamThatConflictsWithAlias() {

public void testBuilderRejectsDataStreamWithConflictingBackingIndices() {
final String dataStreamName = "my-data-stream";
final String conflictingIndex = dataStreamName + "-00001";
final String conflictingIndex = dataStreamName + "-000001";
Metadata.Builder b = Metadata.builder()
.put(IndexMetadata.builder(conflictingIndex)
.settings(settings(Version.CURRENT))
Expand Down

0 comments on commit 1284b2b

Please sign in to comment.