Repository navigation
[Enhancement] Raise default structural limits for deserialization filter - #5826
Conversation
The defaults added in opensearch-project#5721 reject ordinary pushed-down expressions. A CASE WHEN with a NOT IN list inside COUNT(DISTINCT ...) reaches a serialization depth of 28 against a max_depth of 20, and an IN list of about 35 values exceeds max_refs of 1000. Raise the defaults to max_depth=300, max_refs=10000, max_bytes=100000, document the settings, and add regression tests for conditional counts, large IN lists, and excessive nesting. Signed-off-by: Jialiang Liang <[email protected]>
PR Code Analyzer ❗AI-powered 'Code-Diff-Analyzer' found issues on commit de2751e.
The table above displays the top 10 most important findings. Pull Requests Author(s): Please update your Pull Request according to the report above. Repository Maintainer(s): You can Thanks. |
PR Reviewer Guide 🔍(Review updated until commit de2751e)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to de2751e
Previous suggestionsSuggestions up to commit bf4b298
|
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project check has failed because the head coverage (63.36%) 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 #5826 +/- ##
=========================================
Coverage 63.36% 63.36%
Complexity 8872 8872
=========================================
Files 949 949
Lines 40322 40322
Branches 4546 4546
=========================================
Hits 25549 25549
Misses 13929 13929
Partials 844 844
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:
|
Size the defaults against measured legitimate expressions and the limits OpenSearch already enforces. The deepest legitimate expression measured reaches depth 72, and cold deserialization overflows a 1 MB stack at about 1200, so 150 leaves headroom on both sides. Pushed-down scripts are capped by script.max_size_in_bytes (65535) before deserialization, so max_bytes=65536 and max_refs=10000 never reject a script OpenSearch accepted. Add regression tests for deeply nested conditions and CASE with many WHEN clauses. Signed-off-by: Jialiang Liang <[email protected]>
|
Persistent review updated to latest commit de2751e |
|
The backport to |
…rialization filter (#5826) (#5862) Raise the deserialization filter defaults to max_depth=150, max_refs=10000, max_bytes=65536, document the settings, and add regression tests. (cherry picked from commit 803ed31) Signed-off-by: Jialiang Liang <[email protected]>
Description
Follow-up to #5721. The default structural limits added there reject ordinary pushed-down expressions. Every shard then fails with
Failed to deserialize expression codeunless an operator raises the settings. For example, this conditional count fails at the current defaults:This PR raises the defaults to values sized from measurements, documents the three settings, and adds regression tests.
plugins.query.deserialization.max_depthplugins.query.deserialization.max_refsplugins.query.deserialization.max_bytesHow the defaults were sized
Each limit should:
All numbers below were measured with an instrumented build that logged the depth, reference count, and byte count the JDK filter sees for every payload.
1. Existing integration tests. Across the SQL, PPL (v2), and legacy suites (about 2000 tests, 74 unique expression payloads, 2 cursor payloads), the largest values are depth 15, 238 references, and 5.9 KB. All of them fit the current defaults. That's why the suites didn't catch this: none of them contains a moderately complex conditional expression.
2. Representative analytics expressions, run end to end against a test cluster:
CASE+NOT INof 8 values)CASEwith 10WHENs, 3 conditions eachCASEwith 25WHENs, 3 conditions eachCASE WHEN x IN (50 values)CASE WHEN x IN (100 values)AND/ORCASE WHEN x IN (250 values), the largest that fits the script size limitSELECT *, expressions,WHERE ... IN)A trivial
CASEalready costs depth 13. Each further level of nesting adds 3–4, so the currentmax_depth=20admits only 2–3 levels.INlists become a balancedORtree (ExpressionAnalyzer#buildOrTree), so they add depth logarithmically but references and bytes linearly, at about 28 references and 170 bytes per value. Each pushed-down aggregation or filter is a separate script, so a query with several metrics does not accumulate against one limit.3. Limits already in place.
script.max_size_in_bytes(default 65535) is checked byScriptService.compileon every shard before the plugin deserializes anything. I verified this end to end: aCASE WHEN x IN (400 values)fails withexceeded max allowed inline script size in bytes [65535] with size [96601]. An accepted script therefore decodes to at most about 49 KB, which is about 7200 references for legitimate expressions.-Xss) succeeds up to depth ~1200 and overflows at ~1260. On a data node the search thread has already used part of that stack, so the practical ceiling is lower.Why 150 / 10000 / 65536
max_depth= 150max_refs= 10000script.max_size_in_bytesmax_bytes= 65536script.max_size_in_bytesmax_refsandmax_bytesare set just above whatscript.max_size_in_bytesalready permits. On the script path they add no new capacity; they keep a bound on the cursor path, which that setting does not cover.max_depthis the one limit that other settings don't cover, so it stays well below the stack-overflow point.Scope
The limits apply to payloads deserialized by
DefaultExpressionSerializer(v2 expression scripts, used by SQL and by PPL on the v2 engine) andPlanSerializer(SQL cursors). The Calcite engine'sRelJsonSerializerpayload is a singleString, whose structure is carried in JSON, so these limits do not constrain it.Known gap
plugins.query.max_expression_depth(default 1000) bounds AST depth at parse time, which is far deeper thanmax_depthallows. A query can still pass the parser and then be rejected on the data nodes. Aligning the two guards is left for a follow-up.Tests
DefaultExpressionSerializerTest: each of the following round-trips at the new defaults and is rejected at the current onesAND/ORCASEwith 25WHENclausesINlist, the largest that fits inscript.max_size_in_bytesDefaultExpressionSerializerTest: 60 nestedNOTs (depth ~185) are rejected by the filter with anIllegalStateExceptionDeserializationFilterUtilTest: boundary checks updated for the new defaults, plus a check that values exactly at the limits are acceptedRelated Issues
Follow-up to #5721, #5469
Check List
--signoff.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.