[fix](audit) Mark internal query failures as ERR in audit log#62908
Merged
hello-stephen merged 1 commit intoapache:masterfrom Apr 29, 2026
Merged
Conversation
### What problem does this PR solve? Issue Number: https://jira.selectdb-in.cc/browse/CIR-20019 Problem Summary: When an internal query inside StmtExecutor.executeInternalQuery() failed (for example, the column-statistics gather SQL that ANALYZE issues against a user table when the underlying tablet hits a BE IO error), the audit_log entry recorded: state=OK | error_code=0 | error_message=<empty> | return_rows=0 This is misleading: the gather query actually failed, but the audit log makes it look like it succeeded with zero rows. ANALYZE itself still surfaces the failure to the user, but the per-internal-query audit entries hide the root cause, complicating triage. Root cause: executeInternalQuery() wraps the inner work in try { ... } finally { AuditLogHelper.logAuditLog(context, ...) }, but the inner catch handlers only re-throw the exception and never set ConnectContext state to ERR. The default OK state is therefore what gets logged. Fix: add an outer catch (Exception e) around the inner try that, when state has not already been moved to ERR, records ERR_INTERNAL_ERROR together with the message (falling back to root-cause message when the exception message is empty), then re-throws so callers behave as before. The setNereids/setIsQuery/setInternal flags are also moved above the parse step so audit entries for parse/plan failures still carry the right metadata. ### Release note Internal query failures are now correctly recorded as ERR in audit_log instead of misleadingly showing OK with empty error info. ### Check List (For Author) - Test: - Unit Test: StmtExecutorInternalQueryTest#testExecuteInternalQuerySetsErrorStateOnFailure - Regression test: fault_injection_p0/test_audit_log_internal_query_failure - Manual test: reproduced on a local cluster with the LocalFileReader::read_at_impl.io_error debug point; before the fix audit_log shows state=OK / error_message=, after the fix it shows state=ERR / error_code=1815 / full IO_ERROR description. - Behavior changed: Yes (audit_log entries for failed internal queries now show ERR; previously they showed OK). - Does this need documentation: No. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Author
|
run buildall |
Contributor
Author
|
/review |
morrySnow
approved these changes
Apr 28, 2026
Contributor
|
PR approved by at least one committer and no changes requested. |
Contributor
|
PR approved by anyone and no changes requested. |
Contributor
|
/review |
Contributor
|
skip buildall |
1 similar comment
Contributor
|
skip buildall |
github-actions Bot
pushed a commit
that referenced
this pull request
Apr 29, 2026
### What problem does this PR solve?
Problem Summary:
When an internal query inside `StmtExecutor.executeInternalQuery()`
failed (for example, the column-statistics gather SQL that ANALYZE
issues against a user table when the underlying tablet hits a BE IO
error), the audit_log entry recorded:
```
state=OK | error_code=0 | error_message=<empty> | return_rows=0
```
This is misleading: the gather query actually failed, but the audit log
makes it look like it succeeded with zero rows. ANALYZE itself still
surfaces the failure to the user, but the per-internal-query audit
entries hide the root cause, complicating triage.
Root cause: `executeInternalQuery()` wraps the inner work in `try { ...
} finally { AuditLogHelper.logAuditLog(context, ...) }`, but the inner
catch handlers only re-throw the exception and never set
`ConnectContext` state to ERR. The default OK state is therefore what
gets logged.
Fix: add an outer `catch (Exception e)` around the inner try that, when
state has not already been moved to ERR, records `ERR_INTERNAL_ERROR`
together with the message (falling back to root-cause message when the
exception message is empty), then re-throws so callers behave as before.
The `setNereids/setIsQuery/setInternal` flags are also moved above the
parse step so audit entries for parse/plan failures still carry the
right metadata.
### Release note
Internal query failures are now correctly recorded as ERR in audit_log
instead of misleadingly showing OK with empty error info.
### Check List (For Author)
- Test:
- Unit Test:
`StmtExecutorInternalQueryTest#testExecuteInternalQuerySetsErrorStateOnFailure`
- Regression test:
`fault_injection_p0/test_audit_log_internal_query_failure`
- Manual test: reproduced on a local cluster with the
`LocalFileReader::read_at_impl.io_error` debug point; before the fix
audit_log shows `state=OK / error_message=`, after the fix it shows
`state=ERR / error_code=1815 / full IO_ERROR description`.
- Behavior changed: Yes (audit_log entries for failed internal queries
now show ERR; previously they showed OK).
- Does this need documentation: No.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
github-actions Bot
pushed a commit
that referenced
this pull request
Apr 29, 2026
### What problem does this PR solve?
Problem Summary:
When an internal query inside `StmtExecutor.executeInternalQuery()`
failed (for example, the column-statistics gather SQL that ANALYZE
issues against a user table when the underlying tablet hits a BE IO
error), the audit_log entry recorded:
```
state=OK | error_code=0 | error_message=<empty> | return_rows=0
```
This is misleading: the gather query actually failed, but the audit log
makes it look like it succeeded with zero rows. ANALYZE itself still
surfaces the failure to the user, but the per-internal-query audit
entries hide the root cause, complicating triage.
Root cause: `executeInternalQuery()` wraps the inner work in `try { ...
} finally { AuditLogHelper.logAuditLog(context, ...) }`, but the inner
catch handlers only re-throw the exception and never set
`ConnectContext` state to ERR. The default OK state is therefore what
gets logged.
Fix: add an outer `catch (Exception e)` around the inner try that, when
state has not already been moved to ERR, records `ERR_INTERNAL_ERROR`
together with the message (falling back to root-cause message when the
exception message is empty), then re-throws so callers behave as before.
The `setNereids/setIsQuery/setInternal` flags are also moved above the
parse step so audit entries for parse/plan failures still carry the
right metadata.
### Release note
Internal query failures are now correctly recorded as ERR in audit_log
instead of misleadingly showing OK with empty error info.
### Check List (For Author)
- Test:
- Unit Test:
`StmtExecutorInternalQueryTest#testExecuteInternalQuerySetsErrorStateOnFailure`
- Regression test:
`fault_injection_p0/test_audit_log_internal_query_failure`
- Manual test: reproduced on a local cluster with the
`LocalFileReader::read_at_impl.io_error` debug point; before the fix
audit_log shows `state=OK / error_message=`, after the fix it shows
`state=ERR / error_code=1815 / full IO_ERROR description`.
- Behavior changed: Yes (audit_log entries for failed internal queries
now show ERR; previously they showed OK).
- Does this need documentation: No.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced May 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem does this PR solve?
Problem Summary:
When an internal query inside
StmtExecutor.executeInternalQuery()failed (for example, the column-statistics gather SQL that ANALYZE issues against a user table when the underlying tablet hits a BE IO error), the audit_log entry recorded:This is misleading: the gather query actually failed, but the audit log makes it look like it succeeded with zero rows. ANALYZE itself still surfaces the failure to the user, but the per-internal-query audit entries hide the root cause, complicating triage.
Root cause:
executeInternalQuery()wraps the inner work intry { ... } finally { AuditLogHelper.logAuditLog(context, ...) }, but the inner catch handlers only re-throw the exception and never setConnectContextstate to ERR. The default OK state is therefore what gets logged.Fix: add an outer
catch (Exception e)around the inner try that, when state has not already been moved to ERR, recordsERR_INTERNAL_ERRORtogether with the message (falling back to root-cause message when the exception message is empty), then re-throws so callers behave as before. ThesetNereids/setIsQuery/setInternalflags are also moved above the parse step so audit entries for parse/plan failures still carry the right metadata.Release note
Internal query failures are now correctly recorded as ERR in audit_log instead of misleadingly showing OK with empty error info.
Check List (For Author)
StmtExecutorInternalQueryTest#testExecuteInternalQuerySetsErrorStateOnFailurefault_injection_p0/test_audit_log_internal_query_failureLocalFileReader::read_at_impl.io_errordebug point; before the fix audit_log showsstate=OK / error_message=, after the fix it showsstate=ERR / error_code=1815 / full IO_ERROR description.