-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Zen2: Add node id to log output of CoordinatorTests #33929
Merged
Merged
Changes from 1 commit
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 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 |
---|---|---|
|
@@ -39,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; | ||
|
||
|
@@ -56,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; | ||
|
||
|
@@ -185,7 +179,7 @@ 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()); | ||
|
@@ -207,106 +201,36 @@ 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(onNode(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(onNode(new Runnable() { | ||
@Override | ||
public String toString() { | ||
return "delivery of response " + response | ||
+ " to [" + action + "][" + requestId + "]: " + request; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
handleResponse(requestId, response); | ||
} | ||
}, localNode)); | ||
} | ||
|
||
@Override | ||
public void sendResponse(TransportResponse response, TransportResponseOptions options) { | ||
sendResponse(response); | ||
} | ||
|
||
@Override | ||
public void sendResponse(Exception exception) { | ||
scheduler.accept(onNode(new Runnable() { | ||
@Override | ||
public String toString() { | ||
return "delivery of error response " + exception.getMessage() | ||
+ " to [" + action + "][" + requestId + "]: " + request; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
handleRemoteError(requestId, exception); | ||
} | ||
}, localNode)); | ||
} | ||
}; | ||
|
||
try { | ||
processMessageReceived(request, requestHandler, transportChannel); | ||
} catch (Exception e) { | ||
scheduler.accept(onNode(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); | ||
} | ||
}, localNode)); | ||
} | ||
} | ||
); | ||
} | ||
}, destination)); | ||
@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)); | ||
} | ||
} | ||
}; | ||
|
||
|
@@ -362,12 +286,6 @@ 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 | ||
|
@@ -379,7 +297,7 @@ public void run() { | |
|
||
@Override | ||
public String toString() { | ||
return runnable.toString() + " (wrapped for " + node + ")"; | ||
return node.getId() + ": " + runnable.toString(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that having the UUID of the disco node will be useful here when we start rebooting nodes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added the ephemeral id |
||
} | ||
}; | ||
} | ||
|
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
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
DiscoveryNode
thing first, otherwise it ends up a long way from the function call if theRunnable
is 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