-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
Extract references tracking from SearchLookup #68202
Open
romseygeek
wants to merge
16
commits into
elastic:main
Choose a base branch
from
romseygeek:lookup/references
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
553860a
Simplify doc access from SearchLookup
romseygeek 7986ecf
nuke StoredFieldsLookup as well
romseygeek 0d7b6c3
at least make it compile before pushing mate
romseygeek f8f0d5a
Merge remote-tracking branch 'origin/master' into lookup/docmap
romseygeek 0b9abb3
Use CheckedBiconsumer
romseygeek c10a8b3
Track references in SearchLookup internally
romseygeek 5a34a41
Merge remote-tracking branch 'origin/master' into lookup/references
romseygeek 4b9dc70
error message
romseygeek 01d8945
checkstyle
romseygeek 17d4c3b
Always go via lookup()
romseygeek 5289cd6
Merge remote-tracking branch 'origin/master' into lookup/references
romseygeek 810ac89
make TrackingMappedFieldsLookup public
romseygeek 680b7e2
compilation
romseygeek 1c2cd01
*sigh*
romseygeek af997da
Remove trackReferences method, add lookup(String) to context instead
romseygeek fce385e
Merge remote-tracking branch 'origin/master' into lookup/references
romseygeek File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
server/src/main/java/org/elasticsearch/search/lookup/TrackingMappedFieldsLookup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.search.lookup; | ||
|
||
import org.elasticsearch.index.mapper.MappedFieldType; | ||
|
||
import java.util.Collections; | ||
import java.util.LinkedHashSet; | ||
import java.util.Set; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* Used for detecting loops caused by fields referring to other fields. The chain is empty | ||
* for the "top level" lookup created for the entire search. When a lookup is used to load | ||
* fielddata for a field, we fork it and make sure the field name name isn't in the chain, | ||
* then add it to the end. So the lookup for the a field named {@code a} will be {@code ["a"]}. If | ||
* that field looks up the values of a field named {@code b} then | ||
* {@code b}'s chain will contain {@code ["a", "b"]}. | ||
*/ | ||
public final class TrackingMappedFieldsLookup { | ||
|
||
/** | ||
* The maximum depth of field dependencies. | ||
* When a runtime field's doc values depends on another runtime field's doc values, | ||
* which depends on another runtime field's doc values and so on, it can | ||
* make a very deep stack, which we want to limit. | ||
*/ | ||
public static final int MAX_FIELD_CHAIN_DEPTH = 5; | ||
|
||
final Function<String, MappedFieldType> lookup; | ||
final Set<String> references; | ||
|
||
public TrackingMappedFieldsLookup(Function<String, MappedFieldType> lookup) { | ||
this.lookup = lookup; | ||
this.references = Collections.emptySet(); | ||
} | ||
|
||
private TrackingMappedFieldsLookup(Function<String, MappedFieldType> lookup, Set<String> references, String field) { | ||
this.lookup = lookup; | ||
this.references = new LinkedHashSet<>(references); | ||
if (this.references.add(field) == false) { | ||
String message = String.join(" -> ", this.references) + " -> " + field; | ||
throw new IllegalArgumentException("Cyclic dependency detected while resolving runtime fields: " + message); | ||
} | ||
if (this.references.size() > MAX_FIELD_CHAIN_DEPTH) { | ||
throw new IllegalArgumentException("Field requires resolving too many dependent fields: " | ||
+ String.join(" -> ", this.references)); | ||
} | ||
} | ||
|
||
public TrackingMappedFieldsLookup trackingField(String field) { | ||
return new TrackingMappedFieldsLookup(lookup, this.references, field); | ||
} | ||
|
||
public MappedFieldType get(String field) { | ||
return lookup.apply(field); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This wasn't really checking an actual production code path before. We now run a search, which forces the script to look up values triggering the loop handling.