Skip to content

Conversation

@mergify
Copy link
Contributor

@mergify mergify bot commented Dec 26, 2025

Why I'm doing:

When the same SQL query is executed on Follower (forwarded to Leader) vs Leader (local execution), the Digest field in audit logs are inconsistent.

Root Cause:

  • Follower calculates digest before AST analysis (TableName/SlotRef are not fully qualified)
  • Leader calculates digest after AST analysis (TableName/SlotRef contain full catalog.db prefixes)
  • The Analyzer.analyze() phase normalizes AST by filling catalog/db information into TableName and SlotRef objects
  • Different AST states produce different string representations, leading to different MD5 digests

Example:

Follower: Digest=375dd0fba88b41ebe4a4eaa96f5cc692 | IsForwardToLeader=true
Leader:   Digest=2284580445ababd68839ad09e197ce63 | IsForwardToLeader=false

This inconsistency breaks digest-based query tracking, monitoring, and analysis.

What I'm doing:

Solution: Leader computes digest after analysis and returns it to Follower via Thrift RPC

Changes:

  1. Thrift Protocol (FrontendService.thrift)

    • Added sql_digest field to TMasterOpResult structure
  2. Leader Side (ConnectProcessor.java)

    • In doProxyExecute(): Compute SQL digest after AST analysis and set it in result.sql_digest
    • Leader does NOT generate its own audit log (proxy execution only)
  3. Follower Side (ConnectProcessor.java)

    • Overloaded auditAfterExec() to accept optional digestFromLeader parameter
    • In handleQuery() and handleExecute(): Extract sql_digest from Leader's result
    • Use Leader's digest in audit log; fallback to local computation for non-forwarded queries

Flow:

Follower: parse → forward → receive result (with digest) → audit (use Leader's digest)
Leader:   parse → analyze → execute → compute digest → return result (no audit)

Fixes #issue

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
    • This pr needs auto generate documentation
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 4.0
    • 3.5
    • 3.4
    • 3.3

Note

Ensures consistent Digest in audit logs across leader/follower executions.

  • Thrift: Add optional sql_digest to TMasterOpResult in FrontendService.thrift.
  • Leader: In doProxyExecute(), compute digest post-analysis (computeStatementDigest) and set result.sql_digest.
  • Follower: Overload auditAfterExec() to accept digestFromLeader; in handleQuery() and handleExecute(), extract sql_digest from leader result and pass to audit. Falls back to local digest when not forwarded or missing.
  • Only sets audit digest when non-null; no other behavior changes.

Written by Cursor Bugbot for commit bf9c562. This will update automatically on new commits. Configure here.


This is an automatic backport of pull request #67227 done by [Mergify](https://mergify.com).

@wanpengfei-git wanpengfei-git merged commit 736c295 into branch-3.5 Dec 26, 2025
37 of 38 checks passed
@wanpengfei-git wanpengfei-git deleted the mergify/bp/branch-3.5/pr-67227 branch December 26, 2025 08:01
@mergify
Copy link
Contributor Author

mergify bot commented Dec 26, 2025

🧪 CI Insights

Here's what we observed from your CI run for 49f8deb.

🟢 All jobs passed!

But CI Insights is watching 👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants