-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Zen2: Add node id to log output of CoordinatorTests #33929
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 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| */ | ||
| package org.elasticsearch.cluster.coordination; | ||
|
|
||
| import org.apache.logging.log4j.CloseableThreadContext; | ||
| import org.apache.logging.log4j.message.ParameterizedMessage; | ||
| import org.elasticsearch.Version; | ||
| import org.elasticsearch.cluster.ClusterState; | ||
|
|
@@ -38,13 +39,8 @@ | |
| import org.elasticsearch.discovery.zen.UnicastHostsProvider.HostsResolver; | ||
| import org.elasticsearch.indices.cluster.FakeThreadPoolMasterService; | ||
| import org.elasticsearch.test.ESTestCase; | ||
| import org.elasticsearch.test.disruption.DisruptableMockTransport; | ||
| import org.elasticsearch.test.junit.annotations.TestLogging; | ||
| import org.elasticsearch.test.transport.MockTransport; | ||
| import org.elasticsearch.transport.RequestHandlerRegistry; | ||
| import org.elasticsearch.transport.TransportChannel; | ||
| import org.elasticsearch.transport.TransportRequest; | ||
| import org.elasticsearch.transport.TransportResponse; | ||
| import org.elasticsearch.transport.TransportResponseOptions; | ||
| import org.elasticsearch.transport.TransportService; | ||
| import org.hamcrest.Matcher; | ||
|
|
||
|
|
@@ -55,7 +51,6 @@ | |
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.Set; | ||
| import java.util.function.Consumer; | ||
| import java.util.function.Predicate; | ||
| import java.util.stream.Collectors; | ||
|
|
||
|
|
@@ -184,15 +179,15 @@ class ClusterNode extends AbstractComponent { | |
| private final PersistedState persistedState; | ||
| private MasterService masterService; | ||
| private TransportService transportService; | ||
| private MockTransport mockTransport; | ||
| private DisruptableMockTransport mockTransport; | ||
|
|
||
| ClusterNode(int nodeIndex) { | ||
| super(Settings.builder().put(NODE_NAME_SETTING.getKey(), nodeIdFromIndex(nodeIndex)).build()); | ||
| this.nodeIndex = nodeIndex; | ||
| localNode = createDiscoveryNode(); | ||
| persistedState = new InMemoryPersistedState(1L, | ||
| clusterState(1L, 1L, localNode, initialConfiguration, initialConfiguration, 0L)); | ||
| setUp(); | ||
| onNode(this::setUp, localNode).run(); | ||
| } | ||
|
|
||
| private DiscoveryNode createDiscoveryNode() { | ||
|
|
@@ -206,112 +201,44 @@ private DiscoveryNode createDiscoveryNode() { | |
| } | ||
|
|
||
| private void setUp() { | ||
| mockTransport = new MockTransport() { | ||
| mockTransport = new DisruptableMockTransport(logger) { | ||
| @Override | ||
| protected void onSendRequest(long requestId, String action, TransportRequest request, DiscoveryNode destination) { | ||
| assert destination.equals(localNode) == false : "non-local message from " + localNode + " to itself"; | ||
| super.onSendRequest(requestId, action, request, destination); | ||
| protected DiscoveryNode getLocalNode() { | ||
| return localNode; | ||
| } | ||
|
|
||
| @Override | ||
| protected ConnectionStatus getConnectionStatus(DiscoveryNode sender, DiscoveryNode destination) { | ||
| return ConnectionStatus.CONNECTED; | ||
| } | ||
|
|
||
| // connecting and handshaking with a new node happens synchronously, so we cannot enqueue these tasks for later | ||
| final Consumer<Runnable> scheduler; | ||
| @Override | ||
| protected Optional<DisruptableMockTransport> getDisruptedCapturingTransport(DiscoveryNode node, String action) { | ||
| final Predicate<ClusterNode> matchesDestination; | ||
| if (action.equals(HANDSHAKE_ACTION_NAME)) { | ||
| scheduler = Runnable::run; | ||
| matchesDestination = n -> n.getLocalNode().getAddress().equals(destination.getAddress()); | ||
| matchesDestination = n -> n.getLocalNode().getAddress().equals(node.getAddress()); | ||
| } else { | ||
| scheduler = deterministicTaskQueue::scheduleNow; | ||
| matchesDestination = n -> n.getLocalNode().equals(destination); | ||
| matchesDestination = n -> n.getLocalNode().equals(node); | ||
| } | ||
| return clusterNodes.stream().filter(matchesDestination).findAny().map(cn -> cn.mockTransport); | ||
| } | ||
|
|
||
| scheduler.accept(new Runnable() { | ||
| @Override | ||
| public String toString() { | ||
| return "delivery of [" + action + "][" + requestId + "]: " + request; | ||
| } | ||
|
|
||
| @Override | ||
| public void run() { | ||
| clusterNodes.stream().filter(matchesDestination).findAny().ifPresent( | ||
| destinationNode -> { | ||
|
|
||
| final RequestHandlerRegistry requestHandler | ||
| = destinationNode.mockTransport.getRequestHandler(action); | ||
|
|
||
| final TransportChannel transportChannel = new TransportChannel() { | ||
| @Override | ||
| public String getProfileName() { | ||
| return "default"; | ||
| } | ||
|
|
||
| @Override | ||
| public String getChannelType() { | ||
| return "coordinator-test-channel"; | ||
| } | ||
|
|
||
| @Override | ||
| public void sendResponse(final TransportResponse response) { | ||
| scheduler.accept(new Runnable() { | ||
| @Override | ||
| public String toString() { | ||
| return "delivery of response " + response | ||
| + " to [" + action + "][" + requestId + "]: " + request; | ||
| } | ||
|
|
||
| @Override | ||
| public void run() { | ||
| handleResponse(requestId, response); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| @Override | ||
| public void sendResponse(TransportResponse response, TransportResponseOptions options) { | ||
| sendResponse(response); | ||
| } | ||
|
|
||
| @Override | ||
| public void sendResponse(Exception exception) { | ||
| scheduler.accept(new Runnable() { | ||
| @Override | ||
| public String toString() { | ||
| return "delivery of error response " + exception.getMessage() | ||
| + " to [" + action + "][" + requestId + "]: " + request; | ||
| } | ||
|
|
||
| @Override | ||
| public void run() { | ||
| handleRemoteError(requestId, exception); | ||
| } | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| try { | ||
| processMessageReceived(request, requestHandler, transportChannel); | ||
| } catch (Exception e) { | ||
| scheduler.accept(new Runnable() { | ||
| @Override | ||
| public String toString() { | ||
| return "delivery of processing error response " + e.getMessage() | ||
| + " to [" + action + "][" + requestId + "]: " + request; | ||
| } | ||
|
|
||
| @Override | ||
| public void run() { | ||
| handleRemoteError(requestId, e); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| ); | ||
| } | ||
| }); | ||
| @Override | ||
| protected void handle(DiscoveryNode sender, DiscoveryNode destination, String action, Runnable doDelivery) { | ||
| // handshake needs to run inline as the caller blockingly waits on the result | ||
| if (action.equals(HANDSHAKE_ACTION_NAME)) { | ||
| onNode(doDelivery, destination).run(); | ||
| } else { | ||
| deterministicTaskQueue.scheduleNow(onNode(doDelivery, destination)); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| masterService = new FakeThreadPoolMasterService("test", deterministicTaskQueue::scheduleNow); | ||
| masterService = new FakeThreadPoolMasterService("test", | ||
| runnable -> deterministicTaskQueue.scheduleNow(onNode(runnable, localNode))); | ||
| transportService = mockTransport.createTransportService( | ||
| settings, deterministicTaskQueue.getThreadPool(), NOOP_TRANSPORT_INTERCEPTOR, a -> localNode, null, emptySet()); | ||
| settings, deterministicTaskQueue.getThreadPool(runnable -> onNode(runnable, localNode)), NOOP_TRANSPORT_INTERCEPTOR, | ||
| a -> localNode, null, emptySet()); | ||
| coordinator = new Coordinator(settings, transportService, ESAllocationTestCase.createAllocationService(Settings.EMPTY), | ||
| masterService, this::getPersistedState, Cluster.this::provideUnicastHosts, Randomness.get()); | ||
| masterService.setClusterStatePublisher(coordinator); | ||
|
|
@@ -359,9 +286,19 @@ private List<TransportAddress> provideUnicastHosts(HostsResolver ignored) { | |
| } | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| private static void processMessageReceived(TransportRequest request, RequestHandlerRegistry requestHandler, | ||
| TransportChannel transportChannel) throws Exception { | ||
| requestHandler.processMessageReceived(request, transportChannel); | ||
| private static Runnable onNode(Runnable runnable, DiscoveryNode node) { | ||
| return new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| try (CloseableThreadContext.Instance ignored = CloseableThreadContext.put("nodeId", node.getId())) { | ||
| runnable.run(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return node.getId() + ": " + runnable.toString(); | ||
|
||
| } | ||
| }; | ||
| } | ||
| } | ||
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
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
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.
I meant to put the
DiscoveryNodething first, otherwise it ends up a long way from the function call if theRunnableis an anonymous class.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.
ok. With the recent changes, there were no longer any anonymous classes. I've still changed the order