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:
parent
6a5d9d942a
commit
6a9838359c
|
@ -155,6 +155,7 @@ public class TransportClusterStateAction extends TransportMasterNodeReadAction<C
|
|||
|
||||
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);
|
||||
|
|
|
@ -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.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;
|
||||
|
||||
|
@ -118,6 +119,23 @@ public class SimpleClusterStateIT extends ESIntegTestCase {
|
|||
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*"))
|
||||
|
|
Loading…
Reference in New Issue