mrhhsg opened a new pull request, #71080: URL: https://github.com/apache/doris/pull/71080
### Background Hash method initialization selects a variant alternative according to the key types. A method allocates its hash map and shared-pointer control block separately. Aggregation cleanup visits the variant to release aggregate state. ### What problem does this PR solve? Issue Number: None Related PR: None PR Type: Bugfix Problem Summary: A non-Doris exception during method construction can leave the variant valueless, causing aggregation cleanup to terminate with `std::bad_variant_access`. Restore the empty alternative before rethrowing the original exception. Most added lines provide focused failure-injection coverage; successful initialization and query results remain unchanged. ### Details - **Frequency:** Always under the scoped constructor-failure injection on the tested libstdc++ toolchain; natural allocation-failure frequency is unknown. - **Root cause:** `init_hash_method` restores `std::monostate` only for `doris::Exception`. Other exceptions escape after failed variant emplacement without restoring a safely destructible state, so the subsequent aggregation cleanup visit can throw. - **Why existing tests missed it:** `HashTableMethodTest` and `AggregatedDataVariantsTest` cover successful construction and hash operations, not initialization allocation failures. The `agg_nullable` and `aggregate_groupby_null` SQL suites exercise successful aggregation without constructor-failure injection. - **Fix:** Add catch-all rollback at the shared initialization boundary, then use bare rethrow to preserve the original exception. Keep the existing Doris exception-to-Status conversion. A BE_TEST-only scoped construction override enables targeted failure coverage without replacing process allocators. - **Other paths and branches:** Aggregation, join, set, dictionary, and partition-sort callers of this helper inherit the rollback. Direct variant emplacements outside the helper are unchanged. Validation targets master; release-branch applicability and the original introducing PR were not established. ### Testing Local Linux x86_64, Clang 20.1.8, libstdc++15: - `env DORIS_TOOLCHAIN=clang ENABLE_PCH=off BUILD_TYPE_UT=ASAN GTEST_DEATH_TEST_STYLE=threadsafe ./run-be-ut.sh -j 8 --run '--filter=HashMethodInitRollback*.*'`: before the fix, 3 of 5 tests fail, including both allocation-failure cases terminating during real shared-state destruction; after the fix, all 5 pass. - `env DORIS_TOOLCHAIN=clang ENABLE_PCH=off BUILD_TYPE_UT=ASAN ./run-be-ut.sh -j 8 --run '--filter=HashMethodInitRollback*.*:HashTableMethodTest.*:AggregatedDataVariantsTest.*:AggSharedStateTest.*:AggOperatorTestWithGroupBy.*:AggOperatorTestWithOutGroupBy.*:StreamingAggOperatorTest.*:BucketedAggSharedStateTest.*:DistinctStreamingAggOperatorTest.*:PartitionedAggSharedStateTest.*'`: all 83 tests pass, without an external death-test-style setting. - `env BUILD_TYPE=ASAN DORIS_TOOLCHAIN=clang ENABLE_PCH=off ./build.sh --be --fe -j 8`: passes, including Maven checkstyle and packaging; UI and CDC-client packaging disabled. - `./run-regression-test.sh --conf output/local-regression/regression-conf-19200.groovy --run -d query_p0/aggregate -s agg_nullable` and the same command with `-s aggregate_groupby_null`: both pass against the local ASAN cluster, with no suites skipped. - clang-format 16, header hygiene, changed-line clang-tidy, and diff checks pass. ### Notes for Reviewers The construction override is excluded from production compilation; map/control-block allocation order and ownership remain unchanged. Object-stage failure is simulated at the constructor factory boundary; control-block failure uses an object-scoped allocator with the real map and shared-state destructor. These are controlled failures, not a natural OOM or full-process leak-sanitizer run. ### Release note Avoid a secondary aggregation cleanup failure when hash method initialization throws a non-Doris exception; the original exception still propagates. ### Check List (For Author) - Behavior changed: No - Does this need documentation: No - Pre-submission status: Partially verified: full BE/FE unit suites, other architectures, release branches, mixed-version behavior, and remote CI were not run. ### AI Disclosure - Tool: Codex - Generated: Code, tests, and description - Human review: None reported -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
