Skip to content
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

Ensure dynamicMapping updates are handled in insertion order #103047

Merged

Conversation

benwtrent
Copy link
Member

The switch to holding dynamic fields in a hashmap effectively randomizes their iteration order. This can be troublesome when building the mapping update required by these updates. When iterating in an unknown order, recursing to the leaf mapper can occur many times O(n^2). However, starting with insertion order, it will occur only O(n) times.

closes: #103011

@benwtrent benwtrent added >bug :Search Foundations/Mapping Index mappings, including merging and defining field types v8.12.0 v8.11.2 labels Dec 6, 2023
@elasticsearchmachine elasticsearchmachine added the Team:Search Meta label for search team label Dec 6, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search (Team:Search)

@elasticsearchmachine
Copy link
Collaborator

Hi @benwtrent, I've created a changelog YAML for you.

@benwtrent
Copy link
Member Author

I confirmed this fix by running: #103015

The runtime is now at or below what it was in 8.10.

I additionally double checked that the flame graphs were similar, and indeed they are.

Copy link
Member

@piergm piergm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Way to go @benwtrent!

@benwtrent benwtrent added the auto-backport-and-merge Automatically create backport pull requests and merge when ready label Dec 6, 2023
@benwtrent benwtrent merged commit d6e8217 into elastic:main Dec 6, 2023
13 of 15 checks passed
@benwtrent benwtrent deleted the bugfix/fix-dynamic-mapping-regression branch December 6, 2023 19:33
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.11

benwtrent added a commit to benwtrent/elasticsearch that referenced this pull request Dec 6, 2023
…#103047)

The switch to holding dynamic fields in a hashmap effectively randomizes their iteration order. This can be troublesome when building the mapping update required by these updates. When iterating in an unknown order, recursing to the leaf mapper can occur many times `O(n^2)`. However, starting with insertion order, it will occur only `O(n)` times.

closes: elastic#103011
elasticsearchmachine pushed a commit that referenced this pull request Dec 6, 2023
#103083)

The switch to holding dynamic fields in a hashmap effectively randomizes their iteration order. This can be troublesome when building the mapping update required by these updates. When iterating in an unknown order, recursing to the leaf mapper can occur many times `O(n^2)`. However, starting with insertion order, it will occur only `O(n)` times.

closes: #103011
@@ -166,9 +166,9 @@ protected DocumentParserContext(
mappingParserContext,
source,
new HashSet<>(),
new HashMap<>(),
new LinkedHashMap<>(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we restrict the type of the fields to LinkedHashMap ?
i.e.

-    private final Map<String, List<Mapper.Builder>> dynamicMappers;
+    private final LinkedHashMap<String, List<Mapper.Builder>> dynamicMappers;
     private final Set<String> newFieldsSeen;
-    private final Map<String, ObjectMapper.Builder> dynamicObjectMappers;
+    private final LinkedHashMap<String, ObjectMapper.Builder> dynamicObjectMappers;
     private final List<RuntimeField> dynamicRuntimeFields;
     private final DocumentDimensions dimensions;
     private final ObjectMapper parent;
@@ -102,9 +102,9 @@ public abstract class DocumentParserContext {
         MappingParserContext mappingParserContext,
         SourceToParse sourceToParse,
         Set<String> ignoreFields,
-        Map<String, List<Mapper.Builder>> dynamicMappers,
+        LinkedHashMap<String, List<Mapper.Builder>> dynamicMappers,
         Set<String> newFieldsSeen,
-        Map<String, ObjectMapper.Builder> dynamicObjectMappers,
+        LinkedHashMap<String, ObjectMapper.Builder> dynamicObjectMappers,

@benwtrent
Copy link
Member Author

To clarify to folks digging between all the various issues, this PR didn't fully address the problem. See #103011 (comment).

The real fix was in 8.11.4, and was a full revert of the originating bugged code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport-and-merge Automatically create backport pull requests and merge when ready >bug :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Meta label for search team v8.11.3 v8.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Significant ingest performance regression while handling parsing dynamically added objects
5 participants