Repository navigation
Carry the partial_result override off ThreadContext so it survives the security handoff - #5758
Conversation
…e security handoff The per-request partial_result override was stored in Log4j ThreadContext (QueryContext.setPartialResultOverride), set on the transport thread and read on the worker/planning thread by CalciteLogicalIndexScan.tryPartialResultAggregate. The security plugin's transport interceptor does not preserve Log4j ThreadContext across that handoff, so on a security-enabled cluster the override is lost and isPartialResultEnabled silently falls back to the cluster setting. A request that sends partial_result=false to opt out therefore still gets a partial result (with a PARTIAL_RESULT warning) when the cluster setting is on -- the setting's own path is unaffected because it is read from osIndex.getSettings() on the worker thread. This is the same transport->worker handoff bug opensearch-project#5739 fixed for warningsSupported; opensearch-project#5739 moved warningsSupported onto the object graph but left the override on ThreadContext (reasoning the settings fallback made it resilient -- but the fallback masks the drop). Carry the override the same way warningsSupported is carried: PPLQueryRequest.partialResult -> AbstractPlan -> QueryPlan.execute() (worker thread) -> CalcitePlanContext (in its thread-local snapshot, reset per query). tryPartialResultAggregate now reads the override from CalcitePlanContext and falls back to the cluster setting. Removes the dead QueryContext override methods. Reproduced and verified with a new PartialResultSecurityIT case (perRequestPartialResultFalseOverridesClusterSettingUnderSecurity): fails before this change (complete expected, partial returned), passes after. Signed-off-by: Kai Huang <[email protected]>
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
RyanL1997
left a comment
There was a problem hiding this comment.
I'm just thinking of a mechanism to catch the changes like this which will potentially impact the security path. With the current CI setup I think there is still a gap for us to test with security enabled.
The mode (opensearch-project#5657) narrowed an aggregation to the index subset where the group field is aggregatable and labelled the result with a warning. It is being dropped: returning a knowingly incomplete answer to make a query faster is the wrong default to offer, and gating it on a cluster setting, a per-request flag and a response-format check made three moving parts that each had to survive the security plugin's transport-to-worker handoff (opensearch-project#5739, opensearch-project#5743, opensearch-project#5758). Removed: PartialResultAggregatePushdown and its hook in CalciteLogicalIndexScan, plugins.query.partial_result.on_mapping_conflict.enabled, the per-request partial_result field, and the warnings-supported format gate that existed only to protect this feature. A conflicted aggregation once again returns the complete result over every index, which since opensearch-project#5646 pushes down as a _source script rather than failing. Kept whole: the warnings channel it introduced -- Warning, QueryResponse.warnings, CalcitePlanContext.addWarning/drainWarnings, and the SimpleJsonResponseFormatter plumbing. Nothing produces a warning after this commit; opensearch-project#5807 is the next producer, reporting a search that covered only some of its shards. Note for reviewers: dropping partial_result from TransportPPLQueryRequest changes that request's wire format. The class version-gates nothing and the field was appended the same way in 3.9, so this is symmetric with how it arrived, but it does mean a mixed 3.9/3.10 cluster must not route PPL across versions. Signed-off-by: Kai Huang <[email protected]>
* Remove the opt-in partial-result mode for mapping conflicts The mode (#5657) narrowed an aggregation to the index subset where the group field is aggregatable and labelled the result with a warning. It is being dropped: returning a knowingly incomplete answer to make a query faster is the wrong default to offer, and gating it on a cluster setting, a per-request flag and a response-format check made three moving parts that each had to survive the security plugin's transport-to-worker handoff (#5739, #5743, #5758). Removed: PartialResultAggregatePushdown and its hook in CalciteLogicalIndexScan, plugins.query.partial_result.on_mapping_conflict.enabled, the per-request partial_result field, and the warnings-supported format gate that existed only to protect this feature. A conflicted aggregation once again returns the complete result over every index, which since #5646 pushes down as a _source script rather than failing. Kept whole: the warnings channel it introduced -- Warning, QueryResponse.warnings, CalcitePlanContext.addWarning/drainWarnings, and the SimpleJsonResponseFormatter plumbing. Nothing produces a warning after this commit; #5807 is the next producer, reporting a search that covered only some of its shards. Note for reviewers: dropping partial_result from TransportPPLQueryRequest changes that request's wire format. The class version-gates nothing and the field was appended the same way in 3.9, so this is symmetric with how it arrived, but it does mean a mixed 3.9/3.10 cluster must not route PPL across versions. Signed-off-by: Kai Huang <[email protected]> * Drop the per-index mapping retention the feature needed getIndexMappings() on OpenSearchIndex and lastIndexMappings on the describe request existed only so the partitioner could see which index mapped a field which way. Nothing reads them now. The deep copy before merging stays: MergeRuleHelper rewrites the accumulated type's properties in place, so a fetched mapping would otherwise stop describing its own index. Its test now asserts that on the fetched mappings directly rather than through the removed accessor. Signed-off-by: Kai Huang <[email protected]> --------- Signed-off-by: Kai Huang <[email protected]>
…ch-project#5814) * Remove the opt-in partial-result mode for mapping conflicts The mode (opensearch-project#5657) narrowed an aggregation to the index subset where the group field is aggregatable and labelled the result with a warning. It is being dropped: returning a knowingly incomplete answer to make a query faster is the wrong default to offer, and gating it on a cluster setting, a per-request flag and a response-format check made three moving parts that each had to survive the security plugin's transport-to-worker handoff (opensearch-project#5739, opensearch-project#5743, opensearch-project#5758). Removed: PartialResultAggregatePushdown and its hook in CalciteLogicalIndexScan, plugins.query.partial_result.on_mapping_conflict.enabled, the per-request partial_result field, and the warnings-supported format gate that existed only to protect this feature. A conflicted aggregation once again returns the complete result over every index, which since opensearch-project#5646 pushes down as a _source script rather than failing. Kept whole: the warnings channel it introduced -- Warning, QueryResponse.warnings, CalcitePlanContext.addWarning/drainWarnings, and the SimpleJsonResponseFormatter plumbing. Nothing produces a warning after this commit; opensearch-project#5807 is the next producer, reporting a search that covered only some of its shards. Note for reviewers: dropping partial_result from TransportPPLQueryRequest changes that request's wire format. The class version-gates nothing and the field was appended the same way in 3.9, so this is symmetric with how it arrived, but it does mean a mixed 3.9/3.10 cluster must not route PPL across versions. Signed-off-by: Kai Huang <[email protected]> * Drop the per-index mapping retention the feature needed getIndexMappings() on OpenSearchIndex and lastIndexMappings on the describe request existed only so the partitioner could see which index mapped a field which way. Nothing reads them now. The deep copy before merging stays: MergeRuleHelper rewrites the accumulated type's properties in place, so a fetched mapping would otherwise stop describing its own index. Its test now asserts that on the fetched mappings directly rather than through the removed accessor. Signed-off-by: Kai Huang <[email protected]> --------- Signed-off-by: Kai Huang <[email protected]> (cherry picked from commit 6d666ba) Signed-off-by: Kai Huang <[email protected]>
…5865) * Remove the opt-in partial-result mode for mapping conflicts The mode (#5657) narrowed an aggregation to the index subset where the group field is aggregatable and labelled the result with a warning. It is being dropped: returning a knowingly incomplete answer to make a query faster is the wrong default to offer, and gating it on a cluster setting, a per-request flag and a response-format check made three moving parts that each had to survive the security plugin's transport-to-worker handoff (#5739, #5743, #5758). Removed: PartialResultAggregatePushdown and its hook in CalciteLogicalIndexScan, plugins.query.partial_result.on_mapping_conflict.enabled, the per-request partial_result field, and the warnings-supported format gate that existed only to protect this feature. A conflicted aggregation once again returns the complete result over every index, which since #5646 pushes down as a _source script rather than failing. Kept whole: the warnings channel it introduced -- Warning, QueryResponse.warnings, CalcitePlanContext.addWarning/drainWarnings, and the SimpleJsonResponseFormatter plumbing. Nothing produces a warning after this commit; #5807 is the next producer, reporting a search that covered only some of its shards. Note for reviewers: dropping partial_result from TransportPPLQueryRequest changes that request's wire format. The class version-gates nothing and the field was appended the same way in 3.9, so this is symmetric with how it arrived, but it does mean a mixed 3.9/3.10 cluster must not route PPL across versions. * Drop the per-index mapping retention the feature needed getIndexMappings() on OpenSearchIndex and lastIndexMappings on the describe request existed only so the partitioner could see which index mapped a field which way. Nothing reads them now. The deep copy before merging stays: MergeRuleHelper rewrites the accumulated type's properties in place, so a fetched mapping would otherwise stop describing its own index. Its test now asserts that on the fetched mappings directly rather than through the removed accessor. --------- (cherry picked from commit 6d666ba) Signed-off-by: Kai Huang <[email protected]>
Related
warningsSupportedgate off Log4jThreadContextonto the object graphThis PR is a direct follow-up: the same transport→worker
ThreadContexthandoff bug, for the siblingpartial_resultoverride that #5743 left behind.Description
The per-request
partial_resultoverride (thepartial_resultboolean in the PPL request body, e.g. from the Dashboards toggle) was stored in Log4jThreadContextviaQueryContext.setPartialResultOverride. It is set on the transport thread (TransportPPLQueryAction) and read on the worker/planning thread byCalciteLogicalIndexScan.tryPartialResultAggregate→QueryContext.isPartialResultEnabled.The security plugin's transport interceptor does not preserve Log4j
ThreadContextacross the transport→worker handoff. So on a security-enabled cluster the override is dropped before the worker thread reads it, andisPartialResultEnabledsilently falls back to the cluster setting. A request that sendspartial_result: falseto opt out therefore still returns a partial result with aPARTIAL_RESULTwarning whenever the cluster settingplugins.query.partial_result.on_mapping_conflict.enabledis on.Only the override is affected — the cluster-setting path is read from
osIndex.getSettings()on the worker thread, so it works. The bug is invisible without the security plugin (a plain./gradlew runcluster preserves theThreadContext), which is why it wasn't caught earlier.This is the same transport→worker handoff bug fixed in #5743 (issue #5739) for
warningsSupported. That change movedwarningsSupportedonto the object graph but left thepartial_resultoverride onThreadContext, reasoning the settings fallback made it resilient — but the fallback masks the drop rather than surviving it.Fix
Carry the override the same way
warningsSupportedis carried, offThreadContextand onto the object graph:PPLQueryRequest.partialResult(set from the request on the transport thread) →AbstractPlan.partialResultOverride→QueryPlan.execute()(runs on the worker thread) →CalcitePlanContext.setPartialResultOverride(...). It is included inCalcitePlanContext's thread-local snapshot (so it survives the planner's own complex-worker handoff) and reset per query.tryPartialResultAggregatenow reads the override fromCalcitePlanContextand falls back to the cluster setting. The now-deadQueryContext.setPartialResultOverride/isPartialResultEnabled(and the transport-side clear) are removed.Testing
Added
PartialResultSecurityIT.perRequestPartialResultFalseOverridesClusterSettingUnderSecurity— with the cluster setting on, an authenticated user sendspartial_result: falseand must get the complete result (no warning). Run underintegTestWithSecurity:perRequestPartialResultFalseOverridesClusterSettingUnderSecurityexpected:<3> but was:<2>(override dropped → partial)partialResultWarningSurvivesSecurityHandoffcompleteResultCarriesNoWarningWithSecurityQueryPlanTestandPartialResultAggregatePushdownTestalso pass;:opensearch-sql-plugin:compileJava+:integ-test:compileTestJavaclean.Check List