Skip to content

Commit 90072e4

Browse files
authored
Merge branch 'main' into reflection-tests
2 parents b0c2097 + 2993998 commit 90072e4

File tree

8 files changed

+38
-17
lines changed

8 files changed

+38
-17
lines changed

server/src/internalClusterTest/java/org/elasticsearch/search/SearchCancellationIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ public void testCancelMultiSearch() throws Exception {
238238
}
239239
}
240240

241-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/99929")
242241
public void testCancelFailedSearchWhenPartialResultDisallowed() throws Exception {
243242
// Have at least two nodes so that we have parallel execution of two request guaranteed even if max concurrent requests per node
244243
// are limited to 1

server/src/main/java/org/elasticsearch/action/support/broadcast/unpromotable/TransportBroadcastUnpromotableAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected TransportBroadcastUnpromotableAction(
7676

7777
@Override
7878
protected void doExecute(Task task, Request request, ActionListener<Response> listener) {
79-
final var unpromotableShards = request.indexShardRoutingTable.unpromotableShards();
79+
final var unpromotableShards = request.indexShardRoutingTable.assignedUnpromotableShards();
8080
final var responses = new ArrayList<Response>(unpromotableShards.size());
8181

8282
try (var listeners = new RefCountingListener(listener.map(v -> combineUnpromotableShardResponses(responses)))) {

server/src/main/java/org/elasticsearch/action/support/replication/PostWriteRefresh.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void onFailure(Exception e) {
6565
}
6666
});
6767
case IMMEDIATE -> immediate(indexShard, listener.delegateFailureAndWrap((l, r) -> {
68-
if (indexShard.getReplicationGroup().getRoutingTable().allUnpromotableShards().size() > 0) {
68+
if (indexShard.getReplicationGroup().getRoutingTable().unpromotableShards().size() > 0) {
6969
sendUnpromotableRequests(indexShard, r.generation(), true, l, postWriteRefreshTimeout);
7070
} else {
7171
l.onResponse(true);

server/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public List<ShardRouting> assignedShards() {
193193
*
194194
* @return a {@link List} of shards
195195
*/
196-
public List<ShardRouting> unpromotableShards() {
196+
public List<ShardRouting> assignedUnpromotableShards() {
197197
return this.assignedUnpromotableShards;
198198
}
199199

@@ -202,7 +202,7 @@ public List<ShardRouting> unpromotableShards() {
202202
*
203203
* @return a {@link List} of shards
204204
*/
205-
public List<ShardRouting> allUnpromotableShards() {
205+
public List<ShardRouting> unpromotableShards() {
206206
return this.unpromotableShards;
207207
}
208208

server/src/test/java/org/elasticsearch/action/support/broadcast/unpromotable/TransportBroadcastUnpromotableActionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ public void testInvalidNodes() throws Exception {
333333

334334
// We were able to mark shards as stale, so the request finishes successfully
335335
assertThat(safeAwait(broadcastUnpromotableRequest(wrongRoutingTable, true)), equalTo(ActionResponse.Empty.INSTANCE));
336-
for (var shardRouting : wrongRoutingTable.unpromotableShards()) {
336+
for (var shardRouting : wrongRoutingTable.assignedUnpromotableShards()) {
337337
Mockito.verify(shardStateAction)
338338
.remoteShardFailed(
339339
eq(shardRouting.shardId()),

server/src/test/java/org/elasticsearch/action/support/replication/PostWriteRefreshTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public void testPrimaryWithUnpromotables() throws IOException {
162162
new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "message"),
163163
ShardRouting.Role.SEARCH_ONLY
164164
);
165-
when(routingTable.allUnpromotableShards()).thenReturn(List.of(shardRouting));
165+
when(routingTable.unpromotableShards()).thenReturn(List.of(shardRouting));
166166
when(routingTable.shardId()).thenReturn(shardId);
167167
WriteRequest.RefreshPolicy policy = randomFrom(WriteRequest.RefreshPolicy.IMMEDIATE, WriteRequest.RefreshPolicy.WAIT_UNTIL);
168168
postWriteRefresh.refreshShard(policy, primary, result.getTranslogLocation(), f, postWriteRefreshTimeout);
@@ -238,9 +238,9 @@ public void testWaitForWithNullLocationCompletedImmediately() throws IOException
238238
);
239239
// Randomly test scenarios with and without unpromotables
240240
if (randomBoolean()) {
241-
when(routingTable.allUnpromotableShards()).thenReturn(Collections.emptyList());
241+
when(routingTable.unpromotableShards()).thenReturn(Collections.emptyList());
242242
} else {
243-
when(routingTable.allUnpromotableShards()).thenReturn(List.of(shardRouting));
243+
when(routingTable.unpromotableShards()).thenReturn(List.of(shardRouting));
244244
}
245245
WriteRequest.RefreshPolicy policy = WriteRequest.RefreshPolicy.WAIT_UNTIL;
246246
postWriteRefresh.refreshShard(policy, primary, null, f, postWriteRefreshTimeout);

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/InferencePlugin.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ public Collection<?> createComponents(PluginServices services) {
331331

332332
// Add binding for interface -> implementation
333333
components.add(new PluginComponentBinding<>(InferenceServiceRateLimitCalculator.class, calculator));
334-
components.add(calculator);
335334

336335
return components;
337336
}

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/common/InferenceServiceNodeLocalRateLimitCalculatorTests.java

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.elasticsearch.inference.TaskType;
1111
import org.elasticsearch.plugins.Plugin;
1212
import org.elasticsearch.test.ESIntegTestCase;
13+
import org.elasticsearch.test.InternalTestCluster;
1314
import org.elasticsearch.xpack.inference.LocalStateInferencePlugin;
1415
import org.elasticsearch.xpack.inference.external.http.sender.HttpRequestSender;
1516
import org.elasticsearch.xpack.inference.services.SenderService;
@@ -23,6 +24,7 @@
2324
import static org.elasticsearch.xpack.inference.common.InferenceServiceNodeLocalRateLimitCalculator.DEFAULT_MAX_NODES_PER_GROUPING;
2425
import static org.elasticsearch.xpack.inference.common.InferenceServiceNodeLocalRateLimitCalculator.SERVICE_NODE_LOCAL_RATE_LIMIT_CONFIGS;
2526
import static org.hamcrest.Matchers.equalTo;
27+
import static org.hamcrest.Matchers.instanceOf;
2628

2729
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE, numDataNodes = 0)
2830
public class InferenceServiceNodeLocalRateLimitCalculatorTests extends ESIntegTestCase {
@@ -39,7 +41,7 @@ public void testInitialClusterGrouping_Correct() throws Exception {
3941
var nodeNames = internalCluster().startNodes(numNodes);
4042
ensureStableCluster(numNodes);
4143

42-
var firstCalculator = internalCluster().getInstance(InferenceServiceNodeLocalRateLimitCalculator.class, nodeNames.getFirst());
44+
var firstCalculator = getCalculatorInstance(internalCluster(), nodeNames.getFirst());
4345
waitForRateLimitingAssignments(firstCalculator);
4446

4547
RateLimitAssignment firstAssignment = firstCalculator.getRateLimitAssignment(
@@ -49,7 +51,7 @@ public void testInitialClusterGrouping_Correct() throws Exception {
4951

5052
// Verify that all other nodes land on the same assignment
5153
for (String nodeName : nodeNames.subList(1, nodeNames.size())) {
52-
var calculator = internalCluster().getInstance(InferenceServiceNodeLocalRateLimitCalculator.class, nodeName);
54+
var calculator = getCalculatorInstance(internalCluster(), nodeName);
5355
waitForRateLimitingAssignments(calculator);
5456
var currentAssignment = calculator.getRateLimitAssignment(ElasticInferenceService.NAME, TaskType.SPARSE_EMBEDDING);
5557
assertEquals(firstAssignment, currentAssignment);
@@ -75,7 +77,7 @@ public void testNumberOfNodesPerGroup_Decreases_When_NodeLeavesCluster() throws
7577
ensureStableCluster(currentNumberOfNodes);
7678
}
7779

78-
var calculator = internalCluster().getInstance(InferenceServiceNodeLocalRateLimitCalculator.class, nodeLeftInCluster);
80+
var calculator = getCalculatorInstance(internalCluster(), nodeLeftInCluster);
7981
waitForRateLimitingAssignments(calculator);
8082

8183
Set<String> supportedServices = SERVICE_NODE_LOCAL_RATE_LIMIT_CONFIGS.keySet();
@@ -98,7 +100,7 @@ public void testGrouping_RespectsMaxNodesPerGroupingLimit() throws Exception {
98100
var nodeNames = internalCluster().startNodes(numNodes);
99101
ensureStableCluster(numNodes);
100102

101-
var calculator = internalCluster().getInstance(InferenceServiceNodeLocalRateLimitCalculator.class, nodeNames.getFirst());
103+
var calculator = getCalculatorInstance(internalCluster(), nodeNames.getFirst());
102104
waitForRateLimitingAssignments(calculator);
103105

104106
Set<String> supportedServices = SERVICE_NODE_LOCAL_RATE_LIMIT_CONFIGS.keySet();
@@ -117,7 +119,7 @@ public void testInitialRateLimitsCalculation_Correct() throws Exception {
117119
var nodeNames = internalCluster().startNodes(numNodes);
118120
ensureStableCluster(numNodes);
119121

120-
var calculator = internalCluster().getInstance(InferenceServiceNodeLocalRateLimitCalculator.class, nodeNames.getFirst());
122+
var calculator = getCalculatorInstance(internalCluster(), nodeNames.getFirst());
121123
waitForRateLimitingAssignments(calculator);
122124

123125
Set<String> supportedServices = SERVICE_NODE_LOCAL_RATE_LIMIT_CONFIGS.keySet();
@@ -148,7 +150,7 @@ public void testRateLimits_Decrease_OnNodeJoin() throws Exception {
148150
var nodeNames = internalCluster().startNodes(initialNodes);
149151
ensureStableCluster(initialNodes);
150152

151-
var calculator = internalCluster().getInstance(InferenceServiceNodeLocalRateLimitCalculator.class, nodeNames.getFirst());
153+
var calculator = getCalculatorInstance(internalCluster(), nodeNames.getFirst());
152154
waitForRateLimitingAssignments(calculator);
153155

154156
for (var serviceName : SERVICE_NODE_LOCAL_RATE_LIMIT_CONFIGS.keySet()) {
@@ -178,7 +180,7 @@ public void testRateLimits_Increase_OnNodeLeave() throws Exception {
178180
var nodeNames = internalCluster().startNodes(numNodes);
179181
ensureStableCluster(numNodes);
180182

181-
var calculator = internalCluster().getInstance(InferenceServiceNodeLocalRateLimitCalculator.class, nodeNames.getFirst());
183+
var calculator = getCalculatorInstance(internalCluster(), nodeNames.getFirst());
182184
waitForRateLimitingAssignments(calculator);
183185

184186
for (var serviceName : SERVICE_NODE_LOCAL_RATE_LIMIT_CONFIGS.keySet()) {
@@ -208,6 +210,27 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {
208210
return Arrays.asList(LocalStateInferencePlugin.class);
209211
}
210212

213+
private InferenceServiceNodeLocalRateLimitCalculator getCalculatorInstance(InternalTestCluster internalTestCluster, String nodeName) {
214+
InferenceServiceRateLimitCalculator calculatorInstance = internalTestCluster.getInstance(
215+
InferenceServiceRateLimitCalculator.class,
216+
nodeName
217+
);
218+
assertThat(
219+
"["
220+
+ InferenceServiceNodeLocalRateLimitCalculatorTests.class.getName()
221+
+ "] should use ["
222+
+ InferenceServiceNodeLocalRateLimitCalculator.class.getName()
223+
+ "] as implementation for ["
224+
+ InferenceServiceRateLimitCalculator.class.getName()
225+
+ "]. Provided implementation was ["
226+
+ calculatorInstance.getClass().getName()
227+
+ "].",
228+
calculatorInstance,
229+
instanceOf(InferenceServiceNodeLocalRateLimitCalculator.class)
230+
);
231+
return (InferenceServiceNodeLocalRateLimitCalculator) calculatorInstance;
232+
}
233+
211234
private void waitForRateLimitingAssignments(InferenceServiceNodeLocalRateLimitCalculator calculator) throws Exception {
212235
assertBusy(() -> {
213236
var assignment = calculator.getRateLimitAssignment(ElasticInferenceService.NAME, TaskType.SPARSE_EMBEDDING);

0 commit comments

Comments
 (0)