Skip to content

Commit 9946cea

Browse files
Turn RankFeatureShardPhase into utility class (#117616)
This class has no state, no need to pass instances of it around all its members can be static to simplify node construction and the code overall.
1 parent 9e61089 commit 9946cea

File tree

9 files changed

+12
-39
lines changed

9 files changed

+12
-39
lines changed

server/src/main/java/org/elasticsearch/node/NodeConstruction.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,6 @@ private void construct(
10991099
threadPool,
11001100
scriptService,
11011101
bigArrays,
1102-
searchModule.getRankFeatureShardPhase(),
11031102
searchModule.getFetchPhase(),
11041103
responseCollectorService,
11051104
circuitBreakerService,

server/src/main/java/org/elasticsearch/node/NodeServiceProvider.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.elasticsearch.script.ScriptService;
3636
import org.elasticsearch.search.SearchService;
3737
import org.elasticsearch.search.fetch.FetchPhase;
38-
import org.elasticsearch.search.rank.feature.RankFeatureShardPhase;
3938
import org.elasticsearch.tasks.TaskManager;
4039
import org.elasticsearch.telemetry.tracing.Tracer;
4140
import org.elasticsearch.threadpool.ThreadPool;
@@ -119,7 +118,6 @@ SearchService newSearchService(
119118
ThreadPool threadPool,
120119
ScriptService scriptService,
121120
BigArrays bigArrays,
122-
RankFeatureShardPhase rankFeatureShardPhase,
123121
FetchPhase fetchPhase,
124122
ResponseCollectorService responseCollectorService,
125123
CircuitBreakerService circuitBreakerService,
@@ -132,7 +130,6 @@ SearchService newSearchService(
132130
threadPool,
133131
scriptService,
134132
bigArrays,
135-
rankFeatureShardPhase,
136133
fetchPhase,
137134
responseCollectorService,
138135
circuitBreakerService,

server/src/main/java/org/elasticsearch/search/SearchModule.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@
231231
import org.elasticsearch.search.rank.RankDoc;
232232
import org.elasticsearch.search.rank.RankShardResult;
233233
import org.elasticsearch.search.rank.feature.RankFeatureDoc;
234-
import org.elasticsearch.search.rank.feature.RankFeatureShardPhase;
235234
import org.elasticsearch.search.rank.feature.RankFeatureShardResult;
236235
import org.elasticsearch.search.rescore.QueryRescorerBuilder;
237236
import org.elasticsearch.search.rescore.RescorerBuilder;
@@ -1299,10 +1298,6 @@ private void registerQuery(QuerySpec<?> spec) {
12991298
);
13001299
}
13011300

1302-
public RankFeatureShardPhase getRankFeatureShardPhase() {
1303-
return new RankFeatureShardPhase();
1304-
}
1305-
13061301
public FetchPhase getFetchPhase() {
13071302
return new FetchPhase(fetchSubPhases);
13081303
}

server/src/main/java/org/elasticsearch/search/SearchService.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv
286286
private final BigArrays bigArrays;
287287

288288
private final FetchPhase fetchPhase;
289-
private final RankFeatureShardPhase rankFeatureShardPhase;
290289
private volatile Executor searchExecutor;
291290
private volatile boolean enableQueryPhaseParallelCollection;
292291

@@ -325,7 +324,6 @@ public SearchService(
325324
ThreadPool threadPool,
326325
ScriptService scriptService,
327326
BigArrays bigArrays,
328-
RankFeatureShardPhase rankFeatureShardPhase,
329327
FetchPhase fetchPhase,
330328
ResponseCollectorService responseCollectorService,
331329
CircuitBreakerService circuitBreakerService,
@@ -339,7 +337,6 @@ public SearchService(
339337
this.scriptService = scriptService;
340338
this.responseCollectorService = responseCollectorService;
341339
this.bigArrays = bigArrays;
342-
this.rankFeatureShardPhase = rankFeatureShardPhase;
343340
this.fetchPhase = fetchPhase;
344341
this.multiBucketConsumerService = new MultiBucketConsumerService(
345342
clusterService,
@@ -751,9 +748,9 @@ public void executeRankFeaturePhase(RankFeatureShardRequest request, SearchShard
751748
searchContext.rankFeatureResult().incRef();
752749
return searchContext.rankFeatureResult();
753750
}
754-
rankFeatureShardPhase.prepareForFetch(searchContext, request);
751+
RankFeatureShardPhase.prepareForFetch(searchContext, request);
755752
fetchPhase.execute(searchContext, docIds, null);
756-
rankFeatureShardPhase.processFetch(searchContext);
753+
RankFeatureShardPhase.processFetch(searchContext);
757754
var rankFeatureResult = searchContext.rankFeatureResult();
758755
rankFeatureResult.incRef();
759756
return rankFeatureResult;

server/src/main/java/org/elasticsearch/search/rank/feature/RankFeatureShardPhase.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public final class RankFeatureShardPhase {
3535

3636
public static final RankFeatureShardResult EMPTY_RESULT = new RankFeatureShardResult(new RankFeatureDoc[0]);
3737

38-
public RankFeatureShardPhase() {}
38+
private RankFeatureShardPhase() {}
3939

40-
public void prepareForFetch(SearchContext searchContext, RankFeatureShardRequest request) {
40+
public static void prepareForFetch(SearchContext searchContext, RankFeatureShardRequest request) {
4141
if (logger.isTraceEnabled()) {
4242
logger.trace("{}", new SearchContextSourcePrinter(searchContext));
4343
}
@@ -58,7 +58,7 @@ public void prepareForFetch(SearchContext searchContext, RankFeatureShardRequest
5858
}
5959
}
6060

61-
public void processFetch(SearchContext searchContext) {
61+
public static void processFetch(SearchContext searchContext) {
6262
if (logger.isTraceEnabled()) {
6363
logger.trace("{}", new SearchContextSourcePrinter(searchContext));
6464
}
@@ -92,7 +92,7 @@ public void processFetch(SearchContext searchContext) {
9292
}
9393
}
9494

95-
private RankFeaturePhaseRankShardContext shardContext(SearchContext searchContext) {
95+
private static RankFeaturePhaseRankShardContext shardContext(SearchContext searchContext) {
9696
return searchContext.request().source() != null && searchContext.request().source().rankBuilder() != null
9797
? searchContext.request().source().rankBuilder().buildRankFeaturePhaseShardContext()
9898
: null;

server/src/test/java/org/elasticsearch/search/rank/RankFeatureShardPhaseTests.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,7 @@ public void testPrepareForFetch() {
219219
RankFeatureShardRequest request = mock(RankFeatureShardRequest.class);
220220
when(request.getDocIds()).thenReturn(new int[] { 4, 9, numDocs - 1 });
221221

222-
RankFeatureShardPhase rankFeatureShardPhase = new RankFeatureShardPhase();
223-
rankFeatureShardPhase.prepareForFetch(searchContext, request);
222+
RankFeatureShardPhase.prepareForFetch(searchContext, request);
224223

225224
assertNotNull(searchContext.fetchFieldsContext());
226225
assertEquals(searchContext.fetchFieldsContext().fields().size(), 1);
@@ -248,8 +247,7 @@ public void testPrepareForFetchNoRankFeatureContext() {
248247
RankFeatureShardRequest request = mock(RankFeatureShardRequest.class);
249248
when(request.getDocIds()).thenReturn(new int[] { 4, 9, numDocs - 1 });
250249

251-
RankFeatureShardPhase rankFeatureShardPhase = new RankFeatureShardPhase();
252-
rankFeatureShardPhase.prepareForFetch(searchContext, request);
250+
RankFeatureShardPhase.prepareForFetch(searchContext, request);
253251

254252
assertNull(searchContext.fetchFieldsContext());
255253
assertNull(searchContext.fetchResult());
@@ -274,8 +272,7 @@ public void testPrepareForFetchWhileTaskIsCancelled() {
274272
RankFeatureShardRequest request = mock(RankFeatureShardRequest.class);
275273
when(request.getDocIds()).thenReturn(new int[] { 4, 9, numDocs - 1 });
276274

277-
RankFeatureShardPhase rankFeatureShardPhase = new RankFeatureShardPhase();
278-
expectThrows(TaskCancelledException.class, () -> rankFeatureShardPhase.prepareForFetch(searchContext, request));
275+
expectThrows(TaskCancelledException.class, () -> RankFeatureShardPhase.prepareForFetch(searchContext, request));
279276
}
280277
}
281278

@@ -318,11 +315,10 @@ public void testProcessFetch() {
318315
RankFeatureShardRequest request = mock(RankFeatureShardRequest.class);
319316
when(request.getDocIds()).thenReturn(new int[] { 4, 9, numDocs - 1 });
320317

321-
RankFeatureShardPhase rankFeatureShardPhase = new RankFeatureShardPhase();
322318
// this is called as part of the search context initialization
323319
// with the ResultsType.RANK_FEATURE type
324320
searchContext.addRankFeatureResult();
325-
rankFeatureShardPhase.processFetch(searchContext);
321+
RankFeatureShardPhase.processFetch(searchContext);
326322

327323
assertNotNull(searchContext.rankFeatureResult());
328324
assertNotNull(searchContext.rankFeatureResult().rankFeatureResult());
@@ -365,11 +361,10 @@ public void testProcessFetchEmptyHits() {
365361
RankFeatureShardRequest request = mock(RankFeatureShardRequest.class);
366362
when(request.getDocIds()).thenReturn(new int[] { 4, 9, numDocs - 1 });
367363

368-
RankFeatureShardPhase rankFeatureShardPhase = new RankFeatureShardPhase();
369364
// this is called as part of the search context initialization
370365
// with the ResultsType.RANK_FEATURE type
371366
searchContext.addRankFeatureResult();
372-
rankFeatureShardPhase.processFetch(searchContext);
367+
RankFeatureShardPhase.processFetch(searchContext);
373368

374369
assertNotNull(searchContext.rankFeatureResult());
375370
assertNotNull(searchContext.rankFeatureResult().rankFeatureResult());
@@ -410,11 +405,10 @@ public void testProcessFetchWhileTaskIsCancelled() {
410405
RankFeatureShardRequest request = mock(RankFeatureShardRequest.class);
411406
when(request.getDocIds()).thenReturn(new int[] { 4, 9, numDocs - 1 });
412407

413-
RankFeatureShardPhase rankFeatureShardPhase = new RankFeatureShardPhase();
414408
// this is called as part of the search context initialization
415409
// with the ResultsType.RANK_FEATURE type
416410
searchContext.addRankFeatureResult();
417-
expectThrows(TaskCancelledException.class, () -> rankFeatureShardPhase.processFetch(searchContext));
411+
expectThrows(TaskCancelledException.class, () -> RankFeatureShardPhase.processFetch(searchContext));
418412
} finally {
419413
if (searchHits != null) {
420414
searchHits.decRef();

server/src/test/java/org/elasticsearch/snapshots/SnapshotResiliencyTests.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@
180180
import org.elasticsearch.search.SearchService;
181181
import org.elasticsearch.search.builder.SearchSourceBuilder;
182182
import org.elasticsearch.search.fetch.FetchPhase;
183-
import org.elasticsearch.search.rank.feature.RankFeatureShardPhase;
184183
import org.elasticsearch.telemetry.TelemetryProvider;
185184
import org.elasticsearch.telemetry.tracing.Tracer;
186185
import org.elasticsearch.test.ClusterServiceUtils;
@@ -2314,7 +2313,6 @@ public RecyclerBytesStreamOutput newNetworkBytesStream() {
23142313
threadPool,
23152314
scriptService,
23162315
bigArrays,
2317-
new RankFeatureShardPhase(),
23182316
new FetchPhase(Collections.emptyList()),
23192317
responseCollectorService,
23202318
new NoneCircuitBreakerService(),

test/framework/src/main/java/org/elasticsearch/node/MockNode.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.elasticsearch.search.MockSearchService;
4343
import org.elasticsearch.search.SearchService;
4444
import org.elasticsearch.search.fetch.FetchPhase;
45-
import org.elasticsearch.search.rank.feature.RankFeatureShardPhase;
4645
import org.elasticsearch.tasks.TaskManager;
4746
import org.elasticsearch.telemetry.tracing.Tracer;
4847
import org.elasticsearch.test.ESTestCase;
@@ -100,7 +99,6 @@ SearchService newSearchService(
10099
ThreadPool threadPool,
101100
ScriptService scriptService,
102101
BigArrays bigArrays,
103-
RankFeatureShardPhase rankFeatureShardPhase,
104102
FetchPhase fetchPhase,
105103
ResponseCollectorService responseCollectorService,
106104
CircuitBreakerService circuitBreakerService,
@@ -115,7 +113,6 @@ SearchService newSearchService(
115113
threadPool,
116114
scriptService,
117115
bigArrays,
118-
rankFeatureShardPhase,
119116
fetchPhase,
120117
responseCollectorService,
121118
circuitBreakerService,
@@ -129,7 +126,6 @@ SearchService newSearchService(
129126
threadPool,
130127
scriptService,
131128
bigArrays,
132-
rankFeatureShardPhase,
133129
fetchPhase,
134130
responseCollectorService,
135131
circuitBreakerService,

test/framework/src/main/java/org/elasticsearch/search/MockSearchService.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.elasticsearch.search.internal.ReaderContext;
2525
import org.elasticsearch.search.internal.SearchContext;
2626
import org.elasticsearch.search.internal.ShardSearchRequest;
27-
import org.elasticsearch.search.rank.feature.RankFeatureShardPhase;
2827
import org.elasticsearch.telemetry.tracing.Tracer;
2928
import org.elasticsearch.threadpool.ThreadPool;
3029

@@ -83,7 +82,6 @@ public MockSearchService(
8382
ThreadPool threadPool,
8483
ScriptService scriptService,
8584
BigArrays bigArrays,
86-
RankFeatureShardPhase rankFeatureShardPhase,
8785
FetchPhase fetchPhase,
8886
ResponseCollectorService responseCollectorService,
8987
CircuitBreakerService circuitBreakerService,
@@ -96,7 +94,6 @@ public MockSearchService(
9694
threadPool,
9795
scriptService,
9896
bigArrays,
99-
rankFeatureShardPhase,
10097
fetchPhase,
10198
responseCollectorService,
10299
circuitBreakerService,

0 commit comments

Comments
 (0)