-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Check for global blocks after IndexNotFoundException in TransportMasterNodeAction #78128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f4bb014
Check for global blocks first on TransportClusterInfoAction
fcofdez 3e79077
Merge branch 'master' into resolve-index-after
elasticmachine f0dabd5
Generalize the approach
fcofdez 1aec484
Merge remote-tracking branch 'origin/master' into resolve-index-after
fcofdez 0c56fc2
Simplify
fcofdez f08112e
Merge remote-tracking branch 'origin/master' into resolve-index-after
fcofdez aaf0d74
Comment
fcofdez f58c8c0
Assertion
fcofdez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
191 changes: 191 additions & 0 deletions
191
...st/java/org/elasticsearch/action/support/master/info/TransportClusterInfoActionTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,191 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| package org.elasticsearch.action.support.master.info; | ||
|
|
||
| import org.elasticsearch.Version; | ||
| import org.elasticsearch.action.ActionListener; | ||
| import org.elasticsearch.action.ActionRequestValidationException; | ||
| import org.elasticsearch.action.ActionResponse; | ||
| import org.elasticsearch.action.support.ActionFilters; | ||
| import org.elasticsearch.action.support.ActionTestUtils; | ||
| import org.elasticsearch.action.support.PlainActionFuture; | ||
| import org.elasticsearch.action.support.replication.ClusterStateCreationUtils; | ||
| import org.elasticsearch.cluster.ClusterState; | ||
| import org.elasticsearch.cluster.block.ClusterBlockException; | ||
| import org.elasticsearch.cluster.block.ClusterBlocks; | ||
| import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
| import org.elasticsearch.cluster.metadata.Metadata; | ||
| import org.elasticsearch.cluster.node.DiscoveryNode; | ||
| import org.elasticsearch.cluster.node.DiscoveryNodeRole; | ||
| import org.elasticsearch.cluster.service.ClusterService; | ||
| import org.elasticsearch.common.io.stream.StreamInput; | ||
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
| import org.elasticsearch.core.TimeValue; | ||
| import org.elasticsearch.discovery.MasterNotDiscoveredException; | ||
| import org.elasticsearch.indices.TestIndexNameExpressionResolver; | ||
| import org.elasticsearch.tasks.CancellableTask; | ||
| import org.elasticsearch.tasks.Task; | ||
| import org.elasticsearch.tasks.TaskId; | ||
| import org.elasticsearch.test.ESTestCase; | ||
| import org.elasticsearch.test.transport.MockTransport; | ||
| import org.elasticsearch.threadpool.TestThreadPool; | ||
| import org.elasticsearch.threadpool.ThreadPool; | ||
| import org.elasticsearch.transport.TransportService; | ||
| import org.junit.After; | ||
| import org.junit.AfterClass; | ||
| import org.junit.Before; | ||
| import org.junit.BeforeClass; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Collections; | ||
| import java.util.HashSet; | ||
| import java.util.Map; | ||
| import java.util.concurrent.ExecutionException; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import static org.elasticsearch.gateway.GatewayService.STATE_NOT_RECOVERED_BLOCK; | ||
| import static org.elasticsearch.test.ClusterServiceUtils.createClusterService; | ||
| import static org.elasticsearch.test.ClusterServiceUtils.setState; | ||
| import static org.hamcrest.Matchers.instanceOf; | ||
|
|
||
| public class TransportClusterInfoActionTests extends ESTestCase { | ||
| private static ThreadPool threadPool; | ||
|
|
||
| private ClusterService clusterService; | ||
| private TransportService transportService; | ||
| private DiscoveryNode localNode; | ||
| private DiscoveryNode[] allNodes; | ||
|
|
||
| @BeforeClass | ||
| public static void beforeClass() { | ||
| threadPool = new TestThreadPool("TransportMasterNodeActionTests"); | ||
| } | ||
|
|
||
| @Override | ||
| @Before | ||
| public void setUp() throws Exception { | ||
| super.setUp(); | ||
| MockTransport transport = new MockTransport(); | ||
| clusterService = createClusterService(threadPool); | ||
| transportService = transport.createTransportService(clusterService.getSettings(), threadPool, | ||
| TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> clusterService.localNode(), null, Collections.emptySet()); | ||
| transportService.start(); | ||
| transportService.acceptIncomingRequests(); | ||
| localNode = new DiscoveryNode("local_node", buildNewFakeTransportAddress(), Collections.emptyMap(), | ||
| Collections.singleton(DiscoveryNodeRole.MASTER_ROLE), Version.CURRENT); | ||
| allNodes = new DiscoveryNode[]{localNode}; | ||
| } | ||
|
|
||
| @After | ||
| public void tearDown() throws Exception { | ||
| super.tearDown(); | ||
| clusterService.close(); | ||
| transportService.close(); | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void afterClass() { | ||
| ThreadPool.terminate(threadPool, 30, TimeUnit.SECONDS); | ||
| threadPool = null; | ||
| } | ||
|
|
||
| static class Request extends ClusterInfoRequest<Request> { | ||
| Request() { } | ||
|
|
||
| Request(StreamInput in) throws IOException { | ||
| super(in); | ||
| } | ||
|
|
||
| @Override | ||
| public ActionRequestValidationException validate() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public Task createTask(long id, String type, String action, TaskId parentTaskId, Map<String, String> headers) { | ||
| return new CancellableTask(id, type, action, "", parentTaskId, headers); | ||
| } | ||
| } | ||
|
|
||
| static class Response extends ActionResponse { | ||
| private long identity = randomLong(); | ||
|
|
||
| Response() {} | ||
|
|
||
| Response(StreamInput in) throws IOException { | ||
| super(in); | ||
| identity = in.readLong(); | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| out.writeLong(identity); | ||
| } | ||
| } | ||
|
|
||
| static class Action extends TransportClusterInfoAction<Request, Response> { | ||
| Action(String actionName, TransportService transportService, ClusterService clusterService, ThreadPool threadPool) { | ||
| super(actionName, | ||
| transportService, | ||
| clusterService, | ||
| threadPool, | ||
| new ActionFilters(new HashSet<>()), | ||
| Request::new, | ||
| TestIndexNameExpressionResolver.newInstance(), | ||
| Response::new | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| protected void doMasterOperation(Task task, | ||
| Request request, | ||
| String[] concreteIndices, | ||
| ClusterState state, | ||
| ActionListener<Response> listener) { | ||
| listener.onResponse(new Response()); | ||
| } | ||
| } | ||
|
|
||
| public void testGlobalBlocksAreCheckedBeforeResolvingIndices() throws Exception { | ||
| final boolean unblockBeforeTimeout = randomBoolean(); | ||
|
|
||
| Request request = new Request().masterNodeTimeout(TimeValue.timeValueSeconds(unblockBeforeTimeout ? 60 : 0)); | ||
| String indexRequestName = "my-index"; | ||
| request.indices(indexRequestName); | ||
| PlainActionFuture<Response> listener = new PlainActionFuture<>(); | ||
|
|
||
| ClusterState stateWithBlockWithoutIndexMetadata = | ||
| ClusterState.builder(ClusterStateCreationUtils.state(localNode, localNode, allNodes)) | ||
| .blocks(ClusterBlocks.builder().addGlobalBlock(STATE_NOT_RECOVERED_BLOCK)) | ||
| .build(); | ||
| setState(clusterService, stateWithBlockWithoutIndexMetadata); | ||
|
|
||
| ActionTestUtils.execute(new Action("internal:testAction", transportService, clusterService, threadPool), null, request, listener); | ||
|
|
||
| if (unblockBeforeTimeout) { | ||
| assertFalse(listener.isDone()); | ||
| IndexMetadata.Builder indexMetadataBuilder = | ||
| IndexMetadata.builder(indexRequestName) | ||
| .settings(settings(Version.CURRENT)) | ||
| .numberOfShards(1) | ||
| .numberOfReplicas(0); | ||
| ClusterState clusterStateWithoutBlocks = ClusterState.builder(ClusterStateCreationUtils.state(localNode, localNode, allNodes)) | ||
| .metadata(Metadata.builder().put(indexMetadataBuilder).build()) | ||
| .blocks(ClusterBlocks.EMPTY_CLUSTER_BLOCK) | ||
| .build(); | ||
| setState(clusterService, clusterStateWithoutBlocks); | ||
| assertTrue(listener.isDone()); | ||
| listener.get(); | ||
| } else { | ||
| ExecutionException ex = expectThrows(ExecutionException.class, listener::get); | ||
| assertThat(ex.getCause(), instanceOf(MasterNotDiscoveredException.class)); | ||
| assertThat(ex.getCause().getCause(), instanceOf(ClusterBlockException.class)); | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we split this into two tests rather than randomly choosing between these branches?
Also (nit) I have a slight preference for making all the things
final. Or none of them, but ideally not just the one.