-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Fix Transport Stopped Exception #48930
Merged
henningandersen
merged 6 commits into
elastic:master
from
henningandersen:fix_transport_stopped_exception
Nov 13, 2019
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
03e1b2b
Fix Transport Stopped Exception
henningandersen 62af945
Removed LocalTransportException and fixes
henningandersen 3641614
Checkstyle fixes
henningandersen 4e2cc6d
Armin comments
henningandersen c6c741f
Fix node in exception.
henningandersen 78f3b3c
Merge remote-tracking branch 'origin/master' into fix_transport_stopp…
henningandersen 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 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
223 changes: 223 additions & 0 deletions
223
...asticsearch/action/support/replication/TransportReplicationActionRetryOnClosedNodeIT.java
This file contains 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,223 @@ | ||
/* | ||
* 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.support.replication; | ||
|
||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.action.ActionRequest; | ||
import org.elasticsearch.action.ActionResponse; | ||
import org.elasticsearch.action.ActionType; | ||
import org.elasticsearch.action.support.ActionFilters; | ||
import org.elasticsearch.cluster.action.shard.ShardStateAction; | ||
import org.elasticsearch.cluster.metadata.IndexMetaData; | ||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.util.concurrent.ThreadContext; | ||
import org.elasticsearch.index.shard.IndexShard; | ||
import org.elasticsearch.index.shard.ShardId; | ||
import org.elasticsearch.indices.IndicesService; | ||
import org.elasticsearch.plugins.ActionPlugin; | ||
import org.elasticsearch.plugins.NetworkPlugin; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.plugins.PluginsService; | ||
import org.elasticsearch.test.ESIntegTestCase; | ||
import org.elasticsearch.test.InternalTestCluster; | ||
import org.elasticsearch.test.transport.MockTransportService; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.transport.Transport; | ||
import org.elasticsearch.transport.TransportInterceptor; | ||
import org.elasticsearch.transport.TransportRequest; | ||
import org.elasticsearch.transport.TransportRequestOptions; | ||
import org.elasticsearch.transport.TransportResponse; | ||
import org.elasticsearch.transport.TransportResponseHandler; | ||
import org.elasticsearch.transport.TransportService; | ||
import org.hamcrest.Matchers; | ||
|
||
import java.io.IOException; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
|
||
|
||
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0) | ||
public class TransportReplicationActionRetryOnClosedNodeIT extends ESIntegTestCase { | ||
|
||
@Override | ||
protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
return List.of(TestPlugin.class, MockTransportService.TestPlugin.class); | ||
} | ||
|
||
public static class Request extends ReplicationRequest<Request> { | ||
public Request(ShardId shardId) { | ||
super(shardId); | ||
} | ||
|
||
public Request(StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "test-request"; | ||
} | ||
} | ||
|
||
public static class Response extends ReplicationResponse { | ||
public Response() { | ||
} | ||
|
||
public Response(StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
} | ||
|
||
public static class TestAction extends TransportReplicationAction<Request, Request, Response> { | ||
private static final String ACTION_NAME = "internal:test-replication-action"; | ||
private static final ActionType<Response> TYPE = new ActionType<>(ACTION_NAME, Response::new); | ||
|
||
@Inject | ||
public TestAction(Settings settings, TransportService transportService, ClusterService clusterService, | ||
IndicesService indicesService, ThreadPool threadPool, ShardStateAction shardStateAction, | ||
ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) { | ||
super(settings, ACTION_NAME, transportService, clusterService, indicesService, threadPool, shardStateAction, actionFilters, | ||
indexNameExpressionResolver, Request::new, Request::new, ThreadPool.Names.GENERIC); | ||
} | ||
|
||
@Override | ||
protected Response newResponseInstance(StreamInput in) throws IOException { | ||
return new Response(in); | ||
} | ||
|
||
@Override | ||
protected void shardOperationOnPrimary(Request shardRequest, IndexShard primary, | ||
ActionListener<PrimaryResult<Request, Response>> listener) { | ||
listener.onResponse(new PrimaryResult<>(shardRequest, new Response())); | ||
} | ||
|
||
@Override | ||
protected ReplicaResult shardOperationOnReplica(Request shardRequest, IndexShard replica) { | ||
return new ReplicaResult(); | ||
} | ||
} | ||
|
||
public static class TestPlugin extends Plugin implements ActionPlugin, NetworkPlugin { | ||
private CountDownLatch actionRunningLatch = new CountDownLatch(1); | ||
private CountDownLatch actionWaitLatch = new CountDownLatch(1); | ||
private volatile String testActionName; | ||
|
||
public TestPlugin() { | ||
} | ||
|
||
@Override | ||
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() { | ||
return List.of(new ActionHandler<>(TestAction.TYPE, TestAction.class)); | ||
} | ||
|
||
@Override | ||
public List<TransportInterceptor> getTransportInterceptors(NamedWriteableRegistry namedWriteableRegistry, | ||
ThreadContext threadContext) { | ||
return List.of(new TransportInterceptor() { | ||
@Override | ||
public AsyncSender interceptSender(AsyncSender sender) { | ||
return new AsyncSender() { | ||
@Override | ||
public <T extends TransportResponse> void sendRequest(Transport.Connection connection, String action, | ||
TransportRequest request, TransportRequestOptions options, | ||
TransportResponseHandler<T> handler) { | ||
// only activated on primary | ||
if (action.equals(testActionName)) { | ||
actionRunningLatch.countDown(); | ||
try { | ||
actionWaitLatch.await(10, TimeUnit.SECONDS); | ||
} catch (InterruptedException e) { | ||
throw new AssertionError(e); | ||
} | ||
} | ||
sender.sendRequest(connection, action, request, options, handler); | ||
} | ||
}; | ||
} | ||
}); | ||
} | ||
} | ||
|
||
public void testRetryOnStoppedTransportService() throws Exception { | ||
internalCluster().startMasterOnlyNodes(2); | ||
String primary = internalCluster().startDataOnlyNode(); | ||
assertAcked(prepareCreate("test") | ||
.setSettings(Settings.builder() | ||
.put(indexSettings()) | ||
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) | ||
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1) | ||
)); | ||
|
||
String replica = internalCluster().startDataOnlyNode(); | ||
String coordinator = internalCluster().startCoordinatingOnlyNode(Settings.EMPTY); | ||
ensureGreen("test"); | ||
|
||
TestPlugin primaryTestPlugin = getTestPlugin(primary); | ||
// this test only provoked an issue for the primary action, but for completeness, we pick the action randomly | ||
primaryTestPlugin.testActionName = TestAction.ACTION_NAME + (randomBoolean() ? "[p]" : "[r]"); | ||
logger.info("--> Test action {}, primary {}, replica {}", primaryTestPlugin.testActionName, primary, replica); | ||
|
||
AtomicReference<Object> response = new AtomicReference<>(); | ||
CountDownLatch doneLatch = new CountDownLatch(1); | ||
client(coordinator).execute(TestAction.TYPE, new Request(new ShardId(resolveIndex("test"), 0)), | ||
ActionListener.runAfter(ActionListener.wrap( | ||
r -> assertTrue(response.compareAndSet(null, r)), | ||
e -> assertTrue(response.compareAndSet(null, e))), | ||
doneLatch::countDown)); | ||
|
||
assertTrue(primaryTestPlugin.actionRunningLatch.await(10, TimeUnit.SECONDS)); | ||
|
||
MockTransportService primaryTransportService = (MockTransportService) internalCluster().getInstance(TransportService.class, | ||
primary); | ||
// we pause node after TransportService has moved to stopped, but before closing connections, since if connections are closed | ||
// we would not hit the transport service closed case. | ||
primaryTransportService.addOnStopListener(() -> { | ||
primaryTestPlugin.actionWaitLatch.countDown(); | ||
try { | ||
assertTrue(doneLatch.await(10, TimeUnit.SECONDS)); | ||
} catch (InterruptedException e) { | ||
throw new AssertionError(e); | ||
} | ||
}); | ||
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(primary)); | ||
|
||
assertTrue(doneLatch.await(10, TimeUnit.SECONDS)); | ||
if (response.get() instanceof Exception) { | ||
throw new AssertionError(response.get()); | ||
} | ||
} | ||
|
||
private TestPlugin getTestPlugin(String node) { | ||
PluginsService pluginsService = internalCluster().getInstance(PluginsService.class, node); | ||
List<TestPlugin> testPlugins = pluginsService.filterPlugins(TestPlugin.class); | ||
assertThat(testPlugins, Matchers.hasSize(1)); | ||
return testPlugins.get(0); | ||
} | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.
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.
Maybe use the
ExceptionsHelper.unwrap(e, NodeClosedException.class) != null
pattern here too to be a little more resilient to future changes (and present unexpected paths that get us here ...?)?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.
I thought about this too, but ended up keeping this as is, since the unwrap's are different in that
unwrapCause
only unwrapsElasticsearchWrapperException
, whereasunwrap
unwraps all causes. It could be important in case we end up unwrapping a deep exception from another host? Do you think we should try to follow your suggestion anyway?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.
Nah let's not do that. I def. doesn't look impossible for that exception from another node making it here (since it's not trivial to tell it the suggestion is pointless in the first place :)).