-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize TransportNodesAction to not send DiscoveryNodes for NodeStat…
…s, NodesInfo and ClusterStats call Signed-off-by: Pranshu Shukla <[email protected]>
- Loading branch information
Showing
13 changed files
with
454 additions
and
14 deletions.
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
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
134 changes: 134 additions & 0 deletions
134
...r/src/test/java/org/opensearch/action/support/nodes/TransportClusterStatsActionTests.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,134 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.action.support.nodes; | ||
|
||
import org.opensearch.action.admin.cluster.node.stats.NodesStatsRequest; | ||
import org.opensearch.action.admin.cluster.stats.ClusterStatsRequest; | ||
import org.opensearch.action.admin.cluster.stats.TransportClusterStatsAction; | ||
import org.opensearch.action.support.ActionFilters; | ||
import org.opensearch.action.support.PlainActionFuture; | ||
import org.opensearch.cluster.node.DiscoveryNode; | ||
import org.opensearch.cluster.service.ClusterService; | ||
import org.opensearch.common.io.stream.BytesStreamOutput; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.indices.IndicesService; | ||
import org.opensearch.node.NodeService; | ||
import org.opensearch.test.transport.CapturingTransport; | ||
import org.opensearch.threadpool.ThreadPool; | ||
import org.opensearch.transport.TransportService; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class TransportClusterStatsActionTests extends TransportNodesActionTests { | ||
|
||
/** | ||
* By default, we send discovery nodes list to each request that is sent across from the coordinator node. This | ||
* behavior is asserted in this test. | ||
*/ | ||
public void testDefaultBehavior() { | ||
ClusterStatsRequest request = new ClusterStatsRequest(); | ||
request.populateDiscoveryNodesInTransportRequest(true); | ||
Map<String, List<MockClusterStatsNodeRequest>> combinedSentRequest = performNodesInfoAction(request); | ||
|
||
assertNotNull(combinedSentRequest); | ||
combinedSentRequest.forEach((node, capturedRequestList) -> { | ||
assertNotNull(capturedRequestList); | ||
capturedRequestList.forEach(sentRequest -> { | ||
assertNotNull(sentRequest.getDiscoveryNodes()); | ||
assertEquals(sentRequest.getDiscoveryNodes().length, clusterService.state().nodes().getSize()); | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* In the optimized ClusterStats Request, we do not send the DiscoveryNodes List to each node. This behavior is | ||
* asserted in this test. | ||
*/ | ||
public void testOptimizedBehavior() { | ||
ClusterStatsRequest request = new ClusterStatsRequest(); | ||
request.populateDiscoveryNodesInTransportRequest(false); | ||
Map<String, List<MockClusterStatsNodeRequest>> combinedSentRequest = performNodesInfoAction(request); | ||
|
||
assertNotNull(combinedSentRequest); | ||
combinedSentRequest.forEach((node, capturedRequestList) -> { | ||
assertNotNull(capturedRequestList); | ||
capturedRequestList.forEach(sentRequest -> { assertNull(sentRequest.getDiscoveryNodes()); }); | ||
}); | ||
} | ||
|
||
private Map<String, List<MockClusterStatsNodeRequest>> performNodesInfoAction(ClusterStatsRequest request) { | ||
TransportNodesAction action = getTestTransportClusterStatsAction(); | ||
PlainActionFuture<NodesStatsRequest> listener = new PlainActionFuture<>(); | ||
action.new AsyncAction(null, request, listener).start(); | ||
Map<String, List<CapturingTransport.CapturedRequest>> capturedRequests = transport.getCapturedRequestsByTargetNodeAndClear(); | ||
Map<String, List<MockClusterStatsNodeRequest>> combinedSentRequest = new HashMap<>(); | ||
|
||
capturedRequests.forEach((node, capturedRequestList) -> { | ||
List<MockClusterStatsNodeRequest> sentRequestList = new ArrayList<>(); | ||
|
||
capturedRequestList.forEach(preSentRequest -> { | ||
BytesStreamOutput out = new BytesStreamOutput(); | ||
try { | ||
TransportClusterStatsAction.ClusterStatsNodeRequest clusterStatsNodeRequestFromCoordinator = | ||
(TransportClusterStatsAction.ClusterStatsNodeRequest) preSentRequest.request; | ||
clusterStatsNodeRequestFromCoordinator.writeTo(out); | ||
StreamInput in = out.bytes().streamInput(); | ||
MockClusterStatsNodeRequest mockClusterStatsNodeRequest = new MockClusterStatsNodeRequest(in); | ||
sentRequestList.add(mockClusterStatsNodeRequest); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
|
||
combinedSentRequest.put(node, sentRequestList); | ||
}); | ||
|
||
return combinedSentRequest; | ||
} | ||
|
||
public TestTransportClusterStatsAction getTestTransportClusterStatsAction() { | ||
return new TestTransportClusterStatsAction( | ||
THREAD_POOL, | ||
clusterService, | ||
transportService, | ||
nodeService, | ||
indicesService, | ||
new ActionFilters(Collections.emptySet()) | ||
); | ||
} | ||
|
||
private static class TestTransportClusterStatsAction extends TransportClusterStatsAction { | ||
public TestTransportClusterStatsAction( | ||
ThreadPool threadPool, | ||
ClusterService clusterService, | ||
TransportService transportService, | ||
NodeService nodeService, | ||
IndicesService indicesService, | ||
ActionFilters actionFilters | ||
) { | ||
super(threadPool, clusterService, transportService, nodeService, indicesService, actionFilters); | ||
} | ||
} | ||
|
||
private static class MockClusterStatsNodeRequest extends TransportClusterStatsAction.ClusterStatsNodeRequest { | ||
|
||
public MockClusterStatsNodeRequest(StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
|
||
public DiscoveryNode[] getDiscoveryNodes() { | ||
return this.request.concreteNodes(); | ||
} | ||
} | ||
} |
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.