heguanhui opened a new pull request, #63865:
URL: https://github.com/apache/doris/pull/63865
## What problem does this PR solve?
Issue Number: close #xxx
Related PR: #xxx
Problem Summary: The `audit_log` internal table did not record transaction
information (`label` and `txn_id`) for transactional SQL statements
(INSERT/UPDATE/DELETE/MERGE_INTO). Users and DBAs could not trace which
transaction a particular DML operation belonged to, making it difficult to
correlate audit log entries with transaction metadata. Additionally, the
old-style DELETE path (via `DeleteHandler`) did not call
`setOrUpdateInsertResult()`, causing `label`/`txn_id` to be missing even if
they were recorded.
## What is changed and how it works?
1. **Add `label` and `txn_id` fields to `AuditEvent`** — Two new
`@AuditField` annotated public fields with corresponding builder setters.
2. **Populate label/txn_id in `AuditLogHelper.logAuditLogImpl()`** — Only
for transactional statement types (INSERT/UPDATE/DELETE/MERGE_INTO), read from
`ConnectContext.insertResult`. Non-transactional statements (e.g., SELECT) get
empty label and -1 txn_id.
3. **Add `label` and `txn_id` columns to `InternalSchema.AUDIT_SCHEMA`** —
`label` as `varchar(128)`, `txn_id` as `bigint`. Existing audit_log tables will
be auto-altered by `InternalSchemaInitializer.alterAuditSchemaIfNeeded()`.
4. **Serialize label/txn_id in `AuditLoader.fillLogBuffer()`** — Append the
two new fields to the CSV buffer for stream load into audit_log.
5. **Remove duplicate `label` field from `LoadAuditEvent` and
`StreamLoadAuditEvent`** — These subclasses now inherit `label` from the base
`AuditEvent`, avoiding `Class.getFields()` reflection returning duplicate
fields.
6. **Fix old-style DELETE path in `DeleteHandler.process()`** — Call
`ctx.setOrUpdateInsertResult()` after successful commit so that label/txn_id
are available for audit logging.
## Release note
Add `label` (varchar(128)) and `txn_id` (bigint) columns to the `audit_log`
internal table. These columns record the transaction label and transaction ID
for INSERT, UPDATE, DELETE, and MERGE INTO statements, enabling better
transaction tracing and audit analysis.
## Check List (For Author)
- Test: Regression test / Unit Test
- Regression test: `test_audit_log_label_txn_id.groovy` (INSERT
with/without label, UPDATE, DELETE, SELECT)
- Unit Test: `AuditLogHelperTest` (4 tests), `AuditLogBuilderTest` (8
tests), `AuditEventProcessorTest`, `InternalSchemaInitializerTest`,
`InternalSchemaAlterTest`, `AuditLogWorkloadGroupTest` (20 tests total, all
passed)
- Behavior changed: Yes — audit_log table now has two additional columns;
old-style DELETE now populates insertResult
- Does this need documentation: Yes (will add separately)
## Check List (For Reviewer)
- [ ] I have added test cases for this bug fix or new feature
- [ ] This PR will not cause performance regression
- [ ] This PR will not break existing features
--
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]