Repository navigation
Add the audit log entity-type index before the 2.0.8 audit cleanup - #38152
Conversation
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.
❌ PR checklist incompleteThis 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 |
|
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
|
|
Upgrade test on real release instances, MySQL 8.3 and PostgreSQL 15, using the released 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
2.1.0's own index statement never errors when the index already exists: on PostgreSQL |
Code Review ✅ Approved 🔴 High riskAdding 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 VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
…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
…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
Fixes #38157
Describe your changes:
The 2.0.8 post-data script cleans
audit_log_eventwith twoUPDATE ... WHERE entity_type = 'user'statements.audit_log_eventhas no index onentity_typebefore 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_tsfrom the 2.0.8 Java data migration, which runs afterschemaChanges.sqland beforepostDataMigrationSQLScript.sql, so the cleanup UPDATEs use it.(entity_type, event_ts DESC). 2.1.0's MySQL guard checks the name ininformation_schema, and its PostgreSQL statement isCREATE INDEX IF NOT EXISTS, so 2.1.0 skips it.information_schema.statisticsand builds the index in place (writes keep going). PostgreSQL builds itCONCURRENTLY, and an INVALID index left by an interrupted build is dropped and built again. A rerun carries on from where an interrupted one stopped.Type of change:
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.Checklist:
schemaChanges.sql; it is left out on purpose, since editing the released 2.0.8 SQL is what this change avoids.

Confidence 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.
Reviews (6) · Last reviewed commit: "Document that migration queries on large..." · Reviewed by Greptile