-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[Transform] Don't search if all indices are unchanged between checkpoints #77204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -127,7 +127,7 @@ protected void doNextSearch(long waitTimeInNanos, ActionListener<SearchResponse> | |||||
|
|
||||||
| injectPointInTimeIfNeeded( | ||||||
| buildSearchRequest(), | ||||||
| ActionListener.wrap(pitSearchRequest -> { doSearch(pitSearchRequest, nextPhase); }, nextPhase::onFailure) | ||||||
| ActionListener.wrap(pitSearchRequest -> doSearch(pitSearchRequest, nextPhase), nextPhase::onFailure) | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -393,12 +393,12 @@ private void injectPointInTimeIfNeeded( | |||||
| Tuple<String, SearchRequest> namedSearchRequest, | ||||||
| ActionListener<Tuple<String, SearchRequest>> listener | ||||||
| ) { | ||||||
| if (disablePit) { | ||||||
| SearchRequest searchRequest = namedSearchRequest.v2(); | ||||||
| if (disablePit || searchRequest.indices().length == 0) { | ||||||
| listener.onResponse(namedSearchRequest); | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| SearchRequest searchRequest = namedSearchRequest.v2(); | ||||||
| PointInTimeBuilder pit = namedPits.get(namedSearchRequest.v1()); | ||||||
| if (pit != null) { | ||||||
| searchRequest.source().pointInTimeBuilder(pit); | ||||||
|
|
@@ -455,22 +455,30 @@ private void injectPointInTimeIfNeeded( | |||||
| ); | ||||||
| } | ||||||
|
|
||||||
| private void doSearch(Tuple<String, SearchRequest> namedSearchRequest, ActionListener<SearchResponse> listener) { | ||||||
| logger.trace(() -> new ParameterizedMessage("searchRequest: [{}]", namedSearchRequest.v2())); | ||||||
| void doSearch(Tuple<String, SearchRequest> namedSearchRequest, ActionListener<SearchResponse> listener) { | ||||||
| String name = namedSearchRequest.v1(); | ||||||
| SearchRequest searchRequest = namedSearchRequest.v2(); | ||||||
| // We want to treat a request to search 0 indices as a request to do nothing, not a request to search all indices | ||||||
| if (searchRequest.indices().length == 0) { | ||||||
| logger.debug("[{}] Search request [{}] optimized to noop; searchRequest [{}]", getJobId(), name, searchRequest); | ||||||
| listener.onResponse(null); | ||||||
| return; | ||||||
| } | ||||||
| logger.trace("searchRequest: [{}]", searchRequest); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| PointInTimeBuilder pit = namedSearchRequest.v2().pointInTimeBuilder(); | ||||||
| PointInTimeBuilder pit = searchRequest.pointInTimeBuilder(); | ||||||
|
|
||||||
| ClientHelper.executeWithHeadersAsync( | ||||||
| transformConfig.getHeaders(), | ||||||
| ClientHelper.TRANSFORM_ORIGIN, | ||||||
| client, | ||||||
| SearchAction.INSTANCE, | ||||||
| namedSearchRequest.v2(), | ||||||
| searchRequest, | ||||||
| ActionListener.wrap(response -> { | ||||||
| // did the pit change? | ||||||
| if (response.pointInTimeId() != null && (pit == null || response.pointInTimeId() != pit.getEncodedId())) { | ||||||
| namedPits.put(namedSearchRequest.v1(), new PointInTimeBuilder(response.pointInTimeId()).setKeepAlive(PIT_KEEP_ALIVE)); | ||||||
| logger.trace("point in time handle has changed; request [{}]", namedSearchRequest.v1()); | ||||||
| if (response.pointInTimeId() != null && (pit == null || response.pointInTimeId().equals(pit.getEncodedId())) == false) { | ||||||
| namedPits.put(name, new PointInTimeBuilder(response.pointInTimeId()).setKeepAlive(PIT_KEEP_ALIVE)); | ||||||
| logger.trace("point in time handle has changed; request [{}]", name); | ||||||
| } | ||||||
|
|
||||||
| listener.onResponse(response); | ||||||
|
|
@@ -484,18 +492,18 @@ private void doSearch(Tuple<String, SearchRequest> namedSearchRequest, ActionLis | |||||
| new ParameterizedMessage( | ||||||
| "[{}] Search context missing, falling back to normal search; request [{}]", | ||||||
| getJobId(), | ||||||
| namedSearchRequest.v1() | ||||||
| name | ||||||
| ), | ||||||
| e | ||||||
| ); | ||||||
| namedPits.remove(namedSearchRequest.v1()); | ||||||
| namedSearchRequest.v2().source().pointInTimeBuilder(null); | ||||||
| namedPits.remove(name); | ||||||
| searchRequest.source().pointInTimeBuilder(null); | ||||||
| ClientHelper.executeWithHeadersAsync( | ||||||
| transformConfig.getHeaders(), | ||||||
| ClientHelper.TRANSFORM_ORIGIN, | ||||||
| client, | ||||||
| SearchAction.INSTANCE, | ||||||
| namedSearchRequest.v2(), | ||||||
| searchRequest, | ||||||
| listener | ||||||
| ); | ||||||
| return; | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -523,10 +523,8 @@ private void finalizeCheckpoint(ActionListener<Void> listener) { | |
| } | ||
|
|
||
| if (lastCheckpoint != null) { | ||
| long docsIndexed = 0; | ||
| long docsProcessed = 0; | ||
| docsIndexed = progress.getDocumentsIndexed(); | ||
| docsProcessed = progress.getDocumentsProcessed(); | ||
| long docsIndexed = progress.getDocumentsIndexed(); | ||
| long docsProcessed = progress.getDocumentsProcessed(); | ||
|
|
||
| long durationMs = System.currentTimeMillis() - lastCheckpoint.getTimestamp(); | ||
| getStats().incrementCheckpointExponentialAverages(durationMs < 0 ? 0 : durationMs, docsIndexed, docsProcessed); | ||
|
|
@@ -1131,7 +1129,7 @@ private SearchRequest buildQueryToFindChanges() { | |
| // TODO: if buildChangesQuery changes the query it get overwritten | ||
| sourceBuilder.query(filteredQuery); | ||
|
|
||
| logger.debug("[{}] Querying for changes: {}", getJobId(), sourceBuilder); | ||
| logger.debug("[{}] Querying {} for changes: {}", getJobId(), request.indices(), sourceBuilder); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return request.source(sourceBuilder); | ||
| } | ||
|
|
||
|
|
@@ -1168,7 +1166,7 @@ private SearchRequest buildQueryToUpdateDestinationIndex() { | |
| } | ||
|
|
||
| sourceBuilder.query(queryBuilder); | ||
| logger.debug(() -> new ParameterizedMessage("[{}] Querying for data: {}", getJobId(), sourceBuilder)); | ||
| logger.debug("[{}] Querying {} for data: {}", getJobId(), request.indices(), sourceBuilder); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I always thought that the logger would serialize the strings unless we provided a message provider. Consequently, if we weren't on debug level, we are serializing the sourceBuilder unnecessarily. |
||
|
|
||
| return request.source(sourceBuilder) | ||
| .allowPartialSearchResults(false) // shard failures should fail the request | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The introduction of a magic value
nullis dangerous, what if the client returnsnull. It seems better to return an empty result set, so thatnullcauses the transform to fail as before.