Repository navigation
[2.0] Add the audit log entity-type index before the 2.0.8 audit cleanup (backport 2.0 #38152) - #38153
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 |
| void addsTheIndexOnceOnMysql() { | ||
| try (GenericContainer<?> database = | ||
| new GenericContainer<>("mysql:8.3.0") | ||
| .withEnv("MYSQL_DATABASE", DATABASE) | ||
| .withEnv("MYSQL_ROOT_PASSWORD", PASSWORD) | ||
| .withEnv("MYSQL_ROOT_HOST", "%") | ||
| .withExposedPorts(3306) | ||
| .waitingFor( | ||
| Wait.forSuccessfulCommand( | ||
| "mysql --protocol=TCP --host=127.0.0.1 --user=root --password=" | ||
| + PASSWORD | ||
| + " --execute='SELECT 1'"))) { |
There was a problem hiding this comment.
Test methods are too long. Both new tests combine container setup, table creation, migration calls, upgrade checks, and assertions in methods over 40 lines long. The repository requires small, focused methods and says to aim for 15 lines or fewer. Extract the setup and index checks into named helpers so each test shows the behavior it checks.
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Noted. The test follows the existing Testcontainers migration tests in this package. I'm keeping this fix limited to the migration step and leaving the test style as is.
|
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 riskThe 2.0.8 migration adds an audit-log index, changing database schema; index-build interruption or load could delay upgrades on large installations. 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 |
Fixes #38157
Describe your changes:
Backport of #38152 to
2.0. Same change, no differences.The 2.0.8 post-data script rewrites
audit_log_eventrowsWHERE entity_type = 'user', and the table has noentity_typeindex 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 afterschemaChanges.sqland beforepostDataMigrationSQLScript.sql, now addsidx_audit_log_entity_type_ts(MySQL in place, PostgreSQLCONCURRENTLYwith an INVALID index rebuilt).Type of change:
Tests:
2.0:AuditLogEntityTypeIndexTest(real MySQL 8.3 and PostgreSQL 15)Tests run: 2, Failures: 0, Skipped: 0;WorkflowRedeployEntryPointTestTests run: 2, Failures: 0.mvn clean install -pl openmetadata-service -am -DskipTests: BUILD SUCCESS.Checklist:


Confidence Score: 5/5
The PR appears safe to merge, with no outstanding findings.Summary
The PR adds the audit-log index before the 2.0.8 cleanup, with database tests and checks that both migration entry points call the new step. Since the previous review, only migration review guidance changed.
No new actionable issues found.
Reviews (6) · Last reviewed commit: "Document that migration queries on large..." · Reviewed by Greptile