Skip to content

Commit 8b35cf6

Browse files
Merge branch 'main' into esql/settings_stack_telemetry
2 parents 42ecd18 + 6c36fb4 commit 8b35cf6

File tree

65 files changed

+807
-295
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+807
-295
lines changed

docs/changelog/141570.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
area: "Authorization"
2+
issues: []
3+
pr: 141570
4+
summary: Update View CRUD Actions to be Index Actions
5+
type: enhancement

modules/reindex/src/main/java/org/elasticsearch/reindex/AbstractAsyncBulkByScrollAction.java

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
import org.elasticsearch.index.reindex.AbstractBulkByScrollRequest;
3636
import org.elasticsearch.index.reindex.BulkByScrollResponse;
3737
import org.elasticsearch.index.reindex.BulkByScrollTask;
38-
import org.elasticsearch.index.reindex.ClientScrollableHitSource;
38+
import org.elasticsearch.index.reindex.ClientScrollablePaginatedHitSource;
39+
import org.elasticsearch.index.reindex.PaginatedHitSource;
40+
import org.elasticsearch.index.reindex.PaginatedHitSource.SearchFailure;
3941
import org.elasticsearch.index.reindex.ResumeInfo.WorkerResumeInfo;
40-
import org.elasticsearch.index.reindex.ScrollableHitSource;
41-
import org.elasticsearch.index.reindex.ScrollableHitSource.SearchFailure;
4242
import org.elasticsearch.index.reindex.WorkerBulkByScrollTaskState;
4343
import org.elasticsearch.script.CtxMap;
4444
import org.elasticsearch.script.Metadata;
@@ -99,14 +99,14 @@ public abstract class AbstractAsyncBulkByScrollAction<
9999
private final ParentTaskAssigningClient bulkClient;
100100
private final ActionListener<BulkByScrollResponse> listener;
101101
private final Retry bulkRetry;
102-
private final ScrollableHitSource scrollSource;
102+
private final PaginatedHitSource paginatedHitSource;
103103

104104
/**
105105
* This BiFunction is used to apply various changes depending of the Reindex action and the search hit,
106106
* from copying search hit metadata (parent, routing, etc) to potentially transforming the
107107
* {@link RequestWrapper} completely.
108108
*/
109-
private final BiFunction<RequestWrapper<?>, ScrollableHitSource.Hit, RequestWrapper<?>> scriptApplier;
109+
private final BiFunction<RequestWrapper<?>, PaginatedHitSource.Hit, RequestWrapper<?>> scriptApplier;
110110
private int lastBatchSize;
111111
/**
112112
* Keeps track of the total number of bulk operations performed
@@ -176,15 +176,15 @@ public abstract class AbstractAsyncBulkByScrollAction<
176176
this.listener = listener;
177177
BackoffPolicy backoffPolicy = buildBackoffPolicy();
178178
bulkRetry = new Retry(BackoffPolicy.wrap(backoffPolicy, worker::countBulkRetry), threadPool);
179-
scrollSource = buildScrollableResultSource(
179+
paginatedHitSource = buildScrollableResultSource(
180180
backoffPolicy,
181181
prepareSearchRequest(mainRequest, needsSourceDocumentVersions, needsSourceDocumentSeqNoAndPrimaryTerm, needsVectors)
182182
);
183183
scriptApplier = Objects.requireNonNull(buildScriptApplier(), "script applier must not be null");
184184
}
185185

186186
/**
187-
* Prepares a search request to be used in a ScrollableHitSource.
187+
* Prepares a search request to be used in a {@link PaginatedHitSource}.
188188
* Preparation might set a sort order (if not set already) and disable scroll if max docs is small enough.
189189
*/
190190
// Visible for testing
@@ -238,7 +238,7 @@ static <Request extends AbstractBulkByScrollRequest<Request>> SearchRequest prep
238238
*
239239
* Public for testings....
240240
*/
241-
public BiFunction<RequestWrapper<?>, ScrollableHitSource.Hit, RequestWrapper<?>> buildScriptApplier() {
241+
public BiFunction<RequestWrapper<?>, PaginatedHitSource.Hit, RequestWrapper<?>> buildScriptApplier() {
242242
// The default script applier executes a no-op
243243
return (request, searchHit) -> request;
244244
}
@@ -248,12 +248,12 @@ public BiFunction<RequestWrapper<?>, ScrollableHitSource.Hit, RequestWrapper<?>>
248248
* metadata or scripting. That will be handled by copyMetadata and
249249
* apply functions that can be overridden.
250250
*/
251-
protected abstract RequestWrapper<?> buildRequest(ScrollableHitSource.Hit doc);
251+
protected abstract RequestWrapper<?> buildRequest(PaginatedHitSource.Hit doc);
252252

253253
/**
254254
* Copies the metadata from a hit to the request.
255255
*/
256-
protected RequestWrapper<?> copyMetadata(RequestWrapper<?> request, ScrollableHitSource.Hit doc) {
256+
protected RequestWrapper<?> copyMetadata(RequestWrapper<?> request, PaginatedHitSource.Hit doc) {
257257
copyRouting(request, doc.getRouting());
258258
return request;
259259
}
@@ -270,7 +270,7 @@ protected void copyRouting(RequestWrapper<?> request, String routing) {
270270
* from the bulk request. It is also where we fail on invalid search hits, like
271271
* when the document has no source but it's required.
272272
*/
273-
protected boolean accept(ScrollableHitSource.Hit doc) {
273+
protected boolean accept(PaginatedHitSource.Hit doc) {
274274
if (doc.getSource() == null) {
275275
/*
276276
* Either the document didn't store _source or we didn't fetch it for some reason. Since we don't allow the user to
@@ -282,9 +282,9 @@ protected boolean accept(ScrollableHitSource.Hit doc) {
282282
return true;
283283
}
284284

285-
protected BulkRequest buildBulk(Iterable<? extends ScrollableHitSource.Hit> docs) {
285+
protected BulkRequest buildBulk(Iterable<? extends PaginatedHitSource.Hit> docs) {
286286
BulkRequest bulkRequest = new BulkRequest();
287-
for (ScrollableHitSource.Hit doc : docs) {
287+
for (PaginatedHitSource.Hit doc : docs) {
288288
if (accept(doc)) {
289289
RequestWrapper<?> request = scriptApplier.apply(copyMetadata(buildRequest(doc), doc), doc);
290290
if (request != null) {
@@ -295,8 +295,8 @@ protected BulkRequest buildBulk(Iterable<? extends ScrollableHitSource.Hit> docs
295295
return bulkRequest;
296296
}
297297

298-
protected ScrollableHitSource buildScrollableResultSource(BackoffPolicy backoffPolicy, SearchRequest searchRequest) {
299-
return new ClientScrollableHitSource(
298+
protected PaginatedHitSource buildScrollableResultSource(BackoffPolicy backoffPolicy, SearchRequest searchRequest) {
299+
return new ClientScrollablePaginatedHitSource(
300300
logger,
301301
backoffPolicy,
302302
threadPool,
@@ -338,17 +338,17 @@ public void start() {
338338
WorkerResumeInfo workerResumeInfo = resumeInfo.getWorker().get();
339339
startTime.set(workerResumeInfo.startTime());
340340
worker.restoreState(workerResumeInfo.status());
341-
scrollSource.resume(workerResumeInfo);
341+
paginatedHitSource.resume(workerResumeInfo);
342342
} else {
343343
startTime.set(System.nanoTime());
344-
scrollSource.start();
344+
paginatedHitSource.start();
345345
}
346346
} catch (Exception e) {
347347
finishHim(e);
348348
}
349349
}
350350

351-
void onScrollResponse(ScrollableHitSource.AsyncResponse asyncResponse) {
351+
void onScrollResponse(PaginatedHitSource.AsyncResponse asyncResponse) {
352352
onScrollResponse(new ScrollConsumableHitsResponse(asyncResponse));
353353
}
354354

@@ -362,10 +362,10 @@ void onScrollResponse(ScrollConsumableHitsResponse asyncResponse) {
362362
* Process a scroll response.
363363
* @param lastBatchStartTimeNS the time when the last batch started. Used to calculate the throttling delay.
364364
* @param lastBatchSizeToUse the size of the last batch. Used to calculate the throttling delay.
365-
* @param asyncResponse the response to process from ScrollableHitSource
365+
* @param asyncResponse the response to process from {@link PaginatedHitSource}
366366
*/
367367
void onScrollResponse(long lastBatchStartTimeNS, int lastBatchSizeToUse, ScrollConsumableHitsResponse asyncResponse) {
368-
ScrollableHitSource.Response response = asyncResponse.response();
368+
PaginatedHitSource.Response response = asyncResponse.response();
369369
logger.debug("[{}]: got scroll response with [{}] hits", task.getId(), asyncResponse.remainingHits());
370370
if (task.isCancelled()) {
371371
logger.debug("[{}]: finishing early because the task was cancelled", task.getId());
@@ -420,7 +420,7 @@ void prepareBulkRequest(long thisBatchStartTimeNS, ScrollConsumableHitsResponse
420420
return;
421421
}
422422
worker.countBatch();
423-
final List<? extends ScrollableHitSource.Hit> hits;
423+
final List<? extends PaginatedHitSource.Hit> hits;
424424

425425
if (mainRequest.getMaxDocs() != MAX_DOCS_ALL_MATCHES) {
426426
// Truncate the hits if we have more than the request max docs
@@ -528,7 +528,7 @@ void onBulkResponse(BulkResponse response, Runnable onSuccess) {
528528
return;
529529
}
530530

531-
if (scrollSource.hasScroll() == false) {
531+
if (paginatedHitSource.hasScroll() == false) {
532532
// Index contains fewer matching docs than max_docs (found < max_docs <= scroll size)
533533
refreshAndFinish(emptyList(), emptyList(), false);
534534
return;
@@ -611,7 +611,7 @@ protected void finishHim(Exception failure) {
611611
*/
612612
protected void finishHim(Exception failure, List<Failure> indexingFailures, List<SearchFailure> searchFailures, boolean timedOut) {
613613
logger.debug("[{}]: finishing without any catastrophic failures", task.getId());
614-
scrollSource.close(threadPool.getThreadContext().preserveContext(() -> {
614+
paginatedHitSource.close(threadPool.getThreadContext().preserveContext(() -> {
615615
if (failure == null) {
616616
BulkByScrollResponse response = buildResponse(
617617
timeValueNanos(System.nanoTime() - startTime.get()),
@@ -645,7 +645,7 @@ void addDestinationIndices(Collection<String> indices) {
645645
* Set the last returned scrollId. Exists entirely for testing.
646646
*/
647647
void setScroll(String scroll) {
648-
scrollSource.setScroll(scroll);
648+
paginatedHitSource.setScroll(scroll);
649649
}
650650

651651
/**
@@ -841,7 +841,7 @@ public static RequestWrapper<DeleteRequest> wrap(DeleteRequest request) {
841841
*/
842842
public abstract static class ScriptApplier<T extends Metadata>
843843
implements
844-
BiFunction<RequestWrapper<?>, ScrollableHitSource.Hit, RequestWrapper<?>> {
844+
BiFunction<RequestWrapper<?>, PaginatedHitSource.Hit, RequestWrapper<?>> {
845845

846846
// "index" is the default operation
847847
protected static final String INDEX = "index";
@@ -867,7 +867,7 @@ public ScriptApplier(
867867
}
868868

869869
@Override
870-
public RequestWrapper<?> apply(RequestWrapper<?> request, ScrollableHitSource.Hit doc) {
870+
public RequestWrapper<?> apply(RequestWrapper<?> request, PaginatedHitSource.Hit doc) {
871871
if (script == null) {
872872
return request;
873873
}
@@ -883,7 +883,7 @@ public RequestWrapper<?> apply(RequestWrapper<?> request, ScrollableHitSource.Hi
883883
return requestFromOp(request, metadata.getOp());
884884
}
885885

886-
protected abstract CtxMap<T> execute(ScrollableHitSource.Hit doc, Map<String, Object> source);
886+
protected abstract CtxMap<T> execute(PaginatedHitSource.Hit doc, Map<String, Object> source);
887887

888888
protected abstract void updateRequest(RequestWrapper<?> request, T metadata);
889889

@@ -909,24 +909,24 @@ protected RequestWrapper<?> requestFromOp(RequestWrapper<?> request, String op)
909909
}
910910

911911
static class ScrollConsumableHitsResponse {
912-
private final ScrollableHitSource.AsyncResponse asyncResponse;
913-
private final List<? extends ScrollableHitSource.Hit> hits;
912+
private final PaginatedHitSource.AsyncResponse asyncResponse;
913+
private final List<? extends PaginatedHitSource.Hit> hits;
914914
private int consumedOffset = 0;
915915

916-
ScrollConsumableHitsResponse(ScrollableHitSource.AsyncResponse asyncResponse) {
916+
ScrollConsumableHitsResponse(PaginatedHitSource.AsyncResponse asyncResponse) {
917917
this.asyncResponse = asyncResponse;
918918
this.hits = asyncResponse.response().getHits();
919919
}
920920

921-
ScrollableHitSource.Response response() {
921+
PaginatedHitSource.Response response() {
922922
return asyncResponse.response();
923923
}
924924

925-
List<? extends ScrollableHitSource.Hit> consumeRemainingHits() {
925+
List<? extends PaginatedHitSource.Hit> consumeRemainingHits() {
926926
return consumeHits(remainingHits());
927927
}
928928

929-
List<? extends ScrollableHitSource.Hit> consumeHits(int numberOfHits) {
929+
List<? extends PaginatedHitSource.Hit> consumeHits(int numberOfHits) {
930930
if (numberOfHits < 0) {
931931
throw new IllegalArgumentException("Invalid number of hits to consume [" + numberOfHits + "]");
932932
}

modules/reindex/src/main/java/org/elasticsearch/reindex/AsyncDeleteByQueryAction.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import org.elasticsearch.index.reindex.BulkByScrollResponse;
1717
import org.elasticsearch.index.reindex.BulkByScrollTask;
1818
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
19-
import org.elasticsearch.index.reindex.ScrollableHitSource;
19+
import org.elasticsearch.index.reindex.PaginatedHitSource;
2020
import org.elasticsearch.script.ScriptService;
2121
import org.elasticsearch.threadpool.ThreadPool;
2222

@@ -38,14 +38,14 @@ public AsyncDeleteByQueryAction(
3838
}
3939

4040
@Override
41-
protected boolean accept(ScrollableHitSource.Hit doc) {
41+
protected boolean accept(PaginatedHitSource.Hit doc) {
4242
// Delete-by-query does not require the source to delete a document
4343
// and the default implementation checks for it
4444
return true;
4545
}
4646

4747
@Override
48-
protected RequestWrapper<DeleteRequest> buildRequest(ScrollableHitSource.Hit doc) {
48+
protected RequestWrapper<DeleteRequest> buildRequest(PaginatedHitSource.Hit doc) {
4949
DeleteRequest delete = new DeleteRequest();
5050
delete.index(doc.getIndex());
5151
delete.id(doc.getId());
@@ -59,7 +59,7 @@ protected RequestWrapper<DeleteRequest> buildRequest(ScrollableHitSource.Hit doc
5959
* don't care for a deletion.
6060
*/
6161
@Override
62-
protected RequestWrapper<?> copyMetadata(RequestWrapper<?> request, ScrollableHitSource.Hit doc) {
62+
protected RequestWrapper<?> copyMetadata(RequestWrapper<?> request, PaginatedHitSource.Hit doc) {
6363
request.setRouting(doc.getRouting());
6464
return request;
6565
}

modules/reindex/src/main/java/org/elasticsearch/reindex/BulkIndexByScrollResponseContentListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import org.elasticsearch.action.bulk.BulkItemResponse.Failure;
1313
import org.elasticsearch.index.reindex.BulkByScrollResponse;
14-
import org.elasticsearch.index.reindex.ScrollableHitSource.SearchFailure;
14+
import org.elasticsearch.index.reindex.PaginatedHitSource.SearchFailure;
1515
import org.elasticsearch.rest.RestChannel;
1616
import org.elasticsearch.rest.RestResponse;
1717
import org.elasticsearch.rest.RestStatus;

modules/reindex/src/main/java/org/elasticsearch/reindex/Reindexer.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@
4747
import org.elasticsearch.index.mapper.IdFieldMapper;
4848
import org.elasticsearch.index.reindex.BulkByScrollResponse;
4949
import org.elasticsearch.index.reindex.BulkByScrollTask;
50+
import org.elasticsearch.index.reindex.PaginatedHitSource;
5051
import org.elasticsearch.index.reindex.ReindexAction;
5152
import org.elasticsearch.index.reindex.ReindexRequest;
5253
import org.elasticsearch.index.reindex.RemoteInfo;
53-
import org.elasticsearch.index.reindex.ScrollableHitSource;
5454
import org.elasticsearch.index.reindex.WorkerBulkByScrollTaskState;
55-
import org.elasticsearch.reindex.remote.RemoteScrollableHitSource;
55+
import org.elasticsearch.reindex.remote.RemoteScrollablePaginatedHitSource;
5656
import org.elasticsearch.script.CtxMap;
5757
import org.elasticsearch.script.ReindexMetadata;
5858
import org.elasticsearch.script.ReindexScript;
@@ -161,7 +161,7 @@ public void onResponse(BulkByScrollResponse bulkByScrollResponse) {
161161
var searchExceptionSample = Optional.ofNullable(bulkByScrollResponse.getSearchFailures())
162162
.stream()
163163
.flatMap(List::stream)
164-
.map(ScrollableHitSource.SearchFailure::getReason)
164+
.map(PaginatedHitSource.SearchFailure::getReason)
165165
.findFirst();
166166
var bulkExceptionSample = Optional.ofNullable(bulkByScrollResponse.getBulkFailures())
167167
.stream()
@@ -312,13 +312,13 @@ private IndexMode destinationIndexMode(ProjectState state) {
312312
}
313313

314314
@Override
315-
protected ScrollableHitSource buildScrollableResultSource(BackoffPolicy backoffPolicy, SearchRequest searchRequest) {
315+
protected PaginatedHitSource buildScrollableResultSource(BackoffPolicy backoffPolicy, SearchRequest searchRequest) {
316316
if (mainRequest.getRemoteInfo() != null) {
317317
RemoteInfo remoteInfo = mainRequest.getRemoteInfo();
318318
createdThreads = synchronizedList(new ArrayList<>());
319319
assert sslConfig != null : "Reindex ssl config must be set";
320320
RestClient restClient = buildRestClient(remoteInfo, sslConfig, task.getId(), createdThreads);
321-
return new RemoteScrollableHitSource(
321+
return new RemoteScrollablePaginatedHitSource(
322322
logger,
323323
backoffPolicy,
324324
threadPool,
@@ -337,7 +337,7 @@ protected ScrollableHitSource buildScrollableResultSource(BackoffPolicy backoffP
337337
protected void finishHim(
338338
Exception failure,
339339
List<BulkItemResponse.Failure> indexingFailures,
340-
List<ScrollableHitSource.SearchFailure> searchFailures,
340+
List<PaginatedHitSource.SearchFailure> searchFailures,
341341
boolean timedOut
342342
) {
343343
super.finishHim(failure, indexingFailures, searchFailures, timedOut);
@@ -351,7 +351,7 @@ protected void finishHim(
351351
}
352352

353353
@Override
354-
public BiFunction<RequestWrapper<?>, ScrollableHitSource.Hit, RequestWrapper<?>> buildScriptApplier() {
354+
public BiFunction<RequestWrapper<?>, PaginatedHitSource.Hit, RequestWrapper<?>> buildScriptApplier() {
355355
Script script = mainRequest.getScript();
356356
if (script != null) {
357357
assert scriptService != null : "Script service must be set";
@@ -361,7 +361,7 @@ public BiFunction<RequestWrapper<?>, ScrollableHitSource.Hit, RequestWrapper<?>>
361361
}
362362

363363
@Override
364-
protected RequestWrapper<IndexRequest> buildRequest(ScrollableHitSource.Hit doc) {
364+
protected RequestWrapper<IndexRequest> buildRequest(PaginatedHitSource.Hit doc) {
365365
IndexRequest index = new IndexRequest();
366366

367367
// Copy the index from the request so we always write where it asked to write
@@ -456,7 +456,7 @@ static class ReindexScriptApplier extends ScriptApplier<ReindexMetadata> {
456456
}
457457

458458
@Override
459-
protected CtxMap<ReindexMetadata> execute(ScrollableHitSource.Hit doc, Map<String, Object> source) {
459+
protected CtxMap<ReindexMetadata> execute(PaginatedHitSource.Hit doc, Map<String, Object> source) {
460460
if (reindex == null) {
461461
reindex = scriptService.compile(script, ReindexScript.CONTEXT);
462462
}

0 commit comments

Comments
 (0)