Skip to content

[2.1] Add the audit log entity-type index before the 2.0.8 audit cleanup (backport 2.1 #38152) - #38154

Merged
sonika-shah merged 2 commits into
2.1from
fix/audit-log-entity-type-index-v208-2.1
Nov 18, 2026
Merged

sonika-shah merged 2 commits into
2.1from
fix/audit-log-entity-type-index-v208-2.1

Conversation

@sonika-shah

@sonika-shah sonika-shah commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #38157

Describe your changes:

Backport of #38152 to 2.1. Same change, no differences.

The 2.0.8 post-data script rewrites audit_log_event rows WHERE entity_type = 'user', and the table has no entity_type index before 2.1.0, so each UPDATE scans the whole table and a large audit log makes the 2.0.8 upgrade run for hours. The 2.0.8 Java data migration, which runs after schemaChanges.sql and before postDataMigrationSQLScript.sql, now adds idx_audit_log_entity_type_ts (MySQL in place, PostgreSQL CONCURRENTLY with an INVALID index rebuilt).

  • No released SQL changes: no statement hash changes, nothing replays on databases already past 2.0.8.
  • Same name and columns as 2.1.0's index, so 2.1.0 skips its own.
  • A 2.0.8 upgrade interrupted in the post-data script picks the step up on retry.

Type of change:

  • Bug fix

Tests:

  • 2.1: AuditLogEntityTypeIndexTest (real MySQL 8.3 and PostgreSQL 15) Tests run: 2, Failures: 0, Skipped: 0; WorkflowRedeployEntryPointTest Tests run: 2, Failures: 0.
  • mvn clean install -pl openmetadata-service -am -DskipTests: BUILD SUCCESS.

Checklist:

  • I have read the CONTRIBUTING document.
  • I have added tests around the new logic.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no blocking issues were found.

Summary

The backport adds the audit-log index before the 2.0.8 cleanup without changing released SQL.

  • The 2.0.8 upgrade indexes audit events before cleanup.

The earlier mock-test finding remains withdrawn: sonika-shah explained that the test checks wiring, while separate database tests cover the index behavior.

Reviews (6) · Last reviewed commit: "Document that migration queries on large..." · Reviewed by Greptile

The 2.0.8 post-data script rewrites audit_log_event rows WHERE entity_type = 'user', and
the table has no entity_type index before 2.1.0, so each UPDATE scans the whole table.
The 2.0.8 Java data migration, which runs before that script, now adds
idx_audit_log_entity_type_ts (same name and columns as 2.1.0, which then skips it).
The released 2.0.8 SQL is unchanged, so no database that ran it replays anything.
@sonika-shah
sonika-shah requested a review from a team as a code owner November 18, 2026 16:58
@sonika-shah
sonika-shah requested review from harshach and removed request for a team November 18, 2026 16:58
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@sonika-shah

Copy link
Copy Markdown
Collaborator Author

Upgrade run on a real 2.0.7 database, MySQL 8.3 and PostgreSQL 15: fresh database migrated by the released 2.0.7 image, 5,000 audit_log_event rows seeded (151 user rows, some holding authenticationMechanism as an object and some inside a JSON string), then migrate with this branch's jars and bootstrap SQL (the 2.0 build; main and 2.1 carry the identical change).

MySQL PostgreSQL
migrate exit 0, WorkFlow Completed, change log 2.0.9, 2.0.8, 2.0.7 same
Index after upgrade idx_audit_log_entity_type_ts = entity_type ASC, event_ts DESC valid, USING btree (entity_type, event_ts DESC)
Step before the cleanup data migration runs between Run Schema Changes and Run Post DDL in the log step marker 17:00:39.216, audit UPDATEs 17:00:39.384 / .436
Cleanup filter plan type=ref key=idx_audit_log_entity_type_ts Bitmap Index Scan on idx_audit_log_entity_type_ts (unforced)
user rows still holding authenticationMechanism 0 0
migrate again on the upgraded database exit 0, 2.0.8 log rows 31 → 31 exit 0, 26 → 26

@sonika-shah

Copy link
Copy Markdown
Collaborator Author

Upgrade test on real release instances, MySQL 8.3 and PostgreSQL 15, using the released openmetadata/server 2.0.7, 2.0.8 and 2.1.0-rc2 images. The fixed builds are the release image with this branch's common, spec and service jars and its bootstrap/sql. Every migration ran with openmetadata-ops.sh migrate.

Setup: a 2.0.7 server was started and given data through its API (tables, glossary terms, users, bots with JWT tokens, an admin access token). Before the upgrade, 22 of the 32 user audit events it wrote still had authenticationMechanism. After each upgrade the server was started again and checked through its API: version, tables, glossary terms, bots, /v1/audit/logs?entityType=user, and a write.

Path Index built before the 2.0.8 cleanup UPDATEs User rows left to clean Upgraded server
2.0.7 -> this branch (2.0.9) -> 2.1 yes (PG: step 19:34:15.369, UPDATEs .458/.467; MySQL general log: CREATE INDEX 19:45:16.113, UPDATEs .372/.412) 0 starts, 0 ERROR lines, audit API 200, 0 events with authenticationMechanism, writes OK
2.0.7 -> 2.1 directly yes 0 same
Real 2.0.8 killed (SIGKILL) during its audit UPDATE -> retried with the 2.0 or the 2.1 build yes; steps that already ran are skipped 0 same
Same, with the index created by hand before the retry step finds the index and does nothing 0 same
Real 2.0.8 finished -> 2.0.9 2.0.8 not re-run (no new SQL) 0 same
Real 2.0.8 finished -> 2.1 cleanup already done in 2.0.8; v208 step builds the index, 2.1.0's statement then skips 0 same
Already on 2.1.0 -> 2.1 build again nothing re-runs; 2.0.8 log rows unchanged (PG 26 -> 26, MySQL 31 -> 31) 0 same

2.1.0's own index statement never errors when the index already exists: on PostgreSQL IF NOT EXISTS skips it, and on MySQL the information_schema guard runs SELECT 1.

@gitar-bot

gitar-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 🔴 High risk

Adding an audit_log_event index migration changes upgrade-time database structure, and an interrupted or costly build could disrupt upgrades on large audit tables.

Adds the idx_audit_log_entity_type_ts index on audit_log_event during the 2.0.8 Java data migration so the entity-type cleanup no longer scans the full table. No issues found.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@sonika-shah
sonika-shah merged commit 0aad2f1 into 2.1 Nov 18, 2026
47 of 49 checks passed
@sonika-shah
sonika-shah deleted the fix/audit-log-entity-type-index-v208-2.1 branch November 18, 2026 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants