Skip to content

Add the audit log entity-type index before the 2.0.8 audit cleanup - #38152

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

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

Conversation

@sonika-shah

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

Copy link
Copy Markdown
Collaborator

Fixes #38157

Describe your changes:

The 2.0.8 post-data script cleans audit_log_event with two UPDATE ... WHERE entity_type = 'user' statements. audit_log_event has no index on entity_type before 2.1.0, so each UPDATE scans the whole table; on a large audit log the 2.0.8 upgrade runs for hours and can hit the upgrade time limit.

This adds idx_audit_log_entity_type_ts from the 2.0.8 Java data migration, which runs after schemaChanges.sql and before postDataMigrationSQLScript.sql, so the cleanup UPDATEs use it.

  • No released SQL changes. The 2.0.8 SQL files are untouched, so no statement hash changes and no database that already ran 2.0.8 replays anything. A database already past 2.0.8 never runs this step; it gets the index from 2.1.0 as before.
  • Same index as 2.1.0. Same name and columns, (entity_type, event_ts DESC). 2.1.0's MySQL guard checks the name in information_schema, and its PostgreSQL statement is CREATE INDEX IF NOT EXISTS, so 2.1.0 skips it.
  • Guarded per ADR:2026-10-22-guarded-index-ddl-runs-from-a-java-data-migration. MySQL checks information_schema.statistics and builds the index in place (writes keep going). PostgreSQL builds it CONCURRENTLY, and an INVALID index left by an interrupted build is dropped and built again. A rerun carries on from where an interrupted one stopped.
  • Interrupted 2.0.8 upgrades pick it up. A database whose 2.0.8 run stopped in the post-data script has not recorded 2.0.8, so the retry runs the Java migration again: this new step runs (the others are already marked), then the cleanup resumes.

Type of change:

  • Bug fix

Tests:

Unit tests

  • AuditLogEntityTypeIndexTest (new, Testcontainers): MySQL and PostgreSQL. Adds the index on the shipped table shape, runs again without error, rebuilds an INVALID PostgreSQL index, and 2.1.0's own statement for the index then does nothing.
  • WorkflowRedeployEntryPointTest: the 2.0.8 entry points run the MySQL step on MySQL and the PostgreSQL step on PostgreSQL.

Results (local)

  • main: AuditLogEntityTypeIndexTest + WorkflowRedeployEntryPointTest — Tests run: 4, Failures: 0, Errors: 0, Skipped: 0 (real MySQL 8.3 and PostgreSQL 15 containers).
  • mvn clean install -pl openmetadata-service -am -DskipTests: BUILD SUCCESS.
  • An upgrade of a real 2.0.7 database (MySQL and PostgreSQL) with this change is running; results will follow in a comment.

Checklist:

  • I have read the CONTRIBUTING document.
  • I have added tests around the new logic.
  • Decision check: follows ADR:2026-10-22-guarded-index-ddl-runs-from-a-java-data-migration; no new decision. The ADR asks for a comment in the version's schemaChanges.sql; it is left out on purpose, since editing the released 2.0.8 SQL is what this change avoids.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; the latest changes add guidance without changing runtime behavior.

Summary

Adds the audit-log index before the 2.0.8 cleanup and documents that large-table migration queries need an index when they run.

  • The 2.0.8 upgrade adds an audit-log index before its cleanup runs.
  • Migration guidance now covers Java migrations and indexes for large-table queries.

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:57
@sonika-shah
sonika-shah requested review from manerow and a balanced review from Copilot November 18, 2026 16:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

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

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.

Copilot AI balanced review requested due to automatic review settings November 18, 2026 21:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@gitar-bot

gitar-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 🔴 High risk

Adding the entity_type index through the 2.0.8 migration changes the audit_log_event schema; building it may prolong or disrupt upgrades on large tables.

Adds the idx_audit_log_entity_type_ts index in the 2.0.8 Java data migration so the post-data audit_log_event cleanup UPDATEs can use it, without changing any released SQL. No open 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 ed43989 into main Nov 18, 2026
53 of 55 checks passed
@sonika-shah
sonika-shah deleted the fix/audit-log-entity-type-index-v208 branch November 18, 2026 21:58
sonika-shah added a commit that referenced this pull request Nov 18, 2026
…nup (backport 2.0 #38152) (#38153)

* Add the audit log entity-type index before the 2.0.8 audit cleanup

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.

* Document that migration queries on large tables need an index in place when they run
sonika-shah added a commit that referenced this pull request Nov 18, 2026
…nup (backport 2.1 #38152) (#38154)

* Add the audit log entity-type index before the 2.0.8 audit cleanup

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.

* Document that migration queries on large tables need an index in place when they run
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.

Upgrade to 2.0.8 can stall on the audit log cleanup when audit_log_event is large

3 participants