Repository navigation
Fix UnsupportedOperationException merging an empty object with a populated sibling index - #5791
Conversation
PR Reviewer Guide 🔍(Review updated until commit a08d9a0)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to a08d9a0
Previous suggestionsSuggestions up to commit 2bd1750
|
…lated sibling cloneDeep() only allocated a mutable properties map when the source object had properties; for an empty object it left copy.properties as the class-default ImmutableMap.of(). When a wildcard describe merges two indices whose only difference is one carrying a leaf under an otherwise-empty object path, and the empty side is merged first, MergeRuleHelper's in-place put of the sibling's leaf lands on that immutable map and throws UnsupportedOperationException. Always give the copy a mutable LinkedHashMap so the deep merge can add fields regardless of whether the object started empty. The crash only reproduces when the empty-object index sorts first in the unordered map getIndexMappings returns, so the added regression test pins that iteration order to reproduce deterministically. Signed-off-by: Kai Huang <[email protected]>
2bd1750 to
a08d9a0
Compare
|
Persistent review updated to latest commit a08d9a0 |
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project check has failed because the head coverage (63.26%) is below the target coverage (99.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #5791 +/- ##
============================================
- Coverage 63.26% 63.26% -0.01%
+ Complexity 8823 8822 -1
============================================
Files 938 938
Lines 40217 40216 -1
Branches 4532 4531 -1
============================================
- Hits 25442 25441 -1
Misses 13951 13951
Partials 824 824
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
dai-chen
left a comment
There was a problem hiding this comment.
Since the OpenSearchDataType.properties is still an ImmutableMap, could you double check any other code path may mutate it?
I audited |
…lated sibling (#5791) (#5864) cloneDeep() only allocated a mutable properties map when the source object had properties; for an empty object it left copy.properties as the class-default ImmutableMap.of(). When a wildcard describe merges two indices whose only difference is one carrying a leaf under an otherwise-empty object path, and the empty side is merged first, MergeRuleHelper's in-place put of the sibling's leaf lands on that immutable map and throws UnsupportedOperationException. Always give the copy a mutable LinkedHashMap so the deep merge can add fields regardless of whether the object started empty. The crash only reproduces when the empty-object index sorts first in the unordered map getIndexMappings returns, so the added regression test pins that iteration order to reproduce deterministically. (cherry picked from commit d7af0dc) Signed-off-by: Kai Huang <[email protected]>
…indices (#482) OpenSearch 3.9.0 ships opensearch-project/sql#5657, which made wildcard PPL/SQL queries throw UnsupportedOperationException when one index maps an empty object and a sibling index maps a leaf under the same path. After the first rollover of otel-v1-apm-span, events.attributes is an empty object in the new index, so every query on otel-v1-apm-span-* can fail, including Agent Traces. The fix (opensearch-project/sql#5791) was backported to 3.9 in opensearch-project/sql#5864 and is in the 3.9.1 staging image. OpenSearch Dashboards stays on 3.9.0. Signed-off-by: Kyle Hounslow <[email protected]>
Description
A wildcard PPL/SQL query over two indices whose only mapping difference is an
otherwise-empty object path (
a.b.c: {"type":"object"}) on one index versus thesame path carrying a leaf (
a.b.c.leaf) on the other can fail with:Root cause.
OpenSearchDataType.cloneDeep()(added in #5657, which mergesdeep copies so the merge no longer mutates the retained per-index mappings)
only allocated a mutable
propertiesmap when the source object had properties.For an empty object it left
copy.propertiesas the class-defaultImmutableMap.of(). WhengetFieldTypes()deep-merges the two indices and theempty-object side is merged first, it becomes the accumulator whose
chas noproperties; the populated sibling then contributes
leaf, andMergeRuleHelper's in-placeputlands on that immutable map and throws.The crash is intermittent because
getIndexMappings()returns an unordered map(
Collectors.toUnmodifiableMap), so it only fires on runs where the empty-objectindex happens to be merged first.
Fix. Always give the copy a mutable
LinkedHashMap, so the deep merge canadd fields regardless of whether the cloned object started empty. This matches
what
parseMapping()already produces for a freshly parsed empty object (amutable
LinkedHashMap), which is why the pre-#5657 path — merging the parsedmaps directly — did not hit this.
Reproducer
Fails on the runs where the empty index sorts first; passes with this change.
Testing
Added
OpenSearchDescribeIndexRequestTest#getFieldTypesMergesEmptyObjectWithPopulatedSibling,which pins the empty-object index to iterate first so it reproduces
deterministically. It fails with
UnsupportedOperationExceptionbefore the fixand passes after. Existing
OpenSearchDescribeIndexRequestTest,OpenSearchDataType*, andMergeRules.*suites remain green.Related Issues
Check List
--signoffor-s.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.