yujun777 opened a new pull request, #71156: URL: https://github.com/apache/doris/pull/71156
### Background Nereids uses a statement context to store table locks and planning data such as CTE consumer groups and derived statistics. The planner releases the locks explicitly when planning exits. A fallback diagnostic reports an abandoned scope with outstanding locks. ### What problem does this PR solve? Issue Number: None Related PR: None PR Type: Bugfix Problem Summary: The fallback lock diagnostic makes every StatementContext finalizable. This extends the lifetime of its planning graph even when the lock stack is empty and the query no longer holds the context. Register a detached phantom reference only for a scope that acquired a table read lock. ### Details - **Frequency:** The JVM registers all instances for finalization on the affected code. Heap impact rises with the volume and size of planner graphs awaiting collection. - **Root cause:** StatementContext overrides Object.finalize, so pending final references preserve its CTE groups, candidate plans and statistics until finalization. - **Why existing tests missed it:** Planner and connector unit tests check explicit release. SQL regressions exercise planning and query results, with no assertion about the lifetime of the planning graph after the statement completes. - **Fix:** Use a detachable reference containing a table name, thread name and query ID. Explicit release unregisters the diagnostic. If the scope is abandoned, queue delivery logs it once. The owning thread releases table locks. - **Other paths and branches:** SQL cache planning, ordinary planning and statement teardown share the existing release method. The implementation uses the repository's Guava version and Java 8 language and reference APIs to ease a separate backport. - **Behavior change:** Completed statement contexts can be reclaimed independently of Java finalization. A leaked lock scope logs the first locked table, owner thread, and query ID. ### Testing - On upstream/master, StatementContextPlannerLockTest ran three tests. The finalization regression failed as expected. The two resource release tests passed. - On the fix, 107 FE tests passed across StatementContextPlannerLockTest, StatementContextTest, StatementContextPartitionPredicateSafetyTest, NereidsPlannerConnectorPlanningTest and ConnectorStatementScopeTest. - A dedicated G1 JVM paused its Finalizer thread. The old code retained data reachable solely from the statement context until the thread resumed. The fixed code reclaimed that data while the thread was paused, including a path with a registered lock diagnostic. - The fe-core Checkstyle audit completed with zero violations. ### Release note The frontend can reclaim completed Nereids statement planning graphs without waiting for Java finalization. ### Check List (For Author) - Behavior changed: Yes (see Details) - Does this need documentation: No - Pre-submission status: Partially verified: production-scale heap and release-branch validation are pending. -- 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]
