mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 18:35:25 +00:00
Fix block checks when no indices are specified (#19047)
Global cluster blocks were not checked if an empty set of indices were passed as argument to the block checking method. This would lead to issues where some operations are already executed on a cluster before it has recovered its cluster state.
This commit is contained in:
parent
d6ddce2be8
commit
ca6fa9ef19
@ -150,8 +150,12 @@ public class ClusterBlocks extends AbstractDiffable<ClusterBlocks> {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean globalBlocked(ClusterBlockLevel level) {
|
||||
return global(level).isEmpty() == false;
|
||||
}
|
||||
|
||||
public ClusterBlockException globalBlockedException(ClusterBlockLevel level) {
|
||||
if (global(level).isEmpty()) {
|
||||
if (globalBlocked(level) == false) {
|
||||
return null;
|
||||
}
|
||||
return new ClusterBlockException(global(level));
|
||||
@ -175,10 +179,7 @@ public class ClusterBlocks extends AbstractDiffable<ClusterBlocks> {
|
||||
}
|
||||
|
||||
public boolean indexBlocked(ClusterBlockLevel level, String index) {
|
||||
if (!global(level).isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return !blocksForIndex(level, index).isEmpty();
|
||||
return globalBlocked(level) || blocksForIndex(level, index).isEmpty() == false;
|
||||
}
|
||||
|
||||
public ClusterBlockException indicesBlockedException(ClusterBlockLevel level, String[] indices) {
|
||||
@ -188,7 +189,7 @@ public class ClusterBlocks extends AbstractDiffable<ClusterBlocks> {
|
||||
indexIsBlocked = true;
|
||||
}
|
||||
}
|
||||
if (!indexIsBlocked) {
|
||||
if (globalBlocked(level) == false && indexIsBlocked == false) {
|
||||
return null;
|
||||
}
|
||||
Function<String, Stream<ClusterBlock>> blocksForIndexAtLevel = index -> blocksForIndex(level, index).stream();
|
||||
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.action.admin.indices.exists;
|
||||
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.discovery.MasterNotDiscoveredException;
|
||||
import org.elasticsearch.gateway.GatewayService;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
||||
import org.elasticsearch.test.InternalTestCluster;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
|
||||
|
||||
@ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, numClientNodes = 0, transportClientRatio = 0.0)
|
||||
public class IndicesExistsIT extends ESIntegTestCase {
|
||||
|
||||
public void testIndexExistsWithBlocksInPlace() throws IOException {
|
||||
Settings settings = Settings.builder().put(GatewayService.RECOVER_AFTER_NODES_SETTING.getKey(), 99).build();
|
||||
String node = internalCluster().startNode(settings);
|
||||
|
||||
assertThrows(client(node).admin().indices().prepareExists("test").setMasterNodeTimeout(TimeValue.timeValueSeconds(0)),
|
||||
MasterNotDiscoveredException.class);
|
||||
|
||||
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(node)); // shut down node so that test properly cleans up
|
||||
}
|
||||
}
|
@ -20,11 +20,13 @@
|
||||
package org.elasticsearch.cluster.block;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import static org.elasticsearch.test.VersionUtils.randomVersion;
|
||||
@ -76,4 +78,18 @@ public class ClusterBlockTests extends ESTestCase {
|
||||
randomBoolean(), randomFrom(RestStatus.values()), levels);
|
||||
assertThat(clusterBlock.toString(), not(endsWith(",")));
|
||||
}
|
||||
|
||||
public void testGlobalBlocksCheckedIfNoIndicesSpecified() {
|
||||
EnumSet<ClusterBlockLevel> levels = EnumSet.noneOf(ClusterBlockLevel.class);
|
||||
int nbLevels = randomIntBetween(1, ClusterBlockLevel.values().length);
|
||||
for (int j = 0; j < nbLevels; j++) {
|
||||
levels.add(randomFrom(ClusterBlockLevel.values()));
|
||||
}
|
||||
ClusterBlock globalBlock = new ClusterBlock(randomInt(), "cluster block #" + randomInt(), randomBoolean(),
|
||||
randomBoolean(), randomFrom(RestStatus.values()), levels);
|
||||
ClusterBlocks clusterBlocks = new ClusterBlocks(Collections.singleton(globalBlock), ImmutableOpenMap.of());
|
||||
ClusterBlockException exception = clusterBlocks.indicesBlockedException(randomFrom(globalBlock.levels()), new String[0]);
|
||||
assertNotNull(exception);
|
||||
assertEquals(exception.blocks(), Collections.singleton(globalBlock));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user