Skip to content

Commit f53259e

Browse files
authored
Merge branch 'main' into 2025/11/06/idloader-create
2 parents cd6dd73 + 2e8cbc9 commit f53259e

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

server/src/main/java/org/elasticsearch/index/codec/vectors/es93/DirectIOCapableLucene99FlatVectorsFormat.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,22 +266,25 @@ public void nextDocsAndScores(int nextCount, Bits liveDocs, DocAndFloatFeatureBu
266266
buffer.docs[size++] = indexIterator.index();
267267
}
268268
}
269-
int loopBound = size - (size % bulkSize);
269+
final int firstBulkSize = Math.min(bulkSize, size);
270+
for (int j = 0; j < firstBulkSize; j++) {
271+
final long ord = buffer.docs[j];
272+
inputSlice.prefetch(ord * byteSize, byteSize);
273+
}
274+
final int loopBound = size - (size % bulkSize);
270275
int i = 0;
271276
for (; i < loopBound; i += bulkSize) {
272-
for (int j = 0; j < bulkSize; j++) {
273-
long ord = buffer.docs[i + j];
277+
final int nextI = i + bulkSize;
278+
final int nextBulkSize = Math.min(bulkSize, size - nextI);
279+
for (int j = 0; j < nextBulkSize; j++) {
280+
final long ord = buffer.docs[nextI + j];
274281
inputSlice.prefetch(ord * byteSize, byteSize);
275282
}
276283
System.arraycopy(buffer.docs, i, docBuffer, 0, bulkSize);
277284
inner.bulkScore(docBuffer, scoreBuffer, bulkSize);
278285
System.arraycopy(scoreBuffer, 0, buffer.features, i, bulkSize);
279286
}
280-
int countLeft = size - i;
281-
for (int j = i; j < size; j++) {
282-
long ord = buffer.docs[j];
283-
inputSlice.prefetch(ord * byteSize, byteSize);
284-
}
287+
final int countLeft = size - i;
285288
System.arraycopy(buffer.docs, i, docBuffer, 0, countLeft);
286289
inner.bulkScore(docBuffer, scoreBuffer, countLeft);
287290
System.arraycopy(scoreBuffer, 0, buffer.features, i, countLeft);

server/src/test/java/org/elasticsearch/index/query/SearchExecutionContextTests.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import org.apache.lucene.document.Field;
1212
import org.apache.lucene.document.KeywordField;
13-
import org.apache.lucene.document.StringField;
1413
import org.apache.lucene.index.DirectoryReader;
1514
import org.apache.lucene.index.LeafReaderContext;
1615
import org.apache.lucene.index.Term;
@@ -223,18 +222,27 @@ public void testFielddataLookupTerminatesInLoop() {
223222
}
224223

225224
public void testFielddataLookupSometimesLoop() throws IOException {
226-
SearchExecutionContext searchExecutionContext = createSearchExecutionContext(
227-
// simulate a runtime field cycle in the second doc: 1: doc['2'] 2: doc['3'] 3: doc['4'] 4: doc['4']
225+
// create this field so we can use it to make sure we're escaping the loop on only the "first" document
226+
var concreteField = new KeywordFieldMapper.KeywordFieldType("indexed_field", true, true, Collections.emptyMap());
227+
228+
// simulate a runtime field cycle in the second doc: 1: doc['2'] 2: doc['3'] 3: doc['4'] 4: doc['4']
229+
var runtimeFields = List.of(
228230
runtimeField("1", leafLookup -> leafLookup.doc().get("2").get(0).toString()),
229231
runtimeField("2", leafLookup -> leafLookup.doc().get("3").get(0).toString()),
230232
runtimeField("3", leafLookup -> leafLookup.doc().get("4").get(0).toString()),
231-
runtimeField("4", (leafLookup, docId) -> {
232-
if (docId == 0) {
233+
runtimeField("4", leafLookup -> {
234+
if (leafLookup.doc().get("indexed_field").getFirst().equals("first")) {
233235
return "escape!";
234236
}
235-
return leafLookup.doc().get("4").get(0).toString();
237+
return leafLookup.doc().get("4").getFirst().toString();
236238
})
237239
);
240+
SearchExecutionContext searchExecutionContext = createSearchExecutionContext(
241+
"uuid",
242+
null,
243+
createMappingLookup(List.of(concreteField), runtimeFields),
244+
Collections.emptyMap()
245+
);
238246
List<String> values = collect("1", searchExecutionContext, new TermQuery(new Term("indexed_field", "first")));
239247
assertEquals(List.of("escape!"), values);
240248
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> collect("1", searchExecutionContext));
@@ -776,8 +784,8 @@ private static List<String> collect(String field, SearchExecutionContext searchE
776784
private static List<String> collect(String field, SearchExecutionContext searchExecutionContext, Query query) throws IOException {
777785
List<String> result = new ArrayList<>();
778786
try (Directory directory = newDirectory(); RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory)) {
779-
indexWriter.addDocument(List.of(new StringField("indexed_field", "first", Field.Store.NO)));
780-
indexWriter.addDocument(List.of(new StringField("indexed_field", "second", Field.Store.NO)));
787+
indexWriter.addDocument(List.of(new KeywordField("indexed_field", "first", Field.Store.YES)));
788+
indexWriter.addDocument(List.of(new KeywordField("indexed_field", "second", Field.Store.YES)));
781789
try (DirectoryReader reader = indexWriter.getReader()) {
782790
IndexSearcher searcher = newSearcher(reader);
783791
MappedFieldType fieldType = searchExecutionContext.getFieldType(field);

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,7 @@ Collection<Object> createComponents(
11461146
if (authorizationDenialMessages.get() == null) {
11471147
authorizationDenialMessages.set(new AuthorizationDenialMessages.Default());
11481148
}
1149+
final var authorizedProjectsResolver = getCustomAuthorizedProjectsResolverOrDefault(extensionComponents);
11491150
final AuthorizationService authzService = new AuthorizationService(
11501151
settings,
11511152
allRolesStore,
@@ -1164,14 +1165,15 @@ Collection<Object> createComponents(
11641165
authorizationDenialMessages.get(),
11651166
linkedProjectConfigService,
11661167
projectResolver,
1167-
getCustomAuthorizedProjectsResolverOrDefault(extensionComponents),
1168+
authorizedProjectsResolver,
11681169
new CrossProjectModeDecider(settings)
11691170
);
11701171

11711172
components.add(nativeRolesStore); // used by roles actions
11721173
components.add(reservedRolesStore); // used by roles actions
11731174
components.add(allRolesStore); // for SecurityInfoTransportAction and clear roles cache
11741175
components.add(authzService);
1176+
components.add(new PluginComponentBinding<>(AuthorizedProjectsResolver.class, authorizedProjectsResolver));
11751177

11761178
final SecondaryAuthenticator secondaryAuthenticator = new SecondaryAuthenticator(
11771179
securityContext.get(),

0 commit comments

Comments
 (0)