Always return metadata version if metadata is requested (#37674)

If the indices of a ClusterStateRequest are specified, we fail to
include the cluster state metadata version in the response.

Relates  #37633
This commit is contained in:
Nhat Nguyen 2019-01-23 10:24:51 -05:00 committed by GitHub
parent 6a5d9d942a
commit 6a9838359c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -155,6 +155,7 @@ public class TransportClusterStateAction extends TransportMasterNodeReadAction<C
if (request.metaData()) { if (request.metaData()) {
if (request.indices().length > 0) { if (request.indices().length > 0) {
mdBuilder.version(currentState.metaData().version());
String[] indices = indexNameExpressionResolver.concreteIndexNames(currentState, request); String[] indices = indexNameExpressionResolver.concreteIndexNames(currentState, request);
for (String filteredIndex : indices) { for (String filteredIndex : indices) {
IndexMetaData indexMetaData = currentState.metaData().index(filteredIndex); IndexMetaData indexMetaData = currentState.metaData().index(filteredIndex);

View File

@ -66,6 +66,7 @@ import static org.elasticsearch.gateway.GatewayService.STATE_NOT_RECOVERED_BLOCK
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertIndexTemplateExists; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertIndexTemplateExists;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
@ -118,6 +119,23 @@ public class SimpleClusterStateIT extends ESIntegTestCase {
assertThat(clusterStateResponse.getState().metaData().indices().size(), is(0)); 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 { public void testIndexTemplates() throws Exception {
client().admin().indices().preparePutTemplate("foo_template") client().admin().indices().preparePutTemplate("foo_template")
.setPatterns(Collections.singletonList("te*")) .setPatterns(Collections.singletonList("te*"))