Skip to content

Commit

Permalink
Always return metadata version if metadata is requested (#37674)
Browse files Browse the repository at this point in the history
If the indices of a ClusterStateRequest are specified, we fail to
include the cluster state metadata version in the response.

Relates  #37633
  • Loading branch information
dnhatn committed Jan 26, 2019
1 parent 5813f6c commit ec243f2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ private void buildResponse(final ClusterStateRequest request,

if (request.metaData()) {
if (request.indices().length > 0) {
mdBuilder.version(currentState.metaData().version());
String[] indices = indexNameExpressionResolver.concreteIndexNames(currentState, request);
for (String filteredIndex : indices) {
IndexMetaData indexMetaData = currentState.metaData().index(filteredIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertIndexTemplateExists;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is;

Expand Down Expand Up @@ -111,6 +112,23 @@ public void testMetadata() throws Exception {
assertThat(clusterStateResponse.getState().metaData().indices().size(), is(0));
}

public void testMetadataVersion() {
createIndex("index-1");
createIndex("index-2");
long metadataVersion = client().admin().cluster().prepareState().get().getState().metaData().version();
assertThat(metadataVersion, greaterThan(0L));
assertThat(client().admin().cluster().prepareState().setIndices("index-1").get().getState().metaData().version(),
equalTo(metadataVersion));
assertThat(client().admin().cluster().prepareState().setIndices("index-2").get().getState().metaData().version(),
equalTo(metadataVersion));
assertThat(client().admin().cluster().prepareState().setIndices("*").get().getState().metaData().version(),
equalTo(metadataVersion));
assertThat(client().admin().cluster().prepareState().setIndices("not-found").get().getState().metaData().version(),
equalTo(metadataVersion));
assertThat(client().admin().cluster().prepareState().clear().setMetaData(false).get().getState().metaData().version(),
equalTo(0L));
}

public void testIndexTemplates() throws Exception {
client().admin().indices().preparePutTemplate("foo_template")
.setPatterns(Collections.singletonList("te*"))
Expand Down

0 comments on commit ec243f2

Please sign in to comment.